Merge remote-tracking branch 'origin/terencehill/bot_waypoints'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / cmd.qc
1 #include "cmd.qh"
2
3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
5
6 #include <common/command/_mod.qh>
7
8 #include "common.qh"
9 #include "vote.qh"
10
11 #include "../bot/api.qh"
12
13 #include "../campaign.qh"
14 #include "../cheats.qh"
15 #include "../client.qh"
16 #include "../clientkill.qh"
17 #include "../player.qh"
18 #include "../ipban.qh"
19 #include "../mapvoting.qh"
20 #include "../scores.qh"
21 #include "../teamplay.qh"
22
23 #include <server/mutators/_mod.qh>
24 #include <common/gamemodes/_mod.qh>
25
26 #ifdef SVQC
27         #include <common/vehicles/all.qh>
28 #endif
29
30 #include <common/constants.qh>
31 #include <common/deathtypes/all.qh>
32 #include <common/effects/all.qh>
33 #include <common/mapinfo.qh>
34 #include <common/notifications/all.qh>
35 #include <common/physics/player.qh>
36 #include <common/teams.qh>
37 #include <common/util.qh>
38 #include <common/mapobjects/triggers.qh>
39
40 #include <common/minigames/sv_minigames.qh>
41
42 #include <common/monsters/_mod.qh>
43 #include <common/monsters/sv_spawn.qh>
44 #include <common/monsters/sv_monsters.qh>
45
46 #include <lib/warpzone/common.qh>
47
48 // =========================================================
49 //  Server side networked commands code, reworked by Samual
50 //  Last updated: December 28th, 2011
51 // =========================================================
52
53 bool SV_ParseClientCommand_floodcheck(entity this)
54 {
55         entity store = IS_CLIENT(this) ? CS(this) : this; // unfortunately, we need to store these on the client initially
56
57         if (!timeout_status)  // not while paused
58         {
59                 if (time <= (store.cmd_floodtime + autocvar_sv_clientcommand_antispam_time))
60                 {
61                         store.cmd_floodcount += 1;
62                         if (store.cmd_floodcount > autocvar_sv_clientcommand_antispam_count)   return false;  // too much spam, halt
63                 }
64                 else
65                 {
66                         store.cmd_floodtime = time;
67                         store.cmd_floodcount = 1;
68                 }
69         }
70         return true;  // continue, as we're not flooding yet
71 }
72
73
74 // =======================
75 //  Command Sub-Functions
76 // =======================
77
78 void ClientCommand_autoswitch(entity caller, int request, int argc)
79 {
80         switch (request)
81         {
82                 case CMD_REQUEST_COMMAND:
83                 {
84                         if (argv(1) != "")
85                         {
86                                 CS(caller).autoswitch = InterpretBoolean(argv(1));
87                                 sprint(caller, strcat("^1autoswitch is currently turned ", (CS(caller).autoswitch ? "on" : "off"), ".\n"));
88                                 return;
89                         }
90                 }
91
92                 default:
93                         sprint(caller, "Incorrect parameters for ^2autoswitch^7\n");
94                 case CMD_REQUEST_USAGE:
95                 {
96                         sprint(caller, "\nUsage:^3 cmd autoswitch selection\n");
97                         sprint(caller, "  Where 'selection' controls if autoswitch is on or off.\n");
98                         return;
99                 }
100         }
101 }
102
103 void ClientCommand_clientversion(entity caller, int request, int argc)  // internal command, used only by code
104 {
105         switch (request)
106         {
107                 case CMD_REQUEST_COMMAND:
108                 {
109                         if (argv(1) != "")
110                         {
111                                 if (IS_CLIENT(caller))
112                                 {
113                                         CS(caller).version = ((argv(1) == "$gameversion") ? 1 : stof(argv(1)));
114
115                                         if (CS(caller).version < autocvar_gameversion_min || CS(caller).version > autocvar_gameversion_max)
116                                         {
117                                                 CS(caller).version_mismatch = true;
118                                                 ClientKill_TeamChange(caller, -2);  // observe
119                                         }
120                                         else if (autocvar_g_campaign || autocvar_g_balance_teams)
121                                         {
122                                                 // JoinBestTeam(caller, false, true);
123                                         }
124                                         else if (teamplay && !autocvar_sv_spectate && !(Player_GetForcedTeamIndex(caller) > 0))
125                                         {
126                                                 TRANSMUTE(Observer, caller);  // really?
127                                                 stuffcmd(caller, "menu_showteamselect\n");
128                                         }
129                                 }
130
131                                 return;
132                         }
133                 }
134
135                 default:
136                         sprint(caller, "Incorrect parameters for ^2clientversion^7\n");
137                 case CMD_REQUEST_USAGE:
138                 {
139                         sprint(caller, "\nUsage:^3 cmd clientversion version\n");
140                         sprint(caller, "  Where 'version' is the game version reported by caller.\n");
141                         return;
142                 }
143         }
144 }
145
146 void ClientCommand_mv_getpicture(entity caller, int request, int argc)  // internal command, used only by code
147 {
148         switch (request)
149         {
150                 case CMD_REQUEST_COMMAND:
151                 {
152                         if (argv(1) != "")
153                         {
154                                 if (intermission_running) MapVote_SendPicture(caller, stof(argv(1)));
155
156                                 return;
157                         }
158                 }
159
160                 default:
161                         sprint(caller, "Incorrect parameters for ^2mv_getpicture^7\n");
162                 case CMD_REQUEST_USAGE:
163                 {
164                         sprint(caller, "\nUsage:^3 cmd mv_getpicture mapid\n");
165                         sprint(caller, "  Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
166                         return;
167                 }
168         }
169 }
170
171 void ClientCommand_wpeditor(entity caller, int request, int argc)
172 {
173         switch (request)
174         {
175                 case CMD_REQUEST_COMMAND:
176                 {
177                         if (!autocvar_g_waypointeditor)
178                         {
179                                 sprint(caller, "ERROR: this command works only if the waypoint editor is on\n");
180                                 return;
181                         }
182
183                         if (argv(1) != "")
184                         {
185                                 if (argv(1) == "spawn")
186                                 {
187                                         if (!IS_PLAYER(caller))
188                                                 sprint(caller, "ERROR: this command works only if you are player\n");
189                                         else
190                                                 waypoint_spawn_fromeditor(caller);
191                                         return;
192                                 }
193                                 else if (argv(1) == "remove")
194                                 {
195                                         if (!IS_PLAYER(caller))
196                                                 sprint(caller, "ERROR: this command works only if you are player\n");
197                                         else
198                                                 waypoint_remove_fromeditor(caller);
199                                         return;
200                                 }
201                                 else if (argv(1) == "unreachable")
202                                 {
203                                         if (!IS_PLAYER(caller))
204                                                 sprint(caller, "ERROR: this command works only if you are player\n");
205                                         else
206                                                 waypoint_unreachable(caller);
207                                         return;
208                                 }
209                                 else if (argv(1) == "saveall")
210                                 {
211                                         waypoint_saveall();
212                                         return;
213                                 }
214                                 else if (argv(1) == "relinkall")
215                                 {
216                                         waypoint_schedulerelinkall();
217                                         return;
218                                 }
219                                 else if (argv(1) == "symaxis")
220                                 {
221                                         if (argv(2) == "set" || argv(2) == "get")
222                                         {
223                                                 waypoint_getSymmetricalAxis_cmd(caller, (argv(2) == "set"), 3);
224                                                 return;
225                                         }
226                                 }
227                                 else if (argv(1) == "symorigin")
228                                 {
229                                         if (argv(2) == "set" || argv(2) == "get")
230                                         {
231                                                 waypoint_getSymmetricalOrigin_cmd(caller, (argv(2) == "set"), 3);
232                                                 return;
233                                         }
234                                 }
235                         }
236                 }
237
238                 default:
239                         sprint(caller, "Incorrect parameters for ^2wpeditor^7\n");
240                 case CMD_REQUEST_USAGE:
241                 {
242                         sprint(caller, "\nUsage:^3 cmd wpeditor action\n");
243                         sprint(caller, "  Where 'action' can be: spawn, remove, unreachable, saveall, relinkall,\n");
244                         sprint(caller, "   symorigin get|set\n");
245                         sprint(caller, "   symorigin get|set p1 p2 ... pX\n");
246                         sprint(caller, "   symaxis get|set p1 p2\n");
247                         sprint(caller, "    where p1 p2 ... pX are positions \"x y z\" (z can be omitted)\n");
248                         sprint(caller, " symorigin and symaxis commands are useful to determine origin/axis of symmetry"
249                                                         " on maps without ctf flags or where flags aren't perfectly symmetrical\n");
250                         return;
251                 }
252         }
253 }
254
255 void ClientCommand_join(entity caller, int request)
256 {
257         switch (request)
258         {
259                 case CMD_REQUEST_COMMAND:
260                 {
261                         if (!game_stopped)
262                         if (IS_CLIENT(caller) && !IS_PLAYER(caller))
263                         if (joinAllowed(caller))
264                                 Join(caller);
265
266                         return;  // never fall through to usage
267                 }
268
269                 default:
270                 case CMD_REQUEST_USAGE:
271                 {
272                         sprint(caller, "\nUsage:^3 cmd join\n");
273                         sprint(caller, "  No arguments required.\n");
274                         return;
275                 }
276         }
277 }
278
279 void ClientCommand_kill(entity caller, int request)
280 {
281         switch (request)
282         {
283                 case CMD_REQUEST_COMMAND:
284                 {
285                         if(IS_SPEC(caller) || IS_OBSERVER(caller))
286                                 return; // no point warning about this, command does nothing
287
288                         if(GetResourceAmount(caller, RESOURCE_HEALTH) <= 0)
289                         {
290                                 sprint(caller, "Can't die - you are already dead!\n");
291                                 return;
292                         }
293
294                         ClientKill(caller);
295
296                         return;  // never fall through to usage
297                 }
298
299                 default:
300                 case CMD_REQUEST_USAGE:
301                 {
302                         sprint(caller, "\nUsage:^3 cmd kill\n");
303                         sprint(caller, "  No arguments required.\n");
304                         return;
305                 }
306         }
307 }
308
309 void ClientCommand_physics(entity caller, int request, int argc)
310 {
311         switch (request)
312         {
313                 case CMD_REQUEST_COMMAND:
314                 {
315                         string command = strtolower(argv(1));
316
317                         if (!autocvar_g_physics_clientselect)
318                         {
319                                 sprint(caller, "Client physics selection is currently disabled.\n");
320                                 return;
321                         }
322
323                         if (command == "list" || command == "help")
324                         {
325                                 sprint(caller, strcat("Available physics sets: \n\n", autocvar_g_physics_clientselect_options, " default\n"));
326                                 return;
327                         }
328
329                         if (Physics_Valid(command) || command == "default")
330                         {
331                                 stuffcmd(caller, strcat("\nseta cl_physics ", command, "\nsendcvar cl_physics\n"));
332                                 sprint(caller, strcat("^2Physics set successfully changed to ^3", command, "\n"));
333                                 return;
334                         }
335                 }
336
337                 default:
338                         sprint(caller, strcat("Current physics set: ^3", CS(caller).cvar_cl_physics, "\n"));
339                 case CMD_REQUEST_USAGE:
340                 {
341                         sprint(caller, "\nUsage:^3 cmd physics <physics>\n");
342                         sprint(caller, "  See 'cmd physics list' for available physics sets.\n");
343                         sprint(caller, "  Argument 'default' resets to standard physics.\n");
344                         return;
345                 }
346         }
347 }
348
349 void ClientCommand_ready(entity caller, int request)  // todo: anti-spam for toggling readyness
350 {
351         switch (request)
352         {
353                 case CMD_REQUEST_COMMAND:
354                 {
355                         if (IS_CLIENT(caller))
356                         {
357                                 if (warmup_stage || sv_ready_restart || g_race_qualifying == 2)
358                                 {
359                                         if (!readyrestart_happened || sv_ready_restart_repeatable)
360                                         {
361                                                 if (time < game_starttime) // game is already restarting
362                                                         return;
363                                                 if (caller.ready)            // toggle
364                                                 {
365                                                         caller.ready = false;
366                                                         if(IS_PLAYER(caller) || caller.caplayer == 1)
367                                                                 bprint(playername(caller, false), "^2 is ^1NOT^2 ready\n");
368                                                 }
369                                                 else
370                                                 {
371                                                         caller.ready = true;
372                                                         if(IS_PLAYER(caller) || caller.caplayer == 1)
373                                                                 bprint(playername(caller, false), "^2 is ready\n");
374                                                 }
375
376                                                 // cannot reset the game while a timeout is active!
377                                                 if (!timeout_status) ReadyCount();
378                                         }
379                                         else
380                                         {
381                                                 sprint(caller, "^1Game has already been restarted\n");
382                                         }
383                                 }
384                         }
385                         return;  // never fall through to usage
386                 }
387
388                 default:
389                 case CMD_REQUEST_USAGE:
390                 {
391                         sprint(caller, "\nUsage:^3 cmd ready\n");
392                         sprint(caller, "  No arguments required.\n");
393                         return;
394                 }
395         }
396 }
397
398 void ClientCommand_say(entity caller, int request, int argc, string command)
399 {
400         switch (request)
401         {
402                 case CMD_REQUEST_COMMAND:
403                 {
404                         if (argc >= 2)   Say(caller, false, NULL, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
405                         return;  // never fall through to usage
406                 }
407
408                 default:
409                 case CMD_REQUEST_USAGE:
410                 {
411                         sprint(caller, "\nUsage:^3 cmd say <message>\n");
412                         sprint(caller, "  Where 'message' is the string of text to say.\n");
413                         return;
414                 }
415         }
416 }
417
418 void ClientCommand_say_team(entity caller, int request, int argc, string command)
419 {
420         switch (request)
421         {
422                 case CMD_REQUEST_COMMAND:
423                 {
424                         if (argc >= 2)
425                                 Say(caller, true, NULL, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
426                         return;  // never fall through to usage
427                 }
428
429                 default:
430                 case CMD_REQUEST_USAGE:
431                 {
432                         sprint(caller, "\nUsage:^3 cmd say_team <message>\n");
433                         sprint(caller, "  Where 'message' is the string of text to say.\n");
434                         return;
435                 }
436         }
437 }
438
439 .bool team_selected;
440 void ClientCommand_selectteam(entity caller, int request, int argc)
441 {
442         switch (request)
443         {
444                 case CMD_REQUEST_COMMAND:
445                 {
446                         if (argv(1) == "")
447                         {
448                                 return;
449                         }
450                         if (!IS_CLIENT(caller))
451                         {
452                                 return;
453                         }
454                         if (!teamplay)
455                         {
456                                 sprint(caller, "^7selectteam can only be used in teamgames\n");
457                                 return;
458                         }
459                         if (Player_GetForcedTeamIndex(caller) > 0)
460                         {
461                                 sprint(caller, "^7selectteam can not be used as your team is forced\n");
462                                 return;
463                         }
464                         if (lockteams)
465                         {
466                                 sprint(caller, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
467                                 return;
468                         }
469                         float selection;
470                         switch (argv(1))
471                         {
472                                 case "red":
473                                 {
474                                         selection = NUM_TEAM_1;
475                                         break;
476                                 }
477                                 case "blue":
478                                 {
479                                         selection = NUM_TEAM_2;
480                                         break;
481                                 }
482                                 case "yellow":
483                                 {
484                                         selection = NUM_TEAM_3;
485                                         break;
486                                 }
487                                 case "pink":
488                                 {
489                                         selection = NUM_TEAM_4;
490                                         break;
491                                 }
492                                 case "auto":
493                                 {
494                                         selection = (-1);
495                                         break;
496                                 }
497                                 default:
498                                 {
499                                         return;
500                                 }
501                         }
502                         if (caller.team == selection && selection != -1 && !IS_DEAD(caller))
503                         {
504                                 sprint(caller, "^7You already are on that team.\n");
505                                 return;
506                         }
507                         if (CS(caller).wasplayer && autocvar_g_changeteam_banned)
508                         {
509                                 sprint(caller, "^1You cannot change team, forbidden by the server.\n");
510                                 return;
511                         }
512                         if ((selection != -1) && autocvar_g_balance_teams &&
513                                 autocvar_g_balance_teams_prevent_imbalance)
514                         {
515                                 entity balance = TeamBalance_CheckAllowedTeams(caller);
516                                 TeamBalance_GetTeamCounts(balance, caller);
517                                 if ((Team_IndexToBit(Team_TeamToIndex(selection)) &
518                                         TeamBalance_FindBestTeams(balance, caller, false)) == 0)
519                                 {
520                                         Send_Notification(NOTIF_ONE, caller, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
521                                         TeamBalance_Destroy(balance);
522                                         return;
523                                 }
524                                 TeamBalance_Destroy(balance);
525                         }
526                         ClientKill_TeamChange(caller, selection);
527                         if (!IS_PLAYER(caller))
528                         {
529                                 caller.team_selected = true; // avoids asking again for team selection on join
530                         }
531                         return;
532                 }
533                 default:
534                         sprint(caller, "Incorrect parameters for ^2selectteam^7\n");
535                 case CMD_REQUEST_USAGE:
536                 {
537                         sprint(caller, "\nUsage:^3 cmd selectteam team\n");
538                         sprint(caller, "  Where 'team' is the prefered team to try and join.\n");
539                         sprint(caller, "  Full list of options here: \"red, blue, yellow, pink, auto\"\n");
540                         return;
541                 }
542         }
543 }
544
545 void ClientCommand_selfstuff(entity caller, int request, string command)
546 {
547         switch (request)
548         {
549                 case CMD_REQUEST_COMMAND:
550                 {
551                         if (argv(1) != "")
552                         {
553                                 stuffcmd(caller, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
554                                 return;
555                         }
556                 }
557
558                 default:
559                         sprint(caller, "Incorrect parameters for ^2selfstuff^7\n");
560                 case CMD_REQUEST_USAGE:
561                 {
562                         sprint(caller, "\nUsage:^3 cmd selfstuff <command>\n");
563                         sprint(caller, "  Where 'command' is the string to be stuffed to your client.\n");
564                         return;
565                 }
566         }
567 }
568
569 void ClientCommand_sentcvar(entity caller, int request, int argc, string command)
570 {
571         switch (request)
572         {
573                 case CMD_REQUEST_COMMAND:
574                 {
575                         if (argv(1) != "")
576                         {
577                                 // float tokens;
578                                 string s;
579
580                                 if (argc == 2)  // undefined cvar: use the default value on the server then
581                                 {
582                                         s = strcat(substring(command, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
583                                         tokenize_console(s);
584                                 }
585
586                                 GetCvars(caller, CS(caller), 1);
587
588                                 return;
589                         }
590                 }
591
592                 default:
593                         sprint(caller, "Incorrect parameters for ^2sentcvar^7\n");
594                 case CMD_REQUEST_USAGE:
595                 {
596                         sprint(caller, "\nUsage:^3 cmd sentcvar <cvar>\n");
597                         sprint(caller, "  Where 'cvar' is the cvar plus arguments to send to the server.\n");
598                         return;
599                 }
600         }
601 }
602
603 void ClientCommand_spectate(entity caller, int request)
604 {
605         switch (request)
606         {
607                 case CMD_REQUEST_COMMAND:
608                 {
609                         if (!intermission_running && IS_CLIENT(caller))
610                         {
611                                 if((IS_SPEC(caller) || IS_OBSERVER(caller)) && argv(1) != "")
612                                 {
613                                         entity client = GetFilteredEntity(argv(1));
614                                         int spec_accepted = VerifyClientEntity(client, false, false);
615                                         if(spec_accepted > 0 && IS_PLAYER(client))
616                                         {
617                                                 if(Spectate(caller, client))
618                                                         return; // fall back to regular handling
619                                         }
620                                 }
621
622                                 int mutator_returnvalue = MUTATOR_CALLHOOK(ClientCommand_Spectate, caller);
623
624                                 if (mutator_returnvalue == MUT_SPECCMD_RETURN) return;
625
626                                 if ((IS_PLAYER(caller) || mutator_returnvalue == MUT_SPECCMD_FORCE))
627                                 if (autocvar_sv_spectate == 1)
628                                         ClientKill_TeamChange(caller, -2); // observe
629                         }
630                         return; // never fall through to usage
631                 }
632
633                 default:
634                 case CMD_REQUEST_USAGE:
635                 {
636                         sprint(caller, "\nUsage:^3 cmd spectate <client>\n");
637                         sprint(caller, "  Where 'client' can be the player to spectate.\n");
638                         return;
639                 }
640         }
641 }
642
643 void ClientCommand_suggestmap(entity caller, int request, int argc)
644 {
645         switch (request)
646         {
647                 case CMD_REQUEST_COMMAND:
648                 {
649                         if (argv(1) != "")
650                         {
651                                 sprint(caller, strcat(MapVote_Suggest(caller, argv(1)), "\n"));
652                                 return;
653                         }
654                 }
655
656                 default:
657                         sprint(caller, "Incorrect parameters for ^2suggestmap^7\n");
658                 case CMD_REQUEST_USAGE:
659                 {
660                         sprint(caller, "\nUsage:^3 cmd suggestmap map\n");
661                         sprint(caller, "  Where 'map' is the name of the map to suggest.\n");
662                         return;
663                 }
664         }
665 }
666
667 void ClientCommand_tell(entity caller, int request, int argc, string command)
668 {
669         switch (request)
670         {
671                 case CMD_REQUEST_COMMAND:
672                 {
673                         if (argc >= 3)
674                         {
675                                 if(!IS_CLIENT(caller) && IS_REAL_CLIENT(caller)) // connecting
676                                 {
677                                         print_to(caller, "You can't ^2tell^7 a message while connecting.");
678                                         return;
679                                 }
680
681                                 entity tell_to = GetIndexedEntity(argc, 1);
682                                 float tell_accepted = VerifyClientEntity(tell_to, true, false);
683
684                                 if (tell_accepted > 0)   // the target is a real client
685                                 {
686                                         if (tell_to != caller) // and we're allowed to send to them :D
687                                         {
688                                                 // workaround for argv indexes indexing ascii chars instead of utf8 chars
689                                                 // In this case when the player name contains utf8 chars
690                                                 // the message gets partially trimmed in the beginning.
691                                                 // Potentially this bug affects any substring call that uses
692                                                 // argv_start_index and argv_end_index.
693
694                                                 string utf8_enable_save = cvar_string("utf8_enable");
695                                                 cvar_set("utf8_enable", "0");
696                                                 string msg = substring(command, argv_start_index(next_token), argv_end_index(-1) - argv_start_index(next_token));
697                                                 cvar_set("utf8_enable", utf8_enable_save);
698
699                                                 Say(caller, false, tell_to, msg, true);
700                                                 return;
701                                         }
702                                         else { print_to(caller, "You can't ^2tell^7 a message to yourself."); return; }
703                                 }
704                                 else if (argv(1) == "#0")
705                                 {
706                                         trigger_magicear_processmessage_forallears(caller, -1, NULL, substring(command, argv_start_index(next_token), argv_end_index(-1) - argv_start_index(next_token)));
707                                         return;
708                                 }
709                                 else { print_to(caller, strcat("tell: ", GetClientErrorString(tell_accepted, argv(1)), ".")); return; }
710                         }
711                 }
712
713                 default:
714                         sprint(caller, "Incorrect parameters for ^2tell^7\n");
715                 case CMD_REQUEST_USAGE:
716                 {
717                         sprint(caller, "\nUsage:^3 cmd tell client <message>\n");
718                         sprint(caller, "  Where 'client' is the entity number or name of the player to send 'message' to.\n");
719                         return;
720                 }
721         }
722 }
723
724 void ClientCommand_voice(entity caller, int request, int argc, string command)
725 {
726         switch (request)
727         {
728                 case CMD_REQUEST_COMMAND:
729                 {
730                         if (argv(1) != "")
731                         {
732                                 entity e = GetVoiceMessage(argv(1));
733                                 if (!e)
734                                 {
735                                         sprint(caller, sprintf("Invalid voice. Use one of: %s\n", allvoicesamples));
736                                         return;
737                                 }
738                                 string msg = "";
739                                 if (argc >= 3)
740                                         msg = substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2));
741                                 VoiceMessage(caller, e, msg);
742
743                                 return;
744                         }
745                 }
746
747                 default:
748                         sprint(caller, "Incorrect parameters for ^2voice^7\n");
749                 case CMD_REQUEST_USAGE:
750                 {
751                         sprint(caller, "\nUsage:^3 cmd voice messagetype <soundname>\n");
752                         sprint(caller, "  'messagetype' is the type of broadcast to do, like team only or such,\n");
753                         sprint(caller, "  and 'soundname' is the string/filename of the sound/voice message to play.\n");
754                         return;
755                 }
756         }
757 }
758
759 /* use this when creating a new command, making sure to place it in alphabetical order... also,
760 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
761 void ClientCommand_(entity caller, int request)
762 {
763     switch(request)
764     {
765         case CMD_REQUEST_COMMAND:
766         {
767
768             return; // never fall through to usage
769         }
770
771         default:
772         case CMD_REQUEST_USAGE:
773         {
774             sprint(caller, "\nUsage:^3 cmd \n");
775             sprint(caller, "  No arguments required.\n");
776             return;
777         }
778     }
779 }
780 */
781
782
783 // =====================================
784 //  Macro system for networked commands
785 // =====================================
786
787 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
788 #define CLIENT_COMMANDS(ent, request, arguments, command) \
789         CLIENT_COMMAND("autoswitch", ClientCommand_autoswitch(ent, request, arguments), "Whether or not to switch automatically when getting a better weapon") \
790         CLIENT_COMMAND("clientversion", ClientCommand_clientversion(ent, request, arguments), "Release version of the game") \
791         CLIENT_COMMAND("join", ClientCommand_join(ent, request), "Become a player in the game") \
792         CLIENT_COMMAND("kill", ClientCommand_kill(ent, request), "Become a member of the dead") \
793         CLIENT_COMMAND("minigame", ClientCommand_minigame(ent, request, arguments, command), "Start a minigame") \
794         CLIENT_COMMAND("mv_getpicture", ClientCommand_mv_getpicture(ent, request, arguments), "Retrieve mapshot picture from the server") \
795         CLIENT_COMMAND("physics", ClientCommand_physics(ent, request, arguments), "Change physics set") \
796         CLIENT_COMMAND("ready", ClientCommand_ready(ent, request), "Qualify as ready to end warmup stage (or restart server if allowed)") \
797         CLIENT_COMMAND("say", ClientCommand_say(ent, request, arguments, command), "Print a message to chat to all players") \
798         CLIENT_COMMAND("say_team", ClientCommand_say_team(ent, request, arguments, command), "Print a message to chat to all team mates") \
799         CLIENT_COMMAND("selectteam", ClientCommand_selectteam(ent, request, arguments), "Attempt to choose a team to join into") \
800         CLIENT_COMMAND("selfstuff", ClientCommand_selfstuff(ent, request, command), "Stuffcmd a command to your own client") \
801         CLIENT_COMMAND("sentcvar", ClientCommand_sentcvar(ent, request, arguments, command), "New system for sending a client cvar to the server") \
802         CLIENT_COMMAND("spectate", ClientCommand_spectate(ent, request), "Become an observer") \
803         CLIENT_COMMAND("suggestmap", ClientCommand_suggestmap(ent, request, arguments), "Suggest a map to the mapvote at match end") \
804         CLIENT_COMMAND("tell", ClientCommand_tell(ent, request, arguments, command), "Send a message directly to a player") \
805         CLIENT_COMMAND("voice", ClientCommand_voice(ent, request, arguments, command), "Send voice message via sound") \
806         CLIENT_COMMAND("wpeditor", ClientCommand_wpeditor(ent, request, arguments), "Waypoint editor commands") \
807         /* nothing */
808
809 void ClientCommand_macro_help(entity caller)
810 {
811         #define CLIENT_COMMAND(name, function, description) \
812                 { sprint(caller, "  ^2", name, "^7: ", description, "\n"); }
813
814         CLIENT_COMMANDS(NULL, 0, 0, "");
815 #undef CLIENT_COMMAND
816 }
817
818 float ClientCommand_macro_command(int argc, entity caller, string command)
819 {
820         #define CLIENT_COMMAND(name, function, description) \
821                 { if (name == strtolower(argv(0))) { function; return true; } }
822
823         CLIENT_COMMANDS(caller, CMD_REQUEST_COMMAND, argc, command);
824 #undef CLIENT_COMMAND
825
826         return false;
827 }
828
829 float ClientCommand_macro_usage(int argc, entity caller)
830 {
831         #define CLIENT_COMMAND(name, function, description) \
832                 { if (name == strtolower(argv(1))) { function; return true; } }
833
834         CLIENT_COMMANDS(caller, CMD_REQUEST_USAGE, argc, "");
835 #undef CLIENT_COMMAND
836
837         return false;
838 }
839
840 void ClientCommand_macro_write_aliases(float fh)
841 {
842         #define CLIENT_COMMAND(name, function, description) \
843                 { CMD_Write_Alias("qc_cmd_cmd", name, description); }
844
845         CLIENT_COMMANDS(NULL, 0, 0, "");
846 #undef CLIENT_COMMAND
847 }
848
849 // ======================================
850 //  Main Function Called By Engine (cmd)
851 // ======================================
852 // If this function exists, server game code parses clientcommand before the engine code gets it.
853
854 void SV_ParseClientCommand(entity this, string command)
855 {
856         // If invalid UTF-8, don't even parse it
857         string command2 = "";
858         float len = strlen(command);
859         float i;
860         for (i = 0; i < len; ++i)
861                 command2 = strcat(command2, chr2str(str2chr(command, i)));
862         if (command != command2) return;
863
864         // if we're banned, don't even parse the command
865         if (Ban_MaybeEnforceBanOnce(this)) return;
866
867         int argc = tokenize_console(command);
868
869         // Guide for working with argc arguments by example:
870         // argc:   1    - 2      - 3     - 4
871         // argv:   0    - 1      - 2     - 3
872         // cmd     vote - master - login - password
873
874         // for floodcheck
875         switch (strtolower(argv(0)))
876         {
877                 // exempt commands which are not subject to floodcheck
878                 case "begin": break;                               // handled by engine in host_cmd.c
879                 case "download": break;                            // handled by engine in cl_parse.c
880                 case "mv_getpicture": break;                       // handled by server in this file
881                 case "wpeditor": break;                            // handled by server in this file
882                 case "pause": break;                               // handled by engine in host_cmd.c
883                 case "prespawn": break;                            // handled by engine in host_cmd.c
884                 case "sentcvar": break;                            // handled by server in this file
885                 case "spawn": break;                               // handled by engine in host_cmd.c
886                 case "c2s": Net_ClientCommand(this, command); return; // handled by net.qh
887
888                 default:
889                         if (SV_ParseClientCommand_floodcheck(this)) break; // "true": continue, as we're not flooding yet
890                         else return;                                   // "false": not allowed to continue, halt // print("^1ERROR: ^7ANTISPAM CAUGHT: ", command, ".\n");
891         }
892
893         /* NOTE: should this be disabled? It can be spammy perhaps, but hopefully it's okay for now */
894         if (argv(0) == "help")
895         {
896                 if (argc == 1)
897                 {
898                         sprint(this, "\nClient networked commands:\n");
899                         ClientCommand_macro_help(this);
900
901                         sprint(this, "\nCommon networked commands:\n");
902                         CommonCommand_macro_help(this);
903
904                         sprint(this, "\nUsage:^3 cmd COMMAND...^7, where possible commands are listed above.\n");
905                         sprint(this, "For help about a specific command, type cmd help COMMAND\n");
906                         return;
907                 }
908                 else if (CommonCommand_macro_usage(argc, this))  // Instead of trying to call a command, we're going to see detailed information about it
909                 {
910                         return;
911                 }
912                 else if (ClientCommand_macro_usage(argc, this))  // same, but for normal commands now
913                 {
914                         return;
915                 }
916         }
917         else if (MUTATOR_CALLHOOK(SV_ParseClientCommand, this, strtolower(argv(0)), argc, command))
918         {
919                 return;  // handled by a mutator
920         }
921         else if (CheatCommand(this, argc))
922         {
923                 return;  // handled by server/cheats.qc
924         }
925         else if (CommonCommand_macro_command(argc, this, command))
926         {
927                 return;                                          // handled by server/command/common.qc
928         }
929         else if (ClientCommand_macro_command(argc, this, command)) // continue as usual and scan for normal commands
930         {
931                 return;                                          // handled by one of the above ClientCommand_* functions
932         }
933         else
934         {
935                 clientcommand(this, command);
936         }
937 }