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