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