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