4 float Nagger_SendEntity(entity to, float sendflags)
8 WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER);
12 // 2 = player needs to ready up
14 // 8 = player needs to vote
42 if(!(nags & 4)) // no vote called? send no string
45 WriteByte(MSG_ENTITY, nags);
49 WriteByte(MSG_ENTITY, vote_yescount);
50 WriteByte(MSG_ENTITY, vote_nocount);
51 WriteByte(MSG_ENTITY, vote_needed_absolute);
52 WriteChar(MSG_ENTITY, to.vote_vote);
56 WriteString(MSG_ENTITY, votecalledvote_display);
60 for(i = 1; i <= maxclients; i += 8)
62 for(f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e))
63 if(clienttype(e) != CLIENTTYPE_REAL || e.ready)
65 WriteByte(MSG_ENTITY, f);
73 Net_LinkEntity(nagger = spawn(), FALSE, 0, Nagger_SendEntity);
75 void Nagger_VoteChanged()
78 nagger.SendFlags |= 128;
80 void Nagger_VoteCountChanged()
83 nagger.SendFlags |= 64;
85 void Nagger_ReadyCounted()
88 nagger.SendFlags |= 1;
92 string MapVote_Suggest(string m);
94 entity GetPlayer(string name)
100 if(substring(name, 0, 1) == "#") {
101 num = stof(substring(name, 1, 999));
102 if(num >= 1 && num <= maxclients) {
103 for((e = world); num > 0; --num, (e = nextent(e)))
105 //if(clienttype(e) == CLIENTTYPE_REAL)
106 if(e.classname == "player")
110 ns = strdecolorize(name);
111 FOR_EACH_REALPLAYER(e) {
112 if(!strcasecmp(strdecolorize(e.netname), ns)) {
120 //float ctf_clientcommand();
121 float readyrestart_happened;
122 .float lms_spectate_warning;
123 void spawnfunc_func_breakable();
125 .float cmd_floodtime;
126 .float cmd_floodcount;
127 float cmd_floodcheck()
129 if (timeoutStatus != 2)
131 if(time == self.cmd_floodtime)
133 self.cmd_floodcount += 1;
134 if(self.cmd_floodcount > 8)
139 self.cmd_floodtime = time;
140 self.cmd_floodcount = 1;
147 void SV_ParseClientCommand(string s) {
151 cmd_argc = tokenize_console(s);
153 cmd_name = strtolower(argv(0));
154 if(cmd_name != "reportcvar")
155 if(cmd_name != "sentcvar")
156 if(cmd_name != "pause")
157 if(cmd_name != "prespawn")
158 if(cmd_name != "spawn")
159 if(cmd_name != "begin")
163 cmd_string = cmd_name = string_null; // unreference tempstrings
168 if(MUTATOR_CALLHOOK(SV_ParseClientCommand)) {
169 cmd_string = cmd_name = string_null; // unreference tempstrings
170 return; // already handled
172 cmd_string = cmd_name = string_null; // unreference tempstrings
174 if(GameCommand_Vote(s, self)) {
176 } else if(GameCommand_MapVote(argv(0))) {
178 } else if(cmd_name == "checkfail") {
179 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))));
181 } else if(cmd_name == "autoswitch") {
182 // be backwards compatible with older clients (enabled)
183 self.autoswitch = ("0" != argv(1));
184 string autoswitchmsg;
185 if (self.autoswitch) {
186 autoswitchmsg = "on";
188 autoswitchmsg = "off";
190 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
191 } else if(cmd_name == "clientversion") {
192 if not(self.flags & FL_CLIENT)
194 if (argv(1) == "$gameversion") {
195 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.xonotic.com)^8";
196 // either that or someone wants to be funny
199 self.version = stof(argv(1));
201 if(self.version < autocvar_gameversion_min || self.version > autocvar_gameversion_max)
203 self.version_mismatch = 1;
204 ClientKill_TeamChange(-2); // observe
205 } else if(autocvar_g_campaign || autocvar_g_balance_teams || autocvar_g_balance_teams_force) {
206 //JoinBestTeam(self, FALSE, TRUE);
207 } else if(teamplay && !autocvar_sv_spectate && !(self.team_forced > 0)) {
208 self.classname = "observer";
209 stuffcmd(self,"menu_showteamselect\n");
211 } else if(cmd_name == "reportcvar") { // old system
212 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
214 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
215 cmd_argc = tokenize_console(s);
218 } else if(cmd_name == "sentcvar") { // new system
219 if(cmd_argc == 2) // undefined cvar: use the default value on the server then
221 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
222 cmd_argc = tokenize_console(s);
225 } else if(cmd_name == "spectate") {
228 if not(self.flags & FL_CLIENT)
234 if(self.lms_spectate_warning)
236 // mark player as spectator
237 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
241 self.lms_spectate_warning = 1;
242 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");
246 if(self.classname == "player" && autocvar_sv_spectate == 1) {
247 ClientKill_TeamChange(-2); // observe
249 if(g_ca && self.caplayer && (self.classname == "spectator" || self.classname == "observer")) {
250 // in CA, allow a dead player to move to spectatators (without that, caplayer!=0 will be moved back to the player list)
251 sprint(self, "WARNING: you will spectate in the next round.\n");
254 } else if(cmd_name == "join") {
255 if not(self.flags & FL_CLIENT)
258 if (self.classname != "player" && !lockteams)
260 if(nJoinAllowed(1)) {
261 self.classname = "player";
264 PlayerScore_Clear(self);
265 bprint ("^4", self.netname, "^4 is playing now\n");
267 if(autocvar_g_campaign)
268 campaign_bots_may_start = 1;
271 //player may not join because of g_maxplayers is set
272 centerprint(self, PREVENT_JOIN_TEXT);
275 } else if( cmd_name == "selectteam" ) {
276 if not(self.flags & FL_CLIENT)
279 sprint( self, "selectteam can only be used in teamgames\n");
280 } else if(autocvar_g_campaign) {
281 //JoinBestTeam(self, 0);
282 } else if(self.team_forced > 0) {
283 sprint( self, "selectteam can not be used as your team is forced\n");
284 } else if(lockteams) {
285 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
286 } else if( argv(1) == "red" ) {
287 if(self.team != COLOR_TEAM1 || self.deadflag != DEAD_NO)
288 ClientKill_TeamChange(COLOR_TEAM1);
290 sprint( self, "^7You already are on that team.\n");
291 } else if( argv(1) == "blue" ) {
292 if(self.team != COLOR_TEAM2 || self.deadflag != DEAD_NO)
293 ClientKill_TeamChange(COLOR_TEAM2);
295 sprint( self, "^7You already are on that team.\n");
296 } else if( argv(1) == "yellow" ) {
297 if(self.team != COLOR_TEAM3 || self.deadflag != DEAD_NO)
298 ClientKill_TeamChange(COLOR_TEAM3);
300 sprint( self, "^7You already are on that team.\n");
301 } else if( argv(1) == "pink" ) {
302 if(self.team != COLOR_TEAM4 || self.deadflag != DEAD_NO)
303 ClientKill_TeamChange(COLOR_TEAM4);
305 sprint( self, "^7You already are on that team.\n");
306 } else if( argv(1) == "auto" ) {
307 ClientKill_TeamChange(-1);
309 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
311 } else if(cmd_name == "ready") {
312 if not(self.flags & FL_CLIENT)
316 || autocvar_sv_ready_restart || g_race_qualifying == 2)
318 if(!readyrestart_happened || autocvar_sv_ready_restart_repeatable)
320 if (self.ready) // toggle
323 bprint(self.netname, "^2 is ^1NOT^2 ready\n");
328 bprint(self.netname, "^2 is ready\n");
331 // cannot reset the game while a timeout is active!
335 sprint(self, "^1Game has already been restarted\n");
338 } else if(cmd_name == "maplist") {
339 sprint(self, maplist_reply);
340 } else if(cmd_name == "lsmaps") {
341 sprint(self, lsmaps_reply);
342 } else if(cmd_name == "lsnewmaps") {
343 sprint(self, lsnewmaps_reply);
344 } else if(cmd_name == "records") {
345 for(i = 0; i < 10; ++i)
346 sprint(self, records_reply[i]);
347 } else if(cmd_name == "ladder") {
348 sprint(self, ladder_reply);
349 } else if(cmd_name == "rankings") {
350 sprint(self, rankings_reply);
351 } else if(cmd_name == "voice") {
353 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
355 VoiceMessage(argv(1), "");
356 } else if(cmd_name == "say") {
358 Say(self, FALSE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
359 //clientcommand(self, formatmessage(s));
360 } else if(cmd_name == "say_team") {
362 Say(self, TRUE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
363 //clientcommand(self, formatmessage(s));
364 } else if(cmd_name == "tell") {
365 e = GetCommandPlayerSlotTargetFromTokenizedCommand(cmd_argc, 1);
366 if(e && cmd_argc > ParseCommandPlayerSlotTarget_firsttoken)
368 Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
372 if(cmd_argc > ParseCommandPlayerSlotTarget_firsttoken)
373 trigger_magicear_processmessage_forallears(self, -1, world, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
374 sprint(self, "ERROR: usage: tell # playerid text...\n");
376 //clientcommand(self, formatmessage(s));
377 } else if(cmd_name == "info") {
378 cmd_name = cvar_string_builtin(strcat("sv_info_", argv(1))); // This needed fixed for the cvar check
380 sprint(self, "ERROR: unsupported info command\n");
382 wordwrap_sprint(cmd_name, 1111);
383 } else if(cmd_name == "suggestmap") {
384 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
385 } else if(cmd_name == "timeout") {
386 if not(self.flags & FL_CLIENT)
388 if(autocvar_sv_timeout) {
389 if(self.classname == "player") {
391 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
396 sprint(self, "^7Error: only players can call a timeout!\n");
398 } else if(cmd_name == "timein") {
399 if not(self.flags & FL_CLIENT)
401 if(autocvar_sv_timeout) {
404 } else if(cmd_name == "teamstatus") {
405 Score_NicePrint(self);
406 } else if(cmd_name == "cvar_changes") {
407 sprint(self, cvar_changes);
408 } else if(cmd_name == "cvar_purechanges") {
409 sprint(self, cvar_purechanges);
410 } else if(CheatCommand(cmd_argc)) {
413 //if(ctf_clientcommand())
415 // grep for Cmd_AddCommand_WithClientCommand to find them all
416 if(cmd_name != "status")
417 //if(cmd_name != "say") // handled above
418 //if(cmd_name != "say_team") // handled above
419 if(cmd_name != "kill")
420 if(cmd_name != "pause")
421 if(cmd_name != "ping")
422 if(cmd_name != "name")
423 if(cmd_name != "color")
424 if(cmd_name != "rate")
425 if(cmd_name != "pmodel")
426 if(cmd_name != "playermodel")
427 if(cmd_name != "playerskin")
428 if(cmd_name != "prespawn")
429 if(cmd_name != "spawn")
430 if(cmd_name != "begin")
431 if(cmd_name != "pings")
432 if(cmd_name != "sv_startdownload")
433 if(cmd_name != "download")
435 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
440 if(self.jointime > 0 && time > self.jointime + 10 && time > self.nickspamtime) // allow any changes in the first 10 seconds since joining
441 if(cmd_name == "name" || cmd_name == "playermodel") // TODO also playerskin and color?
443 if(self.nickspamtime == 0 || time > self.nickspamtime + autocvar_g_nick_flood_timeout)
444 // good, no serious flood
445 self.nickspamcount = 1;
447 self.nickspamcount += 1;
448 self.nickspamtime = time + autocvar_g_nick_flood_penalty;
450 if (timeoutStatus == 2) //when game is paused, no flood protection
451 self.nickspamcount = self.nickspamtime = 0;
454 clientcommand(self,s);
458 void ReadyRestartForce()
462 bprint("^1Server is restarting...\n");
467 if (checkrules_overtimesadded > 0 && g_race_qualifying != 2) {
468 //we have to decrease timelimit to its original value again!!
470 newTL = autocvar_timelimit;
471 newTL -= checkrules_overtimesadded * autocvar_timelimit_overtime;
472 cvar_set("timelimit", ftos(newTL));
475 checkrules_suddendeathend = checkrules_overtimesadded = checkrules_suddendeathwarning = 0;
478 readyrestart_happened = 1;
479 game_starttime = time;
480 if(!g_ca && !g_arena)
481 game_starttime += RESTART_COUNTDOWN;
482 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
484 inWarmupStage = 0; //once the game is restarted the game is in match stage
486 //reset the .ready status of all players (also spectators)
487 FOR_EACH_CLIENTSLOT(e)
490 Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
492 if(autocvar_teamplay_lockonrestart && teamplay) {
494 bprint("^1The teams are now locked.\n");
497 //initiate the restart-countdown-announcer entity
498 if(autocvar_sv_ready_restart_after_countdown && !g_ca && !g_arena)
500 restartTimer = spawn();
501 restartTimer.think = restartTimer_Think;
502 restartTimer.nextthink = game_starttime;
505 //after a restart every players number of allowed timeouts gets reset, too
506 if(autocvar_sv_timeout)
508 FOR_EACH_REALPLAYER(e)
509 e.allowedTimeouts = autocvar_sv_timeout_number;
512 //reset map immediately if this cvar is not set
513 if (!autocvar_sv_ready_restart_after_countdown)
516 if(autocvar_sv_eventlog)
517 GameLogEcho(":restart");
522 // no arena, assault support yet...
523 if(g_arena | g_assault | gameover | intermission_running | race_completing)
524 localcmd("restart\n");
526 localcmd("\nsv_hook_gamerestart\n");
530 // reset ALL scores, but only do that at the beginning
531 //of the countdown if sv_ready_restart_after_countdown is off!
532 //Otherwise scores could be manipulated during the countdown!
533 if (!autocvar_sv_ready_restart_after_countdown)
538 * Counts how many players are ready. If not enough players are ready, the function
539 * does nothing. If all players are ready, the timelimit will be extended and the
540 * restart_countdown variable is set to allow other functions like PlayerPostThink
541 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
542 * is not set the map will be resetted.
544 * Function is called after the server receives a 'ready' sign from a player.
553 FOR_EACH_REALPLAYER(e)
562 Nagger_ReadyCounted();
564 if(r) // at least one is ready
565 if(r == p) // and, everyone is ready
570 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
573 void restartTimer_Think() {
574 restart_mapalreadyrestarted = 1;
582 * Checks whether the player who calls the timeout is allowed to do so.
583 * If so, it initializes the timeout countdown. It also checks whether another
584 * timeout was already running at this time and reacts correspondingly.
586 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
587 * timeoutInitiator, timeoutStatus, timeoutHandler
589 * This function is called when a player issues the calltimeout command.
591 void evaluateTimeout() {
592 if (inWarmupStage && !g_warmup_allow_timeout)
593 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
594 if (time < game_starttime )
595 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
596 if (timeoutStatus != 2) {
597 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
598 if (autocvar_timelimit) {
599 //a timelimit was used
601 myTl = autocvar_timelimit;
603 float lastPossibleTimeout;
604 lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1;
606 if (lastPossibleTimeout < time - game_starttime)
607 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
610 //player may not call a timeout if he has no calls left
611 if (self.allowedTimeouts < 1)
612 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
613 //now all required checks are passed
614 self.allowedTimeouts -= 1;
615 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)
616 remainingTimeoutTime = autocvar_sv_timeout_length;
617 remainingLeadTime = autocvar_sv_timeout_leadtime;
618 timeoutInitiator = self;
619 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
621 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
622 timeoutHandler = spawn();
623 timeoutHandler.think = timeoutHandler_Think;
625 timeoutHandler.nextthink = time; //always let the entity think asap
627 //inform all connected clients about the timeout call
628 Announce("timeoutcalled");
632 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
633 * and the lead time for the timeout is still active, this countdown just will be aborted (the
634 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
635 * value of the cvar sv_timeout_resumetime.
637 * This function is called when a player issues the resumegame command.
639 void evaluateTimein() {
641 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
642 if (self != timeoutInitiator)
643 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
644 if (timeoutStatus == 1) {
645 remainingTimeoutTime = timeoutStatus = 0;
646 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
647 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
649 else if (timeoutStatus == 2) {
650 //only shorten the remainingTimeoutTime if it makes sense
651 if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) ) {
652 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
653 remainingTimeoutTime = autocvar_sv_timeout_resumetime;
654 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
657 sprint(self, "^7Error: Your resumegame call was discarded!\n");