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

« back to all changes in this revision

Viewing changes to src/kvirc/kvs/kvi_kvs_corefunctions_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 : kvi_kvs_corefunctions_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-2008 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 "kvi_kvs_corefunctions.h"
28
 
#include "kvi_kvs_kernel.h"
29
 
#include "kvi_kvs_arraycast.h"
30
 
#include "kvi_kvs_object_controller.h"
31
 
#include "kvi_locale.h"
32
 
#include "kvi_ircconnection.h"
33
 
#include "kvi_mirccntrl.h"
34
 
#include "kvi_options.h"
35
 
#include "kvi_console.h"
36
 
#include "kvi_ircuserdb.h"
37
 
#include "kvi_ircmask.h"
38
 
#include "kvi_socket.h"
39
 
#include "kvi_app.h"
40
 
#include "kvi_query.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
 
                KviConsole * 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() == KVI_WINDOW_TYPE_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
 
                        Please see the [doc:objects]objects documentation[/doc] for more information.[br]
266
 
                @examples:
267
 
                        [example]
268
 
                                %myobj = $new(widget,0,pippo)
269
 
                        [/example]
270
 
                @seealso:
271
 
                        [doc:objects]Objects documentation[/doc], [cmd]delete[/cmd]
272
 
        */
273
 
 
274
 
        KVSCF(newCKEYWORDWORKAROUND)
275
 
        {
276
 
                // prologue: parameter handling
277
 
                QString szClassName;
278
 
                QString szName;
279
 
                kvs_hobject_t hParent;
280
 
                KviKvsVariantList vList;
281
 
 
282
 
                KVSCF_PARAMETERS_BEGIN
283
 
                        KVSCF_PARAMETER("className",KVS_PT_NONEMPTYSTRING,0,szClassName)
284
 
                        KVSCF_PARAMETER("parentHandle",KVS_PT_HOBJECT,KVS_PF_OPTIONAL,hParent)
285
 
                        KVSCF_PARAMETER("name",KVS_PT_STRING,KVS_PF_OPTIONAL,szName)
286
 
                        KVSCF_PARAMETER("parameterList",KVS_PT_VARIANTLIST,KVS_PF_OPTIONAL,vList)
287
 
                KVSCF_PARAMETERS_END
288
 
 
289
 
                KviKvsObjectClass * pClass = KviKvsKernel::instance()->objectController()->lookupClass(szClassName);
290
 
                if(!pClass)
291
 
                {
292
 
                        KVSCF_pContext->error(__tr2qs_ctx("Class '%Q' is not defined","kvs"),&szClassName);
293
 
                        return false;
294
 
                }
295
 
 
296
 
                KviKvsObject * pParent;
297
 
                if(hParent != (kvs_hobject_t)0)
298
 
                {
299
 
                        pParent = KviKvsKernel::instance()->objectController()->lookupObject(hParent);
300
 
                        if(!pParent)
301
 
                        {
302
 
                                KVSCF_pContext->error(__tr2qs_ctx("The specified parent object does not exist","kvs"));
303
 
                                return false;
304
 
                        }
305
 
                } else {
306
 
                        pParent = 0;
307
 
                }
308
 
 
309
 
                KviKvsObject * pObject = pClass->allocateInstance(pParent,szName,KVSCF_pContext,&vList);
310
 
 
311
 
                // epilogue: set the return value
312
 
                KVSCF_pRetBuffer->setHObject(pObject ? pObject->handle() : (kvs_hobject_t)0);
313
 
                return true;
314
 
        }
315
 
 
316
 
        ///////////////////////////////////////////////////////////////////////////////////////////////
317
 
 
318
 
        /*
319
 
                @doc: nothing
320
 
                @type:
321
 
                        function
322
 
                @title:
323
 
                        $nothing
324
 
                @short:
325
 
                        Evaluates to an empty variable
326
 
                @syntax:
327
 
                        <nothing> $nothing
328
 
                @description:
329
 
                        Evaluates to an empty variable. This is a special value somewhat similar
330
 
                        to the [fnc]$null[/fnc] object: it is used to denote absence
331
 
                        of information. For example, a function might decide to return
332
 
                        a meaningful value when the input parameters are correct and
333
 
                        $nothing when the input parameters are wrong.
334
 
                @seealso:
335
 
                        [fnc]$null[/fnc]
336
 
        */
337
 
 
338
 
        KVSCF(nothing)
339
 
        {
340
 
                Q_UNUSED(__pContext);
341
 
                Q_UNUSED(__pParams);
342
 
 
343
 
                KVSCF_pRetBuffer->setNothing();
344
 
                return true;
345
 
        }
346
 
 
347
 
        ///////////////////////////////////////////////////////////////////////////////////////////////
348
 
 
349
 
 
350
 
        /*
351
 
                @doc: null
352
 
                @type:
353
 
                        function
354
 
                @title:
355
 
                        $null
356
 
                @short:
357
 
                        Evaluates to the null object handle.
358
 
                @syntax:
359
 
                        <hobject> $null
360
 
                @description:
361
 
                        Evaluates to the null object handle. This is a special
362
 
                        object handle that is returned by some functions.
363
 
                        Please note that writing $null is semantically equivalent to writing 0
364
 
                        or even [fnc]$nothing[/fnc] in place of the handle, but $null increases code readability.
365
 
                @seealso:
366
 
                        [fnc]$new[/fnc], [fnc]$nothing[/fnc]
367
 
        */
368
 
 
369
 
        KVSCF(nullCKEYWORDWORKAROUND)
370
 
        {
371
 
                Q_UNUSED(__pContext);
372
 
                Q_UNUSED(__pParams);
373
 
 
374
 
                KVSCF_pRetBuffer->setHObject(0);
375
 
                return true;
376
 
        }
377
 
 
378
 
        ///////////////////////////////////////////////////////////////////////////////////////////////
379
 
 
380
 
        /*
381
 
                @doc: o
382
 
                @type:
383
 
                        function
384
 
                @title:
385
 
                        $o
386
 
                @short:
387
 
                        Returns the RESET mIRC control character
388
 
                @syntax:
389
 
                        <string> $o
390
 
                @description:
391
 
                        Returns the RESET mIRC control character (CTRL+O).[br]
392
 
                @seealso:
393
 
                        [fnc]$k[/fnc], [fnc]$b[/fnc], [fnc]$u[/fnc], [fnc]$r[/fnc]
394
 
        */
395
 
 
396
 
        KVSCF(o)
397
 
        {
398
 
                Q_UNUSED(__pContext);
399
 
                Q_UNUSED(__pParams);
400
 
 
401
 
                KVSCF_pRetBuffer->setString(QString(QChar(KVI_TEXT_RESET)));
402
 
                return true;
403
 
        }
404
 
 
405
 
        ///////////////////////////////////////////////////////////////////////////////////////////////
406
 
 
407
 
        /*
408
 
                @doc: option
409
 
                @type:
410
 
                        function
411
 
                @title:
412
 
                        $option
413
 
                @short:
414
 
                        Returns the value of an option
415
 
                @syntax:
416
 
                        <string> $option(<optionName:string>)
417
 
                @description:
418
 
                        Returns the current value of the internal option named <optionName>.
419
 
                        See the [cmd]option[/cmd] command documentation for more info about options.
420
 
                @examples:
421
 
                        [example]
422
 
                                [cmd]echo[/cmd] $option(fontIrcView)
423
 
                        [/example]
424
 
                @seealso:
425
 
                        [cmd]option[/cmd],
426
 
        */
427
 
 
428
 
        KVSCF(option)
429
 
        {
430
 
                QString szOpt;
431
 
                // FIXME: This should return a variant in general
432
 
                KVSCF_PARAMETERS_BEGIN
433
 
                        KVSCF_PARAMETER("optionName",KVS_PT_NONEMPTYSTRING,0,szOpt)
434
 
                KVSCF_PARAMETERS_END
435
 
                QString tmp;
436
 
                if(g_pApp->getOptionString(szOpt,tmp))KVSCF_pRetBuffer->setString(tmp);
437
 
                else {
438
 
                        KVSCF_pContext->warning(__tr2qs_ctx("There is no option named '%Q'","kvs"),&szOpt);
439
 
                        KVSCF_pRetBuffer->setNothing();
440
 
                }
441
 
                return true;
442
 
        }
443
 
 
444
 
        ///////////////////////////////////////////////////////////////////////////////////////////////
445
 
 
446
 
        /*
447
 
                @doc: query
448
 
                @type:
449
 
                        function
450
 
                @title:
451
 
                        $query
452
 
                @short:
453
 
                        Retrieves the window ID of a specified query
454
 
                @syntax:
455
 
                        $query[(<target>[,<irc context id>])]
456
 
                @description:
457
 
                        Returns the [b]window ID[/b] of the query that has <target>
458
 
                        in the list of targets and is bound to the connection specified by
459
 
                        <irc context id>[br]
460
 
                        If no window matches the specified target or context, and invalid
461
 
                        window ID is returned (0).[br]
462
 
                        If no <irc context id> is specified, this function looks for
463
 
                        the query in the current connection context (if any).[br]
464
 
                        If no <target> is specified, this function returns the current
465
 
                        query window ID, if executed in a query, else 0.[br]
466
 
                @examples:
467
 
                        [example]
468
 
                        [/example]
469
 
                @seealso:
470
 
                        [fnc]$window[/fnc],
471
 
                        [fnc]$channel[/fnc],
472
 
                        [fnc]$console[/fnc]
473
 
                        [doc:window_naming_conventions]Window naming conventions[/doc]
474
 
        */
475
 
 
476
 
        KVSCF(query)
477
 
        {
478
 
                QString szName;
479
 
                kvs_uint_t uContextId;
480
 
                KVSCF_PARAMETERS_BEGIN
481
 
                        KVSCF_PARAMETER("query_name",KVS_PT_NONEMPTYSTRING,KVS_PF_OPTIONAL,szName)
482
 
                        KVSCF_PARAMETER("context_id",KVS_PT_UINT,KVS_PF_OPTIONAL,uContextId)
483
 
                KVSCF_PARAMETERS_END
484
 
 
485
 
                KviWindow * wnd = 0;
486
 
                if(KVSCF_pParams->count() > 0)
487
 
                {
488
 
                        if(KVSCF_pParams->count() > 1)
489
 
                        {
490
 
                                KviConsole * cons = g_pApp->findConsole(uContextId);
491
 
                                if(!cons)KVSCF_pContext->warning(__tr2qs_ctx("No such IRC context (%u)","kvs"),uContextId);
492
 
                                else {
493
 
                                        if(cons->connection())
494
 
                                                wnd = cons->connection()->findQuery(szName);
495
 
                                        else
496
 
                                                wnd = 0;
497
 
                                }
498
 
                        } else {
499
 
                                if(KVSCF_pContext->window()->connection())wnd = KVSCF_pContext->window()->connection()->findQuery(szName);
500
 
                                else {
501
 
                                        if(!KVSCF_pContext->window()->console())
502
 
                                                KVSCF_pContext->warning(__tr2qs_ctx("This window is not associated to an IRC context","kvs"));
503
 
                                        wnd = 0;
504
 
                                }
505
 
                        }
506
 
                } else {
507
 
                        if(KVSCF_pContext->window()->type() == KVI_WINDOW_TYPE_QUERY)wnd = KVSCF_pContext->window();
508
 
                }
509
 
 
510
 
                KVSCF_pRetBuffer->setInteger((kvs_int_t)(wnd ? wnd->numericId() : 0));
511
 
                return true;
512
 
        }
513
 
 
514
 
        ///////////////////////////////////////////////////////////////////////////////////////////////
515
 
 
516
 
        /*
517
 
                @doc: r
518
 
                @type:
519
 
                        function
520
 
                @title:
521
 
                        $r
522
 
                @short:
523
 
                        Returns the REVERSE mIRC control character
524
 
                @syntax:
525
 
                        <string> $r
526
 
                @description:
527
 
                        Returns the REVERSE mIRC control character (CTRL+R).[br]
528
 
                @seealso:
529
 
                        [fnc]$k[/fnc], [fnc]$b[/fnc], [fnc]$u[/fnc], [fnc]$o[/fnc]
530
 
        */
531
 
 
532
 
        KVSCF(r)
533
 
        {
534
 
                Q_UNUSED(__pContext);
535
 
                Q_UNUSED(__pParams);
536
 
 
537
 
                KVSCF_pRetBuffer->setString(QString(QChar(KVI_TEXT_REVERSE)));
538
 
                return true;
539
 
        }
540
 
 
541
 
        ///////////////////////////////////////////////////////////////////////////////////////////////
542
 
 
543
 
        /*
544
 
                @doc: rand
545
 
                @type:
546
 
                        function
547
 
                @title:
548
 
                        $rand
549
 
                @short:
550
 
                        Generates a random number
551
 
                @syntax:
552
 
                        $rand(<max>)
553
 
                @description:
554
 
                        Returns a random integer number from 0 to max inclusive.
555
 
                        You can repeat sequences of random numbers by calling [cmd]srand[/cmd]
556
 
                        with the same seed value. If [cmd]srand[/cmd] has not been called
557
 
                        $rand is automatically seeded with value of 1.
558
 
                        If no <max> is specified, this function returns an integer between
559
 
                        0 and RAND_MAX that is system dependant.
560
 
                @examples:
561
 
                        [example]
562
 
                        [/example]
563
 
                @seealso:
564
 
                        [cmd]srand[/cmd]
565
 
        */
566
 
 
567
 
        KVSCF(rand)
568
 
        {
569
 
                // prologue: parameter handling
570
 
                kvs_uint_t uMax;
571
 
 
572
 
                KVSCF_PARAMETERS_BEGIN
573
 
                        KVSCF_PARAMETER("max",KVS_PT_UINT,KVS_PF_OPTIONAL,uMax)
574
 
                KVSCF_PARAMETERS_END
575
 
                if(KVSCF_pParams->count() > 0)
576
 
                {
577
 
                        KVSCF_pRetBuffer->setInteger(::rand() % (uMax+1));
578
 
                } else {
579
 
                        KVSCF_pRetBuffer->setInteger(::rand());
580
 
                }
581
 
                return true;
582
 
        }
583
 
 
584
 
        ///////////////////////////////////////////////////////////////////////////////////////////////
585
 
 
586
 
        /*
587
 
                @doc: real
588
 
                @type:
589
 
                        function
590
 
                @title:
591
 
                        $real
592
 
                @short:
593
 
                        Casts a variable to a real
594
 
                @syntax:
595
 
                        <real> $real(<data:variant>)
596
 
                @description:
597
 
                        Forces <data> to be a "real" data type with the following
598
 
                        semantics:[br]
599
 
                        [ul]
600
 
                                [li]If <data> is a real, <data> itself is returned.[/li]
601
 
                                [li]If <data> is an integer, <data> itself is returned, in its real form.[/li]
602
 
                                [li]If <data> is a boolean, its numeric value is returned (either 1.0 or 0.0).[/li]
603
 
                                [li]If <data> is an array, the count of its items is returned.[/li]
604
 
                                [li]If <data> is a hash, the count of its items is returned.[/li]
605
 
                                [li]If <data> is a string, its length is returned.[/li]
606
 
                                [li]If <data> is an object, 0.0 is returned if the reference is null (invalid) and 1.0 otherwise[/li]
607
 
                        [/ul]
608
 
                        This function is similar to the C (double) cast.[br]
609
 
                        Note that since KVIrc does most of the casting work automatically
610
 
                        you shouldn't need to use this function.
611
 
                @seealso:
612
 
                        [fnc]$int[/fnc]
613
 
        */
614
 
 
615
 
        KVSCF(real)
616
 
        {
617
 
                KviKvsVariant * v;
618
 
                KVSCF_PARAMETERS_BEGIN
619
 
                        KVSCF_PARAMETER("data",KVS_PT_VARIANT,0,v)
620
 
                KVSCF_PARAMETERS_END
621
 
 
622
 
                kvs_real_t dVal;
623
 
                if(v->asReal(dVal))
624
 
                        KVSCF_pRetBuffer->setReal(dVal);
625
 
                else {
626
 
                        kvs_int_t iVal;
627
 
                        v->castToInteger(iVal);
628
 
                        KVSCF_pRetBuffer->setReal((double)iVal);
629
 
                }
630
 
                return true;
631
 
        }
632
 
 
633
 
        /*
634
 
                @doc: realname
635
 
                @type:
636
 
                        function
637
 
                @title:
638
 
                        $realname
639
 
                @short:
640
 
                        Returns the realname of the specified user
641
 
                @syntax:
642
 
                        <string> $realname(<nickname:string>)
643
 
                @description:
644
 
                        Returns the realname of the specified IRC user IF it is known.[br]
645
 
                        The realname is known if [fnc]$isWellKnown[/fnc] returns 1.[br]
646
 
                        The realname is generally known if the user is on a channel with you
647
 
                        or has an open query with you.[br]
648
 
                        Detailed explaination:[br]
649
 
                        KVIrc has an internal database of users that are currently
650
 
                        visible by *this client*: this includes users on open channels
651
 
                        and queries.[br] The other IRC users are NOT in the database:
652
 
                        this means that KVIrc knows NOTHING about them and can't return
653
 
                        any information immediately. In this case this function will return
654
 
                        an EMPTY string.[br]
655
 
                        If a user is in the database, at least his nickname is known.[br]
656
 
                        The username and hostname are known only if the server provides that information
657
 
                        spontaneously or after a KVIrc request.[br]
658
 
                        KVIrc requests user information for all the users in open queries
659
 
                        and channels. This information takes some time to be retrieved,
660
 
                        in this interval of time KVIrc knows only the user's nickname.
661
 
                        This function will return the string "*" in this case.[br]
662
 
                @seealso:
663
 
                        [fnc]$isWellKnown[/fnc], [fnc]$hostname[/fnc], [fnc]$username[/fnc], [cmd]awhois[/cmd]
664
 
        */
665
 
 
666
 
        KVSCF(realname)
667
 
        {
668
 
                QString szNick;
669
 
 
670
 
                KVSCF_PARAMETERS_BEGIN
671
 
                        KVSCF_PARAMETER("nick",KVS_PT_NONEMPTYSTRING,0,szNick)
672
 
                KVSCF_PARAMETERS_END
673
 
 
674
 
                if(KVSCF_pContext->window()->console())
675
 
                {
676
 
                        if(KVSCF_pContext->window()->console()->isConnected())
677
 
                        {
678
 
                                KviIrcUserEntry * e = KVSCF_pContext->window()->connection()->userDataBase()->find(szNick);
679
 
                                if(e)
680
 
                                {
681
 
                                        KVSCF_pRetBuffer->setString(e->realName());
682
 
                                        return true;
683
 
                                }
684
 
                        }
685
 
                }
686
 
 
687
 
                KVSCF_pRetBuffer->setNothing();
688
 
                return true;
689
 
        }
690
 
 
691
 
 
692
 
        /*
693
 
                @doc: receivedBytes
694
 
                @type:
695
 
                        function
696
 
                @title:
697
 
                        $receivedBytes
698
 
                @short:
699
 
                        Returns total received bytes
700
 
                @syntax:
701
 
                        <uint> $receivedBytes()
702
 
                @description:
703
 
                        Returns total received bytes
704
 
                @seealso:
705
 
                        [fnc]$sentBytes[/fnc]
706
 
        */
707
 
 
708
 
        KVSCF(receivedBytes)
709
 
        {
710
 
                Q_UNUSED(__pContext);
711
 
                Q_UNUSED(__pParams);
712
 
 
713
 
                KVSCF_pRetBuffer->setInteger(g_uIncomingTraffic);
714
 
                return true;
715
 
        }
716
 
 
717
 
        /*
718
 
                @doc: rsort
719
 
                @type:
720
 
                        function
721
 
                @title:
722
 
                        $rsort
723
 
                @short:
724
 
                        Sorts an array in reverse order
725
 
                @syntax:
726
 
                        <array> $rsort(<data:array>)
727
 
                @description:
728
 
                        Sorts an array in descending order.
729
 
                @seealso:
730
 
                        [fnc]$sort[/fnc]
731
 
        */
732
 
 
733
 
        KVSCF(rsort)
734
 
        {
735
 
                KviKvsArrayCast a;
736
 
 
737
 
                KVSCF_PARAMETERS_BEGIN
738
 
                        KVSCF_PARAMETER("data",KVS_PT_ARRAYCAST,0,a)
739
 
                KVSCF_PARAMETERS_END
740
 
 
741
 
                if(a.array())
742
 
                {
743
 
                        KviKvsArray * arry = new KviKvsArray(*(a.array()));
744
 
                        arry->rsort();
745
 
                        KVSCF_pRetBuffer->setArray(arry);
746
 
                } else {
747
 
                        KVSCF_pRetBuffer->setArray(new KviKvsArray());
748
 
                }
749
 
                return true;
750
 
        }
751
 
};