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;
123 void SV_ParseClientCommand(string s) {
129 tokens = tokenize_console(s);
132 if(cmd != "reportcvar")
133 if(cmd != "sentcvar")
135 if(cmd != "prespawn")
143 if(GameCommand_Vote(s, self)) {
145 } else if(GameCommand_MapVote(argv(0))) {
147 } else if(cmd == "autoswitch") {
148 // be backwards compatible with older clients (enabled)
149 self.autoswitch = ("0" != argv(1));
150 local string autoswitchmsg;
151 if (self.autoswitch) {
152 autoswitchmsg = "on";
154 autoswitchmsg = "off";
156 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
157 } else if(cmd == "clientversion") {
158 if not(self.flags & FL_CLIENT)
160 if (argv(1) == "$gameversion") {
161 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.xonotic.com)^8";
162 // either that or someone wants to be funny
165 self.version = stof(argv(1));
167 if(self.version != cvar("gameversion"))
169 self.classname = "observer";
170 self.version_mismatch = 1;
172 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
173 //JoinBestTeam(self, FALSE, TRUE);
174 } else if(teams_matter && !cvar("sv_spectate")) {
175 self.classname = "observer";
176 stuffcmd(self,"menu_showteamselect\n");
178 } else if(cmd == "reportcvar") { // old system
179 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
181 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
182 tokens = tokenize_console(s);
185 } else if(cmd == "sentcvar") { // new system
186 if(tokens == 2) // undefined cvar: use the default value on the server then
188 s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
189 tokens = tokenize_console(s);
192 } else if(cmd == "spectate") {
195 if not(self.flags & FL_CLIENT)
201 if(self.lms_spectate_warning)
203 // mark player as spectator
204 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
208 self.lms_spectate_warning = 1;
209 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");
213 if(self.classname == "player" && cvar("sv_spectate") == 1) {
215 DropFlag(self.flagcarried, world, world);
217 DropBall(self.ballcarried, self.origin, self.velocity);
218 WaypointSprite_PlayerDead();
219 self.classname = "observer";
223 sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
226 } else if(cmd == "join") {
227 if not(self.flags & FL_CLIENT)
230 if (self.classname != "player" && !lockteams)
232 if(isJoinAllowed()) {
233 self.classname = "player";
236 PlayerScore_Clear(self);
237 bprint ("^4", self.netname, "^4 is playing now\n");
238 self.stat_count = WEP_LAST;
240 if(cvar("g_campaign"))
241 campaign_bots_may_start = 1;
244 //player may not join because of g_maxplayers is set
245 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
248 } else if( cmd == "selectteam" ) {
249 if not(self.flags & FL_CLIENT)
251 if( !teams_matter ) {
252 sprint( self, "selecteam can only be used in teamgames\n");
253 } else if(cvar("g_campaign")) {
254 //JoinBestTeam(self, 0);
255 } else if(lockteams) {
256 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
257 } else if( argv(1) == "red" ) {
258 DoTeamChange(COLOR_TEAM1);
259 } else if( argv(1) == "blue" ) {
260 DoTeamChange(COLOR_TEAM2);
261 } else if( argv(1) == "yellow" ) {
262 DoTeamChange(COLOR_TEAM3);
263 } else if( argv(1) == "pink" ) {
264 DoTeamChange(COLOR_TEAM4);
265 } else if( argv(1) == "auto" ) {
268 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
270 } else if(cmd == "ready") {
271 if not(self.flags & FL_CLIENT)
274 if((inWarmupStage && 0 >= g_warmup_limit) // with unlimited warmup players have to be able to restart
275 || cvar("sv_ready_restart") || g_race_qualifying == 2)
277 if(!readyrestart_happened || cvar("sv_ready_restart_repeatable"))
279 if (self.ready) // toggle
282 bprint(self.netname, "^2 is ^1NOT^2 ready\n");
287 bprint(self.netname, "^2 is ready\n");
290 // cannot reset the game while a timeout is active!
294 sprint(self, "^1Game has already been restarted\n");
297 } else if(cmd == "maplist") {
298 sprint(self, maplist_reply);
299 } else if(cmd == "lsmaps") {
300 sprint(self, lsmaps_reply);
301 } else if(cmd == "lsnewmaps") {
302 sprint(self, lsnewmaps_reply);
303 } else if(cmd == "records") {
304 for(i = 0; i < 10; ++i)
305 sprint(self, records_reply[i]);
306 } else if(cmd == "ladder") {
307 sprint(self, ladder_reply);
308 } else if(cmd == "rankings") {
309 sprint(self, rankings_reply);
310 } else if(cmd == "voice") {
312 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
314 VoiceMessage(argv(1), "");
315 } else if(cmd == "say") {
317 Say(self, FALSE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
318 //clientcommand(self, formatmessage(s));
319 } else if(cmd == "say_team") {
321 Say(self, TRUE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
322 //clientcommand(self, formatmessage(s));
323 } else if(cmd == "tell") {
324 e = GetCommandPlayerSlotTargetFromTokenizedCommand(tokens, 1);
325 if(e && tokens > ParseCommandPlayerSlotTarget_firsttoken)
327 Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
331 if(tokens > ParseCommandPlayerSlotTarget_firsttoken)
332 trigger_magicear_processmessage_forallears(self, -1, world, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
333 sprint(self, "ERROR: usage: tell # playerid text...\n");
335 //clientcommand(self, formatmessage(s));
336 } else if(cmd == "info") {
337 cmd = cvar_string_builtin(strcat("sv_info_", argv(1))); // This needed fixed for the cvar check
339 sprint(self, "ERROR: unsupported info command\n");
341 wordwrap_sprint(cmd, 1111);
342 } else if(cmd == "suggestmap") {
343 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
344 } else if(cmd == "timeout") {
345 if not(self.flags & FL_CLIENT)
347 if(cvar("sv_timeout")) {
348 if(self.classname == "player") {
350 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
355 sprint(self, "^7Error: only players can call a timeout!\n");
357 } else if(cmd == "timein") {
358 if not(self.flags & FL_CLIENT)
360 if(cvar("sv_timeout")) {
363 } else if(cmd == "teamstatus") {
364 Score_NicePrint(self);
365 } else if(cmd == "cvar_changes") {
366 sprint(self, cvar_changes);
367 } else if(cmd == "cvar_purechanges") {
368 sprint(self, cvar_purechanges);
369 } else if(CheatCommand(tokens)) {
371 //if(ctf_clientcommand())
373 // grep for Cmd_AddCommand_WithClientCommand to find them all
375 //if(cmd != "say") // handled above
376 //if(cmd != "say_team") // handled above
384 if(cmd != "playermodel")
385 if(cmd != "playerskin")
386 if(cmd != "prespawn")
390 if(cmd != "sv_startdownload")
391 if(cmd != "download")
393 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
397 if(self.jointime > 0 && time > self.jointime + 10 && time > self.nickspamtime) // allow any changes in the first 10 seconds since joining
398 if(cmd == "name" || cmd == "playermodel") // TODO also playerskin and color?
400 if(self.nickspamtime == 0 || time > self.nickspamtime + cvar("g_nick_flood_timeout"))
401 // good, no serious flood
402 self.nickspamcount = 1;
404 self.nickspamcount += 1;
405 self.nickspamtime = time + cvar("g_nick_flood_penalty");
407 if (timeoutStatus == 2) //when game is paused, no flood protection
408 self.nickspamcount = self.nickspamtime = 0;
411 clientcommand(self,s);
415 void ReadyRestartForce()
419 bprint("^1Server is restarting...\n");
424 if (checkrules_overtimesadded > 0 && g_race_qualifying != 2) {
425 //we have to decrease timelimit to its original value again!!
427 newTL = cvar("timelimit");
428 newTL -= checkrules_overtimesadded * cvar("timelimit_overtime");
429 cvar_set("timelimit", ftos(newTL));
432 checkrules_suddendeathend = checkrules_overtimesadded = checkrules_suddendeathwarning = 0;
435 readyrestart_happened = 1;
436 game_starttime = time;
437 if(!g_ca && !g_arena)
438 game_starttime += RESTART_COUNTDOWN;
439 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
441 inWarmupStage = 0; //once the game is restarted the game is in match stage
443 //reset the .ready status of all players (also spectators)
444 FOR_EACH_CLIENTSLOT(e)
447 Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
449 if(cvar("teamplay_lockonrestart") && teams_matter) {
451 bprint("^1The teams are now locked.\n");
454 //initiate the restart-countdown-announcer entity
455 if(cvar("sv_ready_restart_after_countdown") && !g_ca && !g_arena)
457 restartTimer = spawn();
458 restartTimer.think = restartTimer_Think;
459 restartTimer.nextthink = game_starttime;
462 //after a restart every players number of allowed timeouts gets reset, too
463 if(cvar("sv_timeout"))
465 FOR_EACH_REALPLAYER(e)
466 e.allowedTimeouts = cvar("sv_timeout_number");
469 //reset map immediately if this cvar is not set
470 if (!cvar("sv_ready_restart_after_countdown"))
473 if(cvar("sv_eventlog"))
474 GameLogEcho(":restart");
479 // no arena, assault support yet...
480 if(g_arena | g_assault | gameover | intermission_running | race_completing)
481 localcmd("restart\n");
483 localcmd("\nsv_hook_gamerestart\n");
487 // reset ALL scores, but only do that at the beginning
488 //of the countdown if sv_ready_restart_after_countdown is off!
489 //Otherwise scores could be manipulated during the countdown!
490 if (!cvar("sv_ready_restart_after_countdown"))
495 * Counts how many players are ready. If not enough players are ready, the function
496 * does nothing. If all players are ready, the timelimit will be extended and the
497 * restart_countdown variable is set to allow other functions like PlayerPostThink
498 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
499 * is not set the map will be resetted.
501 * Function is called after the server receives a 'ready' sign from a player.
510 FOR_EACH_REALPLAYER(e)
519 Nagger_ReadyCounted();
521 if(r) // at least one is ready
522 if(r == p) // and, everyone is ready
527 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
530 void restartTimer_Think() {
531 restart_mapalreadyrestarted = 1;
539 * Checks whether the player who calls the timeout is allowed to do so.
540 * If so, it initializes the timeout countdown. It also checks whether another
541 * timeout was already running at this time and reacts correspondingly.
543 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
544 * timeoutInitiator, timeoutStatus, timeoutHandler
546 * This function is called when a player issues the calltimeout command.
548 void evaluateTimeout() {
549 if (inWarmupStage && !g_warmup_allow_timeout)
550 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
551 if (time < game_starttime )
552 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
553 if (timeoutStatus != 2) {
554 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
555 if (cvar("timelimit")) {
556 //a timelimit was used
558 myTl = cvar("timelimit");
560 local float lastPossibleTimeout;
561 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
563 if (lastPossibleTimeout < time - game_starttime)
564 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
567 //player may not call a timeout if he has no calls left
568 if (self.allowedTimeouts < 1)
569 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
570 //now all required checks are passed
571 self.allowedTimeouts -= 1;
572 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)
573 remainingTimeoutTime = cvar("sv_timeout_length");
574 remainingLeadTime = cvar("sv_timeout_leadtime");
575 timeoutInitiator = self;
576 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
578 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
579 timeoutHandler = spawn();
580 timeoutHandler.think = timeoutHandler_Think;
582 timeoutHandler.nextthink = time; //always let the entity think asap
584 //inform all connected clients about the timeout call
585 Announce("timeoutcalled");
589 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
590 * and the lead time for the timeout is still active, this countdown just will be aborted (the
591 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
592 * value of the cvar sv_timeout_resumetime.
594 * This function is called when a player issues the resumegame command.
596 void evaluateTimein() {
598 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
599 if (self != timeoutInitiator)
600 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
601 if (timeoutStatus == 1) {
602 remainingTimeoutTime = timeoutStatus = 0;
603 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
604 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
606 else if (timeoutStatus == 2) {
607 //only shorten the remainingTimeoutTime if it makes sense
608 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
609 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
610 remainingTimeoutTime = cvar("sv_timeout_resumetime");
611 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
614 sprint(self, "^7Error: Your resumegame call was discarded!\n");