summaryrefslogtreecommitdiffstats
path: root/src/kvirc/kvs/kvi_kvs_corefunctions_gl.cpp
blob: e8aae4f64b443b6b0bbaf3fdde99f626e292a55b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
//=============================================================================
//
//   File : kvi_kvs_corefunctions_gl.cpp
//   Created on Fri 31 Oct 2003 01:52:04 by Szymon Stefanek
//
//   This file is part of the KVIrc IRC client distribution
//   Copyright (C) 2003-2005 Szymon Stefanek <pragma at kvirc dot net>
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#define __KVIRC__

#include "kvi_kvs_corefunctions.h"

#include "kvi_kvs_kernel.h"

#include "kvi_kvs_timermanager.h"
#include "kvi_kvs_arraycast.h"
#include "kvi_locale.h"
#include "kvi_input.h"
#include "kvi_app.h"
#include "kvi_channel.h"
#include "kvi_console.h"
#include "kvi_iconmanager.h"
#include "kvi_mirccntrl.h"
#include "kvi_frame.h"
#include "kvi_time.h"
#include "kvi_kvs_eventmanager.h"
#include "kvi_kvs_eventhandler.h"
#include <tqregexp.h>
#include "kvi_lagmeter.h"

namespace KviKvsCoreFunctions
{
	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: hash
		@type:
			function
		@title:
			$hash
		@short:
			Explicitly creates a hash
		@syntax:
			<hash> $hash([<key:string>,<value:variant>,[<key:string>,<value:variant>]],...)
		@description:
			Returns a hash with the specified items. Each <value> is indexed by the preceeding <key>.
			This is just an explicit way of creating a hash with a defined set of items,
			useful for increasing readability.
		@examples:
			[example]
				[cmd]alias[/cmd](test){ [cmd]return[/cmd] $hash(1,X,2,Y,3,Z); };
				%x = $test();
				[cmd]foreach[/cmd](%y,%x)
				{
					[cmd]echo[/cmd] %y;
				}
				[cmd]foreach[/cmd](%y,[fnc]$keys[/fnc](%x))
				{
					[cmd]echo[/cmd] %y
				}
			[/example]
		@seealso:
			[fnc]$array[/fnc]
	*/

	KVSCF(hash)
	{
#ifdef COMPILE_NEW_KVS
		KviKvsHash * a = new KviKvsHash();

		for(KviKvsVariant * key = KVSCF_pParams->first();key;key = KVSCF_pParams->next())
		{
			KviKvsVariant * val = KVSCF_pParams->next();
			if(!val)break;
			TQString sz;
			key->asString(sz);
			a->set(sz,new KviKvsVariant(*val));
		}

		KVSCF_pRetBuffer->setHash(a);
#endif
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: hextoAscii
		@type:
			function
		@title:
			$hexToAscii
		@short:
			Returns a decoded hex string
		@syntax:
			$hexToAscii(<hex_encoded_string>)
		@description:
			Decodes the <hex_encoded_string> to its ASCII representation.
		@examples:
			[example]
				[cmd]echo[/cmd] $hexToAscii(6B76697263)
			[/example]
		@seealso:
			[fnc]$asciiToHex[/fnc]
	*/

	KVSCF(hexToAscii)
	{
		TQString szHex;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("hex_encoded_string",KVS_PT_STRING,0,szHex)
		KVSCF_PARAMETERS_END

		KviStr tmp1(szHex);
		char * buf;
		int len = tmp1.hexToBuffer(&buf,true);
		KVSCF_pRetBuffer->setString(TQString(KviTQCString(buf,len+1)));
		KviStr::freeBuffer(buf);
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: hostname
		@type:
			function
		@title:
			$hostname
		@short:
			Returns the hostname of the specified user
		@syntax:
			<string> $hostname(<nickname:string>)
		@description:
			Returns the hostname of the specified IRC user IF it is known.[br]
			The hostname is known if [fnc]$isWellKnown[/fnc] returns 1.[br]
			The hostname is generally known if the user is on a channel with you
			or has an open query with you.[br]
			Detailed explaination:[br]
			KVIrc has an internal database of users that are currently
			visible by *this client*: this includes users on open channels
			and queries.[br] The other IRC users are NOT in the database:
			this means that KVIrc knows NOTHING about them and can't return
			any information immediately. In this case this function will return
			an EMPTY string.[br]
			If a user is in the database, at least his nickname is known.[br]
			The username and hostname are known only if the server provides that information
			spontaneously or after a KVIrc request.[br]
			KVIrc requests user information for all the users in open queries
			and channels. This information takes some time to be retrieved,
			in this interval of time KVIrc knows only the user's nickname.
			This function will return the string "*" in this case.[br]
		@seealso:
			[fnc]$isWellKnown[/fnc], [fnc]$username[/fnc], [cmd]awhois[/cmd]
	*/

	KVSCF(hostname)
	{
		TQString szNick;

		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("nick",KVS_PT_NONEMPTYSTRING,0,szNick)
		KVSCF_PARAMETERS_END

		if(KVSCF_pContext->window()->console())
		{
			if(KVSCF_pContext->window()->console()->isConnected())
			{
				KviIrcUserEntry * e = KVSCF_pContext->window()->connection()->userDataBase()->find(szNick);
				if(e)
				{
					KVSCF_pRetBuffer->setString(e->host());
					return true;
				}
			}
		}

		KVSCF_pRetBuffer->setNothing();
		return true;
	}
	
	//-------------------------------------------------
	/*
 	    @doc: lag
 	    @type:
			function
 	    @title:
 	    		$lag
 	    @short:
	 	        Returns the lag on the current server
 	    @syntax:
 		        <integer> lag
 	    @description:
 	    		This function returns the lag in the current server, in milliseconds.[br]
	*/
	
	KVSCF(lag)
	{
	        if(!KVSCF_pContext->window()->console()) return KVSCF_pContext->errorNoIrcContext();
 	        if(!KVSCF_pContext->window()->console()->connection())  return KVSCF_pContext->warningNoIrcConnection();
 	        if(!KVSCF_pContext->window()->console()->connection()->lagMeter())
 	        {
 	            KVSCF_pContext->warning(__tr2qs("Lag meter was not enabled"));
 	            return false;
 	        }
 	        
 	        KVSCF_pRetBuffer->setInteger( KVSCF_pContext->window()->console()->connection()->lagMeter()->lag());
 	        return true;
	}
	/////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: hptimestamp
		@type:
			function
		@title:
			$hptimestamp
		@short:
			Returns a high precision timestamp
		@syntax:
			<float> $hptimestamp
		@description:
			Returns a high precision timestamp as a floaint point value.
			The timestamp rappresent the number of seconds elapsed since
			a certain moment in the past. The number of seconds
			contains a "high precision" fractional part. The "certain moment" definition
			depends on the platform KVIrc is executed. This means that
			this timestamp is totally useless to rappresent a time value
			but is useful to compute time intervals with sub-second precision.
		@examples:
			[example]
				%tmp = $hptimestamp
				[cmd]echo[/cmd] $($hptimestamp - %tmp)
			[/example]
		@seealso:
			[fnc]$unixTime[/fnc], [fnc]$date[/fnc]
	*/

	KVSCF(hptimestamp)
	{
		struct timeval tv;
		kvi_gettimeofday(&tv,0);
		kvs_real_t dTimestamp = (kvs_real_t)(tv.tv_sec);
		dTimestamp += (((kvs_real_t)(tv.tv_usec)) / 1000000.0);
		KVSCF_pRetBuffer->setReal(dTimestamp);
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: icon
		@type:
			function
		@title:
			$icon
		@short:
			Returns the ID of an icon
		@syntax:
			<integer> $icon(<iconname:string>)
		@description:
			Returns the ID of the icon <iconname>.
			You should always use this function where an <image_id> is required
			and you want to use an internal icon.
			See [fnc]$iconname[/fnc] for a list of the icon names supported by kvirc.[br]
		@examples:
			[example]
				[cmd]echo[/cmd] $icon(linux)
			[/example]
		@seealso:
			[fnc]$iconName[/fnc]
	*/

	KVSCF(icon)
	{
		TQString szName;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("iconName",KVS_PT_NONEMPTYSTRING,0,szName)
		KVSCF_PARAMETERS_END

		KVSCF_pRetBuffer->setInteger(g_pIconManager->getSmallIconIdFromName(szName));
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: iconname
		@type:
			function
		@title:
			$iconname
		@short:
			Returns the name of an icon
		@syntax:
			$iconname(<iconid>)
		@description:
			Returns the name of a builtin icon given an <iconid>.
			The <iconid> is returned by the function [fnc]$icon[/fnc].
			If the <iconid> is not valid, an empty name is returned.[br]
			The following code will list all the available icon names:[br]
			[example]
				%i = 0
				[cmd]do[/cmd] {
					%name = $iconname(%i)
					echo The icon by ID %i is named %name
					%i++
				} [cmd]while[/cmd](%name != "")
			[/example]
		@examples:
			[example]
				[cmd]echo[/cmd] $iconname(24)
				[cmd]echo[/cmd] $iconname([fnc]$icon[/fnc](linux))
			[/example]
		@seealso:
			[fnc]$iconName[/fnc]
	*/

	KVSCF(iconName)
	{
		kvs_uint_t uIco;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("iconid",KVS_PT_UINT,0,uIco)
		KVSCF_PARAMETERS_END

		if(uIco < KVI_NUM_SMALL_ICONS)
		{
			KVSCF_pRetBuffer->setString(g_pIconManager->getSmallIconName(uIco));
		} else {
			KVSCF_pRetBuffer->setNothing();
		}
		return true;
	}


	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: integer
		@type:
			function
		@title:
			$integer
		@short:
			Casts a variable to an integer
		@syntax:
			<integer> $integer(<data:variant>)
		@description:
			Forces <data> to be an integer data type with the following
			semantics:[br]
			[ul]
				[li]If <data> is an integer, <data> itself is returned.[/li]
				[li]If <data> is a boolean, its numeric value is returned (either 1 or 0).[/li]
				[li]If <data> is a real, its integer part is returned.[/li]
				[li]If <data> is an array, the count of its items is returned.[/li]
				[li]If <data> is a hash, the count of its items is returned.[/li]
				[li]If <data> is a string, its length is returned.[/li]
				[li]If <data> is an object, 0 is returned if the reference is null (invalid) and 1 otherwise[/li]
			[/ul]
			This function is similar to the C (int) cast and is internally
			aliased to [fnc]$int[/fnc]() too.
			Note that since KVIrc does most of the casting work automatically
			you shouldn't need to use this function.
		@seealso:
			[fnc]$real[/fnc]
			[fnc]$boolean[/fnc]
	*/

	/*
		@doc: int
		@type:
			function
		@title:
			$int
		@short:
			Casts a variable to an integer
		@syntax:
			<integer> $int(<data:variant>)
		@description:
			This is an internal alias to [fnc]$integer[/fnc]().
		@seealso:
			[fnc]$real[/fnc]
			[fnc]$boolean[/fnc]
	*/

	KVSCF(integer)
	{
		KviKvsVariant * v;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("data",KVS_PT_VARIANT,0,v)
		KVSCF_PARAMETERS_END

		kvs_int_t iVal;
		v->castToInteger(iVal);
		KVSCF_pRetBuffer->setInteger(iVal);
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: isMainWindowActive
		@type:
			function
		@title:
			$isMainWindowActive
		@short:
			Checks if main KVirc window is active
		@syntax:
			<boolean> $isMainWindowActive()
		@description:
			Returns true if the KVIrc's window is currently
			the active window on the current desktop.
	*/

	KVSCF(isMainWindowActive)
	{
		KVSCF_pRetBuffer->setBoolean(g_pFrame->isActiveWindow());
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: isMainWindowMinimized
		@type:
			function
		@title:
			$isMainWindowMinimized
		@short:
			Checks if main KVirc window is minimized
		@syntax:
			<boolean> $isMainWindowMinimized()
		@description:
			Returns true if main KVirc window is minimized and false otherwise.
	*/

	KVSCF(isMainWindowMinimized)
	{
		KVSCF_pRetBuffer->setBoolean(g_pFrame->isMinimized());
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: isempty
		@type:
			function
		@title:
			$isEmpty
		@short:
			Checks if a variable is set (empty or non empty)
		@syntax:
			<boolean> $isEmpty(<data:variant>)
		@description:
			Returns 0 if <data> is actually set to some non-empty value
			and 1 otherwise. Since KVIrc treats unset variables as empty
			ones then this function is the exact opposite of [fnc]$isSet[/fnc].
		@seealso:
			[fnc]$isSet[/fnc]
	*/

	KVSCF(isEmpty)
	{
#ifdef COMPILE_NEW_KVS
		KviKvsVariant * v;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("data",KVS_PT_VARIANT,0,v)
		KVSCF_PARAMETERS_END

		KVSCF_pRetBuffer->setBoolean(v->isEmpty());
#endif
		return true;
	}
	//FIXME: documentation

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: iseventenabled
		@type:
			function
		@title:
			$isEventEnabled
		@short:
			Checks if an event enabled
		@syntax:
			<boolean> $isEventEnabled(<event_name:string>,<handler_name:string>)
		@description:
			Returns 1 if the event handler enabled
	*/

	///////////////////////////////////////////////////////////////////////////////////////////////

	KVSCF(isEventEnabled)
	{
		TQString szEventName,szHandlerName;
		KviKvsScriptEventHandler *h=0;

		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("event_name",KVS_PT_NONEMPTYSTRING,0,szEventName)
			KVSCF_PARAMETER("handler_name",KVS_PT_NONEMPTYSTRING,0,szHandlerName)
		KVSCF_PARAMETERS_END

		bool bOk;
		int iNumber = szEventName.toInt(&bOk);
		bool bIsRaw = (bOk && (iNumber >= 0) && (iNumber < 1000));

		if(bIsRaw)
		{
			if(!KviKvsEventManager::instance()->isValidRawEvent(iNumber))
			{
					KVSCF_pContext->warning(__tr2qs("No such event (%Q)"),&szEventName);
			} else {
				h=KviKvsEventManager::instance()->findScriptRawHandler(iNumber,szHandlerName);
			}
		} else {
			iNumber = KviKvsEventManager::instance()->findAppEventIndexByName(szEventName);
			if(!KviKvsEventManager::instance()->isValidAppEvent(iNumber))
			{
					KVSCF_pContext->warning(__tr2qs("No such event (%Q)"),&szEventName);
			} else {
				h=KviKvsEventManager::instance()->findScriptAppHandler(iNumber,szHandlerName);
			}
		}
		if(h)
			KVSCF_pRetBuffer->setBoolean(h->isEnabled());
		else
			KVSCF_pContext->warning(__tr2qs("No such event handler (%Q) for event %Q"),&szHandlerName,&szEventName);

		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: isnumeric
		@type:
			function
		@title:
			$isNumeric
		@syntax:
			<boolean> $isNumeric(<data:variant>)
		@short:
			Finds whether a variable contains a rappresentation of a number
		@description:
			Returns 1 if the <data> is an integer or a real number, 0 otherwise.
	*/

	KVSCF(isNumeric)
	{
#ifdef COMPILE_NEW_KVS
		KviKvsVariant * v;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("data",KVS_PT_VARIANT,0,v)
		KVSCF_PARAMETERS_END

		KviKvsNumber n;
		KVSCF_pRetBuffer->setBoolean(v->asNumber(n));
#endif
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: isset
		@type:
			function
		@title:
			$isSet
		@short:
			Checks if a variable is set (non-empty)
		@syntax:
			<boolean> $isSet(<data:variant>)
		@description:
			Returns 1 if <data> is actually set to some non-empty value
			and 0 otherwise. If <data> is a variable , then this function
			simply checks if the variable is set. If <data> is a constant
			then this function checks if the constant is non empty.
			Since KVIrc treats empty strings as "unset" values then
			this function could be also called "isNonEmpty" and it is
			the perfect opposite of [fnc]$isEmpty[/fnc]
		@seealso:
			[fnc]$isEmpty[/fnc], [cmd]unset[/cmd]
	*/

	KVSCF(isSet)
	{
#ifdef COMPILE_NEW_KVS
		KviKvsVariant * v;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("data",KVS_PT_VARIANT,0,v)
		KVSCF_PARAMETERS_END

		KVSCF_pRetBuffer->setBoolean(!v->isEmpty());
#endif
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: istimer
		@type:
			function
		@title:
			$isTimer
		@short:
			Checks for a timer existence
		@syntax:
			<boolean> $istimer(<name:string>)
		@description:
			Returns 1 if the timer named <name> is actually running, else 0
		@seealso:
			[cmd]timer[/cmd], [cmd]killtimer[/cmd]
	*/

	KVSCF(isTimer)
	{
		TQString szName;

		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("timerName",KVS_PT_NONEMPTYSTRING,0,szName)
		KVSCF_PARAMETERS_END
		KVSCF_pRetBuffer->setBoolean(KviKvsTimerManager::instance()->timerExists(szName));
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: iswellknown
		@type:
			function
		@title:
			$isWellKnown
		@short:
			Returns $true if the specified user is well known
		@syntax:
			<bool> $isWellKnown(<nickname:string>)
		@description:
			Returns 1 if KVIrc has the basic user information about the specified <nickname>.[br]
			The basic information include the username and hostname.[br]
			This is almost always true if the user is on a channel with you or
			you have an open query with him.[br]
			If $isWellKnown returns 0, [fnc]$username[/fnc] and [fnc]$hostname[/fnc]
			will return empty strings.[br]
			In this case you must use [cmd]awhois[/cmd] to obtain the user basic information.[br]
	*/

	KVSCF(isWellKnown)
	{
		TQString szNick;

		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("nick",KVS_PT_NONEMPTYSTRING,0,szNick)
		KVSCF_PARAMETERS_END

		if(KVSCF_pContext->window()->console())
		{
			if(KVSCF_pContext->window()->console()->isConnected())
			{
				KviIrcUserEntry * e = KVSCF_pContext->window()->connection()->userDataBase()->find(szNick);
				if(e)
				{
					KVSCF_pRetBuffer->setBoolean(e->hasHost() && e->hasUser());
					return true;
				}
			}
		}

		KVSCF_pRetBuffer->setBoolean(false);
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: k
		@type:
			function
		@title:
			$k
		@short:
			Returns the COLOR mIRC control character
		@syntax:
			<string> $k(<foreground:integer>[,<background:integer>])
			<string> $k
		@description:
			Returns the COLOR mIRC control character (TQt::CTRL+K).[br]
			If <foreground> and <background> are passed, a standard mIRC
			color escape is returned.[br]
		@seealso:
			[fnc]$b[/fnc]
	*/

	KVSCF(k)
	{
		kvs_uint_t iFore,iBack;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("foreground",KVS_PT_UINT,KVS_PF_OPTIONAL,iFore)
			KVSCF_PARAMETER("background",KVS_PT_UINT,KVS_PF_OPTIONAL,iBack)
		KVSCF_PARAMETERS_END

		TQString szRet = TQChar(KVI_TEXT_COLOR);
		if(KVSCF_pParams->count() > 0)
		{
			KviTQString::appendFormatted(szRet,"%u",iFore);
			if(KVSCF_pParams->count() > 1)
				KviTQString::appendFormatted(szRet,",%u",iBack);
		}
		KVSCF_pRetBuffer->setString(szRet);
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: keys
		@type:
			function
		@title:
			$keys
		@short:
			Returns the array of keys of a hash
		@syntax:
			<array> $keys(<hash_value:hash>)
		@description:
			Returns an array with the keys of the <hash> parameter.
			<hash> must be obviously a hash (or eventually an empty variable
			that is treated as an empty hash).
		@seealso:
			[cmd]foreach[/cmd]
	*/

	KVSCF(keys)
	{
#ifdef COMPILE_NEW_KVS
		KviKvsHash * pHash;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("hash",KVS_PT_HASH,0,pHash)
		KVSCF_PARAMETERS_END

		KviKvsArray * a = new KviKvsArray();
		kvs_int_t idx = 0;
		KviKvsHashIterator it(*(pHash->dict()));
		while(it.current())
		{
			a->set(idx,new KviKvsVariant(it.currentKey()));
			idx++;
			++it;
		}
		KVSCF_pRetBuffer->setArray(a);
#endif
		return true;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: lang
		@type:
			function
		@title:
			$lang
		@short:
			Returns name of currently used language
		@syntax:
			<string> $lang([<type:string>])
		@description:
			Returns the short name of currently used language
			Type <type> should be one of: [br]
			"full"  - returns full locale name, such as ru_RU.UTF-8 (default)
			"lang"  - return language name, such as "ru_RU"
			"short" - returns only language group such as "ru"
	*/

	KVSCF(lang)
	{
		TQString szType;

		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("type",KVS_PT_NONEMPTYSTRING,KVS_PF_OPTIONAL,szType)
		KVSCF_PARAMETERS_END

		TQString szLocale(KviLocale::localeName().ptr());
		if(szType=="lang") KVSCF_pRetBuffer->setString(szLocale.left(5));
		else if(szType=="short") KVSCF_pRetBuffer->setString(szLocale.left(2));
		else KVSCF_pRetBuffer->setString(szLocale);
		return true;
	}




	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: length
		@type:
			function
		@title:
			$length
		@short:
			Returns the length of a variable
		@syntax:
			<integer> $length(<value:variant>)
		@description:
			When <value> is an array or a hash, it returns the number
			of its elements. When <value> is an object reference it returns 0.
			In all the other cases <value> is interpreted
			as a string and its length is returned.
		@seealso:
			[fnc]$str.len[/fnc]
	*/

	KVSCF(length)
	{
		KviKvsVariant * pVar;
		KVSCF_PARAMETERS_BEGIN
			KVSCF_PARAMETER("value",KVS_PT_VARIANT,0,pVar)
		KVSCF_PARAMETERS_END

		switch(pVar->type())
		{
			case KviKvsVariantData::Array:
				KVSCF_pRetBuffer->setInteger(pVar->array()->size());
			break;
			case KviKvsVariantData::Hash:
				KVSCF_pRetBuffer->setInteger(pVar->hash()->size());
			break;
			case KviKvsVariantData::HObject:
				KVSCF_pRetBuffer->setInteger(0);
			break;
			default:
			{
				TQString tmp;
				pVar->asString(tmp);
				KVSCF_pRetBuffer->setInteger(tmp.length());
			}
			break;
		}
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////

	/*
		@doc: lf
		@type:
			function
		@title:
			$lf
		@short:
			Returns a line feed character
		@syntax:
			<string> $lf
		@description:
			Returns a line feed character
		@seealso:
			[fnc]$cr[/fnc], [fnc]$ascii[/fnc], [fnc]$char[/fnc]
	*/

	KVSCF(lf)
	{
		KVSCF_pRetBuffer->setString(TQString(TQChar('\n')));
		return true;
	}

};