3 float Nagger_SendEntity(entity to, float sendflags)
6 WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER);
26 WriteByte(MSG_ENTITY, nags | 128);
28 WriteString(MSG_ENTITY, votecalledvote_display);
30 WriteString(MSG_ENTITY, "");
33 WriteByte(MSG_ENTITY, nags);
39 Net_LinkEntity(nagger = spawn(), FALSE, 0, Nagger_SendEntity);
41 void Nagger_VoteChanged()
44 nagger.SendFlags |= 128;
46 void Nagger_VoteCountChanged()
49 nagger.SendFlags |= 1;
51 void Nagger_ReadyCounted()
54 nagger.SendFlags |= 1;
58 string MapVote_Suggest(string m);
60 entity GetPlayer(string name)
66 if(substring(name, 0, 1) == "#") {
67 num = stof(substring(name, 1, 999));
68 if(num >= 1 && num <= maxclients) {
69 for((e = world); num > 0; --num, (e = nextent(e)))
71 //if(clienttype(e) == CLIENTTYPE_REAL)
72 if(e.classname == "player")
76 ns = strdecolorize(name);
77 FOR_EACH_REALPLAYER(e) {
78 if(!strcasecmp(strdecolorize(e.netname), ns)) {
86 //float ctf_clientcommand();
87 float readyrestart_happened;
88 void SV_ParseClientCommand(string s) {
90 local float tokens, f, effectnum;
91 local vector start, end;
93 tokens = tokenize_sane(s);
95 if(GameCommand_Vote(s, self)) {
97 } else if(GameCommand_MapVote(argv(0))) {
99 } else if(argv(0) == "autoswitch") {
100 // be backwards compatible with older clients (enabled)
101 self.autoswitch = ("0" != argv(1));
102 local string autoswitchmsg;
103 if (self.autoswitch) {
104 autoswitchmsg = "on";
106 autoswitchmsg = "off";
108 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
109 } else if(argv(0) == "clientversion") {
110 if not(self.flags & FL_CLIENT)
112 if (argv(1) == "$gameversion") {
113 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
114 // either that or someone wants to be funny
117 self.version = stof(argv(1));
119 if(self.version != cvar("gameversion"))
121 self.classname = "observer";
122 self.version_mismatch = 1;
124 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
125 //JoinBestTeam(self, FALSE, TRUE);
126 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
127 self.classname = "observer";
128 stuffcmd(self,"menu_showteamselect\n");
130 } else if(argv(0) == "reportcvar") { // old system
131 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
133 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
134 tokens = tokenize_sane(s);
137 } else if(argv(0) == "sentcvar") { // new system
138 if(tokens == 2) // undefined cvar: use the default value on the server then
140 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
141 tokens = tokenize_sane(s);
144 } else if(argv(0) == "spectate") {
145 if not(self.flags & FL_CLIENT)
148 return; // don't allow spectating in lms, unless player runs out of lives
149 if(self.classname == "player" && cvar("sv_spectate") == 1) {
151 DropFlag(self.flagcarried, world, world);
152 kh_Key_DropAll(self, TRUE);
153 WaypointSprite_PlayerDead();
154 self.classname = "observer";
156 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"));
159 } else if(argv(0) == "join") {
160 if not(self.flags & FL_CLIENT)
163 if (self.classname != "player" && !lockteams)
165 if(isJoinAllowed()) {
166 self.classname = "player";
167 PlayerScore_Clear(self);
168 bprint ("^4", self.netname, "^4 is playing now\n");
172 //player may not join because of g_maxplayers is set
173 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
176 } else if( argv(0) == "selectteam" ) {
177 if not(self.flags & FL_CLIENT)
179 if( !cvar("teamplay") ) {
180 sprint( self, "selecteam can only be used in teamgames\n");
181 } else if(cvar("g_campaign")) {
182 //JoinBestTeam(self, 0);
183 } else if(lockteams) {
184 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
185 } else if( argv(1) == "red" ) {
186 DoTeamChange(COLOR_TEAM1);
187 } else if( argv(1) == "blue" ) {
188 DoTeamChange(COLOR_TEAM2);
189 } else if( argv(1) == "yellow" ) {
190 DoTeamChange(COLOR_TEAM3);
191 } else if( argv(1) == "pink" ) {
192 DoTeamChange(COLOR_TEAM4);
193 } else if( argv(1) == "auto" ) {
196 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
198 } else if(argv(0) == "ready") {
199 if not(self.flags & FL_CLIENT)
201 if((inWarmupStage && 0 <= g_warmup_limit) // with unlimited warmup players have to be able to restart
202 || cvar("sv_ready_restart"))
205 return sprint(self, "^1You cannot reset the game while a timeout is active!\n");
208 //if(!restartAnnouncer)
210 if(!readyrestart_happened || cvar("sv_ready_restart_repeatable"))
213 bprint(self.netname, "^2 is ready\n");
216 sprint(self, "^1game has already been restarted\n");
220 } else if(argv(0) == "maplist") {
221 sprint(self, maplist_reply);
222 } else if(argv(0) == "lsmaps") {
223 sprint(self, lsmaps_reply);
224 } else if(argv(0) == "records") {
225 sprint(self, records_reply);
226 } else if(argv(0) == "voice") {
228 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
230 VoiceMessage(argv(1), "");
231 } else if(argv(0) == "say") {
233 Say(self, FALSE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
234 //clientcommand(self, formatmessage(s));
235 } else if(argv(0) == "say_team") {
237 Say(self, TRUE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
238 //clientcommand(self, formatmessage(s));
239 } else if(argv(0) == "info") {
240 cmd = cvar_string(strcat("sv_info_", argv(1)));
242 sprint(self, "ERROR: unsupported info command\n");
244 wordwrap_sprint(cmd, 1111);
245 } else if(argv(0) == "suggestmap") {
246 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
247 } else if(argv(0) == "timeout") {
248 if not(self.flags & FL_CLIENT)
250 if(cvar("sv_timeout")) {
251 if(self.classname == "player") {
253 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
258 sprint(self, "^7Error: only players can call a timeout!\n");
260 } else if(argv(0) == "timein") {
261 if not(self.flags & FL_CLIENT)
263 if(cvar("sv_timeout")) {
266 } else if(argv(0) == "teamstatus") {
267 Score_NicePrint(self);
268 } else if(argv(0) == "cvar_changes") {
269 sprint(self, cvar_changes);
270 } else if(argv(0) == "pointparticles") {
271 if(sv_cheats && tokens == 5)
275 // origin (0..1, on crosshair line)
278 effectnum = particleeffectnum(argv(1));
280 start = (1-f) * self.origin + f * self.cursor_trace_endpos;
283 pointparticles(effectnum, start, end, f);
286 sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
287 } else if(argv(0) == "trailparticles") {
288 if(sv_cheats && tokens == 3)
292 // shot origin vector
293 effectnum = particleeffectnum(argv(1));
294 W_SetupShot(self, stov(argv(2)), FALSE, FALSE, "");
295 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
296 trailparticles(self, effectnum, w_shotorg, trace_endpos);
299 sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname shotorigin\n");
301 //if(ctf_clientcommand())
304 // grep for Cmd_AddCommand_WithClientCommand to find them all
312 if(cmd != "notarget")
316 //if(cmd != "say") // handled above
317 //if(cmd != "say_team") // handled above
326 if(cmd != "playermodel")
327 if(cmd != "playerskin")
328 if(cmd != "prespawn")
332 if(cmd != "sv_startdownload")
333 if(cmd != "download")
335 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
338 clientcommand(self,s);
342 void ReadyRestartForce()
346 bprint("^1Server is restarting...\n");
351 if(checkrules_overtimeend)
352 checkrules_overtimeend = 0;
354 readyrestart_happened = 1;
355 game_starttime = time + RESTART_COUNTDOWN;
356 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
358 inWarmupStage = 0; //once the game is restarted the game is in match stage
360 //reset the .ready status of all players (also spectators)
361 FOR_EACH_CLIENTSLOT(e)
364 Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
366 if(cvar("teamplay_lockonrestart") && teams_matter) {
368 bprint("^1The teams are now locked.\n");
371 //initiate the restart-countdown-announcer entity
372 restartAnnouncer = spawn();
373 restartAnnouncer.think = restartAnnouncer_Think;
374 restartAnnouncer.nextthink = time;
375 restartAnnouncer.spawnflags = !!cvar("sv_ready_restart_after_countdown");
377 //after a restart every players number of allowed timeouts gets reset, too
378 if(cvar("sv_timeout"))
380 FOR_EACH_REALPLAYER(e)
381 e.allowedTimeouts = cvar("sv_timeout_number");
384 //play the prepareforbattle sound to everyone
385 play2all("announcer/robotic/prepareforbattle.wav");
387 //reset map immediately if this cvar is not set
388 if (!cvar("sv_ready_restart_after_countdown"))
391 if(cvar("sv_eventlog"))
392 GameLogEcho(":restart");
397 // no arena, assault support yet...
398 if(g_arena | g_assault | gameover | intermission_running | race_completing)
399 localcmd("restart\n");
408 * Counts how many players are ready. If not enough players are ready, the function
409 * does nothing. If all players are ready, the timelimit will be extended and the
410 * restart_countdown variable is set to allow other functions like PlayerPostThink
411 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
412 * is not set the map will be resetted.
414 * Function is called after the server receives a 'ready' sign from a player.
423 FOR_EACH_REALPLAYER(e)
432 Nagger_ReadyCounted();
434 if(r) // at least one is ready
435 if(r == p) // and, everyone is ready
440 * Shows the restart countdown for all players.
441 * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
442 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
445 void restartAnnouncer_Think() {
449 c = game_starttime - time;
451 if(c <= 0) { //show the "Begin" message and
452 if(self.spawnflags & 1)
454 restart_mapalreadyrestarted = 1;
458 FOR_EACH_REALCLIENT(plr) {
459 if(plr.classname == "player") {
460 s = strcat(NEWLINES, "^1Begin!");
464 play2all("announcer/robotic/begin.wav");
470 FOR_EACH_REALCLIENT(plr) {
471 if(plr.classname == "player") {
472 s = strcat(NEWLINES, "^1Game starts in ", ftos(f), " seconds");
478 play2all(strcat("announcer/robotic/", ftos(f), ".wav"));
480 self.nextthink = game_starttime - (f - 1);
485 * Checks whether the player who calls the timeout is allowed to do so.
486 * If so, it initializes the timeout countdown. It also checks whether another
487 * timeout was already running at this time and reacts correspondingly.
489 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
490 * timeoutInitiator, timeoutStatus, timeoutHandler
492 * This function is called when a player issues the calltimeout command.
494 void evaluateTimeout() {
495 if (inWarmupStage && !g_warmup_allow_timeout)
496 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
497 if (time < game_starttime )
498 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
499 if (timeoutStatus != 2) {
500 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
501 if (cvar("timelimit")) {
502 //a timelimit was used
504 myTl = cvar("timelimit");
506 local float lastPossibleTimeout;
507 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
509 if (lastPossibleTimeout < time - game_starttime)
510 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
513 //player may not call a timeout if he has no calls left
514 if (self.allowedTimeouts < 1)
515 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
516 //now all required checks are passed
517 self.allowedTimeouts -= 1;
518 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)
519 remainingTimeoutTime = cvar("sv_timeout_length");
520 remainingLeadTime = cvar("sv_timeout_leadtime");
521 timeoutInitiator = self;
522 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
524 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
525 timeoutHandler = spawn();
526 timeoutHandler.think = timeoutHandler_Think;
528 timeoutHandler.nextthink = time; //always let the entity think asap
530 //inform all connected clients about the timeout call
531 play2all("announcer/robotic/timeoutcalled.wav");
535 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
536 * and the lead time for the timeout is still active, this countdown just will be aborted (the
537 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
538 * value of the cvar sv_timeout_resumetime.
540 * This function is called when a player issues the resumegame command.
542 void evaluateTimein() {
544 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
545 if (self != timeoutInitiator)
546 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
547 if (timeoutStatus == 1) {
548 remainingTimeoutTime = timeoutStatus = 0;
549 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
550 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
552 else if (timeoutStatus == 2) {
553 //only shorten the remainingTimeoutTime if it makes sense
554 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
555 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
556 remainingTimeoutTime = cvar("sv_timeout_resumetime");
557 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
560 sprint(self, "^7Error: Your resumegame call was discarded!\n");