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