3 float Nagger_SendEntity(entity to, float sendflags)
6 WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER);
24 WriteByte(MSG_ENTITY, nags | 128);
26 WriteString(MSG_ENTITY, votecalledvote_display);
28 WriteString(MSG_ENTITY, "");
31 WriteByte(MSG_ENTITY, nags);
38 Net_LinkEntity(nagger);
39 nagger.SendEntity = 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 print("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 print("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();
365 FOR_EACH_REALCLIENT(e)
368 WriteByte(MSG_ONE, SVC_TEMPENTITY);
369 WriteByte(MSG_ONE, TE_CSQC_WARMUP);
370 WriteByte(MSG_ONE, 0);
373 if(cvar("teamplay_lockonrestart") && teams_matter) {
375 bprint("^1The teams are now locked.\n");
378 //initiate the restart-countdown-announcer entity
379 restartAnnouncer = spawn();
380 restartAnnouncer.think = restartAnnouncer_Think;
381 restartAnnouncer.nextthink = time;
382 restartAnnouncer.spawnflags = !!cvar("sv_ready_restart_after_countdown");
384 //after a restart every players number of allowed timeouts gets reset, too
385 if(cvar("sv_timeout"))
387 FOR_EACH_REALPLAYER(e)
388 e.allowedTimeouts = cvar("sv_timeout_number");
391 //play the prepareforbattle sound to everyone
392 play2all("announcer/robotic/prepareforbattle.wav");
394 //reset map immediately if this cvar is not set
395 if (!cvar("sv_ready_restart_after_countdown"))
398 if(cvar("sv_eventlog"))
399 GameLogEcho(":restart");
404 // no arena, assault support yet...
405 if(g_arena | g_assault | gameover | intermission_running | race_completing)
406 localcmd("restart\n");
415 * Counts how many players are ready. If not enough players are ready, the function
416 * does nothing. If all players are ready, the timelimit will be extended and the
417 * restart_countdown variable is set to allow other functions like PlayerPostThink
418 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
419 * is not set the map will be resetted.
421 * Function is called after the server receives a 'ready' sign from a player.
430 FOR_EACH_REALPLAYER(e)
439 Nagger_ReadyCounted();
441 if(r) // at least one is ready
442 if(r == p) // and, everyone is ready
447 * Shows the restart countdown for all players.
448 * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
449 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
452 void restartAnnouncer_Think() {
456 c = game_starttime - time;
458 if(c <= 0) { //show the "Begin" message and
459 if(self.spawnflags & 1)
461 restart_mapalreadyrestarted = 1;
465 FOR_EACH_REALCLIENT(plr) {
466 if(plr.classname == "player") {
467 s = strcat(NEWLINES, "^1Begin!");
471 play2all("announcer/robotic/begin.wav");
477 FOR_EACH_REALCLIENT(plr) {
478 if(plr.classname == "player") {
479 s = strcat(NEWLINES, "^1Game starts in ", ftos(f), " seconds");
485 play2all(strcat("announcer/robotic/", ftos(f), ".wav"));
487 self.nextthink = game_starttime - (f - 1);
492 * Checks whether the player who calls the timeout is allowed to do so.
493 * If so, it initializes the timeout countdown. It also checks whether another
494 * timeout was already running at this time and reacts correspondingly.
496 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
497 * timeoutInitiator, timeoutStatus, timeoutHandler
499 * This function is called when a player issues the calltimeout command.
501 void evaluateTimeout() {
502 if (inWarmupStage && !g_warmup_allow_timeout)
503 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
504 if (time < game_starttime )
505 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
506 if (timeoutStatus != 2) {
507 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
508 if (cvar("timelimit")) {
509 //a timelimit was used
511 myTl = cvar("timelimit");
513 local float lastPossibleTimeout;
514 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
516 if (lastPossibleTimeout < time - game_starttime)
517 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
520 //player may not call a timeout if he has no calls left
521 if (self.allowedTimeouts < 1)
522 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
523 //now all required checks are passed
524 self.allowedTimeouts -= 1;
525 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)
526 remainingTimeoutTime = cvar("sv_timeout_length");
527 remainingLeadTime = cvar("sv_timeout_leadtime");
528 timeoutInitiator = self;
529 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
531 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
532 timeoutHandler = spawn();
533 timeoutHandler.think = timeoutHandler_Think;
535 timeoutHandler.nextthink = time; //always let the entity think asap
537 //inform all connected clients about the timeout call
538 play2all("announcer/robotic/timeoutcalled.wav");
542 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
543 * and the lead time for the timeout is still active, this countdown just will be aborted (the
544 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
545 * value of the cvar sv_timeout_resumetime.
547 * This function is called when a player issues the resumegame command.
549 void evaluateTimein() {
551 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
552 if (self != timeoutInitiator)
553 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
554 if (timeoutStatus == 1) {
555 remainingTimeoutTime = timeoutStatus = 0;
556 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
557 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
559 else if (timeoutStatus == 2) {
560 //only shorten the remainingTimeoutTime if it makes sense
561 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
562 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
563 remainingTimeoutTime = cvar("sv_timeout_resumetime");
564 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
567 sprint(self, "^7Error: Your resumegame call was discarded!\n");