]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/command/generic.qc
Remove pre/post includes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / command / generic.qc
1 #if defined(CSQC)
2         #include "../../dpdefs/csprogsdefs.qh"
3         #include "../constants.qh"
4         #include "../util.qh"
5         #include "../mapinfo.qh"
6         #include "generic.qh"
7         #include "shared_defs.qh"
8         #include "../../client/command/cl_cmd.qh"
9         #include "../notifications.qh"
10 #elif defined(MENUQC)
11 #elif defined(SVQC)
12         #include "../../dpdefs/progsdefs.qh"
13     #include "../../dpdefs/dpextensions.qh"
14     #include "../constants.qh"
15     #include "../util.qh"
16     #include "../test.qh"
17     #include "generic.qh"
18     #include "shared_defs.qh"
19     #include "../weapons/config.qh"
20     #include "../notifications.qh"
21     #include "../mapinfo.qh"
22     #include "../../server/command/common.qh"
23     #include "../../server/command/banning.qh"
24     #include "../../server/command/cmd.qh"
25     #include "../../server/command/sv_cmd.qh"
26 #endif
27
28 // =========================================================
29 //  Generic program common command code, written by Samual
30 //  Last updated: February 19th, 2012
31 // =========================================================
32
33 // used by generic commands for better help/usage information
34 string GetProgramCommandPrefix(void)
35 {
36         #ifdef SVQC
37         return "sv_cmd";
38         #endif
39         #ifdef CSQC
40         return "cl_cmd";
41         #endif
42         #ifdef MENUQC
43         return "menu_cmd";
44         #endif
45 }
46
47 // used by curl command
48 void Curl_URI_Get_Callback(int id, float status, string data)
49 {
50         int i = id - URI_GET_CURL;
51         float do_exec = curl_uri_get_exec[i];
52         string do_cvar = curl_uri_get_cvar[i];
53         if(status != 0)
54         {
55                 dprintf("error: status is %d\n", status);
56                 if(do_cvar)
57                         strunzone(do_cvar);
58                 return;
59         }
60         if(do_exec)
61                 localcmd(data);
62         if(do_cvar)
63         {
64                 cvar_set(do_cvar, data);
65                 strunzone(do_cvar);
66         }
67         if(!do_exec)
68                 if (!do_cvar)
69                         print(data);
70 }
71
72
73 // =======================
74 //  Command Sub-Functions
75 // =======================
76
77 void GenericCommand_addtolist(float request, float argc)
78 {
79         switch(request)
80         {
81                 case CMD_REQUEST_COMMAND:
82                 {
83                         if(argc >= 2)
84                         {
85                                 string original_cvar = argv(1);
86                                 string tmp_string = argv(2);
87
88                                 if(cvar_string(original_cvar) == "") // cvar was empty
89                                 {
90                                         cvar_set(original_cvar, tmp_string);
91                                 }
92                                 else // add it to the end of the list if the list doesn't already have it
93                                 {
94                                         argc = tokenizebyseparator(cvar_string(original_cvar), " ");
95                                         int i;
96                                         for(i = 0; i < argc; ++i)
97                                                 if(argv(i) == tmp_string)
98                                                         return; // already in list
99
100                                         cvar_set(original_cvar, strcat(tmp_string, " ", cvar_string(original_cvar)));
101                                 }
102                                 return;
103                         }
104                 }
105
106                 default:
107                         print("Incorrect parameters for ^2addtolist^7\n");
108                 case CMD_REQUEST_USAGE:
109                 {
110                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " addtolist variable value\n"));
111                         print("  Where 'variable' is what to add 'value' to.\n");
112                         print("See also: ^2removefromlist^7\n");
113                         return;
114                 }
115         }
116 }
117
118 void GenericCommand_qc_curl(float request, float argc)
119 {
120         switch(request)
121         {
122                 case CMD_REQUEST_COMMAND:
123                 {
124                         bool do_exec = false;
125                         string do_cvar = string_null;
126                         float key = -1;
127                         int i;
128                         for(i = 1; i+1 < argc; ++i)
129                         {
130                                 if(argv(i) == "--cvar" && i+2 < argc)
131                                 {
132                                         ++i;
133                                         do_cvar = strzone(argv(i));
134                                         continue;
135                                 }
136                                 if(argv(i) == "--exec")
137                                 {
138                                         do_exec = true;
139                                         continue;
140                                 }
141                                 if(argv(i) == "--key" && i+2 < argc)
142                                 {
143                                         ++i;
144                                         key = stof(argv(i));
145                                         continue;
146                                 }
147                                 break;
148                         }
149
150                         // now, argv(i) is the URL
151                         // following args may be POST parameters
152                         string url = argv(i);
153                         ++i;
154                         float buf = buf_create();
155                         int j;
156                         for(j = 0; i+1 < argc; i += 2)
157                                 bufstr_set(buf, ++j, sprintf("%s=%s", uri_escape(argv(i)), uri_escape(argv(i+1))));
158                         if(i < argc)
159                                 bufstr_set(buf, ++j, sprintf("submit=%s", uri_escape(argv(i))));
160
161                         float r;
162                         if(j == 0) // no args: GET
163                                 r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, string_null, string_null, -1, key);
164                         else // with args: POST
165                                 r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, "application/x-www-form-urlencoded", "&", buf, key);
166
167                         if(r)
168                         {
169                                 curl_uri_get_exec[curl_uri_get_pos] = do_exec;
170                                 curl_uri_get_cvar[curl_uri_get_pos] = do_cvar;
171                                 curl_uri_get_pos = (curl_uri_get_pos + 1) % (URI_GET_CURL_END - URI_GET_CURL + 1);
172                         }
173                         else
174                                 print(_("error creating curl handle\n"));
175
176                         buf_del(buf);
177
178                         return;
179                 }
180
181                 default:
182                 case CMD_REQUEST_USAGE:
183                 {
184                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " qc_curl [--key N] [--cvar] [--exec] URL [postargs...]"));
185                         return;
186                 }
187         }
188 }
189
190 void GenericCommand_dumpcommands(float request)
191 {
192         switch(request)
193         {
194                 case CMD_REQUEST_COMMAND:
195                 {
196                         float fh;
197                         string filename = strcat(GetProgramCommandPrefix(), "_dump.txt");
198                         fh = fopen(filename, FILE_WRITE);
199
200                         if(fh >= 0)
201                         {
202                                 #ifdef SVQC
203                                         CMD_Write("dump of server console commands:\n");
204                                         GameCommand_macro_write_aliases(fh);
205
206                                         CMD_Write("\ndump of networked client only commands:\n");
207                                         ClientCommand_macro_write_aliases(fh);
208
209                                         CMD_Write("\ndump of common commands:\n");
210                                         CommonCommand_macro_write_aliases(fh);
211
212                                         CMD_Write("\ndump of ban commands:\n");
213                                         BanCommand_macro_write_aliases(fh);
214                                 #endif
215
216                                 #ifdef CSQC
217                                         CMD_Write("dump of client commands:\n");
218                                         LocalCommand_macro_write_aliases(fh);
219                                 #endif
220
221                                 CMD_Write("\ndump of generic commands:\n");
222                                 GenericCommand_macro_write_aliases(fh);
223
224                                 print("Completed dump of aliases in ^2data/data/", GetProgramCommandPrefix(), "_dump.txt^7.\n");
225
226                                 fclose(fh);
227                         }
228                         else
229                         {
230                                 print("^1Error: ^7Could not dump to file!\n");
231                         }
232                         return;
233                 }
234
235                 default:
236                 case CMD_REQUEST_USAGE:
237                 {
238                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpcommands"));
239                         print("  No arguments required.\n");
240                         return;
241                 }
242         }
243 }
244
245 void GenericCommand_dumpnotifs(float request)
246 {
247         switch(request)
248         {
249                 case CMD_REQUEST_COMMAND:
250                 {
251                         #ifndef MENUQC
252                         float fh, alsoprint = false;
253                         string filename = argv(1);
254
255                         if(filename == "")
256                         {
257                                 filename = "notifications_dump.cfg";
258                                 alsoprint = false;
259                         }
260                         else if(filename == "-")
261                         {
262                                 filename = "notifications_dump.cfg";
263                                 alsoprint = true;
264                         }
265                         fh = fopen(filename, FILE_WRITE);
266
267                         if(fh >= 0)
268                         {
269                                 Dump_Notifications(fh, alsoprint);
270                                 printf("Dumping notifications... File located in ^2data/data/%s^7.\n", filename);
271                                 fclose(fh);
272                         }
273                         else
274                         {
275                                 printf("^1Error: ^7Could not open file '%s'!\n", filename);
276                         }
277                         #else
278                         print(_("Notification dump command only works with cl_cmd and sv_cmd.\n"));
279                         #endif
280                         return;
281                 }
282
283                 default:
284                 case CMD_REQUEST_USAGE:
285                 {
286                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpnotifs [filename]"));
287                         print("  Where 'filename' is the file to write (default is notifications_dump.cfg),\n");
288                         print("  if supplied with '-' output to console as well as default,\n");
289                         print("  if left blank, it will only write to default.\n");
290                         return;
291                 }
292         }
293 }
294
295 void GenericCommand_dumpweapons(float request) // WEAPONTODO: make this work with other progs than just server
296 {
297         switch(request)
298         {
299                 case CMD_REQUEST_COMMAND:
300                 {
301                         #ifdef SVQC
302                         wep_config_file = -1;
303                         wep_config_alsoprint = -1;
304                         string filename = argv(1);
305                         
306                         if(filename == "")
307                         {
308                                 filename = "weapons_dump.cfg";
309                                 wep_config_alsoprint = false;
310                         }
311                         else if(filename == "-")
312                         {
313                                 filename = "weapons_dump.cfg";
314                                 wep_config_alsoprint = true;
315                         }
316                         wep_config_file = fopen(filename, FILE_WRITE);
317                         
318                         if(wep_config_file >= 0)
319                         {
320                                 Dump_Weapon_Settings();
321                                 print(sprintf("Dumping weapons... File located in ^2data/data/%s^7.\n", filename));
322                                 fclose(wep_config_file);
323                                 wep_config_file = -1;
324                                 wep_config_alsoprint = -1;
325                         }
326                         else
327                         {
328                                 print(sprintf("^1Error: ^7Could not open file '%s'!\n", filename));
329                         }
330                         #else
331                         print(_("Weapons dump command only works with sv_cmd.\n"));
332                         #endif
333                         return;
334                 }
335                         
336                 default:
337                 case CMD_REQUEST_USAGE:
338                 {
339                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpweapons [filename]"));
340                         print("  Where 'filename' is the file to write (default is weapons_dump.cfg),\n");
341                         print("  if supplied with '-' output to console as well as default,\n");
342                         print("  if left blank, it will only write to default.\n");
343                         return;
344                 }
345         }
346 }
347
348 void GenericCommand_maplist(float request, float argc)
349 {
350         switch(request)
351         {
352                 case CMD_REQUEST_COMMAND:
353                 {
354                         string tmp_string;
355                         float i;
356
357                         switch(argv(1))
358                         {
359                                 case "add": // appends new maps to the maplist
360                                 {
361                                         if(argc == 3)
362                                         {
363                                                 if (!fexists(strcat("maps/", argv(2), ".bsp")))
364                                                 {
365                                                         print("maplist: ERROR: ", argv(2), " does not exist!\n");
366                                                         break;
367                                                 }
368
369                                                 if(cvar_string("g_maplist") == "")
370                                                         cvar_set("g_maplist", argv(2));
371                                                 else
372                                                         cvar_set("g_maplist", strcat(argv(2), " ", cvar_string("g_maplist")));
373
374                                                 return;
375                                         }
376                                         break; // go to usage
377                                 }
378
379                                 case "cleanup": // scans maplist and only adds back the ones which are really usable
380                                 {
381                                         MapInfo_Enumerate();
382                                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
383                                         argc = tokenizebyseparator(cvar_string("g_maplist"), " ");
384
385                                         tmp_string = "";
386                                         for(i = 0; i < argc; ++i)
387                                                 if(MapInfo_CheckMap(argv(i)))
388                                                         tmp_string = strcat(tmp_string, " ", argv(i));
389
390                                         tmp_string = substring(tmp_string, 1, strlen(tmp_string) - 1);
391                                         cvar_set("g_maplist", tmp_string);
392
393                                         return;
394                                 }
395
396                                 case "remove": // scans maplist and only adds back whatever maps were not provided in argv(2)
397                                 {
398                                         if(argc == 3)
399                                         {
400                                                 argc = tokenizebyseparator(cvar_string("g_maplist"), " ");
401
402                                                 tmp_string = "";
403                                                 for(i = 0; i < argc; ++i)
404                                                         if(argv(i) != argv(2))
405                                                                 tmp_string = strcat(tmp_string, " ", argv(i));
406
407                                                 tmp_string = substring(tmp_string, 1, strlen(tmp_string) - 1);
408                                                 cvar_set("g_maplist", tmp_string);
409
410                                                 return;
411                                         }
412                                         break; // go to usage
413                                 }
414
415                                 case "shuffle": // randomly shuffle the maplist
416                                 {
417                                         cvar_set("g_maplist", shufflewords(cvar_string("g_maplist")));
418                                         return;
419                                 }
420
421                                 default: break;
422                         }
423                 }
424
425                 default:
426                         print("Incorrect parameters for ^2maplist^7\n");
427                 case CMD_REQUEST_USAGE:
428                 {
429                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " maplist action [map]\n"));
430                         print("  Where 'action' is the command to complete,\n");
431                         print("  and 'map' is what it acts upon (if required).\n");
432                         print("  Full list of commands here: \"add, cleanup, remove, shuffle.\"\n");
433                         return;
434                 }
435         }
436 }
437
438 void GenericCommand_nextframe(float request, float arguments, string command)
439 {
440         switch(request)
441         {
442                 case CMD_REQUEST_COMMAND:
443                 {
444                         queue_to_execute_next_frame(substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
445                         return;
446                 }
447
448                 default:
449                 case CMD_REQUEST_USAGE:
450                 {
451                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " nextframe command...\n"));
452                         print("  Where command will be executed next frame of this VM\n");
453                         return;
454                 }
455         }
456 }
457
458 void GenericCommand_removefromlist(float request, float argc)
459 {
460         switch(request)
461         {
462                 case CMD_REQUEST_COMMAND:
463                 {
464                         if(argc == 3)
465                         {
466                                 float i;
467                                 string original_cvar = argv(1);
468                                 string removal = argv(2);
469                                 string tmp_string;
470
471                                 argc = tokenizebyseparator(cvar_string(original_cvar), " ");
472
473                                 tmp_string = "";
474                                 for(i = 0; i < argc; ++i)
475                                         if(argv(i) != removal)
476                                                 tmp_string = strcat(tmp_string, " ", argv(i));
477
478                                 tmp_string = substring(tmp_string, 1, strlen(tmp_string) - 1);
479                                 cvar_set(original_cvar, tmp_string);
480
481                                 return;
482                         }
483                 }
484
485                 default:
486                         print("Incorrect parameters for ^2removefromlist^7\n");
487                 case CMD_REQUEST_USAGE:
488                 {
489                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " removefromlist variable value\n"));
490                         print("  Where 'variable' is what cvar to remove 'value' from.\n");
491                         print("See also: ^2addtolist^7\n");
492                         return;
493                 }
494         }
495 }
496
497 void GenericCommand_restartnotifs(float request)
498 {
499         switch(request)
500         {
501                 case CMD_REQUEST_COMMAND:
502                 {
503                         #ifndef MENUQC
504                         printf(
505                                 strcat(
506                                         "Restart_Notifications(): Restarting %d notifications... ",
507                                         "Counts: MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
508                                 ),
509                                 (
510                                         NOTIF_ANNCE_COUNT +
511                                         NOTIF_INFO_COUNT +
512                                         NOTIF_CENTER_COUNT +
513                                         NOTIF_MULTI_COUNT +
514                                         NOTIF_CHOICE_COUNT
515                                 ),
516                                 NOTIF_ANNCE_COUNT,
517                                 NOTIF_INFO_COUNT,
518                                 NOTIF_CENTER_COUNT,
519                                 NOTIF_MULTI_COUNT,
520                                 NOTIF_CHOICE_COUNT
521                         );
522                         Destroy_All_Notifications();
523                         CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
524                         #else
525                         print(_("Notification restart command only works with cl_cmd and sv_cmd.\n"));
526                         #endif
527                         return;
528                 }
529
530                 default:
531                 case CMD_REQUEST_USAGE:
532                 {
533                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " restartnotifs"));
534                         print("  No arguments required.\n");
535                         return;
536                 }
537         }
538 }
539
540 void GenericCommand_settemp(float request, float argc)
541 {
542         switch(request)
543         {
544                 case CMD_REQUEST_COMMAND:
545                 {
546                         if(argc >= 3)
547                         {
548                                 float f = cvar_settemp(argv(1), argv(2));
549                                 if(f == 1)
550                                         dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
551                                 else if(f == -1)
552                                         dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
553                                 // else cvar_settemp itself errors out
554
555                                 return;
556                         }
557                 }
558
559                 default:
560                         print("Incorrect parameters for ^2settemp^7\n");
561                 case CMD_REQUEST_USAGE:
562                 {
563                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " settemp \"cvar\" \"arguments\"\n"));
564                         print("  Where 'cvar' is the cvar you want to temporarily set with 'arguments'.\n");
565                         print("See also: ^2settemp_restore^7\n");
566                         return;
567                 }
568         }
569 }
570
571 void GenericCommand_settemp_restore(float request, float argc)
572 {
573         switch(request)
574         {
575                 case CMD_REQUEST_COMMAND:
576                 {
577                         float i = cvar_settemp_restore();
578
579                         if(i)
580                                 dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
581                         else
582                                 dprint("Nothing to restore.\n");
583
584                         return;
585                 }
586
587                 default:
588                 case CMD_REQUEST_USAGE:
589                 {
590                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " settemp_restore\n"));
591                         print("  No arguments required.\n");
592                         print("See also: ^2settemp^7\n");
593                         return;
594                 }
595         }
596 }
597
598 void GenericCommand_runtest(float request, float argc)
599 {
600         switch(request)
601         {
602                 case CMD_REQUEST_COMMAND:
603                 {
604                         if(argc > 1)
605                         {
606                                 float i;
607                                 for(i = 1; i < argc; ++i)
608                                         TEST_Run(argv(i));
609                         }
610                         else
611                                 TEST_RunAll();
612                         return;
613                 }
614
615                 default:
616                 case CMD_REQUEST_USAGE:
617                 {
618                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " [function to run]"));
619                         return;
620                 }
621         }
622 }
623
624 /* use this when creating a new command, making sure to place it in alphabetical order... also,
625 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
626 void GenericCommand_(float request)
627 {
628         switch(request)
629         {
630                 case CMD_REQUEST_COMMAND:
631                 {
632
633                         return;
634                 }
635
636                 default:
637                 case CMD_REQUEST_USAGE:
638                 {
639                         print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " "));
640                         print("  No arguments required.\n");
641                         return;
642                 }
643         }
644 }
645 */
646
647 // ==================================
648 //  Macro system for server commands
649 // ==================================
650
651 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
652 #define GENERIC_COMMANDS(request,arguments,command) \
653         GENERIC_COMMAND("addtolist", GenericCommand_addtolist(request, arguments), "Add a string to a cvar") \
654         GENERIC_COMMAND("dumpcommands", GenericCommand_dumpcommands(request), "Dump all commands on the program to *_cmd_dump.txt") \
655         GENERIC_COMMAND("dumpnotifs", GenericCommand_dumpnotifs(request), "Dump all notifications into notifications_dump.txt") \
656         GENERIC_COMMAND("dumpweapons", GenericCommand_dumpweapons(request), "Dump all weapons into weapons_dump.txt") \
657         GENERIC_COMMAND("maplist", GenericCommand_maplist(request, arguments), "Automatic control of maplist") \
658         GENERIC_COMMAND("nextframe", GenericCommand_nextframe(request, arguments, command), "Execute the given command next frame of this VM") \
659         GENERIC_COMMAND("qc_curl", GenericCommand_qc_curl(request, arguments), "Queries a URL") \
660         GENERIC_COMMAND("removefromlist", GenericCommand_removefromlist(request, arguments), "Remove a string from a cvar") \
661         GENERIC_COMMAND("restartnotifs", GenericCommand_restartnotifs(request), "Re-initialize all notifications") \
662         GENERIC_COMMAND("rpn", GenericCommand_rpn(request, arguments, command), "RPN calculator") \
663         GENERIC_COMMAND("settemp", GenericCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored later") \
664         GENERIC_COMMAND("settemp_restore", GenericCommand_settemp_restore(request, arguments), "Restore all cvars set by settemp command") \
665         GENERIC_COMMAND("runtest", GenericCommand_runtest(request, arguments), "Run unit tests") \
666         /* nothing */
667
668 void GenericCommand_macro_help()
669 {
670         #define GENERIC_COMMAND(name,function,description) \
671                 { print("  ^2", name, "^7: ", description, "\n"); }
672
673         GENERIC_COMMANDS(0, 0, "");
674         #undef GENERIC_COMMAND
675
676         return;
677 }
678
679 float GenericCommand_macro_command(float argc, string command)
680 {
681         #define GENERIC_COMMAND(name,function,description) \
682                 { if(name == strtolower(argv(0))) { function; return true; } }
683
684         GENERIC_COMMANDS(CMD_REQUEST_COMMAND, argc, command);
685         #undef GENERIC_COMMAND
686
687         return false;
688 }
689
690 float GenericCommand_macro_usage(float argc)
691 {
692         #define GENERIC_COMMAND(name,function,description) \
693                 { if(name == strtolower(argv(1))) { function; return true; } }
694
695         GENERIC_COMMANDS(CMD_REQUEST_USAGE, argc, "");
696         #undef GENERIC_COMMAND
697
698         return false;
699 }
700
701 void GenericCommand_macro_write_aliases(float fh)
702 {
703         #define GENERIC_COMMAND(name,function,description) \
704                 { CMD_Write_Alias("qc_cmd_svmenu", name, description); }
705
706         GENERIC_COMMANDS(0, 0, "");
707         #undef GENERIC_COMMAND
708
709         return;
710 }
711
712
713 // ===========================================
714 //  Main Common Function For Generic Commands
715 // ===========================================
716 // Commands spread out among all programs (menu, client, and server)
717
718 float GenericCommand(string command)
719 {
720         float argc = tokenize_console(command);
721         float n, j, f, i;
722         string s, s2, c;
723         vector rgb;
724
725         // Guide for working with argc arguments by example:
726         // argc:   1    - 2      - 3     - 4
727         // argv:   0    - 1      - 2     - 3
728         // cmd     vote - master - login - password
729
730         if(GenericCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
731         {
732                 return true; // handled by one of the above GenericCommand_* functions
733         }
734         else if(argc >= 3 && argv(0) == "red")
735         {
736                 s = substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2));
737                 localcmd(strcat(argv(1), " ", GenericCommand_markup(s)));
738                 return true;
739         }
740         else if(argc >= 3 && crc16(0, argv(0)) == 38566 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 59830)
741         {
742                 // other test case
743                 s = strconv(2, 0, 0, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
744
745                 n = floor(random() * 6 + 2);
746
747                 s2 = "";
748                 for(i = 0; i < n; ++i)
749                 {
750                         s2 = strcat(s2, "AH");
751                 }
752
753                 if(random() < 0.1)
754                         s2 = strcat(substring(s2, 1, strlen(s2) - 1), "A");
755
756                 if(s == "")
757                         s = s2;
758                 else
759                         if(random() < 0.8)
760                                 s = strcat(s, " ", s2);
761                         else
762                                 s = strcat(s2, " ", s);
763
764                 s2 = substring(s, strlen(s) - 2, 2);
765                 if(s2 == "AH" || s2 == "AY")
766                         s = strcat(s, "))");
767                 else
768                         s = strcat(s, " ))");
769
770                 if(random() < 0.1)
771                         s = substring(s, 0, strlen(s) - 1);
772
773                 if(random() < 0.1)
774                         s = strconv(1, 0, 0, s);
775
776                 localcmd(strcat(argv(1), " ", s));
777
778                 return true;
779         }
780         else if(argc >= 3 && crc16(0, argv(0)) == 3826 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 55790)
781         {
782                 // test case for terencehill's color codes
783                 s = strdecolorize(substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
784                 s2 = "";
785
786                 n = strlen(s);
787                 j = ((6 * max(1, floor(strlen(s)/32 + random() * 2 - 1))) / n) * (1 - 2 * (random() > 0.5));
788                 f = random() * 6;
789
790                 for(i = 0; i < n; ++i)
791                 {
792                         c = substring(s, i, 1);
793
794                         if(c == ";")
795                                 c = ":";
796                         else if(c == "^")
797                         {
798                                 c = "^^";
799                                 if(substring(s, i+1, 1) == "^")
800                                         ++i;
801                         }
802
803                         if(c != " ")
804                         {
805                                 rgb = hsl_to_rgb('1 0 0' * (j * i + f) + '0 1 .5');
806                                 c = strcat(rgb_to_hexcolor(rgb), c);
807                         }
808                         s2 = strcat(s2, c);
809                 }
810
811                 localcmd(strcat(argv(1), " ", s2));
812
813                 return true;
814         }
815
816         return false;
817 }