]> 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(self.flags & FL_CLIENT)
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(self.flags & FL_CLIENT)
152                         {
153                                 if(self.classname != "player" && !lockteams && !g_arena)
154                                 {
155                                         if(nJoinAllowed(self)) 
156                                         {
157                                                 if(g_ca) { self.caplayer = 1; }
158                                                 if(autocvar_g_campaign) { campaign_bots_may_start = 1; }
159                                                 
160                                                 self.classname = "player";
161                                                 PlayerScore_Clear(self);
162                                                 bprint ("^4", self.netname, "^4 is playing now\n");
163                                                 PutClientInServer();
164                                         }
165                                         else 
166                                         {
167                                                 //player may not join because of g_maxplayers is set
168                                                 centerprint(self, PREVENT_JOIN_TEXT);
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))); WaypointSprite_UpdateSprites(trace_ent.sprite, trace_ent.netname, "", ""); break;
200                                 case "skin": trace_ent.skin = stof(argv(2)); break;
201                                 case "color": trace_ent.colormod = stov(argv(2)); break;
202                                 case "movetarget": trace_ent.monster_moveflags = stof(argv(2)); break;
203                                 default: sprint(self, "Unknown parameter\n"); break;
204                         }
205                         
206                         return; // never fall through to usage
207                 }
208                 default:
209                         sprint(self, "Incorrect parameters for ^2mobedit^7\n");
210                 case CMD_REQUEST_USAGE:
211                 {
212                         sprint(self, "\nUsage:^3 cmd mobedit [argument]\n");
213                         sprint(self, "  Where 'argument' can be name, skin, color or movetarget.\n");
214                         return;
215                 }
216         }
217 }
218         
219 void ClientCommand_mobkill(float request)
220 {
221         switch(request)
222         {
223                 case CMD_REQUEST_COMMAND:
224                 {
225                         makevectors(self.v_angle);
226                         WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * 100, MOVE_NORMAL, self);
227                         
228                         if(trace_ent.flags & FL_MONSTER)
229                         {
230                                 if(trace_ent.realowner != self)
231                                 {
232                                         sprint(self, "That monster does not belong to you.\n");
233                                         return;
234                                 }
235                                 sprint(self, strcat("Your pet '", trace_ent.netname, "' has been brutally mutilated.\n"));
236                                 Damage (trace_ent, world, world, trace_ent.health + trace_ent.max_health, DEATH_KILL, trace_ent.origin, '0 0 0');
237                                 return;
238                         }
239                         else
240                                 sprint(self, "You need to aim at your monster to kill it.\n");
241                         
242                         return;
243                 }
244         
245                 default:
246                         sprint(self, "Incorrect parameters for ^2mobkill^7\n");
247                 case CMD_REQUEST_USAGE:
248                 {
249                         sprint(self, "\nUsage:^3 cmd mobkill\n");
250                         sprint(self, "  Aim at your monster to kill it.\n");
251                         return;
252                 }
253         }
254 }
255
256 void ClientCommand_mobspawn(float request, float argc)
257 {
258         switch(request)
259         {
260                 case CMD_REQUEST_COMMAND:
261                 {
262                         entity e;
263                         string tospawn, mname;
264                         float moveflag;
265                         
266                         moveflag = (argv(2) ? stof(argv(2)) : 1); // follow owner if not defined
267                         tospawn = argv(1);
268                         mname = argv(3);
269                         
270                         if(tospawn == "list")
271                         {
272                                 sprint(self, "Available monsters:\n");
273                                 sprint(self, strcat(autocvar_g_monsters_spawn_list, "\n"));
274                                 return;
275                         }
276                         
277                         if(self.classname != STR_PLAYER) { sprint(self, "You can't spawn monsters while spectating.\n"); }
278                         else if not(autocvar_g_monsters) { sprint(self, "Monsters aren't enabled.\n"); }
279                         else if(g_td) { sprint(self, "You can't spawn monsters in Tower Defense mode.\n"); }
280                         else if(self.deadflag) { sprint(self, "You can't spawn monsters while dead.\n"); }
281                         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"); }
282                         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"); }
283                         else // all worked out, so continue
284                         {
285                                 self.monstercount += 1;
286                                 totalspawned += 1;
287                         
288                                 makevectors(self.v_angle);
289                                 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * 150, MOVE_NORMAL, self);
290                         
291                                 e = spawnmonster(tospawn, self, self, trace_endpos, FALSE, moveflag);
292                                 if(mname) e.netname = strzone(mname);
293                         
294                                 sprint(self, strcat("Spawned 1 ", tospawn, "\n"));
295                         }
296                         
297                         return;
298                 }
299         
300                 default:
301                         sprint(self, "Incorrect parameters for ^2mobspawn^7\n");
302                 case CMD_REQUEST_USAGE:
303                 {
304                         sprint(self, "\nUsage:^3 cmd mobspawn monster\n");
305                         sprint(self, "  See 'cmd mobspawn list' for available arguments.\n");
306                         return;
307                 }
308         }
309 }
310
311 void ClientCommand_ready(float request) // todo: anti-spam for toggling readyness
312 {
313         switch(request)
314         {
315                 case CMD_REQUEST_COMMAND:
316                 {
317                         if(self.flags & FL_CLIENT)
318                         {
319                                 if(inWarmupStage || autocvar_sv_ready_restart || g_race_qualifying == 2)
320                                 {
321                                         if(!readyrestart_happened || autocvar_sv_ready_restart_repeatable)
322                                         {
323                                                 if (self.ready) // toggle
324                                                 {
325                                                         self.ready = FALSE;
326                                                         bprint(self.netname, "^2 is ^1NOT^2 ready\n");
327                                                 }
328                                                 else
329                                                 {
330                                                         self.ready = TRUE;
331                                                         bprint(self.netname, "^2 is ready\n");
332                                                 }
333
334                                                 // cannot reset the game while a timeout is active!
335                                                 if not(timeout_status)
336                                                         ReadyCount();
337                                         } else {
338                                                 sprint(self, "^1Game has already been restarted\n");
339                                         }
340                                 }
341                         }
342                         return; // never fall through to usage
343                 }
344                         
345                 default:
346                 case CMD_REQUEST_USAGE:
347                 {
348                         sprint(self, "\nUsage:^3 cmd ready\n");
349                         sprint(self, "  No arguments required.\n");
350                         return;
351                 }
352         }
353 }
354
355 void ClientCommand_say(float request, float argc, string command)
356 {
357         switch(request)
358         {
359                 case CMD_REQUEST_COMMAND:
360                 {
361                         if(argc >= 2) { Say(self, FALSE, world, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1); }
362                         return; // never fall through to usage
363                 }
364                         
365                 default:
366                 case CMD_REQUEST_USAGE:
367                 {
368                         sprint(self, "\nUsage:^3 cmd say <message>\n");
369                         sprint(self, "  Where 'message' is the string of text to say.\n");
370                         return;
371                 }
372         }
373 }
374
375 void ClientCommand_say_team(float request, float argc, string command)
376 {
377         switch(request)
378         {
379                 case CMD_REQUEST_COMMAND:
380                 {
381                         if(argc >= 2) { Say(self, TRUE, world, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1); }
382                         return; // never fall through to usage
383                 }
384                         
385                 default:
386                 case CMD_REQUEST_USAGE:
387                 {
388                         sprint(self, "\nUsage:^3 cmd say_team <message>\n");
389                         sprint(self, "  Where 'message' is the string of text to say.\n");
390                         return;
391                 }
392         }
393 }
394
395 void ClientCommand_selectteam(float request, float argc)
396 {
397         switch(request)
398         {
399                 case CMD_REQUEST_COMMAND:
400                 {
401                         if(argv(1) != "")
402                         {
403                                 if(self.flags & FL_CLIENT)
404                                 {
405                                         if(teamplay)
406                                                 if not(self.team_forced > 0) 
407                                                         if not(lockteams) 
408                                                         {
409                                                                 float selection;
410                                                                 
411                                                                 switch(argv(1))
412                                                                 {
413                                                                         case "red": selection = COLOR_TEAM1; break;
414                                                                         case "blue": selection = COLOR_TEAM2; break;
415                                                                         case "yellow": selection = COLOR_TEAM3; break;
416                                                                         case "pink": selection = COLOR_TEAM4; break;
417                                                                         case "auto": selection = (-1); break;
418                                                                         
419                                                                         default: selection = 0; break;
420                                                                 }
421                                                                 
422                                                                 if(selection)
423                                                                 {
424                                                                         if(self.team == selection && self.deadflag == DEAD_NO)
425                                                                                 sprint(self, "^7You already are on that team.\n");
426                                                                         else if(self.wasplayer && autocvar_g_changeteam_banned)
427                                                                                 sprint(self, "^1You cannot change team, forbidden by the server.\n");
428                                                                         else
429                                                                                 ClientKill_TeamChange(selection);
430                                                                 }
431                                                         }
432                                                         else
433                                                                 sprint(self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
434                                                 else
435                                                         sprint(self, "^7selectteam can not be used as your team is forced\n");
436                                         else
437                                                 sprint(self, "^7selectteam can only be used in teamgames\n");
438                                 }
439                                 return; 
440                         }
441                 }
442
443                 default:
444                         sprint(self, "Incorrect parameters for ^2selectteam^7\n");
445                 case CMD_REQUEST_USAGE:
446                 {
447                         sprint(self, "\nUsage:^3 cmd selectteam team\n");
448                         sprint(self, "  Where 'team' is the prefered team to try and join.\n");
449                         sprint(self, "  Full list of options here: \"red, blue, yellow, pink, auto\"\n");
450                         return;
451                 }
452         }
453 }
454
455 void ClientCommand_selfstuff(float request, string command)
456 {
457         switch(request)
458         {
459                 case CMD_REQUEST_COMMAND:
460                 {
461                         if(argv(1) != "")
462                         {
463                                 stuffcmd(self, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
464                                 return;
465                         }
466                 }
467                         
468                 default:
469                         sprint(self, "Incorrect parameters for ^2selectteam^7\n");
470                 case CMD_REQUEST_USAGE:
471                 {
472                         sprint(self, "\nUsage:^3 cmd selfstuff <command>\n");
473                         sprint(self, "  Where 'command' is the string to be stuffed to your client.\n");
474                         return;
475                 }
476         }
477 }
478
479 void ClientCommand_sentcvar(float request, float argc, string command)
480 {
481         switch(request)
482         {
483                 case CMD_REQUEST_COMMAND:
484                 {
485                         if(argv(1) != "")
486                         {
487                                 //float tokens;
488                                 string s;
489                                 
490                                 if(argc == 2) // undefined cvar: use the default value on the server then
491                                 {
492                                         s = strcat(substring(command, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
493                                         tokenize_console(s);
494                                 }
495                                 
496                                 GetCvars(1);
497                                 
498                                 return;
499                         }
500                 }
501                         
502                 default:
503                         sprint(self, "Incorrect parameters for ^2sentcvar^7\n");
504                 case CMD_REQUEST_USAGE:
505                 {
506                         sprint(self, "\nUsage:^3 cmd sentcvar <cvar>\n");
507                         sprint(self, "  Where 'cvar' is the cvar plus arguments to send to the server.\n");
508                         return;
509                 }
510         }
511 }
512
513 void ClientCommand_spectate(float request) 
514 {
515         switch(request)
516         {
517                 case CMD_REQUEST_COMMAND:
518                 {
519                         if(self.flags & FL_CLIENT)
520                         {
521                                 if(g_arena) { return; } 
522                                 if(g_lms)
523                                 {
524                                         if(self.lms_spectate_warning)
525                                         {
526                                                 // mark player as spectator
527                                                 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
528                                         }
529                                         else
530                                         {
531                                                 self.lms_spectate_warning = 1;
532                                                 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");
533                                                 return;
534                                         }
535                                 }
536                                 
537                                 if(self.classname == "player" && autocvar_sv_spectate == 1) 
538                                         ClientKill_TeamChange(-2); // observe
539                                 
540                                 // in CA, allow a dead player to move to spectators (without that, caplayer!=0 will be moved back to the player list)
541                                 // note: if arena game mode is ever done properly, this needs to be removed.
542                                 if(g_ca && self.caplayer && (self.classname == "spectator" || self.classname == "observer"))
543                                 {
544                                         sprint(self, "WARNING: you will spectate in the next round.\n");
545                                         self.caplayer = 0;
546                                 }
547                         }
548                         return; // never fall through to usage
549                 }
550                         
551                 default:
552                 case CMD_REQUEST_USAGE:
553                 {
554                         sprint(self, "\nUsage:^3 cmd spectate\n");
555                         sprint(self, "  No arguments required.\n");
556                         return;
557                 }
558         }
559 }
560
561 void ClientCommand_suggestmap(float request, float argc)
562 {
563         switch(request)
564         {
565                 case CMD_REQUEST_COMMAND:
566                 {
567                         if(argv(1) != "")
568                         {
569                                 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
570                                 return;
571                         }
572                 }
573                         
574                 default:
575                         sprint(self, "Incorrect parameters for ^2suggestmap^7\n");
576                 case CMD_REQUEST_USAGE:
577                 {
578                         sprint(self, "\nUsage:^3 cmd suggestmap map\n");
579                         sprint(self, "  Where 'map' is the name of the map to suggest.\n");
580                         return;
581                 }
582         }
583 }
584
585 void ClientCommand_tell(float request, float argc, string command)
586 {
587         switch(request)
588         {
589                 case CMD_REQUEST_COMMAND:
590                 {
591                         if(argc >= 3)
592                         {
593                                 entity tell_to = GetIndexedEntity(argc, 1);
594                                 float tell_accepted = VerifyClientEntity(tell_to, TRUE, FALSE);
595                                 
596                                 if(tell_accepted > 0) // the target is a real client
597                                 {
598                                         if(tell_to != self) // and we're allowed to send to them :D
599                                         {
600                                                 Say(self, FALSE, tell_to, substring(command, argv_start_index(next_token), argv_end_index(-1) - argv_start_index(next_token)), TRUE);
601                                                 return;
602                                         }
603                                         else { print_to(self, "You can't ^2tell^7 a message to yourself."); return; }
604                                 }
605                                 else if(argv(1) == "#0") 
606                                 { 
607                                         trigger_magicear_processmessage_forallears(self, -1, world, substring(command, argv_start_index(next_token), argv_end_index(-1) - argv_start_index(next_token)));
608                                         return;
609                                 }
610                                 else { print_to(self, strcat("tell: ", GetClientErrorString(tell_accepted, argv(1)), ".")); return; }
611                         }
612                 }
613                         
614                 default:
615                         sprint(self, "Incorrect parameters for ^2tell^7\n");
616                 case CMD_REQUEST_USAGE:
617                 {
618                         sprint(self, "\nUsage:^3 cmd tell client <message>\n");
619                         sprint(self, "  Where 'client' is the entity number or name of the player to send 'message' to.\n");
620                         return;
621                 }
622         }
623 }
624
625 void ClientCommand_voice(float request, float argc, string command) 
626 {
627         switch(request)
628         {
629                 case CMD_REQUEST_COMMAND:
630                 {
631                         if(argv(1) != "")
632                         {
633                                 if(argc >= 3)
634                                         VoiceMessage(argv(1), substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
635                                 else
636                                         VoiceMessage(argv(1), "");
637                                         
638                                 return;
639                         }
640                 }
641                         
642                 default:
643                         sprint(self, "Incorrect parameters for ^2voice^7\n");
644                 case CMD_REQUEST_USAGE:
645                 {
646                         sprint(self, "\nUsage:^3 cmd voice messagetype <soundname>\n");
647                         sprint(self, "  'messagetype' is the type of broadcast to do, like team only or such,\n");
648                         sprint(self, "  and 'soundname' is the string/filename of the sound/voice message to play.\n");
649                         return;
650                 }
651         }
652 }
653
654 /* use this when creating a new command, making sure to place it in alphabetical order... also,
655 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
656 void ClientCommand_(float request)
657 {
658         switch(request)
659         {
660                 case CMD_REQUEST_COMMAND:
661                 {
662                         
663                         return; // never fall through to usage
664                 }
665                         
666                 default:
667                 case CMD_REQUEST_USAGE:
668                 {
669                         sprint(self, "\nUsage:^3 cmd \n");
670                         sprint(self, "  No arguments required.\n");
671                         return;
672                 }
673         }
674 }
675 */
676
677
678 // =====================================
679 //  Macro system for networked commands
680 // =====================================
681
682 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
683 #define CLIENT_COMMANDS(request,arguments,command) \
684         CLIENT_COMMAND("autoswitch", ClientCommand_autoswitch(request, arguments), "Whether or not to switch automatically when getting a better weapon") \
685         CLIENT_COMMAND("checkfail", ClientCommand_checkfail(request, command), "Report if a client-side check failed") \
686         CLIENT_COMMAND("clientversion", ClientCommand_clientversion(request, arguments), "Release version of the game") \
687         CLIENT_COMMAND("mv_getpicture", ClientCommand_mv_getpicture(request, arguments), "Retrieve mapshot picture from the server") \
688         CLIENT_COMMAND("join", ClientCommand_join(request), "Become a player in the game") \
689         CLIENT_COMMAND("mobedit", ClientCommand_mobedit(request, arguments), "Edit your monster's properties") \
690         CLIENT_COMMAND("mobkill", ClientCommand_mobkill(request), "Kills your monster") \
691         CLIENT_COMMAND("mobspawn", ClientCommand_mobspawn(request, arguments), "Spawn monsters infront of yourself") \
692         CLIENT_COMMAND("ready", ClientCommand_ready(request), "Qualify as ready to end warmup stage (or restart server if allowed)") \
693         CLIENT_COMMAND("say", ClientCommand_say(request, arguments, command), "Print a message to chat to all players") \
694         CLIENT_COMMAND("say_team", ClientCommand_say_team(request, arguments, command), "Print a message to chat to all team mates") \
695         CLIENT_COMMAND("selectteam", ClientCommand_selectteam(request, arguments), "Attempt to choose a team to join into") \
696         CLIENT_COMMAND("selfstuff", ClientCommand_selfstuff(request, command), "Stuffcmd a command to your own client") \
697         CLIENT_COMMAND("sentcvar", ClientCommand_sentcvar(request, arguments, command), "New system for sending a client cvar to the server") \
698         CLIENT_COMMAND("spectate", ClientCommand_spectate(request), "Become an observer") \
699         CLIENT_COMMAND("suggestmap", ClientCommand_suggestmap(request, arguments), "Suggest a map to the mapvote at match end") \
700         CLIENT_COMMAND("tell", ClientCommand_tell(request, arguments, command), "Send a message directly to a player") \
701         CLIENT_COMMAND("voice", ClientCommand_voice(request, arguments, command), "Send voice message via sound") \
702         /* nothing */
703         
704 void ClientCommand_macro_help()
705 {
706         #define CLIENT_COMMAND(name,function,description) \
707                 { sprint(self, "  ^2", name, "^7: ", description, "\n"); }
708                 
709         CLIENT_COMMANDS(0, 0, "")
710         #undef CLIENT_COMMAND
711         
712         return;
713 }
714
715 float ClientCommand_macro_command(float argc, string command)
716 {
717         #define CLIENT_COMMAND(name,function,description) \
718                 { if(name == strtolower(argv(0))) { function; return TRUE; } }
719                 
720         CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc, command)
721         #undef CLIENT_COMMAND
722         
723         return FALSE;
724 }
725
726 float ClientCommand_macro_usage(float argc)
727 {
728         #define CLIENT_COMMAND(name,function,description) \
729                 { if(name == strtolower(argv(1))) { function; return TRUE; } }
730                 
731         CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc, "")
732         #undef CLIENT_COMMAND
733         
734         return FALSE;
735 }
736
737 void ClientCommand_macro_write_aliases(float fh)
738 {
739         #define CLIENT_COMMAND(name,function,description) \
740                 { CMD_Write_Alias("qc_cmd_cmd", name, description); } 
741                 
742         CLIENT_COMMANDS(0, 0, "")
743         #undef CLIENT_COMMAND
744         
745         return;
746 }
747
748 // ======================================
749 //  Main Function Called By Engine (cmd)
750 // ======================================
751 // If this function exists, server game code parses clientcommand before the engine code gets it.
752
753 void SV_ParseClientCommand(string command)
754 {
755         // if we're banned, don't even parse the command
756         if(Ban_MaybeEnforceBanOnce(self))
757                 return;
758
759         float argc = tokenize_console(command);
760         
761         // for the mutator hook system
762         cmd_name = strtolower(argv(0));
763         cmd_argc = argc;
764         cmd_string = command;
765         
766         // Guide for working with argc arguments by example:
767         // argc:   1    - 2      - 3     - 4
768         // argv:   0    - 1      - 2     - 3 
769         // cmd     vote - master - login - password
770         
771         // for floodcheck
772         switch(strtolower(argv(0)))
773         {
774                 // exempt commands which are not subject to floodcheck
775                 case "begin": break; // handled by engine in host_cmd.c
776                 case "download": break; // handled by engine in cl_parse.c
777                 case "mv_getpicture": break; // handled by server in this file
778                 case "pause": break; // handled by engine in host_cmd.c
779                 case "prespawn": break; // handled by engine in host_cmd.c
780                 case "sentcvar": break; // handled by server in this file
781                 case "spawn": break; // handled by engine in host_cmd.c
782                 
783                 default: 
784                         if(SV_ParseClientCommand_floodcheck())
785                                 break; // "TRUE": continue, as we're not flooding yet
786                         else
787                                 return; // "FALSE": not allowed to continue, halt // print("^1ERROR: ^7ANTISPAM CAUGHT: ", command, ".\n");
788         }
789         
790         /* NOTE: should this be disabled? It can be spammy perhaps, but hopefully it's okay for now */
791         if(argv(0) == "help") 
792         {
793                 if(argc == 1) 
794                 {
795                         sprint(self, "\nClient networked commands:\n");
796                         ClientCommand_macro_help();
797                         
798                         sprint(self, "\nCommon networked commands:\n");
799                         CommonCommand_macro_help(self);
800                         
801                         sprint(self, "\nUsage:^3 cmd COMMAND...^7, where possible commands are listed above.\n");
802                         sprint(self, "For help about a specific command, type cmd help COMMAND\n");
803                         return;
804                 } 
805                 else if(CommonCommand_macro_usage(argc, self)) // Instead of trying to call a command, we're going to see detailed information about it
806                 {
807                         return;
808                 }
809                 else if(ClientCommand_macro_usage(argc)) // same, but for normal commands now
810                 {
811                         return;
812                 }
813         } 
814         else if(MUTATOR_CALLHOOK(SV_ParseClientCommand))
815         {
816                 return; // handled by a mutator
817         }
818         else if(CheatCommand(argc)) 
819         {
820                 return; // handled by server/cheats.qc
821         }
822         else if(CommonCommand_macro_command(argc, self, command))
823         {
824                 return; // handled by server/command/common.qc
825         }
826         else if(ClientCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
827         {
828                 return; // handled by one of the above ClientCommand_* functions
829         }
830         else
831                 clientcommand(self, command);
832 }