entity nagger; float readycount; float Nagger_SendEntity(entity to, float sendflags) { float nags, i, f, b; entity e; WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER); // bits: // 1 = ready // 2 = player needs to ready up // 4 = vote // 8 = player needs to vote // 16 = warmup // sendflags: // 64 = vote counts // 128 = vote string nags = 0; if(readycount) { nags |= 1; if(to.ready == 0) nags |= 2; } if(votecalled) { nags |= 4; if(to.vote_vote == 0) nags |= 8; } if(inWarmupStage) nags |= 16; if(sendflags & 64) nags |= 64; if(sendflags & 128) nags |= 128; if(!(nags & 4)) // no vote called? send no string nags &~= (64 | 128); WriteByte(MSG_ENTITY, nags); if(nags & 64) { WriteByte(MSG_ENTITY, vote_yescount); WriteByte(MSG_ENTITY, vote_nocount); WriteByte(MSG_ENTITY, vote_needed_absolute); WriteChar(MSG_ENTITY, to.vote_vote); } if(nags & 128) WriteString(MSG_ENTITY, votecalledvote_display); if(nags & 1) { for(i = 1; i <= maxclients; i += 8) { for(f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e)) if(clienttype(e) != CLIENTTYPE_REAL || e.ready) f |= b; WriteByte(MSG_ENTITY, f); } } return TRUE; } void Nagger_Init() { Net_LinkEntity(nagger = spawn(), FALSE, 0, Nagger_SendEntity); } void Nagger_VoteChanged() { if(nagger) nagger.SendFlags |= 128; } void Nagger_VoteCountChanged() { if(nagger) nagger.SendFlags |= 64; } void Nagger_ReadyCounted() { if(nagger) nagger.SendFlags |= 1; } void ReadyCount(); string MapVote_Suggest(string m); entity GetPlayer(string name) { float num; entity e; string ns; if(substring(name, 0, 1) == "#") { num = stof(substring(name, 1, 999)); if(num >= 1 && num <= maxclients) { for((e = world); num > 0; --num, (e = nextent(e))) ; //if(clienttype(e) == CLIENTTYPE_REAL) if(e.classname == "player") return e; } } else { ns = strdecolorize(name); FOR_EACH_REALPLAYER(e) { if(!strcasecmp(strdecolorize(e.netname), ns)) { return e; } } } return world; } //float ctf_clientcommand(); float readyrestart_happened; .float lms_spectate_warning; void spawnfunc_func_breakable(); .float cmd_floodtime; .float cmd_floodcount; float cmd_floodcheck() { if (timeoutStatus != 2) { if(time == self.cmd_floodtime) { self.cmd_floodcount += 1; if(self.cmd_floodcount > 8) return TRUE; } else { self.cmd_floodtime = time; self.cmd_floodcount = 1; } } return FALSE; } .float checkfail; void SV_ParseClientCommand(string s) { float i; entity e; cmd_argc = tokenize_console(s); cmd_string = s; cmd_name = strtolower(argv(0)); if(cmd_name != "reportcvar") if(cmd_name != "sentcvar") if(cmd_name != "pause") if(cmd_name != "prespawn") if(cmd_name != "spawn") if(cmd_name != "begin") { if(cmd_floodcheck()) return; } if(MUTATOR_CALLHOOK(SV_ParseClientCommand)) return; // already handled if(GameCommand_Vote(s, self)) { return; } else if(GameCommand_MapVote(argv(0))) { return; } else if(cmd_name == "checkfail") { 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)))); self.checkfail = 1; } else if(cmd_name == "autoswitch") { // be backwards compatible with older clients (enabled) self.autoswitch = ("0" != argv(1)); string autoswitchmsg; if (self.autoswitch) { autoswitchmsg = "on"; } else { autoswitchmsg = "off"; } sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n")); } else if(cmd_name == "clientversion") { if not(self.flags & FL_CLIENT) return; if (argv(1) == "$gameversion") { //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.xonotic.com)^8"; // either that or someone wants to be funny self.version = 1; } else { self.version = stof(argv(1)); } if(self.version < autocvar_gameversion_min || self.version > autocvar_gameversion_max) { self.version_mismatch = 1; ClientKill_TeamChange(-2); // observe } else if(autocvar_g_campaign || autocvar_g_balance_teams || autocvar_g_balance_teams_force) { //JoinBestTeam(self, FALSE, TRUE); } else if(teamplay && !autocvar_sv_spectate && !(self.team_forced > 0)) { self.classname = "observer"; stuffcmd(self,"menu_showteamselect\n"); } } else if(cmd_name == "reportcvar") { // old system if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then { s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\""); cmd_argc = tokenize_console(s); } GetCvars(1); } else if(cmd_name == "sentcvar") { // new system if(cmd_argc == 2) // undefined cvar: use the default value on the server then { s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\""); cmd_argc = tokenize_console(s); } GetCvars(1); } else if(cmd_name == "spectate") { if(cmd_floodcheck()) return; if not(self.flags & FL_CLIENT) return; if(g_arena) return; if(g_lms) { if(self.lms_spectate_warning) { // mark player as spectator PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0)); } else { self.lms_spectate_warning = 1; 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"); return; } } if(self.classname == "player" && autocvar_sv_spectate == 1) { ClientKill_TeamChange(-2); // observe } if(g_ca && self.caplayer && (self.classname == "spectator" || self.classname == "observer")) { // in CA, allow a dead player to move to spectatators (without that, caplayer!=0 will be moved back to the player list) sprint(self, "WARNING: you will spectate in the next round.\n"); self.caplayer = 0; } } else if(cmd_name == "join") { if not(self.flags & FL_CLIENT) return; if(!g_arena) if (self.classname != "player" && !lockteams) { if(nJoinAllowed(1)) { self.classname = "player"; if(g_ca) self.caplayer = 1; PlayerScore_Clear(self); bprint ("^4", self.netname, "^4 is playing now\n"); PutClientInServer(); if(autocvar_g_campaign) campaign_bots_may_start = 1; } else { //player may not join because of g_maxplayers is set centerprint(self, PREVENT_JOIN_TEXT); } } } else if( cmd_name == "selectteam" ) { if not(self.flags & FL_CLIENT) return; if( !teamplay ) { sprint( self, "selectteam can only be used in teamgames\n"); } else if(autocvar_g_campaign) { //JoinBestTeam(self, 0); } else if(self.team_forced > 0) { sprint( self, "selectteam can not be used as your team is forced\n"); } else if(lockteams) { sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n"); } else if( argv(1) == "red" ) { if(self.team != COLOR_TEAM1 || self.deadflag != DEAD_NO) ClientKill_TeamChange(COLOR_TEAM1); else sprint( self, "^7You already are on that team.\n"); } else if( argv(1) == "blue" ) { if(self.team != COLOR_TEAM2 || self.deadflag != DEAD_NO) ClientKill_TeamChange(COLOR_TEAM2); else sprint( self, "^7You already are on that team.\n"); } else if( argv(1) == "yellow" ) { if(self.team != COLOR_TEAM3 || self.deadflag != DEAD_NO) ClientKill_TeamChange(COLOR_TEAM3); else sprint( self, "^7You already are on that team.\n"); } else if( argv(1) == "pink" ) { if(self.team != COLOR_TEAM4 || self.deadflag != DEAD_NO) ClientKill_TeamChange(COLOR_TEAM4); else sprint( self, "^7You already are on that team.\n"); } else if( argv(1) == "auto" ) { ClientKill_TeamChange(-1); } else { sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) ); } } else if(cmd_name == "ready") { if not(self.flags & FL_CLIENT) return; if((inWarmupStage) || autocvar_sv_ready_restart || g_race_qualifying == 2) { if(!readyrestart_happened || autocvar_sv_ready_restart_repeatable) { if (self.ready) // toggle { self.ready = FALSE; bprint(self.netname, "^2 is ^1NOT^2 ready\n"); } else { self.ready = TRUE; bprint(self.netname, "^2 is ready\n"); } // cannot reset the game while a timeout is active! if(!timeoutStatus) ReadyCount(); } else { sprint(self, "^1Game has already been restarted\n"); } } } else if(cmd_name == "maplist") { sprint(self, maplist_reply); } else if(cmd_name == "lsmaps") { sprint(self, lsmaps_reply); } else if(cmd_name == "lsnewmaps") { sprint(self, lsnewmaps_reply); } else if(cmd_name == "records") { for(i = 0; i < 10; ++i) sprint(self, records_reply[i]); } else if(cmd_name == "ladder") { sprint(self, ladder_reply); } else if(cmd_name == "rankings") { sprint(self, rankings_reply); } else if(cmd_name == "voice") { if(cmd_argc >= 3) VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2))); else VoiceMessage(argv(1), ""); } else if(cmd_name == "say") { if(cmd_argc >= 2) Say(self, FALSE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1); //clientcommand(self, formatmessage(s)); } else if(cmd_name == "say_team") { if(cmd_argc >= 2) Say(self, TRUE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1); //clientcommand(self, formatmessage(s)); } else if(cmd_name == "tell") { e = GetCommandPlayerSlotTargetFromTokenizedCommand(cmd_argc, 1); if(e && cmd_argc > ParseCommandPlayerSlotTarget_firsttoken) { Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE); } else { if(cmd_argc > ParseCommandPlayerSlotTarget_firsttoken) trigger_magicear_processmessage_forallears(self, -1, world, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken))); sprint(self, "ERROR: usage: tell # playerid text...\n"); } //clientcommand(self, formatmessage(s)); } else if(cmd_name == "info") { cmd_name = cvar_string_builtin(strcat("sv_info_", argv(1))); // This needed fixed for the cvar check if(cmd_name == "") sprint(self, "ERROR: unsupported info command\n"); else wordwrap_sprint(cmd_name, 1111); } else if(cmd_name == "suggestmap") { sprint(self, strcat(MapVote_Suggest(argv(1)), "\n")); } else if(cmd_name == "timeout") { if not(self.flags & FL_CLIENT) return; if(autocvar_sv_timeout) { if(self.classname == "player") { if(votecalled) sprint(self, "^7Error: you can not call a timeout while a vote is active!\n"); else evaluateTimeout(); } else sprint(self, "^7Error: only players can call a timeout!\n"); } } else if(cmd_name == "timein") { if not(self.flags & FL_CLIENT) return; if(autocvar_sv_timeout) { evaluateTimein(); } } else if(cmd_name == "teamstatus") { Score_NicePrint(self); } else if(cmd_name == "cvar_changes") { sprint(self, cvar_changes); } else if(cmd_name == "cvar_purechanges") { sprint(self, cvar_purechanges); } else if(CheatCommand(cmd_argc)) { } else { #if 0 //if(ctf_clientcommand()) // return; // grep for Cmd_AddCommand_WithClientCommand to find them all if(cmd_name != "status") //if(cmd_name != "say") // handled above //if(cmd_name != "say_team") // handled above if(cmd_name != "kill") if(cmd_name != "pause") if(cmd_name != "ping") if(cmd_name != "name") if(cmd_name != "color") if(cmd_name != "rate") if(cmd_name != "pmodel") if(cmd_name != "playermodel") if(cmd_name != "playerskin") if(cmd_name != "prespawn") if(cmd_name != "spawn") if(cmd_name != "begin") if(cmd_name != "pings") if(cmd_name != "sv_startdownload") if(cmd_name != "download") { print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n"); return; } #endif if(self.jointime > 0 && time > self.jointime + 10 && time > self.nickspamtime) // allow any changes in the first 10 seconds since joining if(cmd_name == "name" || cmd_name == "playermodel") // TODO also playerskin and color? { if(self.nickspamtime == 0 || time > self.nickspamtime + autocvar_g_nick_flood_timeout) // good, no serious flood self.nickspamcount = 1; else self.nickspamcount += 1; self.nickspamtime = time + autocvar_g_nick_flood_penalty; if (timeoutStatus == 2) //when game is paused, no flood protection self.nickspamcount = self.nickspamtime = 0; } clientcommand(self,s); } } void ReadyRestartForce() { entity e; bprint("^1Server is restarting...\n"); VoteReset(); // clear overtime if (checkrules_overtimesadded > 0 && g_race_qualifying != 2) { //we have to decrease timelimit to its original value again!! float newTL; newTL = autocvar_timelimit; newTL -= checkrules_overtimesadded * autocvar_timelimit_overtime; cvar_set("timelimit", ftos(newTL)); } checkrules_suddendeathend = checkrules_overtimesadded = checkrules_suddendeathwarning = 0; readyrestart_happened = 1; game_starttime = time; if(!g_ca && !g_arena) game_starttime += RESTART_COUNTDOWN; restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use inWarmupStage = 0; //once the game is restarted the game is in match stage //reset the .ready status of all players (also spectators) FOR_EACH_CLIENTSLOT(e) e.ready = 0; readycount = 0; Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client if(autocvar_teamplay_lockonrestart && teamplay) { lockteams = 1; bprint("^1The teams are now locked.\n"); } //initiate the restart-countdown-announcer entity if(autocvar_sv_ready_restart_after_countdown && !g_ca && !g_arena) { restartTimer = spawn(); restartTimer.think = restartTimer_Think; restartTimer.nextthink = game_starttime; } //after a restart every players number of allowed timeouts gets reset, too if(autocvar_sv_timeout) { FOR_EACH_REALPLAYER(e) e.allowedTimeouts = autocvar_sv_timeout_number; } //reset map immediately if this cvar is not set if (!autocvar_sv_ready_restart_after_countdown) reset_map(TRUE); if(autocvar_sv_eventlog) GameLogEcho(":restart"); } void ReadyRestart() { // no arena, assault support yet... if(g_arena | g_assault | gameover | intermission_running | race_completing) localcmd("restart\n"); else localcmd("\nsv_hook_gamerestart\n"); ReadyRestartForce(); // reset ALL scores, but only do that at the beginning //of the countdown if sv_ready_restart_after_countdown is off! //Otherwise scores could be manipulated during the countdown! if (!autocvar_sv_ready_restart_after_countdown) Score_ClearAll(); } /** * Counts how many players are ready. If not enough players are ready, the function * does nothing. If all players are ready, the timelimit will be extended and the * restart_countdown variable is set to allow other functions like PlayerPostThink * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown * is not set the map will be resetted. * * Function is called after the server receives a 'ready' sign from a player. */ void ReadyCount() { entity e; float r, p; r = p = 0; FOR_EACH_REALPLAYER(e) { p += 1; if(e.ready) r += 1; } readycount = r; Nagger_ReadyCounted(); if(r) // at least one is ready if(r == p) // and, everyone is ready ReadyRestart(); } /** * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown * is set) */ void restartTimer_Think() { restart_mapalreadyrestarted = 1; reset_map(TRUE); Score_ClearAll(); remove(self); return; } /** * Checks whether the player who calls the timeout is allowed to do so. * If so, it initializes the timeout countdown. It also checks whether another * timeout was already running at this time and reacts correspondingly. * * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime, * timeoutInitiator, timeoutStatus, timeoutHandler * * This function is called when a player issues the calltimeout command. */ void evaluateTimeout() { if (inWarmupStage && !g_warmup_allow_timeout) return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n"); if (time < game_starttime ) return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n"); if (timeoutStatus != 2) { //if the map uses a timelimit make sure that timeout cannot be called right before the map ends if (autocvar_timelimit) { //a timelimit was used float myTl; myTl = autocvar_timelimit; float lastPossibleTimeout; lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1; if (lastPossibleTimeout < time - game_starttime) return sprint(self, "^7Error: It is too late to call a timeout now!\n"); } } //player may not call a timeout if he has no calls left if (self.allowedTimeouts < 1) return sprint(self, "^7Error: You already used all your timeout calls for this map!\n"); //now all required checks are passed self.allowedTimeouts -= 1; 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) remainingTimeoutTime = autocvar_sv_timeout_length; remainingLeadTime = autocvar_sv_timeout_leadtime; timeoutInitiator = self; 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 timeoutStatus = 1; //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing timeoutHandler = spawn(); timeoutHandler.think = timeoutHandler_Think; } timeoutHandler.nextthink = time; //always let the entity think asap //inform all connected clients about the timeout call Announce("timeoutcalled"); } /** * Checks whether a player is allowed to resume the game. If he is allowed to do it, * and the lead time for the timeout is still active, this countdown just will be aborted (the * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding * value of the cvar sv_timeout_resumetime. * * This function is called when a player issues the resumegame command. */ void evaluateTimein() { if (!timeoutStatus) return sprint(self, "^7Error: There is no active timeout which could be aborted!\n"); if (self != timeoutInitiator) return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n"); if (timeoutStatus == 1) { remainingTimeoutTime = timeoutStatus = 0; timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n")); } else if (timeoutStatus == 2) { //only shorten the remainingTimeoutTime if it makes sense if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) ) { bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n")); remainingTimeoutTime = autocvar_sv_timeout_resumetime; timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately } else sprint(self, "^7Error: Your resumegame call was discarded!\n"); } }