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 void SV_ParseClientCommand(string s) {
104 local float tokens, f, effectnum;
105 local vector start, end;
107 tokens = tokenize_sane(s);
109 if(GameCommand_Vote(s, self)) {
111 } else if(GameCommand_MapVote(argv(0))) {
113 } else if(argv(0) == "autoswitch") {
114 // be backwards compatible with older clients (enabled)
115 self.autoswitch = ("0" != argv(1));
116 local string autoswitchmsg;
117 if (self.autoswitch) {
118 autoswitchmsg = "on";
120 autoswitchmsg = "off";
122 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
123 } else if(argv(0) == "clientversion") {
124 if not(self.flags & FL_CLIENT)
126 if (argv(1) == "$gameversion") {
127 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
128 // either that or someone wants to be funny
131 self.version = stof(argv(1));
133 if(self.version != cvar("gameversion"))
135 self.classname = "observer";
136 self.version_mismatch = 1;
138 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
139 //JoinBestTeam(self, FALSE, TRUE);
140 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
141 self.classname = "observer";
142 stuffcmd(self,"menu_showteamselect\n");
144 } else if(argv(0) == "reportcvar") { // old system
145 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
147 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
148 tokens = tokenize_sane(s);
151 } else if(argv(0) == "sentcvar") { // new system
152 if(tokens == 2) // undefined cvar: use the default value on the server then
154 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
155 tokens = tokenize_sane(s);
158 } else if(argv(0) == "spectate") {
159 if not(self.flags & FL_CLIENT)
162 return; // don't allow spectating in lms, unless player runs out of lives
163 if(self.classname == "player" && cvar("sv_spectate") == 1) {
165 DropFlag(self.flagcarried, world, world);
166 kh_Key_DropAll(self, TRUE);
167 WaypointSprite_PlayerDead();
168 self.classname = "observer";
170 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"));
173 } else if(argv(0) == "join") {
174 if not(self.flags & FL_CLIENT)
177 if (self.classname != "player" && !lockteams)
179 if(isJoinAllowed()) {
180 self.classname = "player";
181 PlayerScore_Clear(self);
182 bprint ("^4", self.netname, "^4 is playing now\n");
186 //player may not join because of g_maxplayers is set
187 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
190 } else if( argv(0) == "selectteam" ) {
191 if not(self.flags & FL_CLIENT)
193 if( !cvar("teamplay") ) {
194 sprint( self, "selecteam can only be used in teamgames\n");
195 } else if(cvar("g_campaign")) {
196 //JoinBestTeam(self, 0);
197 } else if(lockteams) {
198 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
199 } else if( argv(1) == "red" ) {
200 DoTeamChange(COLOR_TEAM1);
201 } else if( argv(1) == "blue" ) {
202 DoTeamChange(COLOR_TEAM2);
203 } else if( argv(1) == "yellow" ) {
204 DoTeamChange(COLOR_TEAM3);
205 } else if( argv(1) == "pink" ) {
206 DoTeamChange(COLOR_TEAM4);
207 } else if( argv(1) == "auto" ) {
210 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
212 } else if(argv(0) == "ready") {
213 if not(self.flags & FL_CLIENT)
215 if((inWarmupStage && 0 <= g_warmup_limit) // with unlimited warmup players have to be able to restart
216 || cvar("sv_ready_restart"))
219 return sprint(self, "^1You cannot reset the game while a timeout is active!\n");
222 //if(!restartAnnouncer)
224 if(!readyrestart_happened || cvar("sv_ready_restart_repeatable"))
227 bprint(self.netname, "^2 is ready\n");
230 sprint(self, "^1game has already been restarted\n");
234 } else if(argv(0) == "maplist") {
235 sprint(self, maplist_reply);
236 } else if(argv(0) == "lsmaps") {
237 sprint(self, lsmaps_reply);
238 } else if(argv(0) == "records") {
239 sprint(self, records_reply);
240 } else if(argv(0) == "voice") {
242 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
244 VoiceMessage(argv(1), "");
245 } else if(argv(0) == "say") {
247 Say(self, FALSE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
248 //clientcommand(self, formatmessage(s));
249 } else if(argv(0) == "say_team") {
251 Say(self, TRUE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
252 //clientcommand(self, formatmessage(s));
253 } else if(argv(0) == "info") {
254 cmd = cvar_string(strcat("sv_info_", argv(1)));
256 sprint(self, "ERROR: unsupported info command\n");
258 wordwrap_sprint(cmd, 1111);
259 } else if(argv(0) == "suggestmap") {
260 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
261 } else if(argv(0) == "timeout") {
262 if not(self.flags & FL_CLIENT)
264 if(cvar("sv_timeout")) {
265 if(self.classname == "player") {
267 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
272 sprint(self, "^7Error: only players can call a timeout!\n");
274 } else if(argv(0) == "timein") {
275 if not(self.flags & FL_CLIENT)
277 if(cvar("sv_timeout")) {
280 } else if(argv(0) == "teamstatus") {
281 Score_NicePrint(self);
282 } else if(argv(0) == "cvar_changes") {
283 sprint(self, cvar_changes);
284 } else if(argv(0) == "pointparticles") {
285 if(sv_cheats && tokens == 5)
289 // origin (0..1, on crosshair line)
292 effectnum = particleeffectnum(argv(1));
294 start = (1-f) * self.origin + f * self.cursor_trace_endpos;
297 pointparticles(effectnum, start, end, f);
300 sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
301 } else if(argv(0) == "trailparticles") {
302 if(sv_cheats && tokens == 3)
306 // shot origin vector
307 effectnum = particleeffectnum(argv(1));
308 W_SetupShot(self, stov(argv(2)), FALSE, FALSE, "");
309 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
310 trailparticles(self, effectnum, w_shotorg, trace_endpos);
313 sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname shotorigin\n");
315 //if(ctf_clientcommand())
318 // grep for Cmd_AddCommand_WithClientCommand to find them all
326 if(cmd != "notarget")
330 //if(cmd != "say") // handled above
331 //if(cmd != "say_team") // handled above
340 if(cmd != "playermodel")
341 if(cmd != "playerskin")
342 if(cmd != "prespawn")
346 if(cmd != "sv_startdownload")
347 if(cmd != "download")
349 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
352 clientcommand(self,s);
356 void ReadyRestartForce()
360 bprint("^1Server is restarting...\n");
365 if(checkrules_overtimeend)
366 checkrules_overtimeend = 0;
368 readyrestart_happened = 1;
369 game_starttime = time + RESTART_COUNTDOWN;
370 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
372 inWarmupStage = 0; //once the game is restarted the game is in match stage
374 //reset the .ready status of all players (also spectators)
375 FOR_EACH_CLIENTSLOT(e)
378 Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
380 if(cvar("teamplay_lockonrestart") && teams_matter) {
382 bprint("^1The teams are now locked.\n");
385 //initiate the restart-countdown-announcer entity
386 restartAnnouncer = spawn();
387 restartAnnouncer.think = restartAnnouncer_Think;
388 restartAnnouncer.nextthink = time;
389 restartAnnouncer.spawnflags = !!cvar("sv_ready_restart_after_countdown");
391 //after a restart every players number of allowed timeouts gets reset, too
392 if(cvar("sv_timeout"))
394 FOR_EACH_REALPLAYER(e)
395 e.allowedTimeouts = cvar("sv_timeout_number");
398 //play the prepareforbattle sound to everyone
399 play2all("announcer/robotic/prepareforbattle.wav");
401 //reset map immediately if this cvar is not set
402 if (!cvar("sv_ready_restart_after_countdown"))
405 if(cvar("sv_eventlog"))
406 GameLogEcho(":restart");
411 // no arena, assault support yet...
412 if(g_arena | g_assault | gameover | intermission_running | race_completing)
413 localcmd("restart\n");
415 // reset ALL scores, but only do that at the beginning
416 //of the countdown if sv_ready_restart_after_countdown is off!
417 //Otherwise scores could be manipulated during the countdown!
418 if (!cvar("sv_ready_restart_after_countdown"))
425 * Counts how many players are ready. If not enough players are ready, the function
426 * does nothing. If all players are ready, the timelimit will be extended and the
427 * restart_countdown variable is set to allow other functions like PlayerPostThink
428 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
429 * is not set the map will be resetted.
431 * Function is called after the server receives a 'ready' sign from a player.
440 FOR_EACH_REALPLAYER(e)
449 Nagger_ReadyCounted();
451 if(r) // at least one is ready
452 if(r == p) // and, everyone is ready
457 * Shows the restart countdown for all players.
458 * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
459 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
462 void restartAnnouncer_Think() {
466 c = game_starttime - time;
468 if(c <= 0) { //show the "Begin" message
469 if(self.spawnflags & 1) // if sv_ready_restart_after_countdown is set
472 //don't clear scores for assault mode, which uses ReadyRestartForce (and thus
473 //restartAnnouncer_Think) to start a new round
476 restart_mapalreadyrestarted = 1;
480 FOR_EACH_REALCLIENT(plr) {
481 if(plr.classname == "player") {
482 s = strcat(NEWLINES, "^1Begin!");
486 play2all("announcer/robotic/begin.wav");
492 FOR_EACH_REALCLIENT(plr) {
493 if(plr.classname == "player") {
494 s = strcat(NEWLINES, "^1Game starts in ", ftos(f), " seconds");
500 play2all(strcat("announcer/robotic/", ftos(f), ".wav"));
502 self.nextthink = game_starttime - (f - 1);
507 * Checks whether the player who calls the timeout is allowed to do so.
508 * If so, it initializes the timeout countdown. It also checks whether another
509 * timeout was already running at this time and reacts correspondingly.
511 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
512 * timeoutInitiator, timeoutStatus, timeoutHandler
514 * This function is called when a player issues the calltimeout command.
516 void evaluateTimeout() {
517 if (inWarmupStage && !g_warmup_allow_timeout)
518 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
519 if (time < game_starttime )
520 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
521 if (timeoutStatus != 2) {
522 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
523 if (cvar("timelimit")) {
524 //a timelimit was used
526 myTl = cvar("timelimit");
528 local float lastPossibleTimeout;
529 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
531 if (lastPossibleTimeout < time - game_starttime)
532 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
535 //player may not call a timeout if he has no calls left
536 if (self.allowedTimeouts < 1)
537 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
538 //now all required checks are passed
539 self.allowedTimeouts -= 1;
540 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)
541 remainingTimeoutTime = cvar("sv_timeout_length");
542 remainingLeadTime = cvar("sv_timeout_leadtime");
543 timeoutInitiator = self;
544 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
546 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
547 timeoutHandler = spawn();
548 timeoutHandler.think = timeoutHandler_Think;
550 timeoutHandler.nextthink = time; //always let the entity think asap
552 //inform all connected clients about the timeout call
553 play2all("announcer/robotic/timeoutcalled.wav");
557 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
558 * and the lead time for the timeout is still active, this countdown just will be aborted (the
559 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
560 * value of the cvar sv_timeout_resumetime.
562 * This function is called when a player issues the resumegame command.
564 void evaluateTimein() {
566 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
567 if (self != timeoutInitiator)
568 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
569 if (timeoutStatus == 1) {
570 remainingTimeoutTime = timeoutStatus = 0;
571 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
572 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
574 else if (timeoutStatus == 2) {
575 //only shorten the remainingTimeoutTime if it makes sense
576 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
577 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
578 remainingTimeoutTime = cvar("sv_timeout_resumetime");
579 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
582 sprint(self, "^7Error: Your resumegame call was discarded!\n");