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