File: KviKvsCoreSimpleCommands_sz.cpp

package info (click to toggle)
kvirc 4%3A5.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 31,704 kB
  • sloc: cpp: 230,732; perl: 2,106; pascal: 1,000; sh: 841; ansic: 244; makefile: 61; python: 54; xml: 19
file content (1142 lines) | stat: -rw-r--r-- 35,529 bytes parent folder | download | duplicates (3)
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
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
//=============================================================================
//
//   File : KviKvsCoreSimpleCommands_sz.cpp
//   Creation date : Fri 31 Oct 2003 00:04:25 by Szymon Stefanek
//
//   This file is part of the KVIrc IRC client distribution
//   Copyright (C) 2003-2010 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 option) 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.
//
//=============================================================================

#include "KviKvsCoreSimpleCommands.h"
#include "KviKvsPopupManager.h"
#include "KviKvsScript.h"
#include "KviIrcServerReconnectInfo.h"
#include "KviIrcConnection.h"
#include "KviConsoleWindow.h"
#include "KviLocale.h"
#include "KviApplication.h"
#include "KviAsynchronousConnectionData.h"
#include "KviMainWindow.h"
#include "KviNetUtils.h"
#include "KviMenuBar.h"
#include "KviUserInput.h"
#include "KviChannelWindow.h"
#include "KviQueryWindow.h"
#include "kvi_out.h"

#include <cstdlib>

namespace KviKvsCoreSimpleCommands
{
	/*
		@doc: say
		@type:
			command
		@title:
			say
		@syntax:
			say [-x] [-q] [-r=<window_id>] <text:string>
		@switches:
			!sw: -q | --quiet
			Run quietly
			!sw: -r=<window_id> | --rebind=<window_id>
			Standard command rebinding switch
			!sw: -x | --allow-exec
			Allow the execution of commands by interpreting the leading slash in the <text>
		@short:
			Type text in a window
		@description:
			This command is more or less equivalent to typing text in the input
			bar of the current window. If the -r switch is used
			then the command is rebound to the window specified by <window_id>.
			The main difference is that the variables and identifiers in <text>
			are always parsed (when typing this happen only if the text is a command).[br]
			The switch -x will make say evaluate and execute arbitrary commands, too:
			if <text> begins with a slash then it will be treated as a command
			to be evaluated and executed (after parsing the identifiers etc.).[br]
			If this happens, the executed command will not be send to the active channel.
			[example]
				/say -x /[cmd]echo[/cmd] foo
			[/example]
			will just print "foo".[br]
			Please note that using /say -x with a <text> that isn't a constant
			in the script but comes from some unidentified external source (e.g. the network)
			is a potential security flaw as it enables anyone to execute arbitrary commands:
			don't ever do it.[br]
			When the -x switch is not used, the text is never interpreted as a command.
			-q causes the command to run quietly.[br]
			Please note that /say will also trigger the [event:ontextinput]OnTextInput[/event] event.
			[b]Handle with care.[/b]
	*/

	KVSCSC(say)
	{
		QString szText;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("text", KVS_PT_STRING, KVS_PF_APPENDREMAINING, szText)
		KVSCSC_PARAMETERS_END

		if(KVSCSC_pSwitches->find('x', "allow-exec"))
		{
			// allow execution of commands
			if(!KviUserInput::parse(szText, KVSCSC_pWindow, __tr2qs_ctx("Say: injected commandline", "kvs")))
			{
				if(!KVSCSC_pSwitches->find('q', "quiet"))
					KVSCSC_pContext->warning(__tr2qs_ctx("Say parse error: Broken command", "kvs"));
			}
		}
		else
		{
			KviUserInput::parseNonCommand(szText, KVSCSC_pWindow);
		}
		return true;
	}

	/*
		@doc: server
		@type:
			command
		@title:
			server
		@syntax:
			server [switches] [<server:string> [<port:uint>]]
		@keyterms:
			connecting to a server
		@short:
			Connects to the specified server
		@switches:
			!sw: -b=<local address:string> | --bind-address=<local address:string>
			Bind the outgoing connection to <local address>. The <local address> must be
			either the IP address of a local interface or a local interface name itself
			(e.g. eth0 under Linux, en0 under macOS etc.) suitable for contacting the
			remote <server>:
			this means that if you're going to use the -i switch, the <local address>
			[b]must[/b] be an IPv6 address.
			If using a local interface name as <local address> (working on most, but not all systems),
			the KVIrc network engine will automatically detect the interface address (i.e. the default
			address of that interface).
			!sw: -c=<command sequence:string> | --command=<command sequence:string>
			The <command sequence> will be executed just after the login operations
			have been completed.
			!sw: -f=<socket filter:string> | --filter=<socket filter:string>
			Activates <socket filter> on the connection.
			A socket filter is a plugin that can adapt the IRC protocol to other existing protocols such as OpenNap.
			For plain IRC it is not needed.
			!sw: -i | --ipv6
			Connects to the <server> via the IPv6 protocol
			(if IPv6 support has been compiled in).
			!sw: -n | --new-context
			Forces the connection to be attempted in a new IRC context (server window) instead of the current one.
			!sw: -m | --minimized
			If a new console window is created (due to -n or -u) then create it as minimized.
			!sw: -p=<password:string> | --password=<password:string>
			Uses <password> to login to the server (the password will be stored in the server
			entry too).
			!sw: -q=<nick:string> | --nickname=<nick:string>
			Uses <nick> to login to the server (the nickname will be stored in the server
			entry too).
			!sw: -s | --ssl
			Activates the SSL support for this connection (if OpenSSL support has been compiled in).
			If SSL is enabled and no port is specified, the connection will be made to port 6697.
			!sw: -u | --unused-context
			Forces the connection to be attempted in the first IRC context that has
			no connection in progress. If all the IRC contexts have connections in progress
			then a new one is created.
			!sw: -l | --last
			When <server> and <port> are empty use the last ones used in the IRC context.
		@description:
			Attempts a connection to the specified <server>
			on the specified <port>. If no <port> is specified
			the default 6667 is used. If no <server> is specified,
			the currently selected server from the server list is used
			unless the -l switch is passed: in this case the last server
			that was used in the IRC context is re-used.
			If the <server> is a valid IPv6 address, the -i switch is implied.[br]
			The <server> is added to the server list (if not already
			there) and set as current.[br]
			[br]
			If <server> is in the form [i]id:<some_string>[/i] then <some_string>
			is interpreted as the server's internal ID (specified in the options dialog).
			This is useful when you need to force KVIrc to choose between multiple
			server entries with the same hostname and port stored in the database.[br]
			Please note that this form causes most of the switches to have no effect
			since the entry in the database will override them. If no server
			entry with the specified identifier is found then an error will be generated
			and the connection attempt will stop.
			[br]
			If <server> doesn't seem to be a valid IP address or hostname (i.e. it contains no dots)
			and it doesn't look to be in the form [i]id:<some_string>[/i] then
			it is assumed to be a network name and if such a network is found
			in the server list then the best server for that network is contacted.
			(KVIrc tries to guess the round-robin (random) servers first).[br]
			This behaviour can be forced by adding the [i]net:[/i] prefix to the <server>
			(so it will work even if the network name contains a dot).[br]
			[br]
			The connection is attempted in the current IRC context. If there is already
			a connection in progress then it is [i]brutally[/i] terminated.[br]
		@examples:
			[example]
				server irc.tin.it
				server -i irc6.ircd.it
				server -i ircd.stealth.net 6667
				server irc.undernet.org 6665
				server -n irc.openprojects.net
				server -c="join #kvirc" irc.stealth.net 6665
				server -b=ppp0 irc.tin.it
				server undernet
				server id:mybouncerwithusername1
				server id:mybouncerwithusername2
				server net:under.net
			[/example]
	*/

	KVSCSC(server)
	{
		QString szServer;
		kvs_uint_t uPort;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("server", KVS_PT_STRING, KVS_PF_OPTIONAL, szServer)
		KVSCSC_PARAMETER("port", KVS_PT_UINT, KVS_PF_OPTIONAL, uPort)
		KVSCSC_PARAMETERS_END

		KviConsoleWindow * console = nullptr;
		if(KVSCSC_pSwitches->find('n', "new-context"))
			console = g_pMainWindow->createNewConsole(false, !KVSCSC_pSwitches->find('m', "minimized"));
		else
		{
			if(KVSCSC_pSwitches->find('u', "unused-context"))
			{
				// first try the current console
				console = KVSCSC_pWindow->console();
				if(console)
				{
					// if there is a connection in progress, proceed in searching
					if(console->connectionInProgress())
					{
						console = nullptr;
					}
				}
				if(!console)
				{
					// yep, have to search
					console = g_pMainWindow->firstNotConnectedConsole();
					if(!console)
					{
						console = g_pMainWindow->createNewConsole(false, !KVSCSC_pSwitches->find('m', "minimized"));
					}
				}
			}
			else
				console = KVSCSC_pWindow->console();
		}

		QString szCmd, szBindAddress, szSocketFilter, szPassword, szNick;
		KVSCSC_pSwitches->getAsStringIfExisting('c', "command", szCmd);
		KVSCSC_pSwitches->getAsStringIfExisting('b', "bind-address", szBindAddress);
		KVSCSC_pSwitches->getAsStringIfExisting('f', "filter", szSocketFilter);
		KVSCSC_pSwitches->getAsStringIfExisting('p', "password", szPassword);
		KVSCSC_pSwitches->getAsStringIfExisting('q', "nickname", szNick);

		if(!console)
		{
			KVSCSC_pContext->error(__tr2qs_ctx("Couldn't find a suitable IRC context for the connection, try using -n or -u", "kvs"));
			return false;
		}

		if(szServer.isEmpty())
		{
			// just as hitting "connect"
			if(console->connectionInProgress())
			{
				KVSCSC_pContext->error(__tr2qs_ctx("Another connection is already in progress in the selected IRC context", "kvs"));
				return false;
			}

			KviAsynchronousConnectionData * d = new KviAsynchronousConnectionData();
			d->bUseLastServerInContext = KVSCSC_pSwitches->find('l', "last") != nullptr;
			d->szCommandToExecAfterConnect = szCmd;
			d->szBindAddress = szBindAddress;
			d->szPass = szPassword;
			d->szNick = szNick;
			d->szLinkFilter = szSocketFilter;

			d->m_pReconnectInfo = new KviIrcServerReconnectInfo();
			d->m_pReconnectInfo->m_szNick = szNick;
			d->m_pReconnectInfo->m_szPass = szPassword;

			console->context()->setAsynchronousConnectionData(d);
			console->context()->connectToCurrentServer();
		}
		else
		{
			// server is not empty.
			KviAsynchronousConnectionData * d = new KviAsynchronousConnectionData();
			d->bUseSSL = (KVSCSC_pSwitches->find('s', "ssl") != nullptr);
			d->bSTARTTLS = false;
			d->szServer = szServer;
			// if the user wants to connect using ssl but didn't specify a port, default to 6697
			if (d->bUseSSL && !(uPort > 0))uPort = 6697;
			d->uPort = (kvi_u32_t)uPort;
			d->szLinkFilter = szSocketFilter;
			d->bPortIsOk = (uPort > 0);
#ifdef COMPILE_IPV6_SUPPORT
			d->bUseIPv6 = (KVSCSC_pSwitches->find('i', "ipv6") != nullptr) || KviNetUtils::isValidStringIPv6(szServer);
#else
			d->bUseIPv6 = false;
#endif
			d->szCommandToExecAfterConnect = szCmd;
			d->szBindAddress = szBindAddress;
			d->szPass = szPassword;
			d->szNick = szNick;

			d->m_pReconnectInfo = new KviIrcServerReconnectInfo();
			d->m_pReconnectInfo->m_szNick = szNick;
			d->m_pReconnectInfo->m_szPass = szPassword;

			console->context()->setAsynchronousConnectionData(d);
			console->context()->beginAsynchronousConnect(0);
		}

		return true;
	};

	/*
		@doc: service
		@type:
			command
		@title:
			service
		@syntax:
			service <nickname> <reserved> <distribution> <type> <reserved> [:]<info>
		@short:
			Registers a new service
		@description:
			Registers a new IRC service: this is for IRC operators only.[br]
			This command is an [doc:rfc2812wrappers]RFC2812 command wrapper[/doc]; see that document for more information.[br]
			WARNING: the <info> parameter may contain spaces: in that case you [b]must[/b] add the leading [b]]:[/b]] character.[br]
	*/
	// RFC2921 wrapper

	/*
		@doc: setmenu
		@type:
			command
		@title:
			setmenu
		@syntax:
			setmenu [-q] [-i=<index:integer>] <visible_text:string> [menu_name:string]
		@short:
			Adds a popup menu to the menu bar
		@switches:
			!sw: -q | --quiet
			Run quietly: do not print any warnings
			!sw: -i=<index:integer> | --index=<index:integer>
			Place the popup menu on the left of the existing menubar item at the specified index
		@description:
			Adds an [b]existing[/b] popup menu to the current frame's menu bar.[br]
			<visible_text> is used as menu identification and obviously as the visible
			menu bar text for the new popup.[br]
			If a popup menu with the same <visible_text> or the same <menu_name> already exists in
			the current frame, it is removed first.[br]
			<visible_text> can optionally contain the [b]]&[/b]] character to identify
			the popup menu accelerator.[br]
			[menu_name], if given, must be a valid name of a popup menu created earlier
			with [cmd]defpopup[/cmd] (or the popup editor).[br]
			If [menu_name] is not given, the popup menu identified by <visible_text> is removed.[br]
			If the -i switch is used, the new popup menu will be placed to the left of the default
			menu-bar item specified in the [b]zero based[/b] <index>.[br]
			menu-bar text item: the new popup menu will be placed on the left of that default item.[br]
			If -q is used, this command prints no warnings (intended for use when you are unsure that
			the menu exists - normal warning messages are debugging aids and have no consequence).[br]
		@seealso:
			[cmd]defpopup[/cmd]
		@examples:
			[example]
				setmenu -q -i=2 Test a popup
				setmenu Test
				setmenu ThisDoesNotExist
				setmenu -q ThisDoesNotExist
			[/example]
	*/

	KVSCSC(setmenu)
	{
		QString szVisibleText, szPopupName;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("visible_text", KVS_PT_NONEMPTYSTRING, 0, szVisibleText)
		KVSCSC_PARAMETER("popup_name", KVS_PT_STRING, KVS_PF_OPTIONAL, szPopupName)
		KVSCSC_PARAMETERS_END

		if(szPopupName.isEmpty())
		{
			if(!(g_pMainWindow->mainMenuBar()->removeMenu(szVisibleText)))
			{
				if(!KVSCSC_pSwitches->find('q', "quiet"))
					KVSCSC_pContext->warning(__tr2qs_ctx("No menu bar item with text '%Q'", "kvs"), &szVisibleText);
			}
			return true;
		}

		KviKvsPopupMenu * p = KviKvsPopupManager::instance()->lookup(szPopupName);
		int idx = -1;
		if(KviKvsVariant * pIdx = KVSCSC_pSwitches->find('i', "index"))
		{
			kvs_int_t iIdx;
			if(pIdx->asInteger(iIdx))
				idx = iIdx;
			else
			{
				if(!KVSCSC_pSwitches->find('q', "quiet"))
					KVSCSC_pContext->warning(__tr2qs_ctx("Invalid index specified: ignored", "kvs"));
			}
		}
		g_pMainWindow->mainMenuBar()->removeMenu(szVisibleText);

		idx = g_pMainWindow->mainMenuBar()->getDefaultItemRealIndex(idx);

		if(p)
		{
			g_pMainWindow->mainMenuBar()->addMenu(szVisibleText, p, idx);
		}
		else
		{
			if(!KVSCSC_pSwitches->find('q', "quiet"))
				KVSCSC_pContext->warning(__tr2qs_ctx("The popup '%Q' is not defined", "kvs"), &szPopupName);
		}

		return true;
	}

	/*
		@doc: setreturn
		@type:
			command
		@title:
			setreturn
		@syntax:
			setreturn <string>
		@short:
			Sets the return value of the current command sequence
		@description:
			Sets the return value of the current command sequence to <string>.
			You can call this command multiple times in a command sequence
			(so in fact use it as a write-only variable).
		@examples:
		@seealso:
			[cmd]return[/cmd]
	*/

	KVSCSC(setreturn)
	{
		Q_UNUSED(__pSwitches);

		if(KVSCSC_pParams->count() == 0)
		{
			KVSCSC_pContext->returnValue()->setNothing();
			return false;
		}
		if(KVSCSC_pParams->count() == 1)
		{
			KVSCSC_pContext->returnValue()->copyFrom(*(KVSCSC_pParams->first()));
			return false;
		}

		QString all;
		KVSCSC_pParams->allAsString(all);
		KVSCSC_pContext->returnValue()->setString(all);
		return true;
	}

	/*
		@doc: sockets
		@type:
			command
		@title:
			sockets
		@syntax:
			sockets [[remote server] server mask]
		@short:
			Requests the sockets info from a server
		@description:
			Requests the sockets information from the specified server or the current server if no [remote server] is specified.[br]
			The reply can be filtered by <server mask>.[br]
			This command is an [doc:rfc2812wrappers]RFC2812 command wrapper[/doc]; see that document for more information.[br]
	*/
	// RFC2812 wrapper

	/*
		@doc: squery
		@type:
			command
		@title:
			squery
		@syntax:
			squery <target> <text>
		@switches:
			!sw: -q | --quiet
			Do not print any output
		@short:
			Sends a message to a service
		@description:
			Sends a message to a service in a form similar to [cmd]privmsg[/cmd].[br]
			<target> must be a service(see RFC2812).
			This command is [doc:connection_dependent_commands]connection dependent[/doc].[br]
		@examples:
			[example]
				squery Alis LIST * -min 100
			[/example]
	*/

	KVSCSC(squery)
	{
		QString szTarget, szText;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("target", KVS_PT_NONEMPTYSTRING, 0, szTarget)
		KVSCSC_PARAMETER("text", KVS_PT_STRING, KVS_PF_OPTIONAL | KVS_PF_APPENDREMAINING, szText)
		KVSCSC_PARAMETERS_END

		KVSCSC_REQUIRE_CONNECTION

		KviWindow * w = KVSCSC_pConnection->findChannel(szTarget);
		if(!w)
			w = KVSCSC_pConnection->findQuery(szTarget);

		if(w)
			w->ownMessage(szText, !KVSCSC_pSwitches->find('q', "quiet"));
		else
		{
			QByteArray szT = KVSCSC_pConnection->encodeText(szTarget);
			QByteArray szD = KVSCSC_pConnection->encodeText(szText);

			if(!(KVSCSC_pConnection->sendFmtData("SQUERY %s :%s", szT.data(), szD.data())))
				return KVSCSC_pContext->warningNoIrcConnection();

			if(!KVSCSC_pSwitches->find('q', "quiet"))
				KVSCSC_pWindow->output(KVI_OUT_OWNPRIVMSG, "[SQUERY >>> %Q]: %Q", &szTarget, &szText);
		}

		return true;
	}

	/*
		@doc: squit
		@type:
			command
		@title:
			squit
		@syntax:
			squit <server> [:]<comment>
		@short:
			Disconnects a server socket (ircops only)
		@description:
			Disconnects a server socket: this is for IRC operators only.[br]
			This command is an [doc:rfc2812wrappers]RFC2812 command wrapper[/doc]; see that document for more information.[br]
			WARNING: the <comment> parameter may contain spaces: in that case you MUST add the leading [b]]:[/b]] character
			before.[br]
	*/
	// RFC2812 wrapper

	/*
		@doc: srand
		@type:
			command
		@title:
			srand
		@syntax:
			srand <seed:integer>
		@short:
			Initializes the random number generator
		@description:
			Initializes the random number generator [i]seeding[/i] it with
			<seed> which must be an integer. If no <seed> is passed it defaults to 1.
			Sequences of random numbers can be repeated by using the
			same <seed> value.
		@examples:
	*/

	KVSCSC(srand)
	{
		Q_UNUSED(__pSwitches);
		QString tmp;

		for(int i = 0; i < 10; i++)
			tmp.append(QChar((::rand() % 30) + 65));
		kvs_int_t iSeed;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("seed", KVS_PT_INT, KVS_PF_OPTIONAL, iSeed)
		KVSCSC_PARAMETERS_END
		if(KVSCSC_pParams->count() < 1)
			iSeed = 1;
		::srand(iSeed);
		return true;
	}

	/*
		@doc: stats
		@type:
			command
		@title:
			stats
		@syntax:
			stats [query [target server]]
		@short:
			Requests the stats info from  a server
		@description:
			Requests the stats information from the specified server or the current server if no [target server] is specified.[br]
			The query parameter is usually a letter indicating the type of the query requested: some query letters
			are defined by [anchorlink:https://tools.ietf.org/html/rfc2812]RFC2812[/anchorlink] and some others are server implementation dependent.[br]
			This command is an [doc:rfc2812wrappers]RFC2812 command wrapper[/doc]; see that document for more information.[br]
	*/
	// RFC2812 wrapper

	/*
		@doc: time
		@type:
			command
		@title:
			time
		@syntax:
			time [target server]
		@short:
			Requests the current local time info from a server
		@description:
			Requests time information from the specified server or the current server if no [target server] is specified.[br]
			This command is an [doc:rfc2812wrappers]RFC2812 command wrapper[/doc]; see that document for more information.[br]
	*/
	// RFC2812 wrapper

	/*
		@doc: topic
		@type:
			command
		@title:
			topic
		@syntax:
			topic [<channel:string> [topic text:string]]
		@short:
			Changes topic for the specified channel
		@description:
			Changes the topic for the specified <channel> to <topic text>.
			If no topic is specified, the current channel topic will be returned.[br]
			This command is [i]]server based[/i]]; you will see its results only
			after the server acknowledges it.[br]
			This command is [doc:connection_dependent_commands]connection dependent[/doc].
		@examples:
			[example]
				topic #kvirc KVIrc 3.4.0 has been released!
			[/example]
	*/

	KVSCSC(topic)
	{
		Q_UNUSED(__pSwitches);

		QString szChannel;
		QString szTopic;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("channel", KVS_PT_NONEMPTYSTRING, KVS_PF_OPTIONAL, szChannel)
		KVSCSC_PARAMETER("topic", KVS_PT_STRING, KVS_PF_OPTIONAL | KVS_PF_APPENDREMAINING, szTopic)
		KVSCSC_PARAMETERS_END

		KVSCSC_REQUIRE_CONNECTION

		if(szChannel.isEmpty())
		{
			if(KVSCSC_pWindow->type() == KviWindow::Channel)
				szChannel = KVSCSC_pWindow->target();
			else
			{
				KVSCSC_pContext->error(__tr2qs_ctx("No target channel specified and the current window is not a channel", "kvs"));
				return false;
			}
		}

		QByteArray szC = KVSCSC_pConnection->encodeText(szChannel);
		QByteArray szT = KVSCSC_pConnection->encodeText(szTopic);
		if(szTopic.isEmpty())
		{
			if(!KVSCSC_pConnection->sendFmtData("TOPIC %s", szC.data()))
				return KVSCSC_pContext->warningNoIrcConnection();
		}
		else
		{
			if(!KVSCSC_pConnection->sendFmtData("TOPIC %s :%s", szC.data(), szT.data()))
				return KVSCSC_pContext->warningNoIrcConnection();
		}

		return true;
	}

	/*
		@doc: trace
		@type:
			command
		@title:
			trace
		@syntax:
			trace <target>
		@short:
			Requests trace information about a specified machine in the network
		@description:
			Requests trace information about a specified machine in the network.[br]
			This command is an [doc:rfc2812wrappers]RFC2812 command wrapper[/doc]; see that document for more information.[br]
	*/
	// RFC2812 wrapper

	/*
		@doc: trload
		@type:
			command
		@title:
			trload
		@syntax:
			trload [-v] <catalogue:string> [<catalogue_dir:string>]
		@switches:
			!sw: -v | --verbose
			Warn if a catalogue for the current language cannot be found
		@short:
			Loads a translation catalogue
		@description:
			Loads the specified translation <catalogue> in the current user language.[br]
			The translation catalogues are *.mo files compiled with the standard
			msgfmt program from the gettext package.[br]
			The syntax of the catalogue names is:[br]
			[b]<catalogue_dir>/<catalogue>_<language>.mo[/b][br]
			KVIrc looks for the catalogues in <catalogue_dir> (if specified)
			and in the locale subdirectory of the global and local KVIrc directories.[br]
			<language> is choose automatically by KVIrc depending on the user's locale.[br]
			Catalogues MUST be in UTF-8 encoding.[br]
			After a translation catalogue has been loaded you can
			access its strings by the means of [fnc]$tr[/fnc].[br]
			This function doesn't print any warning unless -v is specified.[br]
			Please note that KVIrc attempts to load the <catalogue> automatically
			when $tr() is used but it looks only in [fnc]$file.localdir[/fnc]/locale/
			and in [fnc]$file.globaldir[/fnc]/locale/. This command is then useful
			to load catalogues that reside in different directories.[br]
			[b]NOTE[/b][br]
			This feature is currently work in progress: the scripting engine
			is not yet fully Unicode and thus some more exotic translations may still suffer...
		@seealso:
			[fnc]$tr[/fnc], [cmd]trunload[/cmd]
	*/

	KVSCSC(trload)
	{
		QString szCatalogue, szDir;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("catalogue", KVS_PT_NONEMPTYSTRING, 0, szCatalogue)
		KVSCSC_PARAMETER("catalogueDir", KVS_PT_STRING, KVS_PF_OPTIONAL, szDir)
		KVSCSC_PARAMETERS_END

		if(!szDir.isEmpty())
		{
			if(KviLocale::instance()->loadCatalogue(szCatalogue, szDir))
				return true;
		}

		g_pApp->getLocalKvircDirectory(szDir, KviApplication::Locale);

		if(KviLocale::instance()->loadCatalogue(szCatalogue, szDir))
			return true;

		g_pApp->getGlobalKvircDirectory(szDir, KviApplication::Locale);

		if(KviLocale::instance()->loadCatalogue(szCatalogue, szDir))
			return true;

		if(KVSCSC_pSwitches->find('v', "verbose"))
			KVSCSC_pContext->warning(__tr2qs_ctx("No catalogue %Q for the current language found", "kvs"), &szCatalogue);

		return true;
	}

	/*
		@doc: trunload
		@type:
			command
		@title:
			trunload
		@syntax:
			trunload [-v] <catalogue:string>
		@switches:
			!sw: -v | --verbose
			Warn if the specified catalogue wasn't loaded at all
		@short:
			Unloads a translation catalogue
		@description:
			Unloads a specified translation catalogue.[br]
			When you no longer need the translation strings contained in the
			catalogue just unload it to free memory.[br]
			This command prints no warnings unload -v is used.[br]
		@seealso:
			[fnc]$tr[/fnc], [cmd]trload[/cmd]
	*/

	KVSCSC(trunload)
	{
		QString szCatalogue;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("catalogue", KVS_PT_NONEMPTYSTRING, 0, szCatalogue)
		KVSCSC_PARAMETERS_END

		if(!KviLocale::instance()->unloadCatalogue(szCatalogue))
		{
			if(KVSCSC_pSwitches->find('v', "verbose"))
				KVSCSC_pContext->warning(__tr2qs_ctx("The catalogue %Q was not loaded", "kvs"), &szCatalogue);
		}
		return true;
	}

	/*
		@doc: unban
		@type:
			command
		@title:
			unban
		@syntax:
			unban <mask_list>
		@short:
			Unsets ban masks for the channel
		@description:
			Removes the ban masks specified in the <mask_list>,
			which is a comma separated list of nicknames.
			This command works only if executed in a channel window.
			The command is translated to a set of MODE messages containing
			a variable number of -b flags.
			This command is [doc:connection_dependent_commands]connection dependent[/doc].
		@examples:
			[example]
				# Unban people on the current channel (say #kvirc)
				unban Maxim,Gizmo!*@*,*!root@*
				# Do the same but from another window belonging to this IRC context
				unban -r=[fnc]$channel[/fnc](#kvirc) Maxim,Gizmo!*@*,*!root@*
				# Do the same from any window
				unban -r=[fnc]$channel[/fnc](#kvirc,[fnc]$context[/fnc](irc.myirc.net,Pragma)) Maxim,Gizmo!*@*,*!root*@*
			[/example]
		@seealso:
			[cmd]op[/cmd],
			[cmd]deop[/cmd],
			[cmd]voice[/cmd],
			[cmd]devoice[/cmd],
			[cmd]ban[/cmd]
	*/

	KVSCSC(unban)
	{
		return multipleModeCommand(__pContext, __pParams, __pSwitches, '-', 'b');
	}

	/*
		@doc: userop
		@type:
			command
		@title:
			userop
		@syntax:
			userop <nickname_list>
		@short:
			Sets userop flag for the specified users
		@description:
			Sets the voice flag for the users specified in <nickname_list>,
			which is a comma separated list of nicknames.
			This command works only if executed in a channel window.
			The command is translated to a set of MODE messages containing
			a variable number of +u flags.
			This command is [doc:connection_dependent_commands]connection dependent[/doc].
		@examples:
			[example]
				userop Pragma,Crocodile
			[/example]
		@seealso:
			[cmd]chanowner[/cmd], [cmd]dechanowner[/cmd], [cmd]chanadmin[/cmd], [cmd]dechanadmin[/cmd], [cmd]op[/cmd], [cmd]halfop[/cmd], [cmd]dehalfop[/cmd], [cmd]voice[/cmd], [cmd]devoice[/cmd], [cmd]deuserop[/cmd]
	*/

	KVSCSC(userop)
	{
		return multipleModeCommand(__pContext, __pParams, __pSwitches, '+', 'u');
	}

	/*
		@doc: version
		@type:
			command
		@title:
			version
		@syntax:
			version [target server]
		@short:
			Requests the version of a server
		@description:
			Requests the version information from the specified server or the current server if no [target server] is specified.[br]
			This command is an [doc:rfc2812wrappers]RFC2812 command wrapper[/doc]; see that document for more information.[br]
	*/
	// RFC2812 wrapper

	/*
		@doc: voice
		@type:
			command
		@title:
			voice
		@syntax:
			voice <nickname_list>
		@short:
			Sets voice flag for the specified users
		@description:
			Sets the voice flag for the users specified in <nickname_list>,
			which is a comma separated list of nicknames.
			This command works only if executed in a channel window.
			The command is translated to a set of MODE messages containing
			a variable number of +v flags.
			This command is [doc:connection_dependent_commands]connection dependent[/doc].
		@examples:
			[example]
				voice Pragma,Crocodile
			[/example]
		@seealso:
			[cmd]chanowner[/cmd], [cmd]dechanowner[/cmd], [cmd]chanadmin[/cmd], [cmd]dechanadmin[/cmd], [cmd]op[/cmd], [cmd]halfop[/cmd], [cmd]dehalfop[/cmd], [cmd]devoice[/cmd], [cmd]userop[/cmd], [cmd]deuserop[/cmd]
	*/

	KVSCSC(voice)
	{
		return multipleModeCommand(__pContext, __pParams, __pSwitches, '+', 'v');
	}

	/*
		@doc: warning
		@type:
			command
		@title:
			warning
		@syntax:
			warning <message:text>
		@short:
			Prints a warning message
		@description:
			Prints a warning message with the appropriate color and message type.
			It doesn't alter the execution of the current script.
		@seealso:
			[cmd]error[/cmd]
	*/

	KVSCSC(warning)
	{
		Q_UNUSED(__pSwitches);

		QString szAll;
		KVSCSC_pParams->allAsString(szAll);
		KVSCSC_pContext->warning("%Q", &szAll);

		return true;
	}

	/*
		@doc: wallops
		@type:
			command
		@title:
			wallops
		@syntax:
			wallops <message:text>
		@short:
			Broadcasts a WALLOPS message
		@description:
			Broadcasts a WALLOPS message to all users whom are set
			to receive WALLOPS messages.
		@seealso:
			[cmd]operwall[/cmd]
	*/

	KVSCSC(wallops)
	{
		Q_UNUSED(__pSwitches);

		QString szMessage;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("message", KVS_PT_NONEMPTYSTRING, KVS_PF_APPENDREMAINING, szMessage)
		KVSCSC_PARAMETERS_END

		KVSCSC_REQUIRE_CONNECTION

		QByteArray szData = KVSCSC_pContext->connection()->encodeText(szMessage);

		if(!KVSCSC_pContext->connection()->sendFmtData("WALLOPS :%s", szData.data()))
			return KVSCSC_pContext->warningNoIrcConnection();

		return true;
	}

	/*
		@doc: who
		@type:
			command
		@title:
			who
		@syntax:
			who <filter>
		@short:
			Requests WHO information
		@description:
			Requests WHO information about users/channels.[br]
			The <filter> is a string specifying the subject of the query.
			In the standard IRC protocol the subject can be a nickname or a channel.
			If a channel name is used as filter then the list of all the users on that channel is returned.
			Recent IRC servers support the WHOX extension which specifies that the <filter> can have
			a much more complex syntax: <mask1> <options> [<mask2>].
			<mask1> is a comma separated list of filters that can contain wildcards (* and ?),
			<options> is a set of characters specifying what <mask1> is matching (nicknames, channel
			names, user names, real names, IP addresses etc) and what kind of information should be returned.
			Look for the extended WHOX syntax on your favorite search engine.[br]
			If no parameter is specified at all, it requests a WHO information about the current
			channel.[br]
			This command is [doc:connection_dependent_commands]connection dependent[/doc].
		@examples:
			[example]
				[comment]# Lists users on #kvirc[/comment]
				who #kvirc
				[comment]# WHOX: Get a list of +o users, aka ircops (works on unreal, bahamut, others)[/comment]
				who 0 o%nuhs
			[/example]
		@seealso:
			[cmd]names[/cmd]
	*/

	KVSCSC(who)
	{
		Q_UNUSED(__pSwitches);

		QString szData;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("filter", KVS_PT_NONEMPTYSTRING, KVS_PF_OPTIONAL | KVS_PF_APPENDREMAINING, szData)
		KVSCSC_PARAMETERS_END

		KVSCSC_REQUIRE_CONNECTION

		if(szData.isEmpty())
		{
			if(KVSCSC_pWindow->type() != KviWindow::Channel)
			{
				KVSCSC_pContext->error(__tr2qs_ctx("No target mask/channel specified and the current window is not a channel", "kvs"));
				return false;
			}

			szData = KVSCSC_pWindow->target();
		}

		QByteArray szData2 = KVSCSC_pConnection->encodeText(szData);

		if(!KVSCSC_pConnection->sendFmtData("WHO %s", szData2.data()))
			return KVSCSC_pContext->warningNoIrcConnection();

		return true;
	}

	/*
		@doc: whois
		@type:
			command
		@title:
			whois
		@syntax:
			whois [server] <nickname>
		@short:
			Requests user information
		@description:
			Requests information about an IRC user specified by <nickname>.[br]
			If [server] is specified, the request is directed to that one. [server]
			may be a nickname so that the request is redirected to the server that
			the user with that nickname is connected to.[br]
			An useful trick is to use the following syntax:[br]
			WHOIS <nickname> <nickname>[br]
			This will requests information about the user <nickname> to the server that he is currently
			connected to; returning the idle time among the other common information.[br]
			This command is [doc:connection_dependent_commands]connection dependent[/doc].
		@examples:
			[example]
			[comment]# Query info about Pragma[/comment]
				whois Pragma
				[comment]# Get the Pragma idle time[/comment]
				whois Pragma Pragma
			[/example]
		@seealso:
			[cmd]whowas[/cmd]
	*/

	KVSCSC(whois)
	{
		Q_UNUSED(__pSwitches);

		QString szNick;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("nickname", KVS_PT_NONEMPTYSTRING, KVS_PF_APPENDREMAINING, szNick)
		KVSCSC_PARAMETERS_END

		KVSCSC_REQUIRE_CONNECTION

		QByteArray szData = KVSCSC_pContext->connection()->encodeText(szNick);

		if(!KVSCSC_pContext->connection()->sendFmtData("WHOIS %s", szData.data()))
			return KVSCSC_pContext->warningNoIrcConnection();

		return true;
	}

	/*
		@doc: whowas
		@type:
			command
		@title:
			whowas
		@syntax:
			whowas <nickname>
		@short:
			Requests user information
		@description:
			Requests information about an IRC user specified by <nickname>.[br]
			WHOWAS requests [i]history[/i] records. See [anchorlink:https://tools.ietf.org/html/rfc2812]RFC2812[/anchorlink] for more info.[br]
			This command is [doc:connection_dependent_commands]connection dependent[/doc].
		@examples:
			[example]
				[comment]# Query past info about Pragma[/comment]
				whowas Pragma
			[/example]
		@seealso:
			[cmd]whois[/cmd]
	*/

	KVSCSC(whowas)
	{
		Q_UNUSED(__pSwitches);

		QString szNick;
		KVSCSC_PARAMETERS_BEGIN
		KVSCSC_PARAMETER("nickname", KVS_PT_NONEMPTYSTRING, KVS_PF_APPENDREMAINING, szNick)
		KVSCSC_PARAMETERS_END

		KVSCSC_REQUIRE_CONNECTION

		QByteArray szData = KVSCSC_pContext->connection()->encodeText(szNick);

		if(!KVSCSC_pContext->connection())
			return KVSCSC_pContext->warningNoIrcConnection();
		if(!KVSCSC_pContext->connection()->sendFmtData("WHOWAS %s", szData.data()))
			return KVSCSC_pContext->warningNoIrcConnection();

		return true;
	}
};