3 float Nagger_SendEntity(entity to, float sendflags)
7 WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER);
28 WriteByte(MSG_ENTITY, nags);
33 WriteString(MSG_ENTITY, votecalledvote_display);
35 WriteString(MSG_ENTITY, "");
40 for(i = 1; i <= maxclients; i += 8)
42 for(f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e))
43 if(clienttype(e) != CLIENTTYPE_REAL || e.ready)
45 WriteByte(MSG_ENTITY, f);
53 Net_LinkEntity(nagger = spawn(), FALSE, 0, Nagger_SendEntity);
55 void Nagger_VoteChanged()
58 nagger.SendFlags |= 128;
60 void Nagger_VoteCountChanged()
63 nagger.SendFlags |= 1;
65 void Nagger_ReadyCounted()
68 nagger.SendFlags |= 1;
72 string MapVote_Suggest(string m);
74 entity GetPlayer(string name)
80 if(substring(name, 0, 1) == "#") {
81 num = stof(substring(name, 1, 999));
82 if(num >= 1 && num <= maxclients) {
83 for((e = world); num > 0; --num, (e = nextent(e)))
85 //if(clienttype(e) == CLIENTTYPE_REAL)
86 if(e.classname == "player")
90 ns = strdecolorize(name);
91 FOR_EACH_REALPLAYER(e) {
92 if(!strcasecmp(strdecolorize(e.netname), ns)) {
100 //float ctf_clientcommand();
101 float readyrestart_happened;
102 .float lms_spectate_warning;
103 void SV_ParseClientCommand(string s) {
105 local float tokens, f, effectnum;
106 local vector start, end;
108 tokens = tokenize_sane(s);
110 if(GameCommand_Vote(s, self)) {
112 } else if(GameCommand_MapVote(argv(0))) {
114 } else if(argv(0) == "autoswitch") {
115 // be backwards compatible with older clients (enabled)
116 self.autoswitch = ("0" != argv(1));
117 local string autoswitchmsg;
118 if (self.autoswitch) {
119 autoswitchmsg = "on";
121 autoswitchmsg = "off";
123 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
124 } else if(argv(0) == "clientversion") {
125 if not(self.flags & FL_CLIENT)
127 if (argv(1) == "$gameversion") {
128 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
129 // either that or someone wants to be funny
132 self.version = stof(argv(1));
134 if(self.version != cvar("gameversion"))
136 self.classname = "observer";
137 self.version_mismatch = 1;
139 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
140 //JoinBestTeam(self, FALSE, TRUE);
141 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
142 self.classname = "observer";
143 stuffcmd(self,"menu_showteamselect\n");
145 } else if(argv(0) == "reportcvar") { // old system
146 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
148 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
149 tokens = tokenize_sane(s);
152 } else if(argv(0) == "sentcvar") { // new system
153 if(tokens == 2) // undefined cvar: use the default value on the server then
155 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
156 tokens = tokenize_sane(s);
159 } else if(argv(0) == "spectate") {
160 if not(self.flags & FL_CLIENT)
166 if(self.lms_spectate_warning)
168 // mark player as spectator
169 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
173 self.lms_spectate_warning = 1;
174 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");
178 if(self.classname == "player" && cvar("sv_spectate") == 1) {
180 DropFlag(self.flagcarried, world, world);
181 kh_Key_DropAll(self, TRUE);
182 WaypointSprite_PlayerDead();
183 self.classname = "observer";
185 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"));
188 } else if(argv(0) == "join") {
189 if not(self.flags & FL_CLIENT)
192 if (self.classname != "player" && !lockteams)
194 if(isJoinAllowed()) {
195 self.classname = "player";
196 PlayerScore_Clear(self);
197 bprint ("^4", self.netname, "^4 is playing now\n");
201 //player may not join because of g_maxplayers is set
202 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
205 } else if( argv(0) == "selectteam" ) {
206 if not(self.flags & FL_CLIENT)
208 if( !cvar("teamplay") ) {
209 sprint( self, "selecteam can only be used in teamgames\n");
210 } else if(cvar("g_campaign")) {
211 //JoinBestTeam(self, 0);
212 } else if(lockteams) {
213 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
214 } else if( argv(1) == "red" ) {
215 DoTeamChange(COLOR_TEAM1);
216 } else if( argv(1) == "blue" ) {
217 DoTeamChange(COLOR_TEAM2);
218 } else if( argv(1) == "yellow" ) {
219 DoTeamChange(COLOR_TEAM3);
220 } else if( argv(1) == "pink" ) {
221 DoTeamChange(COLOR_TEAM4);
222 } else if( argv(1) == "auto" ) {
225 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
227 } else if(argv(0) == "ready") {
228 if not(self.flags & FL_CLIENT)
230 if((inWarmupStage && 0 <= g_warmup_limit) // with unlimited warmup players have to be able to restart
231 || cvar("sv_ready_restart"))
234 return sprint(self, "^1You cannot reset the game while a timeout is active!\n");
238 if(!readyrestart_happened || cvar("sv_ready_restart_repeatable"))
241 bprint(self.netname, "^2 is ready\n");
244 sprint(self, "^1game has already been restarted\n");
248 } else if(argv(0) == "maplist") {
249 sprint(self, maplist_reply);
250 } else if(argv(0) == "lsmaps") {
251 sprint(self, lsmaps_reply);
252 } else if(argv(0) == "records") {
253 sprint(self, records_reply);
254 } else if(argv(0) == "voice") {
256 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
258 VoiceMessage(argv(1), "");
259 } else if(argv(0) == "say") {
261 Say(self, FALSE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
262 //clientcommand(self, formatmessage(s));
263 } else if(argv(0) == "say_team") {
265 Say(self, TRUE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
266 //clientcommand(self, formatmessage(s));
267 } else if(argv(0) == "info") {
268 cmd = cvar_string(strcat("sv_info_", argv(1)));
270 sprint(self, "ERROR: unsupported info command\n");
272 wordwrap_sprint(cmd, 1111);
273 } else if(argv(0) == "suggestmap") {
274 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
275 } else if(argv(0) == "timeout") {
276 if not(self.flags & FL_CLIENT)
278 if(cvar("sv_timeout")) {
279 if(self.classname == "player") {
281 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
286 sprint(self, "^7Error: only players can call a timeout!\n");
288 } else if(argv(0) == "timein") {
289 if not(self.flags & FL_CLIENT)
291 if(cvar("sv_timeout")) {
294 } else if(argv(0) == "teamstatus") {
295 Score_NicePrint(self);
296 } else if(argv(0) == "cvar_changes") {
297 sprint(self, cvar_changes);
298 } else if(argv(0) == "pointparticles") {
299 if(sv_cheats && tokens == 5)
303 // origin (0..1, on crosshair line)
306 effectnum = particleeffectnum(argv(1));
308 start = (1-f) * self.origin + f * self.cursor_trace_endpos;
311 pointparticles(effectnum, start, end, f);
314 sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
315 } else if(argv(0) == "trailparticles") {
316 if(sv_cheats && tokens == 3)
320 // shot origin vector
321 effectnum = particleeffectnum(argv(1));
322 W_SetupShot(self, stov(argv(2)), FALSE, FALSE, "");
323 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
324 trailparticles(self, effectnum, w_shotorg, trace_endpos);
327 sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname shotorigin\n");
329 //if(ctf_clientcommand())
332 // grep for Cmd_AddCommand_WithClientCommand to find them all
340 if(cmd != "notarget")
344 //if(cmd != "say") // handled above
345 //if(cmd != "say_team") // handled above
354 if(cmd != "playermodel")
355 if(cmd != "playerskin")
356 if(cmd != "prespawn")
360 if(cmd != "sv_startdownload")
361 if(cmd != "download")
363 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
366 clientcommand(self,s);
370 void ReadyRestartForce()
374 bprint("^1Server is restarting...\n");
379 if(checkrules_overtimeend)
380 checkrules_overtimeend = 0;
382 readyrestart_happened = 1;
383 game_starttime = time + RESTART_COUNTDOWN;
384 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
386 inWarmupStage = 0; //once the game is restarted the game is in match stage
388 //reset the .ready status of all players (also spectators)
389 FOR_EACH_CLIENTSLOT(e)
392 Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
394 if(cvar("teamplay_lockonrestart") && teams_matter) {
396 bprint("^1The teams are now locked.\n");
399 //initiate the restart-countdown-announcer entity
400 if(cvar("sv_ready_restart_after_countdown"))
402 restartTimer = spawn();
403 restartTimer.think = restartTimer_Think;
404 restartTimer.nextthink = game_starttime;
407 //after a restart every players number of allowed timeouts gets reset, too
408 if(cvar("sv_timeout"))
410 FOR_EACH_REALPLAYER(e)
411 e.allowedTimeouts = cvar("sv_timeout_number");
414 //reset map immediately if this cvar is not set
415 if (!cvar("sv_ready_restart_after_countdown"))
418 if(cvar("sv_eventlog"))
419 GameLogEcho(":restart");
424 // no arena, assault support yet...
425 if(g_arena | g_assault | gameover | intermission_running | race_completing)
426 localcmd("restart\n");
428 // reset ALL scores, but only do that at the beginning
429 //of the countdown if sv_ready_restart_after_countdown is off!
430 //Otherwise scores could be manipulated during the countdown!
431 if (!cvar("sv_ready_restart_after_countdown"))
438 * Counts how many players are ready. If not enough players are ready, the function
439 * does nothing. If all players are ready, the timelimit will be extended and the
440 * restart_countdown variable is set to allow other functions like PlayerPostThink
441 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
442 * is not set the map will be resetted.
444 * Function is called after the server receives a 'ready' sign from a player.
453 FOR_EACH_REALPLAYER(e)
462 Nagger_ReadyCounted();
464 if(r) // at least one is ready
465 if(r == p) // and, everyone is ready
470 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
473 void restartTimer_Think() {
474 restart_mapalreadyrestarted = 1;
481 * Checks whether the player who calls the timeout is allowed to do so.
482 * If so, it initializes the timeout countdown. It also checks whether another
483 * timeout was already running at this time and reacts correspondingly.
485 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
486 * timeoutInitiator, timeoutStatus, timeoutHandler
488 * This function is called when a player issues the calltimeout command.
490 void evaluateTimeout() {
491 if (inWarmupStage && !g_warmup_allow_timeout)
492 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
493 if (time < game_starttime )
494 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
495 if (timeoutStatus != 2) {
496 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
497 if (cvar("timelimit")) {
498 //a timelimit was used
500 myTl = cvar("timelimit");
502 local float lastPossibleTimeout;
503 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
505 if (lastPossibleTimeout < time - game_starttime)
506 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
509 //player may not call a timeout if he has no calls left
510 if (self.allowedTimeouts < 1)
511 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
512 //now all required checks are passed
513 self.allowedTimeouts -= 1;
514 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)
515 remainingTimeoutTime = cvar("sv_timeout_length");
516 remainingLeadTime = cvar("sv_timeout_leadtime");
517 timeoutInitiator = self;
518 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
520 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
521 timeoutHandler = spawn();
522 timeoutHandler.think = timeoutHandler_Think;
524 timeoutHandler.nextthink = time; //always let the entity think asap
526 //inform all connected clients about the timeout call
527 play2all("announcer/robotic/timeoutcalled.wav");
531 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
532 * and the lead time for the timeout is still active, this countdown just will be aborted (the
533 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
534 * value of the cvar sv_timeout_resumetime.
536 * This function is called when a player issues the resumegame command.
538 void evaluateTimein() {
540 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
541 if (self != timeoutInitiator)
542 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
543 if (timeoutStatus == 1) {
544 remainingTimeoutTime = timeoutStatus = 0;
545 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
546 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
548 else if (timeoutStatus == 2) {
549 //only shorten the remainingTimeoutTime if it makes sense
550 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
551 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
552 remainingTimeoutTime = cvar("sv_timeout_resumetime");
553 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
556 sprint(self, "^7Error: Your resumegame call was discarded!\n");