]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/cmd.qc
Bot waypoints: implement crouch waypoints, spawn them with "wpeditor spawn crouch...
[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, (argv(2) == "crosshair"), (argv(2) == "jump"), (argv(2) == "crouch"));
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) == "hardwire")
202                                 {
203                                         waypoint_start_hardwiredlink(caller);
204                                         return;
205                                 }
206                                 else if (argv(1) == "unreachable")
207                                 {
208                                         if (!IS_PLAYER(caller))
209                                                 sprint(caller, "ERROR: this command works only if you are player\n");
210                                         else
211                                                 waypoint_unreachable(caller);
212                                         return;
213                                 }
214                                 else if (argv(1) == "saveall")
215                                 {
216                                         waypoint_saveall();
217                                         return;
218                                 }
219                                 else if (argv(1) == "relinkall")
220                                 {
221                                         waypoint_schedulerelinkall();
222                                         return;
223                                 }
224                                 else if (argv(1) == "symaxis")
225                                 {
226                                         if (argv(2) == "set" || argv(2) == "get")
227                                         {
228                                                 waypoint_getSymmetricalAxis_cmd(caller, (argv(2) == "set"), 3);
229                                                 return;
230                                         }
231                                 }
232                                 else if (argv(1) == "symorigin")
233                                 {
234                                         if (argv(2) == "set" || argv(2) == "get")
235                                         {
236                                                 waypoint_getSymmetricalOrigin_cmd(caller, (argv(2) == "set"), 3);
237                                                 return;
238                                         }
239                                 }
240                         }
241                 }
242
243                 default:
244                         sprint(caller, "Incorrect parameters for ^2wpeditor^7\n");
245                 case CMD_REQUEST_USAGE:
246                 {
247                         sprint(caller, "\nUsage:^3 cmd wpeditor action\n");
248                         sprint(caller, "  Where 'action' can be:\n");
249                         sprint(caller, "   ^5spawn^7: spawns a waypoint at player's position\n");
250                         sprint(caller, "   ^5remove^7: remove player's nearest waypoint\n");
251                         sprint(caller, "   ^5unreachable^7: useful to reveal waypoints and items unreachable from the current position and spawnpoints without a nearest waypoint\n");
252                         sprint(caller, "   ^5saveall^7: saves all waypoints and links to file\n");
253                         sprint(caller, "   ^5relinkall^7: relink all waypoints as if they were respawned\n");
254                         sprint(caller, "   ^5spawn crosshair^7: spawns a waypoint at crosshair's position (useful to spawn custom jumppad waypoints (spawn another waypoint to create destination))\n");
255                         sprint(caller, "   ^5spawn jump^7: spawns a jump waypoint (spawn another waypoint to create destination)\n");
256                         sprint(caller, "   ^5hardwire^7: marks the nearest waypoint as origin of a new hardwired link (spawn another waypoint over an existing one to create destination)\n");
257                         sprint(caller, "   ^5symorigin get|set\n");
258                         sprint(caller, "   ^5symorigin get|set p1 p2 ... pX\n");
259                         sprint(caller, "   ^5symaxis get|set p1 p2\n");
260                         sprint(caller, "   ^7 where p1 p2 ... pX are positions (\"x y z\", z can be omitted) that you know are perfectly symmetrical");
261                         sprint(caller, "   ^7 so you can determine origin/axis of symmetry of maps without ctf flags or where flags aren't perfectly symmetrical\n");
262                         return;
263                 }
264         }
265 }
266
267 void ClientCommand_join(entity caller, int request)
268 {
269         switch (request)
270         {
271                 case CMD_REQUEST_COMMAND:
272                 {
273                         if (!game_stopped)
274                         if (IS_CLIENT(caller) && !IS_PLAYER(caller))
275                         if (joinAllowed(caller))
276                                 Join(caller);
277
278                         return;  // never fall through to usage
279                 }
280
281                 default:
282                 case CMD_REQUEST_USAGE:
283                 {
284                         sprint(caller, "\nUsage:^3 cmd join\n");
285                         sprint(caller, "  No arguments required.\n");
286                         return;
287                 }
288         }
289 }
290
291 void ClientCommand_kill(entity caller, int request)
292 {
293         switch (request)
294         {
295                 case CMD_REQUEST_COMMAND:
296                 {
297                         if(IS_SPEC(caller) || IS_OBSERVER(caller))
298                                 return; // no point warning about this, command does nothing
299
300                         if(GetResource(caller, RES_HEALTH) <= 0)
301                         {
302                                 sprint(caller, "Can't die - you are already dead!\n");
303                                 return;
304                         }
305
306                         ClientKill(caller);
307
308                         return;  // never fall through to usage
309                 }
310
311                 default:
312                 case CMD_REQUEST_USAGE:
313                 {
314                         sprint(caller, "\nUsage:^3 cmd kill\n");
315                         sprint(caller, "  No arguments required.\n");
316                         return;
317                 }
318         }
319 }
320
321 void ClientCommand_physics(entity caller, int request, int argc)
322 {
323         switch (request)
324         {
325                 case CMD_REQUEST_COMMAND:
326                 {
327                         string command = strtolower(argv(1));
328
329                         if (!autocvar_g_physics_clientselect)
330                         {
331                                 sprint(caller, "Client physics selection is currently disabled.\n");
332                                 return;
333                         }
334
335                         if (command == "list" || command == "help")
336                         {
337                                 sprint(caller, strcat("Available physics sets: \n\n", autocvar_g_physics_clientselect_options, " default\n"));
338                                 return;
339                         }
340
341                         if (Physics_Valid(command) || command == "default")
342                         {
343                                 stuffcmd(caller, strcat("\nseta cl_physics ", command, "\nsendcvar cl_physics\n"));
344                                 sprint(caller, strcat("^2Physics set successfully changed to ^3", command, "\n"));
345                                 return;
346                         }
347                 }
348
349                 default:
350                         sprint(caller, strcat("Current physics set: ^3", CS(caller).cvar_cl_physics, "\n"));
351                 case CMD_REQUEST_USAGE:
352                 {
353                         sprint(caller, "\nUsage:^3 cmd physics <physics>\n");
354                         sprint(caller, "  See 'cmd physics list' for available physics sets.\n");
355                         sprint(caller, "  Argument 'default' resets to standard physics.\n");
356                         return;
357                 }
358         }
359 }
360
361 void ClientCommand_ready(entity caller, int request)  // todo: anti-spam for toggling readyness
362 {
363         switch (request)
364         {
365                 case CMD_REQUEST_COMMAND:
366                 {
367                         if (IS_CLIENT(caller))
368                         {
369                                 if (warmup_stage || sv_ready_restart || g_race_qualifying == 2)
370                                 {
371                                         if (!readyrestart_happened || sv_ready_restart_repeatable)
372                                         {
373                                                 if (time < game_starttime) // game is already restarting
374                                                         return;
375                                                 if (caller.ready)            // toggle
376                                                 {
377                                                         caller.ready = false;
378                                                         if(IS_PLAYER(caller) || caller.caplayer == 1)
379                                                                 bprint(playername(caller, false), "^2 is ^1NOT^2 ready\n");
380                                                 }
381                                                 else
382                                                 {
383                                                         caller.ready = true;
384                                                         if(IS_PLAYER(caller) || caller.caplayer == 1)
385                                                                 bprint(playername(caller, false), "^2 is ready\n");
386                                                 }
387
388                                                 // cannot reset the game while a timeout is active!
389                                                 if (!timeout_status) ReadyCount();
390                                         }
391                                         else
392                                         {
393                                                 sprint(caller, "^1Game has already been restarted\n");
394                                         }
395                                 }
396                         }
397                         return;  // never fall through to usage
398                 }
399
400                 default:
401                 case CMD_REQUEST_USAGE:
402                 {
403                         sprint(caller, "\nUsage:^3 cmd ready\n");
404                         sprint(caller, "  No arguments required.\n");
405                         return;
406                 }
407         }
408 }
409
410 void ClientCommand_say(entity caller, int request, int argc, string command)
411 {
412         switch (request)
413         {
414                 case CMD_REQUEST_COMMAND:
415                 {
416                         if (argc >= 2)   Say(caller, false, NULL, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
417                         return;  // never fall through to usage
418                 }
419
420                 default:
421                 case CMD_REQUEST_USAGE:
422                 {
423                         sprint(caller, "\nUsage:^3 cmd say <message>\n");
424                         sprint(caller, "  Where 'message' is the string of text to say.\n");
425                         return;
426                 }
427         }
428 }
429
430 void ClientCommand_say_team(entity caller, int request, int argc, string command)
431 {
432         switch (request)
433         {
434                 case CMD_REQUEST_COMMAND:
435                 {
436                         if (argc >= 2)
437                                 Say(caller, true, NULL, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
438                         return;  // never fall through to usage
439                 }
440
441                 default:
442                 case CMD_REQUEST_USAGE:
443                 {
444                         sprint(caller, "\nUsage:^3 cmd say_team <message>\n");
445                         sprint(caller, "  Where 'message' is the string of text to say.\n");
446                         return;
447                 }
448         }
449 }
450
451 .bool team_selected;
452 void ClientCommand_selectteam(entity caller, int request, int argc)
453 {
454         switch (request)
455         {
456                 case CMD_REQUEST_COMMAND:
457                 {
458                         if (argv(1) == "")
459                         {
460                                 return;
461                         }
462                         if (!IS_CLIENT(caller))
463                         {
464                                 return;
465                         }
466                         if (!teamplay)
467                         {
468                                 sprint(caller, "^7selectteam can only be used in teamgames\n");
469                                 return;
470                         }
471                         if (Player_GetForcedTeamIndex(caller) > 0)
472                         {
473                                 sprint(caller, "^7selectteam can not be used as your team is forced\n");
474                                 return;
475                         }
476                         if (lockteams)
477                         {
478                                 sprint(caller, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
479                                 return;
480                         }
481                         float selection;
482                         switch (argv(1))
483                         {
484                                 case "red":
485                                 {
486                                         selection = NUM_TEAM_1;
487                                         break;
488                                 }
489                                 case "blue":
490                                 {
491                                         selection = NUM_TEAM_2;
492                                         break;
493                                 }
494                                 case "yellow":
495                                 {
496                                         selection = NUM_TEAM_3;
497                                         break;
498                                 }
499                                 case "pink":
500                                 {
501                                         selection = NUM_TEAM_4;
502                                         break;
503                                 }
504                                 case "auto":
505                                 {
506                                         selection = (-1);
507                                         break;
508                                 }
509                                 default:
510                                 {
511                                         return;
512                                 }
513                         }
514                         if (caller.team == selection && selection != -1 && !IS_DEAD(caller))
515                         {
516                                 sprint(caller, "^7You already are on that team.\n");
517                                 return;
518                         }
519                         if (CS(caller).wasplayer && autocvar_g_changeteam_banned)
520                         {
521                                 sprint(caller, "^1You cannot change team, forbidden by the server.\n");
522                                 return;
523                         }
524                         if ((selection != -1) && autocvar_g_balance_teams &&
525                                 autocvar_g_balance_teams_prevent_imbalance)
526                         {
527                                 entity balance = TeamBalance_CheckAllowedTeams(caller);
528                                 TeamBalance_GetTeamCounts(balance, caller);
529                                 if ((Team_IndexToBit(Team_TeamToIndex(selection)) &
530                                         TeamBalance_FindBestTeams(balance, caller, false)) == 0)
531                                 {
532                                         Send_Notification(NOTIF_ONE, caller, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
533                                         TeamBalance_Destroy(balance);
534                                         return;
535                                 }
536                                 TeamBalance_Destroy(balance);
537                         }
538                         ClientKill_TeamChange(caller, selection);
539                         if (!IS_PLAYER(caller))
540                         {
541                                 caller.team_selected = true; // avoids asking again for team selection on join
542                         }
543                         return;
544                 }
545                 default:
546                         sprint(caller, "Incorrect parameters for ^2selectteam^7\n");
547                 case CMD_REQUEST_USAGE:
548                 {
549                         sprint(caller, "\nUsage:^3 cmd selectteam team\n");
550                         sprint(caller, "  Where 'team' is the prefered team to try and join.\n");
551                         sprint(caller, "  Full list of options here: \"red, blue, yellow, pink, auto\"\n");
552                         return;
553                 }
554         }
555 }
556
557 void ClientCommand_selfstuff(entity caller, int request, string command)
558 {
559         switch (request)
560         {
561                 case CMD_REQUEST_COMMAND:
562                 {
563                         if (argv(1) != "")
564                         {
565                                 stuffcmd(caller, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
566                                 return;
567                         }
568                 }
569
570                 default:
571                         sprint(caller, "Incorrect parameters for ^2selfstuff^7\n");
572                 case CMD_REQUEST_USAGE:
573                 {
574                         sprint(caller, "\nUsage:^3 cmd selfstuff <command>\n");
575                         sprint(caller, "  Where 'command' is the string to be stuffed to your client.\n");
576                         return;
577                 }
578         }
579 }
580
581 void ClientCommand_sentcvar(entity caller, int request, int argc, string command)
582 {
583         switch (request)
584         {
585                 case CMD_REQUEST_COMMAND:
586                 {
587                         if (argv(1) != "")
588                         {
589                                 // float tokens;
590                                 string s;
591
592                                 if (argc == 2)  // undefined cvar: use the default value on the server then
593                                 {
594                                         s = strcat(substring(command, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
595                                         tokenize_console(s);
596                                 }
597
598                                 GetCvars(caller, CS(caller), 1);
599
600                                 return;
601                         }
602                 }
603
604                 default:
605                         sprint(caller, "Incorrect parameters for ^2sentcvar^7\n");
606                 case CMD_REQUEST_USAGE:
607                 {
608                         sprint(caller, "\nUsage:^3 cmd sentcvar <cvar>\n");
609                         sprint(caller, "  Where 'cvar' is the cvar plus arguments to send to the server.\n");
610                         return;
611                 }
612         }
613 }
614
615 void ClientCommand_spectate(entity caller, int request)
616 {
617         switch (request)
618         {
619                 case CMD_REQUEST_COMMAND:
620                 {
621                         if (!intermission_running && IS_CLIENT(caller))
622                         {
623                                 if((IS_SPEC(caller) || IS_OBSERVER(caller)) && argv(1) != "")
624                                 {
625                                         entity client = GetFilteredEntity(argv(1));
626                                         int spec_accepted = VerifyClientEntity(client, false, false);
627                                         if(spec_accepted > 0 && IS_PLAYER(client))
628                                         {
629                                                 if(Spectate(caller, client))
630                                                         return; // fall back to regular handling
631                                         }
632                                 }
633
634                                 int mutator_returnvalue = MUTATOR_CALLHOOK(ClientCommand_Spectate, caller);
635
636                                 if (mutator_returnvalue == MUT_SPECCMD_RETURN) return;
637
638                                 if ((IS_PLAYER(caller) || mutator_returnvalue == MUT_SPECCMD_FORCE))
639                                 if (autocvar_sv_spectate == 1)
640                                         ClientKill_TeamChange(caller, -2); // observe
641                         }
642                         return; // never fall through to usage
643                 }
644
645                 default:
646                 case CMD_REQUEST_USAGE:
647                 {
648                         sprint(caller, "\nUsage:^3 cmd spectate <client>\n");
649                         sprint(caller, "  Where 'client' can be the player to spectate.\n");
650                         return;
651                 }
652         }
653 }
654
655 void ClientCommand_suggestmap(entity caller, int request, int argc)
656 {
657         switch (request)
658         {
659                 case CMD_REQUEST_COMMAND:
660                 {
661                         if (argv(1) != "")
662                         {
663                                 sprint(caller, strcat(MapVote_Suggest(caller, argv(1)), "\n"));
664                                 return;
665                         }
666                 }
667
668                 default:
669                         sprint(caller, "Incorrect parameters for ^2suggestmap^7\n");
670                 case CMD_REQUEST_USAGE:
671                 {
672                         sprint(caller, "\nUsage:^3 cmd suggestmap map\n");
673                         sprint(caller, "  Where 'map' is the name of the map to suggest.\n");
674                         return;
675                 }
676         }
677 }
678
679 void ClientCommand_tell(entity caller, int request, int argc, string command)
680 {
681         switch (request)
682         {
683                 case CMD_REQUEST_COMMAND:
684                 {
685                         if (argc >= 3)
686                         {
687                                 if(!IS_CLIENT(caller) && IS_REAL_CLIENT(caller)) // connecting
688                                 {
689                                         print_to(caller, "You can't ^2tell^7 a message while connecting.");
690                                         return;
691                                 }
692
693                                 entity tell_to = GetIndexedEntity(argc, 1);
694                                 float tell_accepted = VerifyClientEntity(tell_to, true, false);
695
696                                 if (tell_accepted > 0)   // the target is a real client
697                                 {
698                                         if (tell_to != caller) // and we're allowed to send to them :D
699                                         {
700                                                 // workaround for argv indexes indexing ascii chars instead of utf8 chars
701                                                 // In this case when the player name contains utf8 chars
702                                                 // the message gets partially trimmed in the beginning.
703                                                 // Potentially this bug affects any substring call that uses
704                                                 // argv_start_index and argv_end_index.
705
706                                                 string utf8_enable_save = cvar_string("utf8_enable");
707                                                 cvar_set("utf8_enable", "0");
708                                                 string msg = substring(command, argv_start_index(next_token), argv_end_index(-1) - argv_start_index(next_token));
709                                                 cvar_set("utf8_enable", utf8_enable_save);
710
711                                                 Say(caller, false, tell_to, msg, true);
712                                                 return;
713                                         }
714                                         else { print_to(caller, "You can't ^2tell^7 a message to yourself."); return; }
715                                 }
716                                 else if (argv(1) == "#0")
717                                 {
718                                         trigger_magicear_processmessage_forallears(caller, -1, NULL, substring(command, argv_start_index(next_token), argv_end_index(-1) - argv_start_index(next_token)));
719                                         return;
720                                 }
721                                 else { print_to(caller, strcat("tell: ", GetClientErrorString(tell_accepted, argv(1)), ".")); return; }
722                         }
723                 }
724
725                 default:
726                         sprint(caller, "Incorrect parameters for ^2tell^7\n");
727                 case CMD_REQUEST_USAGE:
728                 {
729                         sprint(caller, "\nUsage:^3 cmd tell client <message>\n");
730                         sprint(caller, "  Where 'client' is the entity number or name of the player to send 'message' to.\n");
731                         return;
732                 }
733         }
734 }
735
736 void ClientCommand_voice(entity caller, int request, int argc, string command)
737 {
738         switch (request)
739         {
740                 case CMD_REQUEST_COMMAND:
741                 {
742                         if (argv(1) != "")
743                         {
744                                 entity e = GetVoiceMessage(argv(1));
745                                 if (!e)
746                                 {
747                                         sprint(caller, sprintf("Invalid voice. Use one of: %s\n", allvoicesamples));
748                                         return;
749                                 }
750                                 string msg = "";
751                                 if (argc >= 3)
752                                         msg = substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2));
753                                 VoiceMessage(caller, e, msg);
754
755                                 return;
756                         }
757                 }
758
759                 default:
760                         sprint(caller, "Incorrect parameters for ^2voice^7\n");
761                 case CMD_REQUEST_USAGE:
762                 {
763                         sprint(caller, "\nUsage:^3 cmd voice messagetype <soundname>\n");
764                         sprint(caller, "  'messagetype' is the type of broadcast to do, like team only or such,\n");
765                         sprint(caller, "  and 'soundname' is the string/filename of the sound/voice message to play.\n");
766                         return;
767                 }
768         }
769 }
770
771 /* use this when creating a new command, making sure to place it in alphabetical order... also,
772 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
773 void ClientCommand_(entity caller, int request)
774 {
775     switch(request)
776     {
777         case CMD_REQUEST_COMMAND:
778         {
779
780             return; // never fall through to usage
781         }
782
783         default:
784         case CMD_REQUEST_USAGE:
785         {
786             sprint(caller, "\nUsage:^3 cmd \n");
787             sprint(caller, "  No arguments required.\n");
788             return;
789         }
790     }
791 }
792 */
793
794
795 // =====================================
796 //  Macro system for networked commands
797 // =====================================
798
799 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
800 #define CLIENT_COMMANDS(ent, request, arguments, command) \
801         CLIENT_COMMAND("autoswitch", ClientCommand_autoswitch(ent, request, arguments), "Whether or not to switch automatically when getting a better weapon") \
802         CLIENT_COMMAND("clientversion", ClientCommand_clientversion(ent, request, arguments), "Release version of the game") \
803         CLIENT_COMMAND("join", ClientCommand_join(ent, request), "Become a player in the game") \
804         CLIENT_COMMAND("kill", ClientCommand_kill(ent, request), "Become a member of the dead") \
805         CLIENT_COMMAND("minigame", ClientCommand_minigame(ent, request, arguments, command), "Start a minigame") \
806         CLIENT_COMMAND("mv_getpicture", ClientCommand_mv_getpicture(ent, request, arguments), "Retrieve mapshot picture from the server") \
807         CLIENT_COMMAND("physics", ClientCommand_physics(ent, request, arguments), "Change physics set") \
808         CLIENT_COMMAND("ready", ClientCommand_ready(ent, request), "Qualify as ready to end warmup stage (or restart server if allowed)") \
809         CLIENT_COMMAND("say", ClientCommand_say(ent, request, arguments, command), "Print a message to chat to all players") \
810         CLIENT_COMMAND("say_team", ClientCommand_say_team(ent, request, arguments, command), "Print a message to chat to all team mates") \
811         CLIENT_COMMAND("selectteam", ClientCommand_selectteam(ent, request, arguments), "Attempt to choose a team to join into") \
812         CLIENT_COMMAND("selfstuff", ClientCommand_selfstuff(ent, request, command), "Stuffcmd a command to your own client") \
813         CLIENT_COMMAND("sentcvar", ClientCommand_sentcvar(ent, request, arguments, command), "New system for sending a client cvar to the server") \
814         CLIENT_COMMAND("spectate", ClientCommand_spectate(ent, request), "Become an observer") \
815         CLIENT_COMMAND("suggestmap", ClientCommand_suggestmap(ent, request, arguments), "Suggest a map to the mapvote at match end") \
816         CLIENT_COMMAND("tell", ClientCommand_tell(ent, request, arguments, command), "Send a message directly to a player") \
817         CLIENT_COMMAND("voice", ClientCommand_voice(ent, request, arguments, command), "Send voice message via sound") \
818         CLIENT_COMMAND("wpeditor", ClientCommand_wpeditor(ent, request, arguments), "Waypoint editor commands") \
819         /* nothing */
820
821 void ClientCommand_macro_help(entity caller)
822 {
823         #define CLIENT_COMMAND(name, function, description) \
824                 { sprint(caller, "  ^2", name, "^7: ", description, "\n"); }
825
826         CLIENT_COMMANDS(NULL, 0, 0, "");
827 #undef CLIENT_COMMAND
828 }
829
830 float ClientCommand_macro_command(int argc, entity caller, string command)
831 {
832         #define CLIENT_COMMAND(name, function, description) \
833                 { if (name == strtolower(argv(0))) { function; return true; } }
834
835         CLIENT_COMMANDS(caller, CMD_REQUEST_COMMAND, argc, command);
836 #undef CLIENT_COMMAND
837
838         return false;
839 }
840
841 float ClientCommand_macro_usage(int argc, entity caller)
842 {
843         #define CLIENT_COMMAND(name, function, description) \
844                 { if (name == strtolower(argv(1))) { function; return true; } }
845
846         CLIENT_COMMANDS(caller, CMD_REQUEST_USAGE, argc, "");
847 #undef CLIENT_COMMAND
848
849         return false;
850 }
851
852 void ClientCommand_macro_write_aliases(float fh)
853 {
854         #define CLIENT_COMMAND(name, function, description) \
855                 { CMD_Write_Alias("qc_cmd_cmd", name, description); }
856
857         CLIENT_COMMANDS(NULL, 0, 0, "");
858 #undef CLIENT_COMMAND
859 }
860
861 // ======================================
862 //  Main Function Called By Engine (cmd)
863 // ======================================
864 // If this function exists, server game code parses clientcommand before the engine code gets it.
865
866 void SV_ParseClientCommand(entity this, string command)
867 {
868         // If invalid UTF-8, don't even parse it
869         string command2 = "";
870         float len = strlen(command);
871         float i;
872         for (i = 0; i < len; ++i)
873                 command2 = strcat(command2, chr2str(str2chr(command, i)));
874         if (command != command2) return;
875
876         // if we're banned, don't even parse the command
877         if (Ban_MaybeEnforceBanOnce(this)) return;
878
879         int argc = tokenize_console(command);
880
881         // Guide for working with argc arguments by example:
882         // argc:   1    - 2      - 3     - 4
883         // argv:   0    - 1      - 2     - 3
884         // cmd     vote - master - login - password
885
886         // for floodcheck
887         switch (strtolower(argv(0)))
888         {
889                 // exempt commands which are not subject to floodcheck
890                 case "begin": break;                               // handled by engine in host_cmd.c
891                 case "download": break;                            // handled by engine in cl_parse.c
892                 case "mv_getpicture": break;                       // handled by server in this file
893                 case "wpeditor": break;                            // handled by server in this file
894                 case "pause": break;                               // handled by engine in host_cmd.c
895                 case "prespawn": break;                            // handled by engine in host_cmd.c
896                 case "sentcvar": break;                            // handled by server in this file
897                 case "spawn": break;                               // handled by engine in host_cmd.c
898                 case "c2s": Net_ClientCommand(this, command); return; // handled by net.qh
899
900                 default:
901                         if (SV_ParseClientCommand_floodcheck(this)) break; // "true": continue, as we're not flooding yet
902                         else return;                                   // "false": not allowed to continue, halt // print("^1ERROR: ^7ANTISPAM CAUGHT: ", command, ".\n");
903         }
904
905         /* NOTE: should this be disabled? It can be spammy perhaps, but hopefully it's okay for now */
906         if (argv(0) == "help")
907         {
908                 if (argc == 1)
909                 {
910                         sprint(this, "\nClient networked commands:\n");
911                         ClientCommand_macro_help(this);
912
913                         sprint(this, "\nCommon networked commands:\n");
914                         CommonCommand_macro_help(this);
915
916                         sprint(this, "\nUsage:^3 cmd COMMAND...^7, where possible commands are listed above.\n");
917                         sprint(this, "For help about a specific command, type cmd help COMMAND\n");
918                         return;
919                 }
920                 else if (CommonCommand_macro_usage(argc, this))  // Instead of trying to call a command, we're going to see detailed information about it
921                 {
922                         return;
923                 }
924                 else if (ClientCommand_macro_usage(argc, this))  // same, but for normal commands now
925                 {
926                         return;
927                 }
928         }
929         else if (MUTATOR_CALLHOOK(SV_ParseClientCommand, this, strtolower(argv(0)), argc, command))
930         {
931                 return;  // handled by a mutator
932         }
933         else if (CheatCommand(this, argc))
934         {
935                 return;  // handled by server/cheats.qc
936         }
937         else if (CommonCommand_macro_command(argc, this, command))
938         {
939                 return;                                          // handled by server/command/common.qc
940         }
941         else if (ClientCommand_macro_command(argc, this, command)) // continue as usual and scan for normal commands
942         {
943                 return;                                          // handled by one of the above ClientCommand_* functions
944         }
945         else
946         {
947                 clientcommand(this, command);
948         }
949 }