]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/clientcommands.qc
Merge remote branch 'origin/master' into samual/updatecommands
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / clientcommands.qc
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                                                                         ClientKill_TeamChange(selection);
522                                                                 else
523                                                                         sprint(self, "^7You already are on that team.\n");
524                                                         }
525                                                 }
526                                                 else
527                                                         sprint(self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
528                                         else
529                                                 sprint(self, "^7selectteam can not be used as your team is forced\n");
530                                 else
531                                         sprint(self, "^7selectteam can only be used in teamgames\n");
532                         }
533                         return; // never fall through to usage
534                 }
535
536                 default:
537                 case CC_REQUEST_USAGE:
538                 {
539                         //sprint(self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
540                         sprint(self, "\nUsage:^3 cmd selectteam team\n");
541                         sprint(self, "  Where 'team' is the prefered team to try and join.\n");
542                         sprint(self, "  Full list of options here: \"red, blue, yellow, pink, auto\"\n");
543                         return;
544                 }
545         }
546 }
547
548 void ClientCommand_selfstuff(float request, string command)
549 {
550         switch(request)
551         {
552                 case CC_REQUEST_COMMAND:
553                 {
554                         stuffcmd(self, substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
555                         return; // never fall through to usage
556                 }
557                         
558                 default:
559                 case CC_REQUEST_USAGE:
560                 {
561                         sprint(self, "\nUsage:^3 cmd selfstuff command\n");
562                         sprint(self, "  Where 'command' is the string to be stuffed to your client.\n");
563                         return;
564                 }
565         }
566 }
567
568 void ClientCommand_sentcvar(float request, float argc, string command)
569 {
570         switch(request)
571         {
572                 case CC_REQUEST_COMMAND:
573                 {
574                         float tokens;
575                         string s;
576                         
577                         if(argc == 2) // undefined cvar: use the default value on the server then
578                         {
579                                 s = strcat(substring(command, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
580                                 tokens = tokenize_console(s);
581                         }
582                         GetCvars(1);
583                         return; // never fall through to usage
584                 }
585                         
586                 default:
587                 case CC_REQUEST_USAGE:
588                 {
589                         sprint(self, "\nUsage:^3 cmd sentcvar <cvar>\n");
590                         sprint(self, "  Where 'cvar' is the cvar plus arguments to send to the server.\n");
591                         return;
592                 }
593         }
594 }
595
596 void ClientCommand_spectate(float request)
597 {
598         switch(request)
599         {
600                 case CC_REQUEST_COMMAND:
601                 {
602                         if(self.flags & FL_CLIENT)
603                         {
604                                 if(g_arena) { return; } 
605                                 if(g_lms)
606                                 {
607                                         if(self.lms_spectate_warning)
608                                         {
609                                                 // mark player as spectator
610                                                 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
611                                         }
612                                         else
613                                         {
614                                                 self.lms_spectate_warning = 1;
615                                                 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");
616                                                 return;
617                                         }
618                                 }
619                                 
620                                 if(self.classname == "player" && autocvar_sv_spectate == 1) 
621                                         ClientKill_TeamChange(-2); // observe
622                                 
623                                 // in CA, allow a dead player to move to spectatators (without that, caplayer!=0 will be moved back to the player list)
624                                 // note: if arena game mode is ever done properly, this needs to be removed.
625                                 if(g_ca && self.caplayer && (self.classname == "spectator" || self.classname == "observer"))
626                                 {
627                                         sprint(self, "WARNING: you will spectate in the next round.\n");
628                                         self.caplayer = 0;
629                                 }
630                         }
631                         return; // never fall through to usage
632                 }
633                         
634                 default:
635                 case CC_REQUEST_USAGE:
636                 {
637                         sprint(self, "\nUsage:^3 cmd spectate\n");
638                         sprint(self, "  No arguments required.\n");
639                         return;
640                 }
641         }
642 }
643
644 void ClientCommand_suggestmap(float request, float argc)
645 {
646         switch(request)
647         {
648                 case CC_REQUEST_COMMAND:
649                 {
650                         sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
651                         return; // never fall through to usage
652                 }
653                         
654                 default:
655                 case CC_REQUEST_USAGE:
656                 {
657                         sprint(self, "\nUsage:^3 cmd suggestmap map\n");
658                         sprint(self, "  Where 'map' is the name of the map to suggest.\n");
659                         return;
660                 }
661         }
662 }
663
664 void ClientCommand_teamstatus(float request)
665 {
666         switch(request)
667         {
668                 case CC_REQUEST_COMMAND:
669                 {
670                         Score_NicePrint(self);
671                         return; // never fall through to usage
672                 }
673                         
674                 default:
675                 case CC_REQUEST_USAGE:
676                 {
677                         sprint(self, "\nUsage:^3 cmd teamstatus\n");
678                         sprint(self, "  No arguments required.\n");
679                         return;
680                 }
681         }
682 }
683
684 void ClientCommand_tell(float request, float argc, string command)
685 {
686         switch(request)
687         {
688                 case CC_REQUEST_COMMAND:
689                 {
690                         entity e = GetCommandPlayerSlotTargetFromTokenizedCommand(argc, 1);
691                         
692                         if(e && argc > ParseCommandPlayerSlotTarget_firsttoken)
693                         {
694                                 Say(self, FALSE, e, substring(command, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
695                         }
696                         else
697                         {
698                                 if(argc > ParseCommandPlayerSlotTarget_firsttoken)
699                                         trigger_magicear_processmessage_forallears(self, -1, world, substring(command, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
700                         }
701                         return; // never fall through to usage
702                 }
703                         
704                 default:
705                 case CC_REQUEST_USAGE:
706                 {
707                         sprint(self, "\nUsage:^3 cmd tell playerid <message>\n");
708                         sprint(self, "  Where 'playerid' is the entity number of the player to send the 'message' to.\n");
709                         return;
710                 }
711         }
712 }
713
714 void ClientCommand_timein(float request)
715 {
716         switch(request)
717         {
718                 case CC_REQUEST_COMMAND:
719                 {
720                         if(self.flags & FL_CLIENT)
721                         {
722                                 if(autocvar_sv_timeout)
723                                 {
724                                         if (!timeoutStatus)
725                                                 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
726                                         if (self != timeoutInitiator)
727                                                 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
728                                                 
729                                         if (timeoutStatus == 1) 
730                                         {
731                                                 remainingTimeoutTime = timeoutStatus = 0;
732                                                 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
733                                                 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
734                                         }
735                                         else if (timeoutStatus == 2) 
736                                         {
737                                                 //only shorten the remainingTimeoutTime if it makes sense
738                                                 if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) ) 
739                                                 {
740                                                         bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
741                                                         remainingTimeoutTime = autocvar_sv_timeout_resumetime;
742                                                         timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
743                                                 }
744                                                 else
745                                                         sprint(self, "^7Error: Your resumegame call was discarded!\n");
746                                         }
747                                 }
748                         }
749                         return; // never fall through to usage
750                 }
751                         
752                 default:
753                 case CC_REQUEST_USAGE:
754                 {
755                         sprint(self, "\nUsage:^3 cmd timein\n");
756                         sprint(self, "  No arguments required.\n");
757                         return;
758                 }
759         }
760 }
761
762 void ClientCommand_timeout(float request) // DEAR GOD THIS COMMAND IS TERRIBLE.
763 {
764         switch(request)
765         {
766                 case CC_REQUEST_COMMAND:
767                 {
768                         if(self.flags & FL_CLIENT)
769                         {
770                                 if(autocvar_sv_timeout) 
771                                 {
772                                         if(self.classname == "player") 
773                                         {
774                                                 if(votecalled)
775                                                         sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
776                                                 else
777                                                 {
778                                                         if (inWarmupStage && !g_warmup_allow_timeout)
779                                                                 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
780                                                         if (time < game_starttime )
781                                                                 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
782                                                                 
783                                                         if (timeoutStatus != 2) {
784                                                                 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
785                                                                 if (autocvar_timelimit) {
786                                                                         //a timelimit was used
787                                                                         float myTl;
788                                                                         myTl = autocvar_timelimit;
789
790                                                                         float lastPossibleTimeout;
791                                                                         lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1;
792
793                                                                         if (lastPossibleTimeout < time - game_starttime)
794                                                                                 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
795                                                                 }
796                                                         }
797                                                         
798                                                         //player may not call a timeout if he has no calls left
799                                                         if (self.allowedTimeouts < 1)
800                                                                 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
801                                                                 
802                                                                 
803                                                         //now all required checks are passed
804                                                         self.allowedTimeouts -= 1;
805                                                         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)
806                                                         remainingTimeoutTime = autocvar_sv_timeout_length;
807                                                         remainingLeadTime = autocvar_sv_timeout_leadtime;
808                                                         timeoutInitiator = self;
809                                                         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
810                                                                 timeoutStatus = 1;
811                                                                 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
812                                                                 timeoutHandler = spawn();
813                                                                 timeoutHandler.think = timeoutHandler_Think;
814                                                         }
815                                                         timeoutHandler.nextthink = time; //always let the entity think asap
816
817                                                         //inform all connected clients about the timeout call
818                                                         Announce("timeoutcalled");
819                                                 }
820                                         }
821                                         else
822                                                 sprint(self, "^7Error: only players can call a timeout!\n");
823                                 }
824                         }
825                         return; // never fall through to usage
826                 }
827                         
828                 default:
829                 case CC_REQUEST_USAGE:
830                 {
831                         sprint(self, "\nUsage:^3 cmd timeout\n");
832                         sprint(self, "  No arguments required.\n");
833                         return;
834                 }
835         }
836 }
837
838 void ClientCommand_voice(float request, float argc, string command)
839 {
840         switch(request)
841         {
842                 case CC_REQUEST_COMMAND:
843                 {
844                         if(argc >= 3)
845                                 VoiceMessage(argv(1), substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
846                         else
847                                 VoiceMessage(argv(1), "");
848                         return; // never fall through to usage
849                 }
850                         
851                 default:
852                 case CC_REQUEST_USAGE:
853                 {
854                         sprint(self, "\nUsage:^3 cmd voice\n");
855                         sprint(self, "  FIXME ARGUMENTS UNKNOWN.\n");
856                         return;
857                 }
858         }
859 }
860
861 string strlimitedlen(string input, float strip_colors, float limit)
862 {
863         if(strlen((strip_colors ? strdecolorize(input) : input)) <= limit)
864                 return input;
865         else
866                 return strcat(substring(input, 0, (strlen(input) - 3)), "...");
867 }
868
869 void ClientCommand_who(float request)
870 {
871         switch(request)
872         {
873                 case CC_REQUEST_COMMAND:
874                 {
875                         float total_listed_players, tmp_hours, tmp_minutes, tmp_seconds;
876                         entity tmp_player;
877                         string tmp_player_name;
878                         
879                         sprint(self, strcat("List of client information", (autocvar_sv_status_privacy ? " (some data is hidden for privacy)" : string_null), ":\n"));
880                         sprint(self, sprintf(" %-4s %-20s %-5s %-3s %-9s %-16s %s\n", "ent", "nickname", "ping", "pl", "time", "ip", "crypto_id"));
881                         
882                         FOR_EACH_CLIENT(tmp_player)
883                         {
884                                 tmp_player_name = strlimitedlen(tmp_player.netname, TRUE, 20);
885                                 
886                                 tmp_hours = tmp_minutes = tmp_seconds = 0;
887                                 
888                                 tmp_seconds = (time - tmp_player.jointime);
889                                 tmp_minutes = (tmp_seconds / 60);
890                                 
891                                 if(tmp_minutes)
892                                 {
893                                         tmp_seconds -= (tmp_minutes * 60);
894                                         tmp_hours = (tmp_minutes / 60);
895                                         
896                                         if(tmp_hours) { tmp_minutes -= (tmp_hours * 60); }
897                                 }
898                                 
899                                 sprint(self, sprintf(" %-4s %-20s %-5d %-3d %-9s %-16s %s\n", 
900                                         strcat("#", ftos(num_for_edict(tmp_player))), 
901                                         strcat(tmp_player_name, sprintf("%*s", (20 - strlen(strdecolorize(tmp_player_name))), "")),
902                                         tmp_player.ping, tmp_player.ping_packetloss, 
903                                         sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds),
904                                         (autocvar_sv_status_privacy ? "hidden" : tmp_player.netaddress),
905                                         (autocvar_sv_status_privacy ? "hidden" : tmp_player.crypto_idfp)));
906                                         
907                                 ++total_listed_players;
908                         }
909                         
910                         sprint(self, strcat("Finished listing ", ftos(total_listed_players), " client(s). \n"));
911                         
912                         return; // never fall through to usage
913                 }
914                         
915                 default:
916                 case CC_REQUEST_USAGE:
917                 {
918                         sprint(self, "\nUsage:^3 cmd who\n");
919                         sprint(self, "  No arguments required.\n");
920                         return;
921                 }
922         }
923 }
924
925 /* use this when creating a new command, making sure to place it in alphabetical order.
926 void ClientCommand_(float request)
927 {
928         switch(request)
929         {
930                 case CC_REQUEST_COMMAND:
931                 {
932                         
933                         return; // never fall through to usage
934                 }
935                         
936                 default:
937                 case CC_REQUEST_USAGE:
938                 {
939                         sprint(self, "\nUsage:^3 cmd \n");
940                         sprint(self, "  No arguments required.\n");
941                         return;
942                 }
943         }
944 }
945 */
946
947
948 // =====================================
949 //  Macro system for networked commands
950 // =====================================
951
952 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
953 #define CLIENT_COMMANDS(request,arguments,command) \
954         CLIENT_COMMAND("autoswitch", ClientCommand_autoswitch(request, arguments), "Whether or not to switch automatically when getting a better weapon") \
955         CLIENT_COMMAND("checkfail", ClientCommand_checkfail(request, command), "Report if a client-side check failed") \
956         CLIENT_COMMAND("clientversion", ClientCommand_clientversion(request, arguments), "Release version of the game") \
957         CLIENT_COMMAND("cvar_changes", ClientCommand_cvar_changes(request), "Prints a list of all changed server cvars") \
958         CLIENT_COMMAND("cvar_purechanges", ClientCommand_cvar_purechanges(request), "Prints a list of all changed gameplay cvars") \
959         CLIENT_COMMAND("getmapvotepic", ClientCommand_getmapvotepic(request, arguments), "Retrieve mapshot picture from the server") \
960         CLIENT_COMMAND("info", ClientCommand_info(request, arguments), "Request for unique server information set up by admin") \
961         CLIENT_COMMAND("join", ClientCommand_join(request), "Become a player in the game") \
962         CLIENT_COMMAND("ladder", ClientCommand_ladder(request), "Get information about top players if supported") \
963         CLIENT_COMMAND("lsmaps", ClientCommand_lsmaps(request), "List maps which can be used with the current game mode") \
964         CLIENT_COMMAND("lsnewmaps", ClientCommand_lsnewmaps(request), "List maps which TODO") \
965         CLIENT_COMMAND("maplist", ClientCommand_maplist(request), "Full server maplist reply") \
966         CLIENT_COMMAND("rankings", ClientCommand_rankings(request), "Print information about rankings") \
967         CLIENT_COMMAND("ready", ClientCommand_ready(request), "Qualify as ready to end warmup stage (or restart server if allowed)") \
968         CLIENT_COMMAND("records", ClientCommand_records(request), "List top 10 records for the current map") \
969         CLIENT_COMMAND("reportcvar", ClientCommand_reportcvar(request, arguments, command), "Old system for sending a client cvar to the server") \
970         CLIENT_COMMAND("say", ClientCommand_say(request, arguments, command), "Print a message to chat to all players") \
971         CLIENT_COMMAND("say_team", ClientCommand_say_team(request, arguments, command), "Print a message to chat to all team mates") \
972         CLIENT_COMMAND("selectteam", ClientCommand_selectteam(request, arguments), "Attempt to choose a team to join into") \
973         CLIENT_COMMAND("selfstuff", ClientCommand_selfstuff(request, command), "Stuffcmd a command to your own client") \
974         CLIENT_COMMAND("sentcvar", ClientCommand_sentcvar(request, arguments, command), "New system for sending a client cvar to the server") \
975         CLIENT_COMMAND("spectate", ClientCommand_spectate(request), "Become an observer") \
976         CLIENT_COMMAND("suggestmap", ClientCommand_suggestmap(request, arguments), "Suggest a map to the mapvote at match end") \
977         CLIENT_COMMAND("teamstatus", ClientCommand_teamstatus(request), "Print detailed score information for all players") \
978         CLIENT_COMMAND("tell", ClientCommand_tell(request, arguments, command), "Send a message directly to a player") \
979         CLIENT_COMMAND("timein", ClientCommand_timein(request), "Resume the game from being paused with a timeout") \
980         CLIENT_COMMAND("timeout", ClientCommand_timeout(request), "Call a timeout which pauses the game for certain amount of time unless unpaused") \
981         CLIENT_COMMAND("voice", ClientCommand_voice(request, arguments, command), "Send voice message via sound") \
982         CLIENT_COMMAND("vote", VoteCommand(request, self, arguments, command), "Request an action to be voted upon by players") \
983         CLIENT_COMMAND("who", ClientCommand_who(request), "Display detailed client information about all players") \
984         /* nothing */
985         
986 void ClientCommand_macro_help()
987 {
988         #define CLIENT_COMMAND(name,function,description) \
989                 { print("  ^2", name, "^7: ", description, "\n"); }
990                 
991         CLIENT_COMMANDS(0, 0, "")
992         #undef CLIENT_COMMAND
993         
994         return;
995 }
996
997 float ClientCommand_macro_command(float argc, string command)
998 {
999         #define CLIENT_COMMAND(name,function,description) \
1000                 { if(name == strtolower(argv(0))) { function; return TRUE; } }
1001                 
1002         CLIENT_COMMANDS(CC_REQUEST_COMMAND, argc, command)
1003         #undef CLIENT_COMMAND
1004         
1005         return FALSE;
1006 }
1007
1008 float ClientCommand_macro_usage(float argc, string command)
1009 {
1010         #define CLIENT_COMMAND(name,function,description) \
1011                 { if(name == strtolower(argv(1))) { function; return TRUE; } }
1012                 
1013         CLIENT_COMMANDS(CC_REQUEST_USAGE, argc, command)
1014         #undef CLIENT_COMMAND
1015         
1016         return FALSE;
1017 }
1018
1019
1020 // ======================================
1021 //  Main Function Called By Engine (cmd)
1022 // ======================================
1023 // If this function exists, server game code parses clientcommand before the engine code gets it.
1024
1025 void SV_ParseClientCommand(string command)
1026 {
1027         float argc = tokenize_console(command);
1028         
1029         // for floodcheck
1030         switch(strtolower(argv(0)))
1031         {
1032                 // exempt commands which are not subject to floodcheck
1033                 case "begin": break; // handled by engine in host_cmd.c
1034                 case "getmapvotepic": break; // handled by server in this file
1035                 case "pause": break; // handled by engine in host_cmd.c
1036                 case "prespawn": break; // handled by engine in host_cmd.c
1037                 case "reportcvar": break; // handled by server in this file
1038                 case "sentcvar": break; // handled by server in this file
1039                 case "spawn": break; // handled by engine in host_cmd.c
1040                 
1041                 default: 
1042                         if(SV_ParseClientCommand_floodcheck())
1043                                 break; // "TRUE": continue, as we're not flooding yet
1044                         else
1045                                 return; // "FALSE": not allowed to continue, halt
1046         }
1047         
1048         /* NOTE: totally disabled for now, however the functionality and descriptions are there if we ever want it.
1049         if(argv(0) == "help") 
1050         {
1051                 if(argc == 1) 
1052                 {
1053                         sprint(self, "\nUsage:^3 cmd COMMAND...^7, where possible commands are:\n");
1054                         ClientCommand_macro_help;
1055                         sprint(self, "For help about specific commands, type cmd help COMMAND\n");
1056                         return;
1057                 } 
1058                 else if(ClientCommand_macro_usage(argc, command)) // Instead of trying to call a command, we're going to see detailed information about it
1059                 {
1060                         return;
1061                 }
1062         } 
1063         else*/ if(MUTATOR_CALLHOOK(SV_ParseClientCommand))
1064         {
1065                 return; // handled by a mutator
1066         }
1067         else if(CheatCommand(argc)) 
1068         {
1069                 return; // handled by server/cheats.qc
1070         }
1071         else if(ClientCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
1072         {
1073                 return; // handled by one of the above GameCommand_* functions
1074         }
1075         else
1076                 clientcommand(self, command);
1077 }