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