~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/kvirc/kvs/KviKvsCoreFunctions_mr.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KviKvsCoreFunctions_mr.cpp
 
4
//   Creation date : Fri 31 Oct 2003 01:52:04 by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc IRC client distribution
 
7
//   Copyright (C) 2003-2010 Szymon Stefanek <pragma at kvirc dot net>
 
8
//
 
9
//   This program is FREE software. You can redistribute it and/or
 
10
//   modify it under the terms of the GNU General Public License
 
11
//   as published by the Free Software Foundation; either version 2
 
12
//   of the License, or (at your opinion) any later version.
 
13
//
 
14
//   This program is distributed in the HOPE that it will be USEFUL,
 
15
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
17
//   See the GNU General Public License for more details.
 
18
//
 
19
//   You should have received a copy of the GNU General Public License
 
20
//   along with this program. If not, write to the Free Software Foundation,
 
21
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
22
//
 
23
//=============================================================================
 
24
 
 
25
 
 
26
 
 
27
#include "KviKvsCoreFunctions.h"
 
28
#include "KviKvsKernel.h"
 
29
#include "KviKvsArrayCast.h"
 
30
#include "KviKvsObjectController.h"
 
31
#include "KviLocale.h"
 
32
#include "KviIrcConnection.h"
 
33
#include "KviControlCodes.h"
 
34
#include "KviOptions.h"
 
35
#include "KviConsoleWindow.h"
 
36
#include "KviIrcUserDataBase.h"
 
37
#include "KviIrcMask.h"
 
38
#include "kvi_socket.h"
 
39
#include "KviApplication.h"
 
40
#include "KviQueryWindow.h"
 
41
 
 
42
#include <stdlib.h> // rand & srand
 
43
 
 
44
namespace KviKvsCoreFunctions
 
45
{
 
46
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
47
 
 
48
        /*
 
49
                @doc: mask
 
50
                @type:
 
51
                        function
 
52
                @title:
 
53
                        $mask
 
54
                @short:
 
55
                        Retrieves the host mask of a user
 
56
                @syntax:
 
57
                        $mask[(<nickname>[,<mask_type>])]
 
58
                @description:
 
59
                        Returns the specified type of mask for the user with <nickname>.[br]
 
60
                        If the host or username are not known, the mask may contain less information
 
61
                        than requested.[br]
 
62
                        If the <nickname> is not given it is assumed to be the current nickname.[br]
 
63
                        If <mask_type> is not given or is invalid, it is assumed to be 0.[br]
 
64
                        Available mask types:[br]
 
65
                        0 : nick!user@machine.host.top  (nick!user@XXX.XXX.XXX.XXX) (default)[br]
 
66
                        1 : nick!user@*.abc.host.top        (nick!user@XXX.XXX.XXX.*)[br]
 
67
                        2 : nick!user@*[br]
 
68
                        3 : nick!*@machine.host.top     (nick!user@XXX.XXX.XXX.XXX)[br]
 
69
                        4 : nick!*@*.abc.host.top           (nick!user@XXX.XXX.XXX.*)[br]
 
70
                        5 : nick!*@*[br]
 
71
                        6 : *!user@machine.host.top     (*!user@XXX.XXX.XXX.XX)[br]
 
72
                        7 : *!user@*.abc.host.top           (*!user@XXX.XXX.XXX.*)[br]
 
73
                        8 : *!user@*[br]
 
74
                        9 : *!*@machine.host.top        (*!*@XXX.XXX.XXX.XXX)[br]
 
75
                        10: *!*@*.abc.host.top              (*!*@XXX.XXX.XXX.*)[br]
 
76
                        11: nick!*user@machine.host.top (nick!*user@XXX.XXX.XXX.XXX)[br]
 
77
                        12: nick!*user@*.abc.host.top       (nick!*user@XXX.XXX.XXX.*)[br]
 
78
                        13: nick!*user@*[br]
 
79
                        14: *!*user@machine.host.top    (*!*user@XXX.XXX.XXX.XXX)[br]
 
80
                        15: *!*user@*.abc.host.top          (*!*user@XXX.XXX.XXX.*)[br]
 
81
                        16: *!*user@*[br]
 
82
                        17: nick!~user@*.host.top       (nick!~user@XXX.XXX.*)[br]
 
83
                        18: nick!*@*.host.top          (nick!*@XXX.XXX.*)[br]
 
84
                        19: *!~user@*.host.top          (*!~user@XXX.XXX.*)[br]
 
85
                        20: nick!*user@*.host.top          (nick!*user@XXX.XXX.*)[br]
 
86
                        21: *!*user@*.host.top          (*!user@*XXX.XXX.*)[br]
 
87
                        22: nick!~user@*.host.top       (nick!~user@XXX.XXX.*)[br]
 
88
                        23: nick!*@*.host.top          (nick!*@XXX.XXX.*)[br]
 
89
                        24: *!~user@*.host.top          (*!~user@XXX.XXX.*)[br]
 
90
                        25: nick!*user@*.host.top          (nick!*user@XXX.XXX.*)[br]
 
91
                        26: *!*user@*.host.top          (*!user@*XXX.XXX.*)[br]
 
92
                        If some data is missing, these types may change:[br]
 
93
                        For example, if the hostname is missing, the mask type 3 or 4 may be reduced to type 5.[br]
 
94
                        If the user with <nickname> is not found in the current IRC context user database,
 
95
                        an empty string is returned.[br]
 
96
                        The masks 22-26 are the smart versions of the masks 17-21 that try take care of masked ip addresses
 
97
                        in the form xxx.xxx.INVALID-TOP-MASK. If a masked ip address is found then
 
98
                        the XXX.XXX.* or XXX.* host mask is returned instead of the (wrong) *.INVALID-TOP-MASK
 
99
                @examples:
 
100
                @seealso:
 
101
        */
 
102
 
 
103
        KVSCF(mask)
 
104
        {
 
105
                QString szNick;
 
106
                kvs_uint_t maskType;
 
107
 
 
108
                KVSCF_PARAMETERS_BEGIN
 
109
                        KVSCF_PARAMETER("nickname",KVS_PT_STRING,KVS_PF_OPTIONAL,szNick)
 
110
                        KVSCF_PARAMETER("maskType",KVS_PT_UINT,KVS_PF_OPTIONAL,maskType)
 
111
                KVSCF_PARAMETERS_END
 
112
 
 
113
                if(maskType > 26) maskType = 0;
 
114
 
 
115
                if(KVSCF_pContext->window()->console())
 
116
                {
 
117
                        if(KVSCF_pContext->window()->console()->isConnected())
 
118
                        {
 
119
                                KviIrcUserEntry * e = KVSCF_pContext->window()->connection()->userDataBase()->find(szNick.isEmpty() ? KVSCF_pContext->window()->connection()->currentNickName() : szNick);
 
120
                                if(e)
 
121
                                {
 
122
                                        KviIrcMask u;
 
123
                                        u.setNick(szNick);
 
124
                                        u.setUsername(e->user());
 
125
                                        u.setHost(e->host());
 
126
 
 
127
                                        QString tmp;
 
128
                                        u.mask(tmp,(KviIrcMask::MaskType)maskType);
 
129
                                        KVSCF_pRetBuffer->setString(tmp);
 
130
                                        return true;
 
131
                                }
 
132
                        }
 
133
                }
 
134
                KVSCF_pRetBuffer->setNothing();
 
135
                return true;
 
136
        }
 
137
 
 
138
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
139
 
 
140
        /*
 
141
                @doc: me
 
142
                @type:
 
143
                        function
 
144
                @title:
 
145
                        $me
 
146
                @short:
 
147
                        Returns the current nickname
 
148
                @syntax:
 
149
                        <string> $me[(<irc_context_id:uint>)]
 
150
                @description:
 
151
                        Returns the current nickname used in the specified IRC context.[br]
 
152
                        If no <irc_context_id> is specified, the current IRC context is used.[br]
 
153
                        If you are not connected to a server, this function will return a null string.[br]
 
154
                        If the current window is a DCC chat and no irc_context is specified,
 
155
                        the local nickname is returned.[br]
 
156
                        If the current window does not belong to any IRC context, no irc_context_id
 
157
                        is specified, and the current window is not a DCC chat, a warning is printed.[br]
 
158
        */
 
159
 
 
160
        KVSCF(me)
 
161
        {
 
162
                kvs_uint_t uCntx;
 
163
 
 
164
                KVSCF_PARAMETERS_BEGIN
 
165
                        KVSCF_PARAMETER("irc_context_id",KVS_PT_UINT,KVS_PF_OPTIONAL,uCntx)
 
166
                KVSCF_PARAMETERS_END
 
167
 
 
168
                KviConsoleWindow * cns;
 
169
 
 
170
                if(KVSCF_pParams->count() > 0)
 
171
                {
 
172
                        cns = g_pApp->findConsole(uCntx);
 
173
                        if(cns)
 
174
                        {
 
175
                                if(cns->isConnected())
 
176
                                        KVSCF_pRetBuffer->setString(cns->connection()->currentNickName());
 
177
                                else
 
178
                                        KVSCF_pRetBuffer->setNothing();
 
179
                        } else {
 
180
                                KVSCF_pRetBuffer->setNothing();
 
181
                        }
 
182
                } else {
 
183
                        if(KVSCF_pContext->window()->console())
 
184
                        {
 
185
                                cns = KVSCF_pContext->window()->console();
 
186
                                if(cns->isConnected())
 
187
                                        KVSCF_pRetBuffer->setString(cns->connection()->currentNickName());
 
188
                                else
 
189
                                        KVSCF_pRetBuffer->setNothing();
 
190
                        } else {
 
191
                                if(KVSCF_pContext->window()->type() == KviWindow::DccChat)
 
192
                                {
 
193
                                        KVSCF_pRetBuffer->setString(KVSCF_pContext->window()->localNick());
 
194
                                } else {
 
195
                                        KVSCF_pContext->warning(__tr2qs_ctx("This window has no associated IRC context and is not a DCC chat","kvs"));
 
196
                                        KVSCF_pRetBuffer->setNothing();
 
197
                                }
 
198
                        }
 
199
                }
 
200
                return true;
 
201
        }
 
202
 
 
203
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
204
 
 
205
        /*
 
206
                @doc: msgtype
 
207
                @type:
 
208
                        function
 
209
                @title:
 
210
                        $msgtype
 
211
                @short:
 
212
                        Returns the id of a message type color set
 
213
                @syntax:
 
214
                        $msgtype(<message type color set name>)
 
215
                @description:
 
216
                        Returns the id of a message type color set used by the [cmd]echo[/cmd] command.
 
217
                        You can take a look at the options dialog section related to the
 
218
                        message output to see the list of available message type names.
 
219
                @examples:
 
220
                        [example]
 
221
                                [cmd]echo[/cmd] -i=$msgtype(Highlight) Highlighted text!
 
222
                        [/example]
 
223
                @seealso:
 
224
                        [cmd]echo[/cmd]
 
225
        */
 
226
 
 
227
        KVSCF(msgtype)
 
228
        {
 
229
                QString szName;
 
230
                KVSCF_PARAMETERS_BEGIN
 
231
                        KVSCF_PARAMETER("msg_type_color_set_name",KVS_PT_NONEMPTYSTRING,0,szName)
 
232
                KVSCF_PARAMETERS_END
 
233
 
 
234
                QString tmp = "msgtype";
 
235
                tmp += szName;
 
236
                for(int i=0;i< KVI_NUM_MSGTYPE_OPTIONS;i++)
 
237
                {
 
238
                        if(KviQString::equalCI(tmp,g_msgtypeOptionsTable[i].name))
 
239
                        {
 
240
                                KVSCF_pRetBuffer->setInteger(i);
 
241
                                return true;
 
242
                        }
 
243
                }
 
244
                KVSCF_pRetBuffer->setInteger(0);
 
245
                return true;
 
246
        }
 
247
 
 
248
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
249
 
 
250
        /*
 
251
                @doc: new
 
252
                @type:
 
253
                        function
 
254
                @title:
 
255
                        $new
 
256
                @short:
 
257
                        Creates a new object
 
258
                @syntax:
 
259
                        $new(<className>,[<parentHandle> [,<name>[,<param>[,<param>[...]]]])
 
260
                @description:
 
261
                        Creates a new instance of the object <class> with
 
262
                        the parent object <parent_id> and the specified <name>.[br]
 
263
                        <name> and <parent_id> are optional: if not specified, <name>
 
264
                        is assumed to be an empty string and <parent_id> default to 0 (parentless object).[br]
 
265
                        This function accepts a list of optional parameters that will be passed to the <class>'s constructor.
 
266
                        Please see the [doc:objects]objects documentation[/doc] for more information.[br]
 
267
                @examples:
 
268
                        [example]
 
269
                                %myobj = $new(widget,0,pippo)
 
270
                        [/example]
 
271
                @seealso:
 
272
                        [doc:objects]Objects documentation[/doc], [cmd]delete[/cmd]
 
273
        */
 
274
 
 
275
        KVSCF(newCKEYWORDWORKAROUND)
 
276
        {
 
277
                // prologue: parameter handling
 
278
                QString szClassName;
 
279
                QString szName;
 
280
                kvs_hobject_t hParent = 0;
 
281
                KviKvsVariantList vList;
 
282
 
 
283
                KVSCF_PARAMETERS_BEGIN
 
284
                        KVSCF_PARAMETER("className",KVS_PT_NONEMPTYSTRING,0,szClassName)
 
285
                        KVSCF_PARAMETER("parentHandle",KVS_PT_HOBJECT,KVS_PF_OPTIONAL,hParent)
 
286
                        KVSCF_PARAMETER("name",KVS_PT_STRING,KVS_PF_OPTIONAL,szName)
 
287
                        KVSCF_PARAMETER("parameterList",KVS_PT_VARIANTLIST,KVS_PF_OPTIONAL,vList)
 
288
                KVSCF_PARAMETERS_END
 
289
 
 
290
                KviKvsObjectClass * pClass = KviKvsKernel::instance()->objectController()->lookupClass(szClassName);
 
291
                if(!pClass)
 
292
                {
 
293
                        KVSCF_pContext->error(__tr2qs_ctx("Class '%Q' is not defined","kvs"),&szClassName);
 
294
                        return false;
 
295
                }
 
296
 
 
297
                KviKvsObject * pParent;
 
298
                if(hParent != (kvs_hobject_t)0)
 
299
                {
 
300
                        pParent = KviKvsKernel::instance()->objectController()->lookupObject(hParent);
 
301
                        if(!pParent)
 
302
                        {
 
303
                                KVSCF_pContext->error(__tr2qs_ctx("The specified parent object does not exist","kvs"));
 
304
                                return false;
 
305
                        }
 
306
                } else {
 
307
                        pParent = 0;
 
308
                }
 
309
 
 
310
                KviKvsObject * pObject = pClass->allocateInstance(pParent,szName,KVSCF_pContext,&vList);
 
311
 
 
312
                // epilogue: set the return value
 
313
                KVSCF_pRetBuffer->setHObject(pObject ? pObject->handle() : (kvs_hobject_t)0);
 
314
                return true;
 
315
        }
 
316
 
 
317
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
318
 
 
319
        /*
 
320
                @doc: nothing
 
321
                @type:
 
322
                        function
 
323
                @title:
 
324
                        $nothing
 
325
                @short:
 
326
                        Evaluates to an empty variable
 
327
                @syntax:
 
328
                        <nothing> $nothing
 
329
                @description:
 
330
                        Evaluates to an empty variable. This is a special value somewhat similar
 
331
                        to the [fnc]$null[/fnc] object: it is used to denote absence
 
332
                        of information. For example, a function might decide to return
 
333
                        a meaningful value when the input parameters are correct and
 
334
                        $nothing when the input parameters are wrong.
 
335
                @seealso:
 
336
                        [fnc]$null[/fnc]
 
337
        */
 
338
 
 
339
        KVSCF(nothing)
 
340
        {
 
341
                Q_UNUSED(__pContext);
 
342
                Q_UNUSED(__pParams);
 
343
 
 
344
                KVSCF_pRetBuffer->setNothing();
 
345
                return true;
 
346
        }
 
347
 
 
348
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
349
 
 
350
 
 
351
        /*
 
352
                @doc: null
 
353
                @type:
 
354
                        function
 
355
                @title:
 
356
                        $null
 
357
                @short:
 
358
                        Evaluates to the null object handle.
 
359
                @syntax:
 
360
                        <hobject> $null
 
361
                @description:
 
362
                        Evaluates to the null object handle. This is a special
 
363
                        object handle that is returned by some functions.
 
364
                        Please note that writing $null is semantically equivalent to writing 0
 
365
                        or even [fnc]$nothing[/fnc] in place of the handle, but $null increases code readability.
 
366
                @seealso:
 
367
                        [fnc]$new[/fnc], [fnc]$nothing[/fnc]
 
368
        */
 
369
 
 
370
        KVSCF(nullCKEYWORDWORKAROUND)
 
371
        {
 
372
                Q_UNUSED(__pContext);
 
373
                Q_UNUSED(__pParams);
 
374
 
 
375
                KVSCF_pRetBuffer->setHObject(0);
 
376
                return true;
 
377
        }
 
378
 
 
379
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
380
 
 
381
        /*
 
382
                @doc: o
 
383
                @type:
 
384
                        function
 
385
                @title:
 
386
                        $o
 
387
                @short:
 
388
                        Returns the RESET mIRC control character
 
389
                @syntax:
 
390
                        <string> $o
 
391
                @description:
 
392
                        Returns the RESET mIRC control character (CTRL+O).[br]
 
393
                @seealso:
 
394
                        [fnc]$k[/fnc], [fnc]$b[/fnc], [fnc]$u[/fnc], [fnc]$r[/fnc]
 
395
        */
 
396
 
 
397
        KVSCF(o)
 
398
        {
 
399
                Q_UNUSED(__pContext);
 
400
                Q_UNUSED(__pParams);
 
401
 
 
402
                KVSCF_pRetBuffer->setString(QString(QChar(KviControlCodes::Reset)));
 
403
                return true;
 
404
        }
 
405
 
 
406
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
407
 
 
408
        /*
 
409
                @doc: option
 
410
                @type:
 
411
                        function
 
412
                @title:
 
413
                        $option
 
414
                @short:
 
415
                        Returns the value of an option
 
416
                @syntax:
 
417
                        <string> $option(<optionName:string>)
 
418
                @description:
 
419
                        Returns the current value of the internal option named <optionName>.
 
420
                        See the [cmd]option[/cmd] command documentation for more info about options.
 
421
                @examples:
 
422
                        [example]
 
423
                                [cmd]echo[/cmd] $option(fontIrcView)
 
424
                        [/example]
 
425
                @seealso:
 
426
                        [cmd]option[/cmd],
 
427
        */
 
428
 
 
429
        KVSCF(option)
 
430
        {
 
431
                QString szOpt;
 
432
                // FIXME: This should return a variant in general
 
433
                KVSCF_PARAMETERS_BEGIN
 
434
                        KVSCF_PARAMETER("optionName",KVS_PT_NONEMPTYSTRING,0,szOpt)
 
435
                KVSCF_PARAMETERS_END
 
436
                QString tmp;
 
437
                if(g_pApp->getOptionString(szOpt,tmp))KVSCF_pRetBuffer->setString(tmp);
 
438
                else {
 
439
                        KVSCF_pContext->warning(__tr2qs_ctx("There is no option named '%Q'","kvs"),&szOpt);
 
440
                        KVSCF_pRetBuffer->setNothing();
 
441
                }
 
442
                return true;
 
443
        }
 
444
 
 
445
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
446
 
 
447
        /*
 
448
                @doc: query
 
449
                @type:
 
450
                        function
 
451
                @title:
 
452
                        $query
 
453
                @short:
 
454
                        Retrieves the window ID of a specified query
 
455
                @syntax:
 
456
                        $query[(<target>[,<irc context id>])]
 
457
                @description:
 
458
                        Returns the [b]window ID[/b] of the query that has <target>
 
459
                        in the list of targets and is bound to the connection specified by
 
460
                        <irc context id>[br]
 
461
                        If no window matches the specified target or context, and invalid
 
462
                        window ID is returned (0).[br]
 
463
                        If no <irc context id> is specified, this function looks for
 
464
                        the query in the current connection context (if any).[br]
 
465
                        If no <target> is specified, this function returns the current
 
466
                        query window ID, if executed in a query, else 0.[br]
 
467
                @examples:
 
468
                        [example]
 
469
                        [/example]
 
470
                @seealso:
 
471
                        [fnc]$window[/fnc],
 
472
                        [fnc]$channel[/fnc],
 
473
                        [fnc]$console[/fnc]
 
474
                        [doc:window_naming_conventions]Window naming conventions[/doc]
 
475
        */
 
476
 
 
477
        KVSCF(query)
 
478
        {
 
479
                QString szName;
 
480
                kvs_uint_t uContextId;
 
481
                KVSCF_PARAMETERS_BEGIN
 
482
                        KVSCF_PARAMETER("query_name",KVS_PT_NONEMPTYSTRING,KVS_PF_OPTIONAL,szName)
 
483
                        KVSCF_PARAMETER("context_id",KVS_PT_UINT,KVS_PF_OPTIONAL,uContextId)
 
484
                KVSCF_PARAMETERS_END
 
485
 
 
486
                KviWindow * wnd = 0;
 
487
                if(KVSCF_pParams->count() > 0)
 
488
                {
 
489
                        if(KVSCF_pParams->count() > 1)
 
490
                        {
 
491
                                KviConsoleWindow * cons = g_pApp->findConsole(uContextId);
 
492
                                if(!cons)KVSCF_pContext->warning(__tr2qs_ctx("No such IRC context (%u)","kvs"),uContextId);
 
493
                                else {
 
494
                                        if(cons->connection())
 
495
                                                wnd = cons->connection()->findQuery(szName);
 
496
                                        else
 
497
                                                wnd = 0;
 
498
                                }
 
499
                        } else {
 
500
                                if(KVSCF_pContext->window()->connection())wnd = KVSCF_pContext->window()->connection()->findQuery(szName);
 
501
                                else {
 
502
                                        if(!KVSCF_pContext->window()->console())
 
503
                                                KVSCF_pContext->warning(__tr2qs_ctx("This window is not associated to an IRC context","kvs"));
 
504
                                        wnd = 0;
 
505
                                }
 
506
                        }
 
507
                } else {
 
508
                        if(KVSCF_pContext->window()->type() == KviWindow::Query)wnd = KVSCF_pContext->window();
 
509
                }
 
510
 
 
511
                KVSCF_pRetBuffer->setInteger((kvs_int_t)(wnd ? wnd->numericId() : 0));
 
512
                return true;
 
513
        }
 
514
 
 
515
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
516
 
 
517
        /*
 
518
                @doc: r
 
519
                @type:
 
520
                        function
 
521
                @title:
 
522
                        $r
 
523
                @short:
 
524
                        Returns the REVERSE mIRC control character
 
525
                @syntax:
 
526
                        <string> $r
 
527
                @description:
 
528
                        Returns the REVERSE mIRC control character (CTRL+R).[br]
 
529
                @seealso:
 
530
                        [fnc]$k[/fnc], [fnc]$b[/fnc], [fnc]$u[/fnc], [fnc]$o[/fnc]
 
531
        */
 
532
 
 
533
        KVSCF(r)
 
534
        {
 
535
                Q_UNUSED(__pContext);
 
536
                Q_UNUSED(__pParams);
 
537
 
 
538
                KVSCF_pRetBuffer->setString(QString(QChar(KviControlCodes::Reverse)));
 
539
                return true;
 
540
        }
 
541
 
 
542
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
543
 
 
544
        /*
 
545
                @doc: rand
 
546
                @type:
 
547
                        function
 
548
                @title:
 
549
                        $rand
 
550
                @short:
 
551
                        Generates a random number
 
552
                @syntax:
 
553
                        $rand(<max>)
 
554
                @description:
 
555
                        Returns a random integer number from 0 to max inclusive.
 
556
                        You can repeat sequences of random numbers by calling [cmd]srand[/cmd]
 
557
                        with the same seed value. If [cmd]srand[/cmd] has not been called
 
558
                        $rand is automatically seeded with value of 1.
 
559
                        If no <max> is specified, this function returns an integer between
 
560
                        0 and RAND_MAX that is system dependant.
 
561
                @examples:
 
562
                        [example]
 
563
                        [/example]
 
564
                @seealso:
 
565
                        [cmd]srand[/cmd]
 
566
        */
 
567
 
 
568
        KVSCF(rand)
 
569
        {
 
570
                // prologue: parameter handling
 
571
                kvs_uint_t uMax;
 
572
 
 
573
                KVSCF_PARAMETERS_BEGIN
 
574
                        KVSCF_PARAMETER("max",KVS_PT_UINT,KVS_PF_OPTIONAL,uMax)
 
575
                KVSCF_PARAMETERS_END
 
576
                if(KVSCF_pParams->count() > 0)
 
577
                {
 
578
                        KVSCF_pRetBuffer->setInteger(::rand() % (uMax+1));
 
579
                } else {
 
580
                        KVSCF_pRetBuffer->setInteger(::rand());
 
581
                }
 
582
                return true;
 
583
        }
 
584
 
 
585
        ///////////////////////////////////////////////////////////////////////////////////////////////
 
586
 
 
587
        /*
 
588
                @doc: real
 
589
                @type:
 
590
                        function
 
591
                @title:
 
592
                        $real
 
593
                @short:
 
594
                        Casts a variable to a real
 
595
                @syntax:
 
596
                        <real> $real(<data:variant>)
 
597
                @description:
 
598
                        Forces <data> to be a "real" data type with the following
 
599
                        semantics:[br]
 
600
                        [ul]
 
601
                                [li]If <data> is a real, <data> itself is returned.[/li]
 
602
                                [li]If <data> is an integer, <data> itself is returned, in its real form.[/li]
 
603
                                [li]If <data> is a boolean, its numeric value is returned (either 1.0 or 0.0).[/li]
 
604
                                [li]If <data> is an array, the count of its items is returned.[/li]
 
605
                                [li]If <data> is a hash, the count of its items is returned.[/li]
 
606
                                [li]If <data> is a string, its length is returned.[/li]
 
607
                                [li]If <data> is an object, 0.0 is returned if the reference is null (invalid) and 1.0 otherwise[/li]
 
608
                        [/ul]
 
609
                        This function is similar to the C (double) cast.[br]
 
610
                        Note that since KVIrc does most of the casting work automatically
 
611
                        you shouldn't need to use this function.
 
612
                @seealso:
 
613
                        [fnc]$int[/fnc]
 
614
        */
 
615
 
 
616
        KVSCF(real)
 
617
        {
 
618
                KviKvsVariant * v;
 
619
                KVSCF_PARAMETERS_BEGIN
 
620
                        KVSCF_PARAMETER("data",KVS_PT_VARIANT,0,v)
 
621
                KVSCF_PARAMETERS_END
 
622
 
 
623
                kvs_real_t dVal;
 
624
                if(v->asReal(dVal))
 
625
                        KVSCF_pRetBuffer->setReal(dVal);
 
626
                else {
 
627
                        kvs_int_t iVal;
 
628
                        v->castToInteger(iVal);
 
629
                        KVSCF_pRetBuffer->setReal((double)iVal);
 
630
                }
 
631
                return true;
 
632
        }
 
633
 
 
634
        /*
 
635
                @doc: realname
 
636
                @type:
 
637
                        function
 
638
                @title:
 
639
                        $realname
 
640
                @short:
 
641
                        Returns the realname of the specified user
 
642
                @syntax:
 
643
                        <string> $realname(<nickname:string>)
 
644
                @description:
 
645
                        Returns the realname of the specified IRC user IF it is known.[br]
 
646
                        The realname is known if [fnc]$isWellKnown[/fnc] returns 1.[br]
 
647
                        The realname is generally known if the user is on a channel with you
 
648
                        or has an open query with you.[br]
 
649
                        Detailed explaination:[br]
 
650
                        KVIrc has an internal database of users that are currently
 
651
                        visible by *this client*: this includes users on open channels
 
652
                        and queries.[br] The other IRC users are NOT in the database:
 
653
                        this means that KVIrc knows NOTHING about them and can't return
 
654
                        any information immediately. In this case this function will return
 
655
                        an EMPTY string.[br]
 
656
                        If a user is in the database, at least his nickname is known.[br]
 
657
                        The username and hostname are known only if the server provides that information
 
658
                        spontaneously or after a KVIrc request.[br]
 
659
                        KVIrc requests user information for all the users in open queries
 
660
                        and channels. This information takes some time to be retrieved,
 
661
                        in this interval of time KVIrc knows only the user's nickname.
 
662
                        This function will return the string "*" in this case.[br]
 
663
                @seealso:
 
664
                        [fnc]$isWellKnown[/fnc], [fnc]$hostname[/fnc], [fnc]$username[/fnc], [cmd]awhois[/cmd]
 
665
        */
 
666
 
 
667
        KVSCF(realname)
 
668
        {
 
669
                QString szNick;
 
670
 
 
671
                KVSCF_PARAMETERS_BEGIN
 
672
                        KVSCF_PARAMETER("nick",KVS_PT_NONEMPTYSTRING,0,szNick)
 
673
                KVSCF_PARAMETERS_END
 
674
 
 
675
                if(KVSCF_pContext->window()->console())
 
676
                {
 
677
                        if(KVSCF_pContext->window()->console()->isConnected())
 
678
                        {
 
679
                                KviIrcUserEntry * e = KVSCF_pContext->window()->connection()->userDataBase()->find(szNick);
 
680
                                if(e)
 
681
                                {
 
682
                                        KVSCF_pRetBuffer->setString(e->realName());
 
683
                                        return true;
 
684
                                }
 
685
                        }
 
686
                }
 
687
 
 
688
                KVSCF_pRetBuffer->setNothing();
 
689
                return true;
 
690
        }
 
691
 
 
692
 
 
693
        /*
 
694
                @doc: receivedBytes
 
695
                @type:
 
696
                        function
 
697
                @title:
 
698
                        $receivedBytes
 
699
                @short:
 
700
                        Returns total received bytes
 
701
                @syntax:
 
702
                        <uint> $receivedBytes()
 
703
                @description:
 
704
                        Returns total received bytes
 
705
                @seealso:
 
706
                        [fnc]$sentBytes[/fnc]
 
707
        */
 
708
 
 
709
        KVSCF(receivedBytes)
 
710
        {
 
711
                Q_UNUSED(__pContext);
 
712
                Q_UNUSED(__pParams);
 
713
 
 
714
                KVSCF_pRetBuffer->setInteger(g_uIncomingTraffic);
 
715
                return true;
 
716
        }
 
717
 
 
718
        /*
 
719
                @doc: rsort
 
720
                @type:
 
721
                        function
 
722
                @title:
 
723
                        $rsort
 
724
                @short:
 
725
                        Sorts an array in reverse order
 
726
                @syntax:
 
727
                        <array> $rsort(<data:array>)
 
728
                @description:
 
729
                        Sorts an array in descending order.
 
730
                @seealso:
 
731
                        [fnc]$sort[/fnc]
 
732
        */
 
733
 
 
734
        KVSCF(rsort)
 
735
        {
 
736
                KviKvsArrayCast a;
 
737
 
 
738
                KVSCF_PARAMETERS_BEGIN
 
739
                        KVSCF_PARAMETER("data",KVS_PT_ARRAYCAST,0,a)
 
740
                KVSCF_PARAMETERS_END
 
741
 
 
742
                if(a.array())
 
743
                {
 
744
                        KviKvsArray * arry = new KviKvsArray(*(a.array()));
 
745
                        arry->rsort();
 
746
                        KVSCF_pRetBuffer->setArray(arry);
 
747
                } else {
 
748
                        KVSCF_pRetBuffer->setArray(new KviKvsArray());
 
749
                }
 
750
                return true;
 
751
        }
 
752
};