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 .float floodcontrol_chat;
62 .float floodcontrol_team;
63 void Say(entity source, float teamsay, string msgin)
65 string msgstr, colorstr, cmsgstr, namestr;
69 if(Ban_MaybeEnforceBan(source))
73 if(substring(msgin, 0, 1) == " ")
74 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
76 msgin = formatmessage(msgin);
81 if(source.classname != "player")
82 colorstr = "^0"; // black for spectators
84 colorstr = Team_ColorCode(source.team);
88 if(intermission_running)
92 * using bprint solves this... me stupid
93 // how can we prevent the message from appearing in a listen server?
94 // for now, just give "say" back and only handle say_team
97 clientcommand(self, strcat("say ", msgin));
102 if(cvar("g_chat_teamcolors"))
103 namestr = playername(source);
105 namestr = source.netname;
108 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin, "\n"));
109 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", wordwrap(msgin, 50));
112 msgstr = strzone(strcat("\{1}", namestr, "^7: ", msgin, "\n"));
120 var .float flood_field;
124 flood_spl = cvar("g_chat_flood_spl_team");
125 flood_burst = cvar("g_chat_flood_burst_team");
126 flood_lmax = cvar("g_chat_flood_lmax_team");
127 flood_field = floodcontrol_team;
131 flood_spl = cvar("g_chat_flood_spl");
132 flood_burst = cvar("g_chat_flood_burst");
133 flood_lmax = cvar("g_chat_flood_lmax");
134 flood_field = floodcontrol_chat;
136 flood_burst = max(0, flood_burst - 1);
137 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
138 lines = ceil(strlennocol(msgstr) / 75);
139 if(flood_lmax && lines > flood_lmax)
141 else if(time >= self.flood_field)
142 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
149 if(cvar("g_chat_flood_notify_flooder"))
152 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
154 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
157 sprint(self, msgstr);
158 print("NOTE: ", playername(self), "^7 is flooding.\n");
162 if(source.classname == "player")
164 FOR_EACH_REALPLAYER(head)
166 if(head.team == source.team)
168 sprint(head, msgstr);
169 centerprint(head, cmsgstr);
175 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
177 sprint(head, msgstr);
178 centerprint(head, cmsgstr);
184 // TODO invent a cvar name for allowing global chat by spectators during warmup anyway
185 if(cvar("g_chat_nospectators") && source.classname != "player") {
186 FOR_EACH_REALCLIENT(head) if(head.classname != "player") {
187 sprint(head, msgstr);
197 entity GetPlayer(string name)
203 if(substring(name, 0, 1) == "#") {
204 num = stof(substring(name, 1, 999));
205 if(num >= 1 && num <= maxclients) {
206 for((e = world); num > 0; --num, (e = nextent(e)))
208 //if(clienttype(e) == CLIENTTYPE_REAL)
209 if(e.classname == "player")
213 ns = strdecolorize(name);
214 FOR_EACH_REALPLAYER(e) {
215 if(!strcasecmp(strdecolorize(e.netname), ns)) {
223 //float ctf_clientcommand();
224 float readyrestart_happened;
225 void SV_ParseClientCommand(string s) {
227 local float tokens, f, effectnum;
228 local vector start, end;
230 tokens = tokenize_sane(s);
232 if(GameCommand_Vote(s, self)) {
234 } else if(GameCommand_MapVote(argv(0))) {
236 } else if(argv(0) == "autoswitch") {
237 // be backwards compatible with older clients (enabled)
238 self.autoswitch = ("0" != argv(1));
239 local string autoswitchmsg;
240 if (self.autoswitch) {
241 autoswitchmsg = "on";
243 autoswitchmsg = "off";
245 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
246 } else if(argv(0) == "clientversion") {
247 if not(self.flags & FL_CLIENT)
249 if (argv(1) == "$gameversion") {
250 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
251 // either that or someone wants to be funny
254 self.version = stof(argv(1));
256 if(self.version != cvar("gameversion"))
258 self.classname = "observer";
259 self.version_mismatch = 1;
261 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
262 //JoinBestTeam(self, FALSE, TRUE);
263 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
264 self.classname = "observer";
265 stuffcmd(self,"menu_showteamselect\n");
267 } else if(argv(0) == "reportcvar") { // old system
268 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
270 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
271 tokens = tokenize_sane(s);
274 } else if(argv(0) == "sentcvar") { // new system
275 if(tokens == 2) // undefined cvar: use the default value on the server then
277 s = strcat(substring(s, argv_start_index(0), argv_end_index(1)), " \"", cvar_defstring(argv(1)), "\"");
278 tokens = tokenize_sane(s);
281 } else if(argv(0) == "spectate") {
282 if not(self.flags & FL_CLIENT)
285 return; // don't allow spectating in lms, unless player runs out of lives
286 if(self.classname == "player" && cvar("sv_spectate") == 1) {
288 DropFlag(self.flagcarried, world, world);
289 kh_Key_DropAll(self, TRUE);
290 WaypointSprite_PlayerDead();
291 self.classname = "observer";
293 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"));
296 } else if(argv(0) == "join") {
297 if not(self.flags & FL_CLIENT)
300 if (self.classname != "player" && !lockteams)
302 if(isJoinAllowed()) {
303 self.classname = "player";
304 PlayerScore_Clear(self);
305 bprint ("^4", self.netname, "^4 is playing now\n");
309 //player may not join because of g_maxplayers is set
310 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
313 } else if( argv(0) == "selectteam" ) {
314 if not(self.flags & FL_CLIENT)
316 if( !cvar("teamplay") ) {
317 sprint( self, "selecteam can only be used in teamgames\n");
318 } else if(cvar("g_campaign")) {
319 //JoinBestTeam(self, 0);
320 } else if(lockteams) {
321 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
322 } else if( argv(1) == "red" ) {
323 DoTeamChange(COLOR_TEAM1);
324 } else if( argv(1) == "blue" ) {
325 DoTeamChange(COLOR_TEAM2);
326 } else if( argv(1) == "yellow" ) {
327 DoTeamChange(COLOR_TEAM3);
328 } else if( argv(1) == "pink" ) {
329 DoTeamChange(COLOR_TEAM4);
330 } else if( argv(1) == "auto" ) {
333 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
335 } else if(argv(0) == "ready") {
336 if not(self.flags & FL_CLIENT)
338 if((inWarmupStage && 0 <= g_warmup_limit) // with unlimited warmup players have to be able to restart
339 || cvar("sv_ready_restart"))
342 return sprint(self, "^1You cannot reset the game while a timeout is active!\n");
345 //if(!restartAnnouncer)
347 if(!readyrestart_happened || cvar("sv_ready_restart_repeatable"))
350 bprint(self.netname, "^2 is ready\n");
353 sprint(self, "^1game has already been restarted\n");
357 } else if(argv(0) == "maplist") {
358 sprint(self, maplist_reply);
359 } else if(argv(0) == "lsmaps") {
360 sprint(self, lsmaps_reply);
361 } else if(argv(0) == "records") {
362 sprint(self, records_reply);
363 } else if(argv(0) == "voice") {
364 VoiceMessage(argv(1));
365 } else if(argv(0) == "say") {
367 Say(self, FALSE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
368 //clientcommand(self, formatmessage(s));
369 } else if(argv(0) == "say_team") {
371 Say(self, TRUE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
372 //clientcommand(self, formatmessage(s));
373 } else if(argv(0) == "info") {
374 cmd = cvar_string(strcat("sv_info_", argv(1)));
376 sprint(self, "ERROR: unsupported info command\n");
378 wordwrap_sprint(cmd, 1111);
379 } else if(argv(0) == "suggestmap") {
380 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
381 } else if(argv(0) == "calltimeout") {
382 if not(self.flags & FL_CLIENT)
384 if(cvar("sv_timeout")) {
385 if(self.classname == "player") {
387 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
389 evaluateTimeoutCall();
392 sprint(self, "^7Error: only players can call a timeout!\n");
394 } else if(argv(0) == "resumegame") {
395 if not(self.flags & FL_CLIENT)
397 if(cvar("sv_timeout")) {
398 evaluateResumeGame();
400 } else if(argv(0) == "teamstatus") {
401 Score_NicePrint(self);
402 } else if(argv(0) == "cvar_changes") {
403 sprint(self, cvar_changes);
404 } else if(argv(0) == "pointparticles") {
405 if(sv_cheats && tokens == 5)
409 // origin (0..1, on crosshair line)
412 effectnum = particleeffectnum(argv(1));
414 start = (1-f) * self.origin + f * self.cursor_trace_endpos;
417 pointparticles(effectnum, start, end, f);
420 print("Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
421 } else if(argv(0) == "trailparticles") {
422 if(sv_cheats && tokens == 3)
426 // shot origin vector
427 effectnum = particleeffectnum(argv(1));
428 W_SetupShot(self, stov(argv(2)), FALSE, FALSE, "");
429 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
430 trailparticles(self, effectnum, w_shotorg, trace_endpos);
433 print("Usage: sv_cheats 1; restart; cmd trailparticles effectname shotorigin\n");
435 //if(ctf_clientcommand())
438 // grep for Cmd_AddCommand_WithClientCommand to find them all
446 if(cmd != "notarget")
450 //if(cmd != "say") // handled above
451 //if(cmd != "say_team") // handled above
460 if(cmd != "playermodel")
461 if(cmd != "playerskin")
462 if(cmd != "prespawn")
466 if(cmd != "sv_startdownload")
467 if(cmd != "download")
469 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
472 clientcommand(self,s);
476 void ReadyRestartForce()
480 bprint("^1Server is restarting...\n");
485 if(checkrules_overtimeend)
486 checkrules_overtimeend = 0;
488 readyrestart_happened = 1;
489 game_starttime = time + RESTART_COUNTDOWN;
490 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
492 inWarmupStage = 0; //once the game is restarted the game is in match stage
494 //reset the .ready status of all players (also spectators)
495 FOR_EACH_CLIENTSLOT(e)
498 Nagger_ReadyCounted();
499 FOR_EACH_REALCLIENT(e)
502 WriteByte(MSG_ONE, SVC_TEMPENTITY);
503 WriteByte(MSG_ONE, TE_CSQC_WARMUP);
504 WriteByte(MSG_ONE, 0);
507 if(cvar("teamplay_lockonrestart") && teams_matter) {
509 bprint("^1The teams are now locked.\n");
512 //initiate the restart-countdown-announcer entity
513 restartAnnouncer = spawn();
514 restartAnnouncer.think = restartAnnouncer_Think;
515 restartAnnouncer.nextthink = time;
516 restartAnnouncer.spawnflags = !!cvar("sv_ready_restart_after_countdown");
518 //after a restart every players number of allowed timeouts gets reset, too
519 if(cvar("sv_timeout"))
521 FOR_EACH_REALPLAYER(e)
522 e.allowedTimeouts = cvar("sv_timeout_number");
525 //play the prepareforbattle sound to everyone
526 play2all("announcer/robotic/prepareforbattle.wav");
528 //reset map immediately if this cvar is not set
529 if (!cvar("sv_ready_restart_after_countdown"))
532 if(cvar("sv_eventlog"))
533 GameLogEcho(":restart");
538 // no arena, assault support yet...
539 if(g_arena | g_assault | gameover | intermission_running | race_completing)
540 localcmd("restart\n");
549 * Counts how many players are ready. If not enough players are ready, the function
550 * does nothing. If all players are ready, the timelimit will be extended and the
551 * restart_countdown variable is set to allow other functions like PlayerPostThink
552 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
553 * is not set the map will be resetted.
555 * Function is called after the server receives a 'ready' sign from a player.
564 FOR_EACH_REALPLAYER(e)
573 Nagger_ReadyCounted();
575 if(r) // at least one is ready
576 if(r == p) // and, everyone is ready
581 * Shows the restart countdown for all players.
582 * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
583 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
586 void restartAnnouncer_Think() {
590 c = game_starttime - time;
592 if(c <= 0) { //show the "Begin" message and
593 if(self.spawnflags & 1)
595 restart_mapalreadyrestarted = 1;
599 FOR_EACH_REALCLIENT(plr) {
600 if(plr.classname == "player") {
601 s = strcat(NEWLINES, "^1Begin!");
605 play2all("announcer/robotic/begin.wav");
611 FOR_EACH_REALCLIENT(plr) {
612 if(plr.classname == "player") {
613 s = strcat(NEWLINES, "^1Game starts in ", ftos(f), " seconds");
619 play2all(strcat("announcer/robotic/", ftos(f), ".wav"));
621 self.nextthink = game_starttime - (f - 1);
626 * Checks whether the player who calls the timeout is allowed to do so.
627 * If so, it initializes the timeout countdown. It also checks whether another
628 * timeout was already running at this time and reacts correspondingly.
630 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
631 * timeoutInitiator, timeoutStatus, timeoutHandler
633 * This function is called when a player issues the calltimeout command.
635 void evaluateTimeoutCall() {
636 if (inWarmupStage && !g_warmup_allow_timeout)
637 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
638 if (time < game_starttime )
639 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
640 if (timeoutStatus != 2) {
641 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
642 if (cvar("timelimit")) {
643 //a timelimit was used
645 myTl = cvar("timelimit");
647 local float lastPossibleTimeout;
648 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
650 if (lastPossibleTimeout < time - game_starttime)
651 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
654 //player may not call a timeout if he has no calls left
655 if (self.allowedTimeouts < 1)
656 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
657 //now all required checks are passed
658 self.allowedTimeouts -= 1;
659 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)
660 remainingTimeoutTime = cvar("sv_timeout_length");
661 remainingLeadTime = cvar("sv_timeout_leadtime");
662 timeoutInitiator = self;
663 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
665 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
666 timeoutHandler = spawn();
667 timeoutHandler.think = timeoutHandler_Think;
669 timeoutHandler.nextthink = time; //always let the entity think asap
671 //inform all connected clients about the timeout call
672 play2all("announcer/robotic/timeoutcalled.wav");
676 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
677 * and the lead time for the timeout is still active, this countdown just will be aborted (the
678 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
679 * value of the cvar sv_timeout_resumetime.
681 * This function is called when a player issues the resumegame command.
683 void evaluateResumeGame() {
685 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
686 if (self != timeoutInitiator)
687 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
688 if (timeoutStatus == 1) {
689 remainingTimeoutTime = timeoutStatus = 0;
690 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
691 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
693 else if (timeoutStatus == 2) {
694 //only shorten the remainingTimeoutTime if it makes sense
695 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
696 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
697 remainingTimeoutTime = cvar("sv_timeout_resumetime");
698 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
701 sprint(self, "^7Error: Your resumegame call was discarded!\n");