1 // ====================================================
2 // Shared code for server commands, written by Samual
3 // Last updated: December 13th, 2011
4 // ====================================================
6 // find a player which matches the input string, and return their entity number
7 float GetFilteredNumber(string input)
9 entity tmp_player, selection;
10 float output, matches;
12 // check and see if we can get a number from input like "#3" or "3"
13 if(substring(input, 0, 1) == "#")
14 output = stof(substring(input, 1, -1));
18 // if we can't, check and see if we can match the input to the netname of any player in the game
21 FOR_EACH_CLIENT(tmp_player)
22 if (strdecolorize(tmp_player.netname) == strdecolorize(input))
23 selection = tmp_player;
25 if (selection) { output = num_for_edict(selection); }
28 print(strcat("input: ", input, ", output: ", ftos(output), ",\n"));
32 // switch between sprint and print depending on whether the reciever is the server or a player
33 void print_to(entity to, string input)
36 sprint(to, strcat(input, "\n"));
42 // ===================================================
43 // Common commands used in both sv_cmd.qc and cmd.qc
44 // ===================================================
46 void CommonCommand_cvar_changes(float request)
50 case CMD_REQUEST_COMMAND:
52 print_to(self, cvar_changes);
53 return; // never fall through to usage
57 case CMD_REQUEST_USAGE:
59 print_to(self, "\nUsage:^3 sv_cmd cvar_changes\n");
60 print_to(self, " No arguments required.\n");
61 //print_to(self, "See also: ^2cvar_purechanges^7\n");
67 void CommonCommand_cvar_purechanges(float request)
71 case CMD_REQUEST_COMMAND:
73 print_to(self, cvar_purechanges);
74 return; // never fall through to usage
78 case CMD_REQUEST_USAGE:
80 print_to(self, "\nUsage:^3 sv_cmd cvar_purechanges\n");
81 print_to(self, " No arguments required.\n");
82 //print_to(self, "See also: ^2cvar_changes^7\n");
88 void CommonCommand_info(float request, float argc)
92 case CMD_REQUEST_COMMAND:
96 command = builtin_cvar_string(strcat("sv_info_", argv(1)));
98 wordwrap_sprint(command, 1111); // why 1111?
100 print_to(self, "ERROR: unsupported info command\n");
102 return; // never fall through to usage
106 case CMD_REQUEST_USAGE:
108 print_to(self, "\nUsage:^3 cmd info request\n");
109 print_to(self, " Where 'request' is the suffixed string appended onto the request for cvar.\n");
115 void CommonCommand_ladder(float request)
119 case CMD_REQUEST_COMMAND:
121 print_to(self, ladder_reply);
122 return; // never fall through to usage
126 case CMD_REQUEST_USAGE:
128 print_to(self, "\nUsage:^3 cmd ladder\n");
129 print_to(self, " No arguments required.\n");
135 void CommonCommand_lsmaps(float request)
139 case CMD_REQUEST_COMMAND:
141 print_to(self, lsmaps_reply);
142 return; // never fall through to usage
146 case CMD_REQUEST_USAGE:
148 print_to(self, "\nUsage:^3 cmd lsmaps\n");
149 print_to(self, " No arguments required.\n");
155 void CommonCommand_lsnewmaps(float request)
159 case CMD_REQUEST_COMMAND:
161 print_to(self, lsnewmaps_reply);
162 return; // never fall through to usage
166 case CMD_REQUEST_USAGE:
168 print_to(self, "\nUsage:^3 cmd lsnewmaps\n");
169 print_to(self, " No arguments required.\n");
175 void CommonCommand_maplist(float request)
179 case CMD_REQUEST_COMMAND:
181 print_to(self, maplist_reply);
182 return; // never fall through to usage
186 case CMD_REQUEST_USAGE:
188 print_to(self, "\nUsage:^3 cmd maplist\n");
189 print_to(self, " No arguments required.\n");
195 void GameCommand_rankings(float request) // this is OLD.... jeez.
199 case CMD_REQUEST_COMMAND:
201 strunzone(rankings_reply);
202 rankings_reply = strzone(getrankings());
203 print(rankings_reply);
208 case CMD_REQUEST_USAGE:
210 print("\nUsage:^3 sv_cmd rankings\n");
211 print(" No arguments required.\n");
217 void CommonCommand_rankings(float request)
221 case CMD_REQUEST_COMMAND:
223 print_to(self, rankings_reply);
224 return; // never fall through to usage
228 case CMD_REQUEST_USAGE:
230 print_to(self, "\nUsage:^3 cmd rankings\n");
231 print_to(self, " No arguments required.\n");
237 void CommonCommand_records(float request) // TODO: Isn't this flooding with the sprint messages? Old code, but perhaps bad?
241 case CMD_REQUEST_COMMAND:
245 for(i = 0; i < 10; ++i)
246 print_to(self, records_reply[i]);
248 return; // never fall through to usage
252 case CMD_REQUEST_USAGE:
254 print_to(self, "\nUsage:^3 cmd records\n");
255 print_to(self, " No arguments required.\n");
261 void CommonCommand_teamstatus(float request)
265 case CMD_REQUEST_COMMAND:
267 Score_NicePrint(self);
268 return; // never fall through to usage
272 case CMD_REQUEST_USAGE:
274 print_to(self, "\nUsage:^3 cmd teamstatus\n");
275 print_to(self, " No arguments required.\n");
282 void CommonCommand_timein(float request)
286 case CMD_REQUEST_COMMAND:
288 if(self.flags & FL_CLIENT)
290 if(autocvar_sv_timeout)
293 return print_to(self, "^7Error: There is no active timeout which could be aborted!\n");
294 if (self != timeoutInitiator)
295 return print_to(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
297 if (timeoutStatus == 1)
299 remainingTimeoutTime = timeoutStatus = 0;
300 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
301 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
303 else if (timeoutStatus == 2)
305 //only shorten the remainingTimeoutTime if it makes sense
306 if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) )
308 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
309 remainingTimeoutTime = autocvar_sv_timeout_resumetime;
310 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
313 print_to(self, "^7Error: Your resumegame call was discarded!\n");
317 return; // never fall through to usage
321 case CMD_REQUEST_USAGE:
323 print_to(self, "\nUsage:^3 cmd timein\n");
324 print_to(self, " No arguments required.\n");
330 void CommonCommand_timeout(float request) // DEAR GOD THIS COMMAND IS TERRIBLE.
334 case CMD_REQUEST_COMMAND:
336 if(self.flags & FL_CLIENT)
338 if(autocvar_sv_timeout)
340 if(self.classname == "player")
343 print_to(self, "^7Error: you can not call a timeout while a vote is active!\n");
346 if (inWarmupStage && !g_warmup_allow_timeout)
347 return print_to(self, "^7Error: You can not call a timeout in warmup-stage!\n");
348 if (time < game_starttime )
349 return print_to(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
351 if (timeoutStatus != 2) {
352 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
353 if (autocvar_timelimit) {
354 //a timelimit was used
356 myTl = autocvar_timelimit;
358 float lastPossibleTimeout;
359 lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1;
361 if (lastPossibleTimeout < time - game_starttime)
362 return print_to(self, "^7Error: It is too late to call a timeout now!\n");
366 //player may not call a timeout if he has no calls left
367 if (self.allowedTimeouts < 1)
368 return print_to(self, "^7Error: You already used all your timeout calls for this map!\n");
371 //now all required checks are passed
372 self.allowedTimeouts -= 1;
373 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)
374 remainingTimeoutTime = autocvar_sv_timeout_length;
375 remainingLeadTime = autocvar_sv_timeout_leadtime;
376 timeoutInitiator = self;
377 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
379 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
380 timeoutHandler = spawn();
381 timeoutHandler.think = timeoutHandler_Think;
383 timeoutHandler.nextthink = time; //always let the entity think asap
385 //inform all connected clients about the timeout call
386 Announce("timeoutcalled");
390 print_to(self, "^7Error: only players can call a timeout!\n");
393 return; // never fall through to usage
397 case CMD_REQUEST_USAGE:
399 print_to(self, "\nUsage:^3 cmd timeout\n");
400 print_to(self, " No arguments required.\n");
406 void CommonCommand_who(float request)
410 case CMD_REQUEST_COMMAND:
412 float total_listed_players, tmp_hours, tmp_minutes, tmp_seconds;
414 //string tmp_player_name;
416 print_to(self, strcat("List of client information", (autocvar_sv_status_privacy ? " (some data is hidden for privacy)" : string_null), ":\n"));
417 print_to(self, sprintf(" %-4s %-20s %-5s %-3s %-9s %-16s %s\n", "ent", "nickname", "ping", "pl", "time", "ip", "crypto_id"));
419 FOR_EACH_CLIENT(tmp_player)
421 //tmp_player_name = strlimitedlen(tmp_player.netname, "...", TRUE, 20);
423 tmp_hours = tmp_minutes = tmp_seconds = 0;
425 tmp_seconds = (time - tmp_player.jointime);
426 tmp_minutes = (tmp_seconds / 60);
430 tmp_seconds -= (tmp_minutes * 60);
431 tmp_hours = (tmp_minutes / 60);
433 if(tmp_hours) { tmp_minutes -= (tmp_hours * 60); }
436 print_to(self, sprintf(" %-4s %-20s %-5d %-3d %-9s %-16s %s\n",
437 strcat("#", ftos(num_for_edict(tmp_player))),
438 tmp_player.netname, //strcat(tmp_player_name, sprintf("%*s", (20 - strlen(strdecolorize(tmp_player_name))), "")),
439 tmp_player.ping, tmp_player.ping_packetloss,
440 sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds),
441 (autocvar_sv_status_privacy ? "hidden" : tmp_player.netaddress),
442 (autocvar_sv_status_privacy ? "hidden" : tmp_player.crypto_idfp)));
444 ++total_listed_players;
447 print_to(self, strcat("Finished listing ", ftos(total_listed_players), " client(s). \n"));
449 return; // never fall through to usage
453 case CMD_REQUEST_USAGE:
455 print_to(self, "\nUsage:^3 cmd who\n");
456 print_to(self, " No arguments required.\n");
462 /* use this when creating a new command, making sure to place it in alphabetical order.
463 void CommonCommand_(float request)
467 case CMD_REQUEST_COMMAND:
470 return; // never fall through to usage
474 case CMD_REQUEST_USAGE:
476 print_to(self, "\nUsage:^3 cmd \n");
477 print_to(self, " No arguments required.\n");