3 float Nagger_SendEntity(entity to, float sendflags)
7 WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER);
28 WriteByte(MSG_ENTITY, nags);
32 WriteString(MSG_ENTITY, votecalledvote_display);
37 for(i = 1; i <= maxclients; i += 8)
39 for(f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e))
40 if(clienttype(e) != CLIENTTYPE_REAL || e.ready)
42 WriteByte(MSG_ENTITY, f);
50 Net_LinkEntity(nagger = spawn(), FALSE, 0, Nagger_SendEntity);
52 void Nagger_VoteChanged()
55 nagger.SendFlags |= 128;
57 void Nagger_VoteCountChanged()
60 nagger.SendFlags |= 1;
62 void Nagger_ReadyCounted()
65 nagger.SendFlags |= 1;
69 string MapVote_Suggest(string m);
71 entity GetPlayer(string name)
77 if(substring(name, 0, 1) == "#") {
78 num = stof(substring(name, 1, 999));
79 if(num >= 1 && num <= maxclients) {
80 for((e = world); num > 0; --num, (e = nextent(e)))
82 //if(clienttype(e) == CLIENTTYPE_REAL)
83 if(e.classname == "player")
87 ns = strdecolorize(name);
88 FOR_EACH_REALPLAYER(e) {
89 if(!strcasecmp(strdecolorize(e.netname), ns)) {
97 //float ctf_clientcommand();
98 float readyrestart_happened;
99 .float lms_spectate_warning;
100 void spawnfunc_func_breakable();
102 .float cmd_floodtime;
103 .float cmd_floodcount;
104 float cmd_floodcheck()
106 if (timeoutStatus != 2)
108 if(time == self.cmd_floodtime)
110 self.cmd_floodcount += 1;
111 if(self.cmd_floodcount > 8)
116 self.cmd_floodtime = time;
117 self.cmd_floodcount = 1;
124 void SV_ParseClientCommand(string s) {
130 tokens = tokenize_console(s);
133 if(cmd != "reportcvar")
134 if(cmd != "sentcvar")
136 if(cmd != "prespawn")
144 if(GameCommand_Vote(s, self)) {
146 } else if(GameCommand_MapVote(argv(0))) {
148 } else if(cmd == "checkfail") {
149 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))));
151 } else if(cmd == "autoswitch") {
152 // be backwards compatible with older clients (enabled)
153 self.autoswitch = ("0" != argv(1));
154 local string autoswitchmsg;
155 if (self.autoswitch) {
156 autoswitchmsg = "on";
158 autoswitchmsg = "off";
160 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
161 } else if(cmd == "clientversion") {
162 if not(self.flags & FL_CLIENT)
164 if (argv(1) == "$gameversion") {
165 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.xonotic.com)^8";
166 // either that or someone wants to be funny
169 self.version = stof(argv(1));
171 if(self.version < autocvar_gameversion_min || self.version > autocvar_gameversion_max)
173 self.version_mismatch = 1;
174 ClientKill_TeamChange(-2); // observe
175 } else if(autocvar_g_campaign || autocvar_g_balance_teams || autocvar_g_balance_teams_force) {
176 //JoinBestTeam(self, FALSE, TRUE);
177 } else if(teams_matter && !autocvar_sv_spectate && !(self.team_forced > 0)) {
178 self.classname = "observer";
179 stuffcmd(self,"menu_showteamselect\n");
181 } else if(cmd == "reportcvar") { // old system
182 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
184 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
185 tokens = tokenize_console(s);
188 } else if(cmd == "sentcvar") { // new system
189 if(tokens == 2) // undefined cvar: use the default value on the server then
191 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
192 tokens = tokenize_console(s);
195 } else if(cmd == "spectate") {
198 if not(self.flags & FL_CLIENT)
204 if(self.lms_spectate_warning)
206 // mark player as spectator
207 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
211 self.lms_spectate_warning = 1;
212 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");
216 if(self.classname == "player" && autocvar_sv_spectate == 1) {
217 ClientKill_TeamChange(-2); // observe
219 } else if(cmd == "join") {
220 if not(self.flags & FL_CLIENT)
223 if (self.classname != "player" && !lockteams)
225 if(nJoinAllowed(1)) {
226 self.classname = "player";
229 PlayerScore_Clear(self);
230 bprint ("^4", self.netname, "^4 is playing now\n");
232 if(autocvar_g_campaign)
233 campaign_bots_may_start = 1;
236 //player may not join because of g_maxplayers is set
237 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
240 } else if( cmd == "selectteam" ) {
241 if not(self.flags & FL_CLIENT)
243 if( !teams_matter ) {
244 sprint( self, "selectteam can only be used in teamgames\n");
245 } else if(autocvar_g_campaign) {
246 //JoinBestTeam(self, 0);
247 } else if(self.team_forced > 0) {
248 sprint( self, "selectteam can not be used as your team is forced\n");
249 } else if(lockteams) {
250 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
251 } else if( argv(1) == "red" ) {
252 ClientKill_TeamChange(COLOR_TEAM1);
253 } else if( argv(1) == "blue" ) {
254 ClientKill_TeamChange(COLOR_TEAM2);
255 } else if( argv(1) == "yellow" ) {
256 ClientKill_TeamChange(COLOR_TEAM3);
257 } else if( argv(1) == "pink" ) {
258 ClientKill_TeamChange(COLOR_TEAM4);
259 } else if( argv(1) == "auto" ) {
260 ClientKill_TeamChange(-1);
262 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
264 } else if(cmd == "ready") {
265 if not(self.flags & FL_CLIENT)
269 || autocvar_sv_ready_restart || g_race_qualifying == 2)
271 if(!readyrestart_happened || autocvar_sv_ready_restart_repeatable)
273 if (self.ready) // toggle
276 bprint(self.netname, "^2 is ^1NOT^2 ready\n");
281 bprint(self.netname, "^2 is ready\n");
284 // cannot reset the game while a timeout is active!
288 sprint(self, "^1Game has already been restarted\n");
291 } else if(cmd == "maplist") {
292 sprint(self, maplist_reply);
293 } else if(cmd == "lsmaps") {
294 sprint(self, lsmaps_reply);
295 } else if(cmd == "lsnewmaps") {
296 sprint(self, lsnewmaps_reply);
297 } else if(cmd == "records") {
298 for(i = 0; i < 10; ++i)
299 sprint(self, records_reply[i]);
300 } else if(cmd == "ladder") {
301 sprint(self, ladder_reply);
302 } else if(cmd == "rankings") {
303 sprint(self, rankings_reply);
304 } else if(cmd == "voice") {
306 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
308 VoiceMessage(argv(1), "");
309 } else if(cmd == "say") {
311 Say(self, FALSE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
312 //clientcommand(self, formatmessage(s));
313 } else if(cmd == "say_team") {
315 Say(self, TRUE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
316 //clientcommand(self, formatmessage(s));
317 } else if(cmd == "tell") {
318 e = GetCommandPlayerSlotTargetFromTokenizedCommand(tokens, 1);
319 if(e && tokens > ParseCommandPlayerSlotTarget_firsttoken)
321 Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
325 if(tokens > ParseCommandPlayerSlotTarget_firsttoken)
326 trigger_magicear_processmessage_forallears(self, -1, world, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
327 sprint(self, "ERROR: usage: tell # playerid text...\n");
329 //clientcommand(self, formatmessage(s));
330 } else if(cmd == "info") {
331 cmd = cvar_string_builtin(strcat("sv_info_", argv(1))); // This needed fixed for the cvar check
333 sprint(self, "ERROR: unsupported info command\n");
335 wordwrap_sprint(cmd, 1111);
336 } else if(cmd == "suggestmap") {
337 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
338 } else if(cmd == "timeout") {
339 if not(self.flags & FL_CLIENT)
341 if(autocvar_sv_timeout) {
342 if(self.classname == "player") {
344 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
349 sprint(self, "^7Error: only players can call a timeout!\n");
351 } else if(cmd == "timein") {
352 if not(self.flags & FL_CLIENT)
354 if(autocvar_sv_timeout) {
357 } else if(cmd == "teamstatus") {
358 Score_NicePrint(self);
359 } else if(cmd == "cvar_changes") {
360 sprint(self, cvar_changes);
361 } else if(cmd == "cvar_purechanges") {
362 sprint(self, cvar_purechanges);
363 } else if(CheatCommand(tokens)) {
365 //if(ctf_clientcommand())
367 // grep for Cmd_AddCommand_WithClientCommand to find them all
369 //if(cmd != "say") // handled above
370 //if(cmd != "say_team") // handled above
378 if(cmd != "playermodel")
379 if(cmd != "playerskin")
380 if(cmd != "prespawn")
384 if(cmd != "sv_startdownload")
385 if(cmd != "download")
387 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
391 if(self.jointime > 0 && time > self.jointime + 10 && time > self.nickspamtime) // allow any changes in the first 10 seconds since joining
392 if(cmd == "name" || cmd == "playermodel") // TODO also playerskin and color?
394 if(self.nickspamtime == 0 || time > self.nickspamtime + autocvar_g_nick_flood_timeout)
395 // good, no serious flood
396 self.nickspamcount = 1;
398 self.nickspamcount += 1;
399 self.nickspamtime = time + autocvar_g_nick_flood_penalty;
401 if (timeoutStatus == 2) //when game is paused, no flood protection
402 self.nickspamcount = self.nickspamtime = 0;
405 clientcommand(self,s);
409 void ReadyRestartForce()
413 bprint("^1Server is restarting...\n");
418 if (checkrules_overtimesadded > 0 && g_race_qualifying != 2) {
419 //we have to decrease timelimit to its original value again!!
421 newTL = autocvar_timelimit;
422 newTL -= checkrules_overtimesadded * autocvar_timelimit_overtime;
423 cvar_set("timelimit", ftos(newTL));
426 checkrules_suddendeathend = checkrules_overtimesadded = checkrules_suddendeathwarning = 0;
429 readyrestart_happened = 1;
430 game_starttime = time;
431 if(!g_ca && !g_arena)
432 game_starttime += RESTART_COUNTDOWN;
433 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
435 inWarmupStage = 0; //once the game is restarted the game is in match stage
437 //reset the .ready status of all players (also spectators)
438 FOR_EACH_CLIENTSLOT(e)
441 Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
443 if(autocvar_teamplay_lockonrestart && teams_matter) {
445 bprint("^1The teams are now locked.\n");
448 //initiate the restart-countdown-announcer entity
449 if(autocvar_sv_ready_restart_after_countdown && !g_ca && !g_arena)
451 restartTimer = spawn();
452 restartTimer.think = restartTimer_Think;
453 restartTimer.nextthink = game_starttime;
456 //after a restart every players number of allowed timeouts gets reset, too
457 if(autocvar_sv_timeout)
459 FOR_EACH_REALPLAYER(e)
460 e.allowedTimeouts = autocvar_sv_timeout_number;
463 //reset map immediately if this cvar is not set
464 if (!autocvar_sv_ready_restart_after_countdown)
467 if(autocvar_sv_eventlog)
468 GameLogEcho(":restart");
473 // no arena, assault support yet...
474 if(g_arena | g_assault | gameover | intermission_running | race_completing)
475 localcmd("restart\n");
477 localcmd("\nsv_hook_gamerestart\n");
481 // reset ALL scores, but only do that at the beginning
482 //of the countdown if sv_ready_restart_after_countdown is off!
483 //Otherwise scores could be manipulated during the countdown!
484 if (!autocvar_sv_ready_restart_after_countdown)
489 * Counts how many players are ready. If not enough players are ready, the function
490 * does nothing. If all players are ready, the timelimit will be extended and the
491 * restart_countdown variable is set to allow other functions like PlayerPostThink
492 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
493 * is not set the map will be resetted.
495 * Function is called after the server receives a 'ready' sign from a player.
504 FOR_EACH_REALPLAYER(e)
513 Nagger_ReadyCounted();
515 if(r) // at least one is ready
516 if(r == p) // and, everyone is ready
521 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
524 void restartTimer_Think() {
525 restart_mapalreadyrestarted = 1;
533 * Checks whether the player who calls the timeout is allowed to do so.
534 * If so, it initializes the timeout countdown. It also checks whether another
535 * timeout was already running at this time and reacts correspondingly.
537 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
538 * timeoutInitiator, timeoutStatus, timeoutHandler
540 * This function is called when a player issues the calltimeout command.
542 void evaluateTimeout() {
543 if (inWarmupStage && !g_warmup_allow_timeout)
544 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
545 if (time < game_starttime )
546 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
547 if (timeoutStatus != 2) {
548 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
549 if (autocvar_timelimit) {
550 //a timelimit was used
552 myTl = autocvar_timelimit;
554 local float lastPossibleTimeout;
555 lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1;
557 if (lastPossibleTimeout < time - game_starttime)
558 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
561 //player may not call a timeout if he has no calls left
562 if (self.allowedTimeouts < 1)
563 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
564 //now all required checks are passed
565 self.allowedTimeouts -= 1;
566 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)
567 remainingTimeoutTime = autocvar_sv_timeout_length;
568 remainingLeadTime = autocvar_sv_timeout_leadtime;
569 timeoutInitiator = self;
570 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
572 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
573 timeoutHandler = spawn();
574 timeoutHandler.think = timeoutHandler_Think;
576 timeoutHandler.nextthink = time; //always let the entity think asap
578 //inform all connected clients about the timeout call
579 Announce("timeoutcalled");
583 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
584 * and the lead time for the timeout is still active, this countdown just will be aborted (the
585 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
586 * value of the cvar sv_timeout_resumetime.
588 * This function is called when a player issues the resumegame command.
590 void evaluateTimein() {
592 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
593 if (self != timeoutInitiator)
594 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
595 if (timeoutStatus == 1) {
596 remainingTimeoutTime = timeoutStatus = 0;
597 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
598 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
600 else if (timeoutStatus == 2) {
601 //only shorten the remainingTimeoutTime if it makes sense
602 if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) ) {
603 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
604 remainingTimeoutTime = autocvar_sv_timeout_resumetime;
605 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
608 sprint(self, "^7Error: Your resumegame call was discarded!\n");