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) {
153 tokens = tokenize_console(s);
155 cmd = strtolower(argv(0));
156 if(cmd != "reportcvar")
157 if(cmd != "sentcvar")
159 if(cmd != "prespawn")
167 if(GameCommand_Vote(s, self)) {
169 } else if(GameCommand_MapVote(argv(0))) {
171 } else if(cmd == "checkfail") {
172 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))));
174 } else if(cmd == "autoswitch") {
175 // be backwards compatible with older clients (enabled)
176 self.autoswitch = ("0" != argv(1));
177 string autoswitchmsg;
178 if (self.autoswitch) {
179 autoswitchmsg = "on";
181 autoswitchmsg = "off";
183 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
184 } else if(cmd == "clientversion") {
185 if not(self.flags & FL_CLIENT)
187 if (argv(1) == "$gameversion") {
188 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.xonotic.com)^8";
189 // either that or someone wants to be funny
192 self.version = stof(argv(1));
194 if(self.version < autocvar_gameversion_min || self.version > autocvar_gameversion_max)
196 self.version_mismatch = 1;
197 ClientKill_TeamChange(-2); // observe
198 } else if(autocvar_g_campaign || autocvar_g_balance_teams || autocvar_g_balance_teams_force) {
199 //JoinBestTeam(self, FALSE, TRUE);
200 } else if(teamplay && !autocvar_sv_spectate && !(self.team_forced > 0)) {
201 self.classname = "observer";
202 stuffcmd(self,"menu_showteamselect\n");
204 } else if(cmd == "reportcvar") { // old system
205 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
207 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
208 tokens = tokenize_console(s);
211 } else if(cmd == "sentcvar") { // new system
212 if(tokens == 2) // 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 tokens = tokenize_console(s);
218 } else if(cmd == "spectate") {
221 if not(self.flags & FL_CLIENT)
227 if(self.lms_spectate_warning)
229 // mark player as spectator
230 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
234 self.lms_spectate_warning = 1;
235 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");
239 if(self.classname == "player" && autocvar_sv_spectate == 1) {
240 ClientKill_TeamChange(-2); // observe
242 if(g_ca && self.caplayer && (self.classname == "spectator" || self.classname == "observer")) {
243 // in CA, allow a dead player to move to spectatators (without that, caplayer!=0 will be moved back to the player list)
244 sprint(self, "WARNING: you will spectate in the next round.\n");
247 } else if(cmd == "join") {
248 if not(self.flags & FL_CLIENT)
251 if (self.classname != "player" && !lockteams)
253 if(nJoinAllowed(1)) {
254 self.classname = "player";
257 PlayerScore_Clear(self);
258 bprint ("^4", self.netname, "^4 is playing now\n");
260 if(autocvar_g_campaign)
261 campaign_bots_may_start = 1;
264 //player may not join because of g_maxplayers is set
265 centerprint(self, PREVENT_JOIN_TEXT);
268 } else if( cmd == "selectteam" ) {
269 if not(self.flags & FL_CLIENT)
272 sprint( self, "selectteam can only be used in teamgames\n");
273 } else if(autocvar_g_campaign) {
274 //JoinBestTeam(self, 0);
275 } else if(self.team_forced > 0) {
276 sprint( self, "selectteam can not be used as your team is forced\n");
277 } else if(lockteams) {
278 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
279 } else if( argv(1) == "red" ) {
280 if(self.team != COLOR_TEAM1 || self.deadflag != DEAD_NO)
281 ClientKill_TeamChange(COLOR_TEAM1);
283 sprint( self, "^7You already are on that team.\n");
284 } else if( argv(1) == "blue" ) {
285 if(self.team != COLOR_TEAM2 || self.deadflag != DEAD_NO)
286 ClientKill_TeamChange(COLOR_TEAM2);
288 sprint( self, "^7You already are on that team.\n");
289 } else if( argv(1) == "yellow" ) {
290 if(self.team != COLOR_TEAM3 || self.deadflag != DEAD_NO)
291 ClientKill_TeamChange(COLOR_TEAM3);
293 sprint( self, "^7You already are on that team.\n");
294 } else if( argv(1) == "pink" ) {
295 if(self.team != COLOR_TEAM4 || self.deadflag != DEAD_NO)
296 ClientKill_TeamChange(COLOR_TEAM4);
298 sprint( self, "^7You already are on that team.\n");
299 } else if( argv(1) == "auto" ) {
300 ClientKill_TeamChange(-1);
302 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
304 } else if(cmd == "ready") {
305 if not(self.flags & FL_CLIENT)
309 || autocvar_sv_ready_restart || g_race_qualifying == 2)
311 if(!readyrestart_happened || autocvar_sv_ready_restart_repeatable)
313 if (self.ready) // toggle
316 bprint(self.netname, "^2 is ^1NOT^2 ready\n");
321 bprint(self.netname, "^2 is ready\n");
324 // cannot reset the game while a timeout is active!
328 sprint(self, "^1Game has already been restarted\n");
331 } else if(cmd == "maplist") {
332 sprint(self, maplist_reply);
333 } else if(cmd == "lsmaps") {
334 sprint(self, lsmaps_reply);
335 } else if(cmd == "lsnewmaps") {
336 sprint(self, lsnewmaps_reply);
337 } else if(cmd == "records") {
338 for(i = 0; i < 10; ++i)
339 sprint(self, records_reply[i]);
340 } else if(cmd == "ladder") {
341 sprint(self, ladder_reply);
342 } else if(cmd == "rankings") {
343 sprint(self, rankings_reply);
344 } else if(cmd == "voice") {
346 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
348 VoiceMessage(argv(1), "");
349 } else if(cmd == "say") {
351 Say(self, FALSE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
352 //clientcommand(self, formatmessage(s));
353 } else if(cmd == "say_team") {
355 Say(self, TRUE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
356 //clientcommand(self, formatmessage(s));
357 } else if(cmd == "tell") {
358 e = GetCommandPlayerSlotTargetFromTokenizedCommand(tokens, 1);
359 if(e && tokens > ParseCommandPlayerSlotTarget_firsttoken)
361 Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
365 if(tokens > ParseCommandPlayerSlotTarget_firsttoken)
366 trigger_magicear_processmessage_forallears(self, -1, world, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
367 sprint(self, "ERROR: usage: tell # playerid text...\n");
369 //clientcommand(self, formatmessage(s));
370 } else if(cmd == "info") {
371 cmd = cvar_string_builtin(strcat("sv_info_", argv(1))); // This needed fixed for the cvar check
373 sprint(self, "ERROR: unsupported info command\n");
375 wordwrap_sprint(cmd, 1111);
376 } else if(cmd == "suggestmap") {
377 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
378 } else if(cmd == "timeout") {
379 if not(self.flags & FL_CLIENT)
381 if(autocvar_sv_timeout) {
382 if(self.classname == "player") {
384 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
389 sprint(self, "^7Error: only players can call a timeout!\n");
391 } else if(cmd == "timein") {
392 if not(self.flags & FL_CLIENT)
394 if(autocvar_sv_timeout) {
397 } else if(cmd == "teamstatus") {
398 Score_NicePrint(self);
399 } else if(cmd == "cvar_changes") {
400 sprint(self, cvar_changes);
401 } else if(cmd == "cvar_purechanges") {
402 sprint(self, cvar_purechanges);
403 } else if(CheatCommand(tokens)) {
406 //if(ctf_clientcommand())
408 // grep for Cmd_AddCommand_WithClientCommand to find them all
410 //if(cmd != "say") // handled above
411 //if(cmd != "say_team") // handled above
419 if(cmd != "playermodel")
420 if(cmd != "playerskin")
421 if(cmd != "prespawn")
425 if(cmd != "sv_startdownload")
426 if(cmd != "download")
428 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
433 if(self.jointime > 0 && time > self.jointime + 10 && time > self.nickspamtime) // allow any changes in the first 10 seconds since joining
434 if(cmd == "name" || cmd == "playermodel") // TODO also playerskin and color?
436 if(self.nickspamtime == 0 || time > self.nickspamtime + autocvar_g_nick_flood_timeout)
437 // good, no serious flood
438 self.nickspamcount = 1;
440 self.nickspamcount += 1;
441 self.nickspamtime = time + autocvar_g_nick_flood_penalty;
443 if (timeoutStatus == 2) //when game is paused, no flood protection
444 self.nickspamcount = self.nickspamtime = 0;
447 clientcommand(self,s);
451 void ReadyRestartForce()
455 bprint("^1Server is restarting...\n");
460 if (checkrules_overtimesadded > 0 && g_race_qualifying != 2) {
461 //we have to decrease timelimit to its original value again!!
463 newTL = autocvar_timelimit;
464 newTL -= checkrules_overtimesadded * autocvar_timelimit_overtime;
465 cvar_set("timelimit", ftos(newTL));
468 checkrules_suddendeathend = checkrules_overtimesadded = checkrules_suddendeathwarning = 0;
471 readyrestart_happened = 1;
472 game_starttime = time;
473 if(!g_ca && !g_arena)
474 game_starttime += RESTART_COUNTDOWN;
475 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
477 inWarmupStage = 0; //once the game is restarted the game is in match stage
479 //reset the .ready status of all players (also spectators)
480 FOR_EACH_CLIENTSLOT(e)
483 Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
485 if(autocvar_teamplay_lockonrestart && teamplay) {
487 bprint("^1The teams are now locked.\n");
490 //initiate the restart-countdown-announcer entity
491 if(autocvar_sv_ready_restart_after_countdown && !g_ca && !g_arena)
493 restartTimer = spawn();
494 restartTimer.think = restartTimer_Think;
495 restartTimer.nextthink = game_starttime;
498 //after a restart every players number of allowed timeouts gets reset, too
499 if(autocvar_sv_timeout)
501 FOR_EACH_REALPLAYER(e)
502 e.allowedTimeouts = autocvar_sv_timeout_number;
505 //reset map immediately if this cvar is not set
506 if (!autocvar_sv_ready_restart_after_countdown)
509 if(autocvar_sv_eventlog)
510 GameLogEcho(":restart");
515 // no arena, assault support yet...
516 if(g_arena | g_assault | gameover | intermission_running | race_completing)
517 localcmd("restart\n");
519 localcmd("\nsv_hook_gamerestart\n");
523 // reset ALL scores, but only do that at the beginning
524 //of the countdown if sv_ready_restart_after_countdown is off!
525 //Otherwise scores could be manipulated during the countdown!
526 if (!autocvar_sv_ready_restart_after_countdown)
531 * Counts how many players are ready. If not enough players are ready, the function
532 * does nothing. If all players are ready, the timelimit will be extended and the
533 * restart_countdown variable is set to allow other functions like PlayerPostThink
534 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
535 * is not set the map will be resetted.
537 * Function is called after the server receives a 'ready' sign from a player.
546 FOR_EACH_REALPLAYER(e)
555 Nagger_ReadyCounted();
557 if(r) // at least one is ready
558 if(r == p) // and, everyone is ready
563 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
566 void restartTimer_Think() {
567 restart_mapalreadyrestarted = 1;
575 * Checks whether the player who calls the timeout is allowed to do so.
576 * If so, it initializes the timeout countdown. It also checks whether another
577 * timeout was already running at this time and reacts correspondingly.
579 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
580 * timeoutInitiator, timeoutStatus, timeoutHandler
582 * This function is called when a player issues the calltimeout command.
584 void evaluateTimeout() {
585 if (inWarmupStage && !g_warmup_allow_timeout)
586 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
587 if (time < game_starttime )
588 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
589 if (timeoutStatus != 2) {
590 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
591 if (autocvar_timelimit) {
592 //a timelimit was used
594 myTl = autocvar_timelimit;
596 float lastPossibleTimeout;
597 lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1;
599 if (lastPossibleTimeout < time - game_starttime)
600 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
603 //player may not call a timeout if he has no calls left
604 if (self.allowedTimeouts < 1)
605 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
606 //now all required checks are passed
607 self.allowedTimeouts -= 1;
608 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)
609 remainingTimeoutTime = autocvar_sv_timeout_length;
610 remainingLeadTime = autocvar_sv_timeout_leadtime;
611 timeoutInitiator = self;
612 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
614 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
615 timeoutHandler = spawn();
616 timeoutHandler.think = timeoutHandler_Think;
618 timeoutHandler.nextthink = time; //always let the entity think asap
620 //inform all connected clients about the timeout call
621 Announce("timeoutcalled");
625 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
626 * and the lead time for the timeout is still active, this countdown just will be aborted (the
627 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
628 * value of the cvar sv_timeout_resumetime.
630 * This function is called when a player issues the resumegame command.
632 void evaluateTimein() {
634 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
635 if (self != timeoutInitiator)
636 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
637 if (timeoutStatus == 1) {
638 remainingTimeoutTime = timeoutStatus = 0;
639 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
640 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
642 else if (timeoutStatus == 2) {
643 //only shorten the remainingTimeoutTime if it makes sense
644 if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) ) {
645 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
646 remainingTimeoutTime = autocvar_sv_timeout_resumetime;
647 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
650 sprint(self, "^7Error: Your resumegame call was discarded!\n");