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.SendFlags = 128;
40 nagger.SendEntity = Nagger_SendEntity;
42 void Nagger_VoteChanged()
45 nagger.SendFlags = 128;
47 void Nagger_VoteCountChanged()
52 void Nagger_ReadyCounted()
59 string MapVote_Suggest(string m);
61 entity GetPlayer(string name)
67 if(substring(name, 0, 1) == "#") {
68 num = stof(substring(name, 1, 999));
69 if(num >= 1 && num <= maxclients) {
70 for((e = world); num > 0; --num, (e = nextent(e)))
72 //if(clienttype(e) == CLIENTTYPE_REAL)
73 if(e.classname == "player")
77 ns = strdecolorize(name);
78 FOR_EACH_REALPLAYER(e) {
79 if(!strcasecmp(strdecolorize(e.netname), ns)) {
87 //float ctf_clientcommand();
88 float readyrestart_happened;
89 void SV_ParseClientCommand(string s) {
91 local float tokens, f, effectnum;
92 local vector start, end;
94 tokens = tokenize_sane(s);
96 if(GameCommand_Vote(s, self)) {
98 } else if(GameCommand_MapVote(argv(0))) {
100 } else if(argv(0) == "autoswitch") {
101 // be backwards compatible with older clients (enabled)
102 self.autoswitch = ("0" != argv(1));
103 local string autoswitchmsg;
104 if (self.autoswitch) {
105 autoswitchmsg = "on";
107 autoswitchmsg = "off";
109 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
110 } else if(argv(0) == "clientversion") {
111 if not(self.flags & FL_CLIENT)
113 if (argv(1) == "$gameversion") {
114 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
115 // either that or someone wants to be funny
118 self.version = stof(argv(1));
120 if(self.version != cvar("gameversion"))
122 self.classname = "observer";
123 self.version_mismatch = 1;
125 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
126 //JoinBestTeam(self, FALSE, TRUE);
127 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
128 self.classname = "observer";
129 stuffcmd(self,"menu_showteamselect\n");
131 } else if(argv(0) == "reportcvar") { // old system
132 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
134 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
135 tokens = tokenize_sane(s);
138 } else if(argv(0) == "sentcvar") { // new system
139 if(tokens == 2) // undefined cvar: use the default value on the server then
141 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
142 tokens = tokenize_sane(s);
145 } else if(argv(0) == "spectate") {
146 if not(self.flags & FL_CLIENT)
149 return; // don't allow spectating in lms, unless player runs out of lives
150 if(self.classname == "player" && cvar("sv_spectate") == 1) {
152 DropFlag(self.flagcarried, world, world);
153 kh_Key_DropAll(self, TRUE);
154 WaypointSprite_PlayerDead();
155 self.classname = "observer";
157 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"));
160 } else if(argv(0) == "join") {
161 if not(self.flags & FL_CLIENT)
164 if (self.classname != "player" && !lockteams)
166 if(isJoinAllowed()) {
167 self.classname = "player";
168 PlayerScore_Clear(self);
169 bprint ("^4", self.netname, "^4 is playing now\n");
173 //player may not join because of g_maxplayers is set
174 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
177 } else if( argv(0) == "selectteam" ) {
178 if not(self.flags & FL_CLIENT)
180 if( !cvar("teamplay") ) {
181 sprint( self, "selecteam can only be used in teamgames\n");
182 } else if(cvar("g_campaign")) {
183 //JoinBestTeam(self, 0);
184 } else if(lockteams) {
185 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
186 } else if( argv(1) == "red" ) {
187 DoTeamChange(COLOR_TEAM1);
188 } else if( argv(1) == "blue" ) {
189 DoTeamChange(COLOR_TEAM2);
190 } else if( argv(1) == "yellow" ) {
191 DoTeamChange(COLOR_TEAM3);
192 } else if( argv(1) == "pink" ) {
193 DoTeamChange(COLOR_TEAM4);
194 } else if( argv(1) == "auto" ) {
197 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
199 } else if(argv(0) == "ready") {
200 if not(self.flags & FL_CLIENT)
202 if((inWarmupStage && 0 <= g_warmup_limit) // with unlimited warmup players have to be able to restart
203 || cvar("sv_ready_restart"))
206 return sprint(self, "^1You cannot reset the game while a timeout is active!\n");
209 //if(!restartAnnouncer)
211 if(!readyrestart_happened || cvar("sv_ready_restart_repeatable"))
214 bprint(self.netname, "^2 is ready\n");
217 sprint(self, "^1game has already been restarted\n");
221 } else if(argv(0) == "maplist") {
222 sprint(self, maplist_reply);
223 } else if(argv(0) == "lsmaps") {
224 sprint(self, lsmaps_reply);
225 } else if(argv(0) == "records") {
226 sprint(self, records_reply);
227 } else if(argv(0) == "voice") {
229 VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
231 VoiceMessage(argv(1), "");
232 } else if(argv(0) == "say") {
234 Say(self, FALSE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
235 //clientcommand(self, formatmessage(s));
236 } else if(argv(0) == "say_team") {
238 Say(self, TRUE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
239 //clientcommand(self, formatmessage(s));
240 } else if(argv(0) == "info") {
241 cmd = cvar_string(strcat("sv_info_", argv(1)));
243 sprint(self, "ERROR: unsupported info command\n");
245 wordwrap_sprint(cmd, 1111);
246 } else if(argv(0) == "suggestmap") {
247 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
248 } else if(argv(0) == "timeout") {
249 if not(self.flags & FL_CLIENT)
251 if(cvar("sv_timeout")) {
252 if(self.classname == "player") {
254 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
259 sprint(self, "^7Error: only players can call a timeout!\n");
261 } else if(argv(0) == "timein") {
262 if not(self.flags & FL_CLIENT)
264 if(cvar("sv_timeout")) {
267 } else if(argv(0) == "teamstatus") {
268 Score_NicePrint(self);
269 } else if(argv(0) == "cvar_changes") {
270 sprint(self, cvar_changes);
271 } else if(argv(0) == "pointparticles") {
272 if(sv_cheats && tokens == 5)
276 // origin (0..1, on crosshair line)
279 effectnum = particleeffectnum(argv(1));
281 start = (1-f) * self.origin + f * self.cursor_trace_endpos;
284 pointparticles(effectnum, start, end, f);
287 print("Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
288 } else if(argv(0) == "trailparticles") {
289 if(sv_cheats && tokens == 3)
293 // shot origin vector
294 effectnum = particleeffectnum(argv(1));
295 W_SetupShot(self, stov(argv(2)), FALSE, FALSE, "");
296 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
297 trailparticles(self, effectnum, w_shotorg, trace_endpos);
300 print("Usage: sv_cheats 1; restart; cmd trailparticles effectname shotorigin\n");
302 //if(ctf_clientcommand())
305 // grep for Cmd_AddCommand_WithClientCommand to find them all
313 if(cmd != "notarget")
317 //if(cmd != "say") // handled above
318 //if(cmd != "say_team") // handled above
327 if(cmd != "playermodel")
328 if(cmd != "playerskin")
329 if(cmd != "prespawn")
333 if(cmd != "sv_startdownload")
334 if(cmd != "download")
336 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
339 clientcommand(self,s);
343 void ReadyRestartForce()
347 bprint("^1Server is restarting...\n");
352 if(checkrules_overtimeend)
353 checkrules_overtimeend = 0;
355 readyrestart_happened = 1;
356 game_starttime = time + RESTART_COUNTDOWN;
357 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
359 inWarmupStage = 0; //once the game is restarted the game is in match stage
361 //reset the .ready status of all players (also spectators)
362 FOR_EACH_CLIENTSLOT(e)
365 Nagger_ReadyCounted();
366 FOR_EACH_REALCLIENT(e)
369 WriteByte(MSG_ONE, SVC_TEMPENTITY);
370 WriteByte(MSG_ONE, TE_CSQC_WARMUP);
371 WriteByte(MSG_ONE, 0);
374 if(cvar("teamplay_lockonrestart") && teams_matter) {
376 bprint("^1The teams are now locked.\n");
379 //initiate the restart-countdown-announcer entity
380 restartAnnouncer = spawn();
381 restartAnnouncer.think = restartAnnouncer_Think;
382 restartAnnouncer.nextthink = time;
383 restartAnnouncer.spawnflags = !!cvar("sv_ready_restart_after_countdown");
385 //after a restart every players number of allowed timeouts gets reset, too
386 if(cvar("sv_timeout"))
388 FOR_EACH_REALPLAYER(e)
389 e.allowedTimeouts = cvar("sv_timeout_number");
392 //play the prepareforbattle sound to everyone
393 play2all("announcer/robotic/prepareforbattle.wav");
395 //reset map immediately if this cvar is not set
396 if (!cvar("sv_ready_restart_after_countdown"))
399 if(cvar("sv_eventlog"))
400 GameLogEcho(":restart");
405 // no arena, assault support yet...
406 if(g_arena | g_assault | gameover | intermission_running | race_completing)
407 localcmd("restart\n");
416 * Counts how many players are ready. If not enough players are ready, the function
417 * does nothing. If all players are ready, the timelimit will be extended and the
418 * restart_countdown variable is set to allow other functions like PlayerPostThink
419 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
420 * is not set the map will be resetted.
422 * Function is called after the server receives a 'ready' sign from a player.
431 FOR_EACH_REALPLAYER(e)
440 Nagger_ReadyCounted();
442 if(r) // at least one is ready
443 if(r == p) // and, everyone is ready
448 * Shows the restart countdown for all players.
449 * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
450 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
453 void restartAnnouncer_Think() {
457 c = game_starttime - time;
459 if(c <= 0) { //show the "Begin" message and
460 if(self.spawnflags & 1)
462 restart_mapalreadyrestarted = 1;
466 FOR_EACH_REALCLIENT(plr) {
467 if(plr.classname == "player") {
468 s = strcat(NEWLINES, "^1Begin!");
472 play2all("announcer/robotic/begin.wav");
478 FOR_EACH_REALCLIENT(plr) {
479 if(plr.classname == "player") {
480 s = strcat(NEWLINES, "^1Game starts in ", ftos(f), " seconds");
486 play2all(strcat("announcer/robotic/", ftos(f), ".wav"));
488 self.nextthink = game_starttime - (f - 1);
493 * Checks whether the player who calls the timeout is allowed to do so.
494 * If so, it initializes the timeout countdown. It also checks whether another
495 * timeout was already running at this time and reacts correspondingly.
497 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
498 * timeoutInitiator, timeoutStatus, timeoutHandler
500 * This function is called when a player issues the calltimeout command.
502 void evaluateTimeout() {
503 if (inWarmupStage && !g_warmup_allow_timeout)
504 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
505 if (time < game_starttime )
506 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
507 if (timeoutStatus != 2) {
508 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
509 if (cvar("timelimit")) {
510 //a timelimit was used
512 myTl = cvar("timelimit");
514 local float lastPossibleTimeout;
515 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
517 if (lastPossibleTimeout < time - game_starttime)
518 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
521 //player may not call a timeout if he has no calls left
522 if (self.allowedTimeouts < 1)
523 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
524 //now all required checks are passed
525 self.allowedTimeouts -= 1;
526 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)
527 remainingTimeoutTime = cvar("sv_timeout_length");
528 remainingLeadTime = cvar("sv_timeout_leadtime");
529 timeoutInitiator = self;
530 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
532 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
533 timeoutHandler = spawn();
534 timeoutHandler.think = timeoutHandler_Think;
536 timeoutHandler.nextthink = time; //always let the entity think asap
538 //inform all connected clients about the timeout call
539 play2all("announcer/robotic/timeoutcalled.wav");
543 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
544 * and the lead time for the timeout is still active, this countdown just will be aborted (the
545 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
546 * value of the cvar sv_timeout_resumetime.
548 * This function is called when a player issues the resumegame command.
550 void evaluateTimein() {
552 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
553 if (self != timeoutInitiator)
554 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
555 if (timeoutStatus == 1) {
556 remainingTimeoutTime = timeoutStatus = 0;
557 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
558 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
560 else if (timeoutStatus == 2) {
561 //only shorten the remainingTimeoutTime if it makes sense
562 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
563 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
564 remainingTimeoutTime = cvar("sv_timeout_resumetime");
565 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
568 sprint(self, "^7Error: Your resumegame call was discarded!\n");