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