3 float Nagger_SendEntity(entity to, float sendflags)
7 WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER);
28 if(!(nags & 4)) // no vote called? send no string
31 WriteByte(MSG_ENTITY, nags);
35 WriteString(MSG_ENTITY, votecalledvote_display);
40 for(i = 1; i <= maxclients; i += 8)
42 for(f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e))
43 if(clienttype(e) != CLIENTTYPE_REAL || e.ready)
45 WriteByte(MSG_ENTITY, f);
53 Net_LinkEntity(nagger = spawn(), FALSE, 0, Nagger_SendEntity);
55 void Nagger_VoteChanged()
58 nagger.SendFlags |= 128;
60 void Nagger_VoteCountChanged()
63 nagger.SendFlags |= 1;
65 void Nagger_ReadyCounted()
68 nagger.SendFlags |= 1;
72 string MapVote_Suggest(string m);
74 entity GetPlayer(string name)
80 if(substring(name, 0, 1) == "#") {
81 num = stof(substring(name, 1, 999));
82 if(num >= 1 && num <= maxclients) {
83 for((e = world); num > 0; --num, (e = nextent(e)))
85 //if(clienttype(e) == CLIENTTYPE_REAL)
86 if(e.classname == "player")
90 ns = strdecolorize(name);
91 FOR_EACH_REALPLAYER(e) {
92 if(!strcasecmp(strdecolorize(e.netname), ns)) {
100 //float ctf_clientcommand();
101 float readyrestart_happened;
102 .float lms_spectate_warning;
103 void spawnfunc_func_breakable();
105 .float cmd_floodtime;
106 .float cmd_floodcount;
107 float cmd_floodcheck()
109 if (timeoutStatus != 2)
111 if(time == self.cmd_floodtime)
113 self.cmd_floodcount += 1;
114 if(self.cmd_floodcount > 8)
119 self.cmd_floodtime = time;
120 self.cmd_floodcount = 1;
127 void SV_ParseClientCommand(string s) {
133 tokens = tokenize_console(s);
135 cmd = strtolower(argv(0));
136 if(cmd != "reportcvar")
137 if(cmd != "sentcvar")
139 if(cmd != "prespawn")
147 if(GameCommand_Vote(s, self)) {
149 } else if(GameCommand_MapVote(argv(0))) {
151 } else if(cmd == "checkfail") {
152 print(sprintf("CHECKFAIL: %s (%s) epically failed check %s\n", self.netname, self.netaddress, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))));
154 } else if(cmd == "autoswitch") {
155 // be backwards compatible with older clients (enabled)
156 self.autoswitch = ("0" != argv(1));
157 local string autoswitchmsg;
158 if (self.autoswitch) {
159 autoswitchmsg = "on";
161 autoswitchmsg = "off";
163 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
164 } else if(cmd == "clientversion") {
165 if not(self.flags & FL_CLIENT)
167 if (argv(1) == "$gameversion") {
168 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.xonotic.com)^8";
169 // either that or someone wants to be funny
172 self.version = stof(argv(1));
174 if(self.version < autocvar_gameversion_min || self.version > autocvar_gameversion_max)
176 self.version_mismatch = 1;
177 ClientKill_TeamChange(-2); // observe
178 } else if(autocvar_g_campaign || autocvar_g_balance_teams || autocvar_g_balance_teams_force) {
179 //JoinBestTeam(self, FALSE, TRUE);
180 } else if(teamplay && !autocvar_sv_spectate && !(self.team_forced > 0)) {
181 self.classname = "observer";
182 stuffcmd(self,"menu_showteamselect\n");
184 } else if(cmd == "reportcvar") { // old system
185 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
187 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
188 tokens = tokenize_console(s);
191 } else if(cmd == "sentcvar") { // new system
192 if(tokens == 2) // undefined cvar: use the default value on the server then
194 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
195 tokens = tokenize_console(s);
198 } else if(cmd == "spectate") {
201 if not(self.flags & FL_CLIENT)
207 if(self.lms_spectate_warning)
209 // mark player as spectator
210 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
214 self.lms_spectate_warning = 1;
215 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");
219 if(self.classname == "player" && autocvar_sv_spectate == 1) {
220 ClientKill_TeamChange(-2); // observe
222 } else if(cmd == "join") {
223 if not(self.flags & FL_CLIENT)
226 if (self.classname != "player" && !lockteams)
228 if(nJoinAllowed(1)) {
229 self.classname = "player";
232 PlayerScore_Clear(self);
233 bprint ("^4", self.netname, "^4 is playing now\n");
235 if(autocvar_g_campaign)
236 campaign_bots_may_start = 1;
239 //player may not join because of g_maxplayers is set
240 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
243 } else if( cmd == "selectteam" ) {
244 if not(self.flags & FL_CLIENT)
247 sprint( self, "selectteam can only be used in teamgames\n");
248 } else if(autocvar_g_campaign) {
249 //JoinBestTeam(self, 0);
250 } else if(self.team_forced > 0) {
251 sprint( self, "selectteam can not be used as your team is forced\n");
252 } else if(lockteams) {
253 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
254 } else if( argv(1) == "red" ) {
255 ClientKill_TeamChange(COLOR_TEAM1);
256 } else if( argv(1) == "blue" ) {
257 ClientKill_TeamChange(COLOR_TEAM2);
258 } else if( argv(1) == "yellow" ) {
259 ClientKill_TeamChange(COLOR_TEAM3);
260 } else if( argv(1) == "pink" ) {
261 ClientKill_TeamChange(COLOR_TEAM4);
262 } else if( argv(1) == "auto" ) {
263 ClientKill_TeamChange(-1);
265 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
267 } else if(cmd == "ready") {
268 if not(self.flags & FL_CLIENT)
272 || autocvar_sv_ready_restart || g_race_qualifying == 2)
274 if(!readyrestart_happened || autocvar_sv_ready_restart_repeatable)
276 if (self.ready) // toggle
279 bprint(self.netname, "^2 is ^1NOT^2 ready\n");
284 bprint(self.netname, "^2 is ready\n");
287 // cannot reset the game while a timeout is active!
291 sprint(self, "^1Game has already been restarted\n");
294 } else if(cmd == "maplist") {
295 sprint(self, maplist_reply);
296 } else if(cmd == "lsmaps") {
297 sprint(self, lsmaps_reply);
298 } else if(cmd == "lsnewmaps") {
299 sprint(self, lsnewmaps_reply);
300 } else if(cmd == "records") {
301 for(i = 0; i < 10; ++i)
302 sprint(self, records_reply[i]);
303 } else if(cmd == "ladder") {
304 sprint(self, ladder_reply);
305 } else if(cmd == "rankings") {
306 sprint(self, rankings_reply);
307 } else if(cmd == "voice") {
309 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
311 VoiceMessage(argv(1), "");
312 } else if(cmd == "say") {
314 Say(self, FALSE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
315 //clientcommand(self, formatmessage(s));
316 } else if(cmd == "say_team") {
318 Say(self, TRUE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
319 //clientcommand(self, formatmessage(s));
320 } else if(cmd == "tell") {
321 e = GetCommandPlayerSlotTargetFromTokenizedCommand(tokens, 1);
322 if(e && tokens > ParseCommandPlayerSlotTarget_firsttoken)
324 Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
328 if(tokens > ParseCommandPlayerSlotTarget_firsttoken)
329 trigger_magicear_processmessage_forallears(self, -1, world, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
330 sprint(self, "ERROR: usage: tell # playerid text...\n");
332 //clientcommand(self, formatmessage(s));
333 } else if(cmd == "info") {
334 cmd = cvar_string_builtin(strcat("sv_info_", argv(1))); // This needed fixed for the cvar check
336 sprint(self, "ERROR: unsupported info command\n");
338 wordwrap_sprint(cmd, 1111);
339 } else if(cmd == "suggestmap") {
340 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
341 } else if(cmd == "timeout") {
342 if not(self.flags & FL_CLIENT)
344 if(autocvar_sv_timeout) {
345 if(self.classname == "player") {
347 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
352 sprint(self, "^7Error: only players can call a timeout!\n");
354 } else if(cmd == "timein") {
355 if not(self.flags & FL_CLIENT)
357 if(autocvar_sv_timeout) {
360 } else if(cmd == "teamstatus") {
361 Score_NicePrint(self);
362 } else if(cmd == "cvar_changes") {
363 sprint(self, cvar_changes);
364 } else if(cmd == "cvar_purechanges") {
365 sprint(self, cvar_purechanges);
366 } else if(CheatCommand(tokens)) {
369 //if(ctf_clientcommand())
371 // grep for Cmd_AddCommand_WithClientCommand to find them all
373 //if(cmd != "say") // handled above
374 //if(cmd != "say_team") // handled above
382 if(cmd != "playermodel")
383 if(cmd != "playerskin")
384 if(cmd != "prespawn")
388 if(cmd != "sv_startdownload")
389 if(cmd != "download")
391 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
396 if(self.jointime > 0 && time > self.jointime + 10 && time > self.nickspamtime) // allow any changes in the first 10 seconds since joining
397 if(cmd == "name" || cmd == "playermodel") // TODO also playerskin and color?
399 if(self.nickspamtime == 0 || time > self.nickspamtime + autocvar_g_nick_flood_timeout)
400 // good, no serious flood
401 self.nickspamcount = 1;
403 self.nickspamcount += 1;
404 self.nickspamtime = time + autocvar_g_nick_flood_penalty;
406 if (timeoutStatus == 2) //when game is paused, no flood protection
407 self.nickspamcount = self.nickspamtime = 0;
410 clientcommand(self,s);
414 void ReadyRestartForce()
418 bprint("^1Server is restarting...\n");
423 if (checkrules_overtimesadded > 0 && g_race_qualifying != 2) {
424 //we have to decrease timelimit to its original value again!!
426 newTL = autocvar_timelimit;
427 newTL -= checkrules_overtimesadded * autocvar_timelimit_overtime;
428 cvar_set("timelimit", ftos(newTL));
431 checkrules_suddendeathend = checkrules_overtimesadded = checkrules_suddendeathwarning = 0;
434 readyrestart_happened = 1;
435 game_starttime = time;
436 if(!g_ca && !g_arena)
437 game_starttime += RESTART_COUNTDOWN;
438 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
440 inWarmupStage = 0; //once the game is restarted the game is in match stage
442 //reset the .ready status of all players (also spectators)
443 FOR_EACH_CLIENTSLOT(e)
446 Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
448 if(autocvar_teamplay_lockonrestart && teamplay) {
450 bprint("^1The teams are now locked.\n");
453 //initiate the restart-countdown-announcer entity
454 if(autocvar_sv_ready_restart_after_countdown && !g_ca && !g_arena)
456 restartTimer = spawn();
457 restartTimer.think = restartTimer_Think;
458 restartTimer.nextthink = game_starttime;
461 //after a restart every players number of allowed timeouts gets reset, too
462 if(autocvar_sv_timeout)
464 FOR_EACH_REALPLAYER(e)
465 e.allowedTimeouts = autocvar_sv_timeout_number;
468 //reset map immediately if this cvar is not set
469 if (!autocvar_sv_ready_restart_after_countdown)
472 if(autocvar_sv_eventlog)
473 GameLogEcho(":restart");
478 // no arena, assault support yet...
479 if(g_arena | g_assault | gameover | intermission_running | race_completing)
480 localcmd("restart\n");
482 localcmd("\nsv_hook_gamerestart\n");
486 // reset ALL scores, but only do that at the beginning
487 //of the countdown if sv_ready_restart_after_countdown is off!
488 //Otherwise scores could be manipulated during the countdown!
489 if (!autocvar_sv_ready_restart_after_countdown)
494 * Counts how many players are ready. If not enough players are ready, the function
495 * does nothing. If all players are ready, the timelimit will be extended and the
496 * restart_countdown variable is set to allow other functions like PlayerPostThink
497 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
498 * is not set the map will be resetted.
500 * Function is called after the server receives a 'ready' sign from a player.
509 FOR_EACH_REALPLAYER(e)
518 Nagger_ReadyCounted();
520 if(r) // at least one is ready
521 if(r == p) // and, everyone is ready
526 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
529 void restartTimer_Think() {
530 restart_mapalreadyrestarted = 1;
538 * Checks whether the player who calls the timeout is allowed to do so.
539 * If so, it initializes the timeout countdown. It also checks whether another
540 * timeout was already running at this time and reacts correspondingly.
542 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
543 * timeoutInitiator, timeoutStatus, timeoutHandler
545 * This function is called when a player issues the calltimeout command.
547 void evaluateTimeout() {
548 if (inWarmupStage && !g_warmup_allow_timeout)
549 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
550 if (time < game_starttime )
551 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
552 if (timeoutStatus != 2) {
553 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
554 if (autocvar_timelimit) {
555 //a timelimit was used
557 myTl = autocvar_timelimit;
559 local float lastPossibleTimeout;
560 lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1;
562 if (lastPossibleTimeout < time - game_starttime)
563 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
566 //player may not call a timeout if he has no calls left
567 if (self.allowedTimeouts < 1)
568 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
569 //now all required checks are passed
570 self.allowedTimeouts -= 1;
571 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)
572 remainingTimeoutTime = autocvar_sv_timeout_length;
573 remainingLeadTime = autocvar_sv_timeout_leadtime;
574 timeoutInitiator = self;
575 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
577 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
578 timeoutHandler = spawn();
579 timeoutHandler.think = timeoutHandler_Think;
581 timeoutHandler.nextthink = time; //always let the entity think asap
583 //inform all connected clients about the timeout call
584 Announce("timeoutcalled");
588 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
589 * and the lead time for the timeout is still active, this countdown just will be aborted (the
590 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
591 * value of the cvar sv_timeout_resumetime.
593 * This function is called when a player issues the resumegame command.
595 void evaluateTimein() {
597 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
598 if (self != timeoutInitiator)
599 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
600 if (timeoutStatus == 1) {
601 remainingTimeoutTime = timeoutStatus = 0;
602 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
603 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
605 else if (timeoutStatus == 2) {
606 //only shorten the remainingTimeoutTime if it makes sense
607 if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) ) {
608 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
609 remainingTimeoutTime = autocvar_sv_timeout_resumetime;
610 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
613 sprint(self, "^7Error: Your resumegame call was discarded!\n");