]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/common.qh
Create separate .qh files for each of the other .qc command files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / common.qh
1 // =========================================================
2 //  Server side networked commands code, reworked by Samual
3 //  Last updated: December 11th, 2011
4 // =========================================================
5
6 #define CC_REQUEST_COMMAND 1
7 #define CC_REQUEST_USAGE 2
8
9 .float cmd_floodtime;
10 .float cmd_floodcount;
11 .float checkfail;
12 .float lms_spectate_warning;
13
14 string MapVote_Suggest(string m);
15 //void MapVote_SendPicture(float id)
16
17 // move any necessary sprint statements to "print_to"
18
19 // ============================
20 //  Misc. Supporting Functions
21 // ============================
22
23 float SV_ParseClientCommand_floodcheck()
24 {
25         if (timeoutStatus != 2) // if the game is not paused... but wait, doesn't that mean it could be dos'd by pausing it? eh? (old code)
26         {
27                 if(time <= (self.cmd_floodtime + autocvar_sv_clientcommand_antispam_time))
28                 {
29                         self.cmd_floodcount += 1;
30                         if(self.cmd_floodcount > autocvar_sv_clientcommand_antispam_count) { return FALSE; } // too much spam, halt
31                 }
32                 else
33                 {
34                         self.cmd_floodtime = time;
35                         self.cmd_floodcount = 1;
36                 }
37         }
38         return TRUE; // continue, as we're not flooding yet
39 }
40
41
42 // =======================
43 //  Command Sub-Functions
44 // =======================
45
46 void ClientCommand_autoswitch(float request, float argc)
47 {
48         switch(request)
49         {
50                 case CC_REQUEST_COMMAND:
51                 {
52                         self.autoswitch = ("0" != argv(1));
53                         sprint(self, strcat("^1autoswitch is currently turned ", (self.autoswitch ? "on" : "off"), ".\n"));
54                         return; // never fall through to usage
55                 }
56                         
57                 default:
58                 case CC_REQUEST_USAGE:
59                 {
60                         sprint(self, "\nUsage:^3 cmd autoswitch selection\n");
61                         sprint(self, "  Where 'selection' is 1 or 0 for on or off.\n"); 
62                         return;
63                 }
64         }
65 }
66
67 void ClientCommand_checkfail(float request, string command) // used only by client side code
68 {
69         switch(request)
70         {
71                 case CC_REQUEST_COMMAND:
72                 {
73                         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))));
74                         self.checkfail = 1;
75                         return; // never fall through to usage
76                 }
77                         
78                 default:
79                 case CC_REQUEST_USAGE:
80                 {
81                         sprint(self, "\nUsage:^3 cmd checkfail message\n");
82                         sprint(self, "  Where 'message' is the message reported by client about the fail.\n");
83                         return;
84                 }
85         }
86 }
87
88 void ClientCommand_clientversion(float request, float argc) // used only by client side code
89 {
90         switch(request)
91         {
92                 case CC_REQUEST_COMMAND:
93                 {
94                         if(self.flags & FL_CLIENT)
95                         {
96                                 self.version = ((argv(1) == "$gameversion") ? 1 : stof(argv(1)));
97                                 
98                                 if(self.version < autocvar_gameversion_min || self.version > autocvar_gameversion_max)
99                                 {
100                                         self.version_mismatch = 1;
101                                         ClientKill_TeamChange(-2); // observe
102                                 } 
103                                 else if(autocvar_g_campaign || autocvar_g_balance_teams || autocvar_g_balance_teams_force) 
104                                 {
105                                         //JoinBestTeam(self, FALSE, TRUE);
106                                 } 
107                                 else if(teamplay && !autocvar_sv_spectate && !(self.team_forced > 0)) 
108                                 {
109                                         self.classname = "observer"; // really?
110                                         stuffcmd(self, "menu_showteamselect\n");
111                                 }
112                         }
113                         return; // never fall through to usage
114                 }
115                         
116                 default:
117                 case CC_REQUEST_USAGE:
118                 {
119                         sprint(self, "\nUsage:^3 cmd clientversion version\n");
120                         sprint(self, "  Where 'version' is the game version reported by self.\n");
121                         return;
122                 }
123         }
124 }
125
126 void ClientCommand_cvar_changes(float request)
127 {
128         switch(request)
129         {
130                 case CC_REQUEST_COMMAND:
131                 {
132                         sprint(self, cvar_changes);
133                         return; // never fall through to usage
134                 }
135                         
136                 default:
137                 case CC_REQUEST_USAGE:
138                 {
139                         sprint(self, "\nUsage:^3 sv_cmd cvar_changes\n");
140                         sprint(self, "  No arguments required.\n");
141                         //sprint(self, "See also: ^2cvar_purechanges^7\n");
142                         return;
143                 }
144         }
145 }
146
147 void ClientCommand_cvar_purechanges(float request)
148 {
149         switch(request)
150         {
151                 case CC_REQUEST_COMMAND:
152                 {
153                         sprint(self, cvar_purechanges);
154                         return; // never fall through to usage
155                 }
156                         
157                 default:
158                 case CC_REQUEST_USAGE:
159                 {
160                         sprint(self, "\nUsage:^3 sv_cmd cvar_purechanges\n");
161                         sprint(self, "  No arguments required.\n");
162                         //sprint(self, "See also: ^2cvar_changes^7\n");
163                         return;
164                 }
165         }
166 }
167
168 void ClientCommand_getmapvotepic(float request, float argc)
169 {
170         switch(request)
171         {
172                 case CC_REQUEST_COMMAND:
173                 {
174                         if(intermission_running)                                
175                                 MapVote_SendPicture(stof(argv(1)));
176
177                         return; // never fall through to usage
178                 }
179                         
180                 default:
181                 case CC_REQUEST_USAGE:
182                 {
183                         sprint(self, "\nUsage:^3 cmd getmapvotepic mapid\n");
184                         sprint(self, "  Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
185                         return;
186                 }
187         }
188 }
189
190 void ClientCommand_info(float request, float argc)
191 {       
192         switch(request)
193         {
194                 case CC_REQUEST_COMMAND:
195                 {
196                         string command;
197                         
198                         command = builtin_cvar_string(strcat("sv_info_", argv(1))); 
199                         if(command)
200                                 wordwrap_sprint(command, 1111); // why 1111?
201                         else
202                                 sprint(self, "ERROR: unsupported info command\n");
203                                 
204                         return; // never fall through to usage
205                 }
206                         
207                 default:
208                 case CC_REQUEST_USAGE:
209                 {
210                         sprint(self, "\nUsage:^3 cmd info request\n");
211                         sprint(self, "  Where 'request' is the suffixed string appended onto the request for cvar.\n");
212                         return;
213                 }
214         }
215 }
216
217 void ClientCommand_join(float request)
218 {
219         switch(request)
220         {
221                 case CC_REQUEST_COMMAND:
222                 {
223                         if(self.flags & FL_CLIENT)
224                         {
225                                 if(self.classname != "player" && !lockteams && !g_arena)
226                                 {
227                                         if(nJoinAllowed(1)) 
228                                         {
229                                                 if(g_ca) { self.caplayer = 1; }
230                                                 if(autocvar_g_campaign) { campaign_bots_may_start = 1; }
231                                                 
232                                                 self.classname = "player";
233                                                 PlayerScore_Clear(self);
234                                                 bprint ("^4", self.netname, "^4 is playing now\n");
235                                                 PutClientInServer();
236                                         }
237                                         else 
238                                         {
239                                                 //player may not join because of g_maxplayers is set
240                                                 centerprint(self, PREVENT_JOIN_TEXT);
241                                         }
242                                 }
243                         }
244                         return; // never fall through to usage
245                 }
246                         
247                 default:
248                 case CC_REQUEST_USAGE:
249                 {
250                         sprint(self, "\nUsage:^3 cmd join\n");
251                         sprint(self, "  No arguments required.\n");
252                         return;
253                 }
254         }
255 }
256
257 void ClientCommand_ladder(float request)
258 {
259         switch(request)
260         {
261                 case CC_REQUEST_COMMAND:
262                 {
263                         sprint(self, ladder_reply);
264                         return; // never fall through to usage
265                 }
266                         
267                 default:
268                 case CC_REQUEST_USAGE:
269                 {
270                         sprint(self, "\nUsage:^3 cmd ladder\n");
271                         sprint(self, "  No arguments required.\n");
272                         return;
273                 }
274         }
275 }
276
277 void ClientCommand_lsmaps(float request)
278 {
279         switch(request)
280         {
281                 case CC_REQUEST_COMMAND:
282                 {
283                         sprint(self, lsmaps_reply);
284                         return; // never fall through to usage
285                 }
286                         
287                 default:
288                 case CC_REQUEST_USAGE:
289                 {
290                         sprint(self, "\nUsage:^3 cmd lsmaps\n");
291                         sprint(self, "  No arguments required.\n");
292                         return;
293                 }
294         }
295 }
296
297 void ClientCommand_lsnewmaps(float request)
298 {
299         switch(request)
300         {
301                 case CC_REQUEST_COMMAND:
302                 {
303                         sprint(self, lsnewmaps_reply);
304                         return; // never fall through to usage
305                 }
306                         
307                 default:
308                 case CC_REQUEST_USAGE:
309                 {
310                         sprint(self, "\nUsage:^3 cmd lsnewmaps\n");
311                         sprint(self, "  No arguments required.\n");
312                         return;
313                 }
314         }
315 }
316
317 void ClientCommand_maplist(float request)
318 {
319         switch(request)
320         {
321                 case CC_REQUEST_COMMAND:
322                 {
323                         sprint(self, maplist_reply);
324                         return; // never fall through to usage
325                 }
326                         
327                 default:
328                 case CC_REQUEST_USAGE:
329                 {
330                         sprint(self, "\nUsage:^3 cmd maplist\n");
331                         sprint(self, "  No arguments required.\n");
332                         return;
333                 }
334         }
335 }
336
337 void ClientCommand_rankings(float request)
338 {
339         switch(request)
340         {
341                 case CC_REQUEST_COMMAND:
342                 {
343                         sprint(self, rankings_reply);
344                         return; // never fall through to usage
345                 }
346                         
347                 default:
348                 case CC_REQUEST_USAGE:
349                 {
350                         sprint(self, "\nUsage:^3 cmd rankings\n");
351                         sprint(self, "  No arguments required.\n");
352                         return;
353                 }
354         }
355 }
356
357 void ClientCommand_ready(float request) 
358 {
359         switch(request)
360         {
361                 case CC_REQUEST_COMMAND:
362                 {
363                         if(self.flags & FL_CLIENT)
364                         {
365                                 if(inWarmupStage || autocvar_sv_ready_restart || g_race_qualifying == 2)
366                                 {
367                                         if(!readyrestart_happened || autocvar_sv_ready_restart_repeatable)
368                                         {
369                                                 if (self.ready) // toggle
370                                                 {
371                                                         self.ready = FALSE;
372                                                         bprint(self.netname, "^2 is ^1NOT^2 ready\n");
373                                                 }
374                                                 else
375                                                 {
376                                                         self.ready = TRUE;
377                                                         bprint(self.netname, "^2 is ready\n");
378                                                 }
379
380                                                 // cannot reset the game while a timeout is active!
381                                                 if(!timeoutStatus)
382                                                         ReadyCount();
383                                         } else {
384                                                 sprint(self, "^1Game has already been restarted\n");
385                                         }
386                                 }
387                         }
388                         return; // never fall through to usage
389                 }
390                         
391                 default:
392                 case CC_REQUEST_USAGE:
393                 {
394                         sprint(self, "\nUsage:^3 cmd ready\n");
395                         sprint(self, "  No arguments required.\n");
396                         return;
397                 }
398         }
399 }
400
401 void ClientCommand_records(float request) // TODO: Isn't this flooding with the sprint messages? Old code, but perhaps bad?
402 {       
403         switch(request)
404         {
405                 case CC_REQUEST_COMMAND:
406                 {
407                         float i;
408                         
409                         for(i = 0; i < 10; ++i)
410                                 sprint(self, records_reply[i]);
411                                 
412                         return; // never fall through to usage
413                 }
414                         
415                 default:
416                 case CC_REQUEST_USAGE:
417                 {
418                         sprint(self, "\nUsage:^3 cmd records\n");
419                         sprint(self, "  No arguments required.\n");
420                         return;
421                 }
422         }
423 }
424
425 void ClientCommand_reportcvar(float request, float argc, string command) // TODO: confirm this works
426 {       
427         switch(request)
428         {
429                 case CC_REQUEST_COMMAND:
430                 {
431                         float tokens;
432                         string s;
433                         
434                         if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
435                         {
436                                 s = strcat(substring(command, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
437                                 tokens = tokenize_console(s);
438                         }
439                         GetCvars(1);
440                         return; // never fall through to usage
441                 }
442                         
443                 default:
444                 case CC_REQUEST_USAGE:
445                 {
446                         sprint(self, "\nUsage:^3 cmd reportcvar <cvar>\n");
447                         sprint(self, "  Where 'cvar' is the cvar plus arguments to send to the server.\n");
448                         return;
449                 }
450         }
451 }
452
453 void ClientCommand_say(float request, float argc, string command)
454 {
455         switch(request)
456         {
457                 case CC_REQUEST_COMMAND:
458                 {
459                         if(argc >= 2) { Say(self, FALSE, world, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1); }
460                         return; // never fall through to usage
461                 }
462                         
463                 default:
464                 case CC_REQUEST_USAGE:
465                 {
466                         sprint(self, "\nUsage:^3 cmd say <message>\n");
467                         sprint(self, "  Where 'message' is the string of text to say.\n");
468                         return;
469                 }
470         }
471 }
472
473 void ClientCommand_say_team(float request, float argc, string command)
474 {
475         switch(request)
476         {
477                 case CC_REQUEST_COMMAND:
478                 {
479                         if(argc >= 2) { Say(self, TRUE, world, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1); }
480                         return; // never fall through to usage
481                 }
482                         
483                 default:
484                 case CC_REQUEST_USAGE:
485                 {
486                         sprint(self, "\nUsage:^3 cmd say_team <message>\n");
487                         sprint(self, "  Where 'message' is the string of text to say.\n");
488                         return;
489                 }
490         }
491 }
492
493 void ClientCommand_selectteam(float request, float argc) // TODO: Update the messages for this command
494 {
495         switch(request)
496         {
497                 case CC_REQUEST_COMMAND:
498                 {
499                         float selection;
500                         
501                         if (self.flags & FL_CLIENT)
502                         {
503                                 if(teamplay)
504                                         if not(self.team_forced > 0) 
505                                                 if not(lockteams) 
506                                                 {
507                                                         switch(argv(1))
508                                                         {
509                                                                 case "red": selection = COLOR_TEAM1; break;
510                                                                 case "blue": selection = COLOR_TEAM2; break;
511                                                                 case "yellow": selection = COLOR_TEAM3; break;
512                                                                 case "pink": selection = COLOR_TEAM4; break;
513                                                                 case "auto": selection = (-1); break;
514                                                                 
515                                                                 default: break;
516                                                         }
517                                                         
518                                                         if(selection)
519                                                         {
520                                                                 if(self.team == selection && self.deadflag == DEAD_NO)
521                                                                         sprint(self, "^7You already are on that team.\n");
522                                                                 else if(self.wasplayer && autocvar_g_changeteam_banned)
523                                                                         sprint(self, "^1You cannot change team, forbidden by the server.\n");
524                                                                 else
525                                                                         ClientKill_TeamChange(selection);
526                                                         }
527                                                 }
528                                                 else
529                                                         sprint(self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
530                                         else
531                                                 sprint(self, "^7selectteam can not be used as your team is forced\n");
532                                 else
533                                         sprint(self, "^7selectteam can only be used in teamgames\n");
534                         }
535                         return; // never fall through to usage
536                 }
537
538                 default:
539                 case CC_REQUEST_USAGE:
540                 {
541                         //sprint(self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
542                         sprint(self, "\nUsage:^3 cmd selectteam team\n");
543                         sprint(self, "  Where 'team' is the prefered team to try and join.\n");
544                         sprint(self, "  Full list of options here: \"red, blue, yellow, pink, auto\"\n");
545                         return;
546                 }
547         }
548 }
549
550 void ClientCommand_selfstuff(float request, string command)
551 {
552         switch(request)
553         {
554                 case CC_REQUEST_COMMAND:
555                 {
556                         stuffcmd(self, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
557                         return; // never fall through to usage
558                 }
559                         
560                 default:
561                 case CC_REQUEST_USAGE:
562                 {
563                         sprint(self, "\nUsage:^3 cmd selfstuff command\n");
564                         sprint(self, "  Where 'command' is the string to be stuffed to your client.\n");
565                         return;
566                 }
567         }
568 }
569
570 void ClientCommand_sentcvar(float request, float argc, string command)
571 {
572         switch(request)
573         {
574                 case CC_REQUEST_COMMAND:
575                 {
576                         float tokens;
577                         string s;
578                         
579                         if(argc == 2) // undefined cvar: use the default value on the server then
580                         {
581                                 s = strcat(substring(command, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
582                                 tokens = tokenize_console(s);
583                         }
584                         GetCvars(1);
585                         return; // never fall through to usage
586                 }
587                         
588                 default:
589                 case CC_REQUEST_USAGE:
590                 {
591                         sprint(self, "\nUsage:^3 cmd sentcvar <cvar>\n");
592                         sprint(self, "  Where 'cvar' is the cvar plus arguments to send to the server.\n");
593                         return;
594                 }
595         }
596 }
597
598 void ClientCommand_spectate(float request)
599 {
600         switch(request)
601         {
602                 case CC_REQUEST_COMMAND:
603                 {
604                         if(self.flags & FL_CLIENT)
605                         {
606                                 if(g_arena) { return; } 
607                                 if(g_lms)
608                                 {
609                                         if(self.lms_spectate_warning)
610                                         {
611                                                 // mark player as spectator
612                                                 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
613                                         }
614                                         else
615                                         {
616                                                 self.lms_spectate_warning = 1;
617                                                 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");
618                                                 return;
619                                         }
620                                 }
621                                 
622                                 if(self.classname == "player" && autocvar_sv_spectate == 1) 
623                                         ClientKill_TeamChange(-2); // observe
624                                 
625                                 // in CA, allow a dead player to move to spectatators (without that, caplayer!=0 will be moved back to the player list)
626                                 // note: if arena game mode is ever done properly, this needs to be removed.
627                                 if(g_ca && self.caplayer && (self.classname == "spectator" || self.classname == "observer"))
628                                 {
629                                         sprint(self, "WARNING: you will spectate in the next round.\n");
630                                         self.caplayer = 0;
631                                 }
632                         }
633                         return; // never fall through to usage
634                 }
635                         
636                 default:
637                 case CC_REQUEST_USAGE:
638                 {
639                         sprint(self, "\nUsage:^3 cmd spectate\n");
640                         sprint(self, "  No arguments required.\n");
641                         return;
642                 }
643         }
644 }
645
646 void ClientCommand_suggestmap(float request, float argc)
647 {
648         switch(request)
649         {
650                 case CC_REQUEST_COMMAND:
651                 {
652                         sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
653                         return; // never fall through to usage
654                 }
655                         
656                 default:
657                 case CC_REQUEST_USAGE:
658                 {
659                         sprint(self, "\nUsage:^3 cmd suggestmap map\n");
660                         sprint(self, "  Where 'map' is the name of the map to suggest.\n");
661                         return;
662                 }
663         }
664 }
665
666 void ClientCommand_teamstatus(float request)
667 {
668         switch(request)
669         {
670                 case CC_REQUEST_COMMAND:
671                 {
672                         Score_NicePrint(self);
673                         return; // never fall through to usage
674                 }
675                         
676                 default:
677                 case CC_REQUEST_USAGE:
678                 {
679                         sprint(self, "\nUsage:^3 cmd teamstatus\n");
680                         sprint(self, "  No arguments required.\n");
681                         return;
682                 }
683         }
684 }
685
686 void ClientCommand_tell(float request, float argc, string command)
687 {
688         switch(request)
689         {
690                 case CC_REQUEST_COMMAND:
691                 {
692                         entity e = GetCommandPlayerSlotTargetFromTokenizedCommand(argc, 1);
693                         
694                         if(e && argc > ParseCommandPlayerSlotTarget_firsttoken)
695                         {
696                                 Say(self, FALSE, e, substring(command, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
697                         }
698                         else
699                         {
700                                 if(argc > ParseCommandPlayerSlotTarget_firsttoken)
701                                         trigger_magicear_processmessage_forallears(self, -1, world, substring(command, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
702                         }
703                         return; // never fall through to usage
704                 }
705                         
706                 default:
707                 case CC_REQUEST_USAGE:
708                 {
709                         sprint(self, "\nUsage:^3 cmd tell playerid <message>\n");
710                         sprint(self, "  Where 'playerid' is the entity number of the player to send the 'message' to.\n");
711                         return;
712                 }
713         }
714 }
715
716 void ClientCommand_timein(float request)
717 {
718         switch(request)
719         {
720                 case CC_REQUEST_COMMAND:
721                 {
722                         if(self.flags & FL_CLIENT)
723                         {
724                                 if(autocvar_sv_timeout)
725                                 {
726                                         if (!timeoutStatus)
727                                                 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
728                                         if (self != timeoutInitiator)
729                                                 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
730                                                 
731                                         if (timeoutStatus == 1) 
732                                         {
733                                                 remainingTimeoutTime = timeoutStatus = 0;
734                                                 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
735                                                 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
736                                         }
737                                         else if (timeoutStatus == 2) 
738                                         {
739                                                 //only shorten the remainingTimeoutTime if it makes sense
740                                                 if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) ) 
741                                                 {
742                                                         bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
743                                                         remainingTimeoutTime = autocvar_sv_timeout_resumetime;
744                                                         timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
745                                                 }
746                                                 else
747                                                         sprint(self, "^7Error: Your resumegame call was discarded!\n");
748                                         }
749                                 }
750                         }
751                         return; // never fall through to usage
752                 }
753                         
754                 default:
755                 case CC_REQUEST_USAGE:
756                 {
757                         sprint(self, "\nUsage:^3 cmd timein\n");
758                         sprint(self, "  No arguments required.\n");
759                         return;
760                 }
761         }
762 }
763
764 void ClientCommand_timeout(float request) // DEAR GOD THIS COMMAND IS TERRIBLE.
765 {
766         switch(request)
767         {
768                 case CC_REQUEST_COMMAND:
769                 {
770                         if(self.flags & FL_CLIENT)
771                         {
772                                 if(autocvar_sv_timeout) 
773                                 {
774                                         if(self.classname == "player") 
775                                         {
776                                                 if(votecalled)
777                                                         sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
778                                                 else
779                                                 {
780                                                         if (inWarmupStage && !g_warmup_allow_timeout)
781                                                                 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
782                                                         if (time < game_starttime )
783                                                                 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
784                                                                 
785                                                         if (timeoutStatus != 2) {
786                                                                 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
787                                                                 if (autocvar_timelimit) {
788                                                                         //a timelimit was used
789                                                                         float myTl;
790                                                                         myTl = autocvar_timelimit;
791
792                                                                         float lastPossibleTimeout;
793                                                                         lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1;
794
795                                                                         if (lastPossibleTimeout < time - game_starttime)
796                                                                                 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
797                                                                 }
798                                                         }
799                                                         
800                                                         //player may not call a timeout if he has no calls left
801                                                         if (self.allowedTimeouts < 1)
802                                                                 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
803                                                                 
804                                                                 
805                                                         //now all required checks are passed
806                                                         self.allowedTimeouts -= 1;
807                                                         bprint(self.netname, " ^7called a timeout (", ftos(self.allowedTimeouts), " timeouts left)!\n"); //write a bprint who started the timeout (and how many he has left)
808                                                         remainingTimeoutTime = autocvar_sv_timeout_length;
809                                                         remainingLeadTime = autocvar_sv_timeout_leadtime;
810                                                         timeoutInitiator = self;
811                                                         if (timeoutStatus == 0) { //if another timeout was already active, don't change its status (which was 1 or 2) to 1, only change it to 1 if no timeout was active yet
812                                                                 timeoutStatus = 1;
813                                                                 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
814                                                                 timeoutHandler = spawn();
815                                                                 timeoutHandler.think = timeoutHandler_Think;
816                                                         }
817                                                         timeoutHandler.nextthink = time; //always let the entity think asap
818
819                                                         //inform all connected clients about the timeout call
820                                                         Announce("timeoutcalled");
821                                                 }
822                                         }
823                                         else
824                                                 sprint(self, "^7Error: only players can call a timeout!\n");
825                                 }
826                         }
827                         return; // never fall through to usage
828                 }
829                         
830                 default:
831                 case CC_REQUEST_USAGE:
832                 {
833                         sprint(self, "\nUsage:^3 cmd timeout\n");
834                         sprint(self, "  No arguments required.\n");
835                         return;
836                 }
837         }
838 }
839
840 void ClientCommand_voice(float request, float argc, string command)
841 {
842         switch(request)
843         {
844                 case CC_REQUEST_COMMAND:
845                 {
846                         if(argc >= 3)
847                                 VoiceMessage(argv(1), substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
848                         else
849                                 VoiceMessage(argv(1), "");
850                         return; // never fall through to usage
851                 }
852                         
853                 default:
854                 case CC_REQUEST_USAGE:
855                 {
856                         sprint(self, "\nUsage:^3 cmd voice\n");
857                         sprint(self, "  FIXME ARGUMENTS UNKNOWN.\n");
858                         return;
859                 }
860         }
861 }
862
863 string strlimitedlen(string input, float strip_colors, float limit)
864 {
865         if(strlen((strip_colors ? strdecolorize(input) : input)) <= limit)
866                 return input;
867         else
868                 return strcat(substring(input, 0, (strlen(input) - 3)), "...");
869 }
870
871 void ClientCommand_who(float request)
872 {
873         switch(request)
874         {
875                 case CC_REQUEST_COMMAND:
876                 {
877                         float total_listed_players, tmp_hours, tmp_minutes, tmp_seconds;
878                         entity tmp_player;
879                         string tmp_player_name;
880                         
881                         sprint(self, strcat("List of client information", (autocvar_sv_status_privacy ? " (some data is hidden for privacy)" : string_null), ":\n"));
882                         sprint(self, sprintf(" %-4s %-20s %-5s %-3s %-9s %-16s %s\n", "ent", "nickname", "ping", "pl", "time", "ip", "crypto_id"));
883                         
884                         FOR_EACH_CLIENT(tmp_player)
885                         {
886                                 tmp_player_name = strlimitedlen(tmp_player.netname, TRUE, 20);
887                                 
888                                 tmp_hours = tmp_minutes = tmp_seconds = 0;
889                                 
890                                 tmp_seconds = (time - tmp_player.jointime);
891                                 tmp_minutes = (tmp_seconds / 60);
892                                 
893                                 if(tmp_minutes)
894                                 {
895                                         tmp_seconds -= (tmp_minutes * 60);
896                                         tmp_hours = (tmp_minutes / 60);
897                                         
898                                         if(tmp_hours) { tmp_minutes -= (tmp_hours * 60); }
899                                 }
900                                 
901                                 sprint(self, sprintf(" %-4s %-20s %-5d %-3d %-9s %-16s %s\n", 
902                                         strcat("#", ftos(num_for_edict(tmp_player))), 
903                                         tmp_player.netname, //strcat(tmp_player_name, sprintf("%*s", (20 - strlen(strdecolorize(tmp_player_name))), "")),
904                                         tmp_player.ping, tmp_player.ping_packetloss, 
905                                         sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds),
906                                         (autocvar_sv_status_privacy ? "hidden" : tmp_player.netaddress),
907                                         (autocvar_sv_status_privacy ? "hidden" : tmp_player.crypto_idfp)));
908                                         
909                                 ++total_listed_players;
910                         }
911                         
912                         sprint(self, strcat("Finished listing ", ftos(total_listed_players), " client(s). \n"));
913                         
914                         return; // never fall through to usage
915                 }
916                         
917                 default:
918                 case CC_REQUEST_USAGE:
919                 {
920                         sprint(self, "\nUsage:^3 cmd who\n");
921                         sprint(self, "  No arguments required.\n");
922                         return;
923                 }
924         }
925 }
926
927 /* use this when creating a new command, making sure to place it in alphabetical order.
928 void ClientCommand_(float request)
929 {
930         switch(request)
931         {
932                 case CC_REQUEST_COMMAND:
933                 {
934                         
935                         return; // never fall through to usage
936                 }
937                         
938                 default:
939                 case CC_REQUEST_USAGE:
940                 {
941                         sprint(self, "\nUsage:^3 cmd \n");
942                         sprint(self, "  No arguments required.\n");
943                         return;
944                 }
945         }
946 }
947 */
948
949
950 // =====================================
951 //  Macro system for networked commands
952 // =====================================
953
954 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
955 #define CLIENT_COMMANDS(request,arguments,command) \
956         CLIENT_COMMAND("autoswitch", ClientCommand_autoswitch(request, arguments), "Whether or not to switch automatically when getting a better weapon") \
957         CLIENT_COMMAND("checkfail", ClientCommand_checkfail(request, command), "Report if a client-side check failed") \
958         CLIENT_COMMAND("clientversion", ClientCommand_clientversion(request, arguments), "Release version of the game") \
959         CLIENT_COMMAND("cvar_changes", ClientCommand_cvar_changes(request), "Prints a list of all changed server cvars") \
960         CLIENT_COMMAND("cvar_purechanges", ClientCommand_cvar_purechanges(request), "Prints a list of all changed gameplay cvars") \
961         CLIENT_COMMAND("getmapvotepic", ClientCommand_getmapvotepic(request, arguments), "Retrieve mapshot picture from the server") \
962         CLIENT_COMMAND("info", ClientCommand_info(request, arguments), "Request for unique server information set up by admin") \
963         CLIENT_COMMAND("join", ClientCommand_join(request), "Become a player in the game") \
964         CLIENT_COMMAND("ladder", ClientCommand_ladder(request), "Get information about top players if supported") \
965         CLIENT_COMMAND("lsmaps", ClientCommand_lsmaps(request), "List maps which can be used with the current game mode") \
966         CLIENT_COMMAND("lsnewmaps", ClientCommand_lsnewmaps(request), "List maps which TODO") \
967         CLIENT_COMMAND("maplist", ClientCommand_maplist(request), "Full server maplist reply") \
968         CLIENT_COMMAND("rankings", ClientCommand_rankings(request), "Print information about rankings") \
969         CLIENT_COMMAND("ready", ClientCommand_ready(request), "Qualify as ready to end warmup stage (or restart server if allowed)") \
970         CLIENT_COMMAND("records", ClientCommand_records(request), "List top 10 records for the current map") \
971         CLIENT_COMMAND("reportcvar", ClientCommand_reportcvar(request, arguments, command), "Old system for sending a client cvar to the server") \
972         CLIENT_COMMAND("say", ClientCommand_say(request, arguments, command), "Print a message to chat to all players") \
973         CLIENT_COMMAND("say_team", ClientCommand_say_team(request, arguments, command), "Print a message to chat to all team mates") \
974         CLIENT_COMMAND("selectteam", ClientCommand_selectteam(request, arguments), "Attempt to choose a team to join into") \
975         CLIENT_COMMAND("selfstuff", ClientCommand_selfstuff(request, command), "Stuffcmd a command to your own client") \
976         CLIENT_COMMAND("sentcvar", ClientCommand_sentcvar(request, arguments, command), "New system for sending a client cvar to the server") \
977         CLIENT_COMMAND("spectate", ClientCommand_spectate(request), "Become an observer") \
978         CLIENT_COMMAND("suggestmap", ClientCommand_suggestmap(request, arguments), "Suggest a map to the mapvote at match end") \
979         CLIENT_COMMAND("teamstatus", ClientCommand_teamstatus(request), "Print detailed score information for all players") \
980         CLIENT_COMMAND("tell", ClientCommand_tell(request, arguments, command), "Send a message directly to a player") \
981         CLIENT_COMMAND("timein", ClientCommand_timein(request), "Resume the game from being paused with a timeout") \
982         CLIENT_COMMAND("timeout", ClientCommand_timeout(request), "Call a timeout which pauses the game for certain amount of time unless unpaused") \
983         CLIENT_COMMAND("voice", ClientCommand_voice(request, arguments, command), "Send voice message via sound") \
984         CLIENT_COMMAND("vote", VoteCommand(request, self, arguments, command), "Request an action to be voted upon by players") \
985         CLIENT_COMMAND("who", ClientCommand_who(request), "Display detailed client information about all players") \
986         /* nothing */
987         
988 void ClientCommand_macro_help()
989 {
990         #define CLIENT_COMMAND(name,function,description) \
991                 { print("  ^2", name, "^7: ", description, "\n"); }
992                 
993         CLIENT_COMMANDS(0, 0, "")
994         #undef CLIENT_COMMAND
995         
996         return;
997 }
998
999 float ClientCommand_macro_command(float argc, string command)
1000 {
1001         #define CLIENT_COMMAND(name,function,description) \
1002                 { if(name == strtolower(argv(0))) { function; return TRUE; } }
1003                 
1004         CLIENT_COMMANDS(CC_REQUEST_COMMAND, argc, command)
1005         #undef CLIENT_COMMAND
1006         
1007         return FALSE;
1008 }
1009
1010 float ClientCommand_macro_usage(float argc, string command)
1011 {
1012         #define CLIENT_COMMAND(name,function,description) \
1013                 { if(name == strtolower(argv(1))) { function; return TRUE; } }
1014                 
1015         CLIENT_COMMANDS(CC_REQUEST_USAGE, argc, command)
1016         #undef CLIENT_COMMAND
1017         
1018         return FALSE;
1019 }
1020
1021
1022 // ======================================
1023 //  Main Function Called By Engine (cmd)
1024 // ======================================
1025 // If this function exists, server game code parses clientcommand before the engine code gets it.
1026
1027 void SV_ParseClientCommand(string command)
1028 {
1029         float argc = tokenize_console(command);
1030         
1031         // for floodcheck
1032         switch(strtolower(argv(0)))
1033         {
1034                 // exempt commands which are not subject to floodcheck
1035                 case "begin": break; // handled by engine in host_cmd.c
1036                 case "getmapvotepic": break; // handled by server in this file
1037                 case "pause": break; // handled by engine in host_cmd.c
1038                 case "prespawn": break; // handled by engine in host_cmd.c
1039                 case "reportcvar": break; // handled by server in this file
1040                 case "sentcvar": break; // handled by server in this file
1041                 case "spawn": break; // handled by engine in host_cmd.c
1042                 
1043                 default: 
1044                         if(SV_ParseClientCommand_floodcheck())
1045                                 break; // "TRUE": continue, as we're not flooding yet
1046                         else
1047                                 return; // "FALSE": not allowed to continue, halt
1048         }
1049         
1050         /* NOTE: totally disabled for now, however the functionality and descriptions are there if we ever want it.
1051         if(argv(0) == "help") 
1052         {
1053                 if(argc == 1) 
1054                 {
1055                         sprint(self, "\nUsage:^3 cmd COMMAND...^7, where possible commands are:\n");
1056                         ClientCommand_macro_help;
1057                         sprint(self, "For help about specific commands, type cmd help COMMAND\n");
1058                         return;
1059                 } 
1060                 else if(ClientCommand_macro_usage(argc, command)) // Instead of trying to call a command, we're going to see detailed information about it
1061                 {
1062                         return;
1063                 }
1064         } 
1065         else*/ if(MUTATOR_CALLHOOK(SV_ParseClientCommand))
1066         {
1067                 return; // handled by a mutator
1068         }
1069         else if(CheatCommand(argc)) 
1070         {
1071                 return; // handled by server/cheats.qc
1072         }
1073         else if(ClientCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
1074         {
1075                 return; // handled by one of the above GameCommand_* functions
1076         }
1077         else
1078                 clientcommand(self, command);
1079 }