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 void SV_ParseClientCommand(string s) {
230 if(GameCommand_Vote(s, self)) {
232 } else if(GameCommand_MapVote(argv(0))) {
234 } else if(argv(0) == "autoswitch") {
235 // be backwards compatible with older clients (enabled)
236 self.autoswitch = ("0" != argv(1));
237 local string autoswitchmsg;
238 if (self.autoswitch) {
239 autoswitchmsg = "on";
241 autoswitchmsg = "off";
243 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
244 } else if(argv(0) == "clientversion") {
245 if not(self.flags & FL_CLIENT)
247 if (argv(1) == "$gameversion") {
248 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
249 // either that or someone wants to be funny
252 self.version = stof(argv(1));
254 if(self.version != cvar("gameversion"))
256 self.classname = "observer";
257 self.version_mismatch = 1;
259 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
260 //JoinBestTeam(self, FALSE, TRUE);
261 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
262 self.classname = "observer";
263 stuffcmd(self,"menu_showteamselect\n");
265 } else if(argv(0) == "reportcvar") { // old system
267 } else if(argv(0) == "sentcvar") { // new system
269 } else if(argv(0) == "spectate") {
270 if not(self.flags & FL_CLIENT)
273 return; // don't allow spectating in lms, unless player runs out of lives
274 if(self.classname == "player" && cvar("sv_spectate") == 1) {
276 DropFlag(self.flagcarried, world, world);
277 kh_Key_DropAll(self, TRUE);
278 WaypointSprite_PlayerDead();
279 self.classname = "observer";
281 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"));
284 } else if(argv(0) == "join") {
285 if not(self.flags & FL_CLIENT)
288 if (self.classname != "player" && !lockteams)
290 if(isJoinAllowed()) {
291 self.classname = "player";
292 PlayerScore_Clear(self);
293 bprint ("^4", self.netname, "^4 is playing now\n");
297 //player may not join because of g_maxplayers is set
298 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
301 } else if( argv(0) == "selectteam" ) {
302 if not(self.flags & FL_CLIENT)
304 if( !cvar("teamplay") ) {
305 sprint( self, "selecteam can only be used in teamgames\n");
306 } else if(cvar("g_campaign")) {
307 //JoinBestTeam(self, 0);
308 } else if(lockteams) {
309 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
310 } else if( argv(1) == "red" ) {
311 DoTeamChange(COLOR_TEAM1);
312 } else if( argv(1) == "blue" ) {
313 DoTeamChange(COLOR_TEAM2);
314 } else if( argv(1) == "yellow" ) {
315 DoTeamChange(COLOR_TEAM3);
316 } else if( argv(1) == "pink" ) {
317 DoTeamChange(COLOR_TEAM4);
318 } else if( argv(1) == "auto" ) {
321 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
323 } else if(argv(0) == "ready") {
324 if not(self.flags & FL_CLIENT)
326 if((inWarmupStage && 0 < g_warmup_limit) // with unlimited warmup players have to be able to restart
327 || cvar("sv_ready_restart"))
330 return sprint(self, "^1You cannot reset the game while a timeout is active!\n");
333 if(!restart_countdown || cvar("sv_ready_restart_repeatable"))
336 bprint(self.netname, "^2 is ready\n");
339 sprint(self, "^1game has already been restarted\n");
342 } else if(argv(0) == "maplist") {
345 n = tokenize(cvar_string("g_maplist"));
346 sprint(self, "^7Maps in list: ");
347 for(i = 0, j = 0; i < n; ++i)
349 if(MapInfo_CheckMap(argv(i)))
355 sprint(self, strcat(col, argv(i), " "));
360 } else if(argv(0) == "lsmaps") {
361 sprint(self, "^7Maps available: ");
362 for(i = 0; i < MapInfo_count; ++i)
368 sprint(self, strcat(col, MapInfo_BSPName_ByID(i), " "));
371 } else if(argv(0) == "voice") {
372 VoiceMessage(argv(1));
373 } else if(argv(0) == "say") {
374 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
375 //clientcommand(self, formatmessage(s));
376 } else if(argv(0) == "say_team") {
377 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
378 //clientcommand(self, formatmessage(s));
379 } else if(argv(0) == "info") {
380 cmd = cvar_string(strcat("sv_info_", argv(1)));
382 sprint(self, "ERROR: unsupported info command\n");
384 wordwrap_sprint(cmd, 1111);
385 } else if(argv(0) == "suggestmap") {
386 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
387 } else if(argv(0) == "calltimeout") {
388 if not(self.flags & FL_CLIENT)
390 if(cvar("sv_timeout")) {
391 if(self.classname == "player") {
393 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
395 evaluateTimeoutCall();
398 sprint(self, "^7Error: only players can call a timeout!\n");
400 } else if(argv(0) == "resumegame") {
401 if not(self.flags & FL_CLIENT)
403 if(cvar("sv_timeout")) {
404 evaluateResumeGame();
406 } else if(argv(0) == "teamstatus") {
407 Score_NicePrint(self);
408 } else if(argv(0) == "cvar_changes") {
409 sprint(self, cvar_changes);
411 //if(ctf_clientcommand())
414 /* checks not needed any more since DP has separated clientcommands and regular commands
417 //if(cmd != "say") // handled above
418 //if(cmd != "say_team") // handled above
429 if(cmd != "playermodel")
430 if(cmd != "playerskin")
431 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
433 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
437 clientcommand(self,s);
445 bprint("^1Server is restarting...\n");
449 // no arena, assault support yet...
450 if(g_arena | g_assault | gameover | intermission_running | race_completing)
451 localcmd("restart\n");
454 if(checkrules_overtimeend)
455 checkrules_overtimeend = 0;
457 restart_countdown = time + RESTART_COUNTDOWN;
458 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
459 if(0 < cvar("timelimit") || inWarmupStage)
461 // remember original timelimit on first restart
463 timelimit_orig = cvar("timelimit");
464 //only set the new timelimit if, when loading the map, a timelimit was really set
466 cvar_set("timelimit", ftos(timelimit_orig + ceil(restart_countdown)/60));
469 inWarmupStage = 0; //once the game is restarted the game is in match stage
471 //reset the .ready status of all players (also spectators)
472 FOR_EACH_CLIENTSLOT(e)
474 FOR_EACH_REALCLIENT(e)
477 WriteByte(MSG_ONE, SVC_TEMPENTITY);
478 WriteByte(MSG_ONE, TE_CSQC_WARMUP);
479 WriteByte(MSG_ONE, 0);
482 if(cvar("teamplay_lockonrestart") && teams_matter) {
484 bprint("^1The teams are now locked.\n");
487 //initiate the restart-countdown-announcer entity
488 restartAnnouncer = spawn();
489 restartAnnouncer.think = restartAnnouncer_Think;
490 restartAnnouncer.nextthink = time;
491 restartAnnouncer.cnt = RESTART_COUNTDOWN;
493 //after a restart every players number of allowed timeouts gets reset, too
494 if(cvar("sv_timeout"))
496 FOR_EACH_REALPLAYER(e)
497 e.allowedTimeouts = cvar("sv_timeout_number");
500 //play the prepareforbattle sound to everyone
501 play2all("announcer/robotic/prepareforbattle.wav");
503 //reset map immediately if this cvar is not set
504 if (!cvar("sv_ready_restart_after_countdown"))
510 if(cvar("sv_eventlog"))
511 GameLogEcho(":restart");
515 * Counts how many players are ready. If not enough players are ready, the function
516 * does nothing. If all players are ready, the timelimit will be extended and the
517 * restart_countdown variable is set to allow other functions like PlayerPostThink
518 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
519 * is not set the map will be resetted.
521 * Function is called after the server receives a 'ready' sign from a player.
530 FOR_EACH_REALPLAYER(e)
539 if(r) // at least one is ready
540 if(r == p) // and, everyone is ready
543 Nagger_ReadyCounted();
547 * Shows the restart countdown for all players.
548 * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
549 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
552 void restartAnnouncer_Think() {
555 if(self.cnt <= 0) { //show the "Begin" message and
556 if (cvar("sv_ready_restart_after_countdown")) {
557 restart_mapalreadyrestarted = 1;
561 FOR_EACH_REALCLIENT(plr) {
562 if(plr.classname == "player") {
563 s = strcat(NEWLINES, "^1Begin!");
567 play2all("announcer/robotic/begin.wav");
573 FOR_EACH_REALCLIENT(plr) {
574 if(plr.classname == "player") {
575 s = strcat(NEWLINES, "^1Game starts in ", ftos(self.cnt), " seconds");
581 play2all(strcat("announcer/robotic/", ftos(self.cnt), ".ogg"));
583 self.nextthink = time + 1;
589 * Checks whether the player who calls the timeout is allowed to do so.
590 * If so, it initializes the timeout countdown. It also checks whether another
591 * timeout was already running at this time and reacts correspondingly.
593 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
594 * timeoutInitiator, timeoutStatus, timeoutHandler
596 * This function is called when a player issues the calltimeout command.
598 void evaluateTimeoutCall() {
599 if (inWarmupStage && !g_warmup_allow_timeout)
600 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
601 if (time < restart_countdown )
602 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
603 if (timeoutStatus != 2) {
604 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
605 if (cvar("timelimit")) {
606 //a timelimit was used
608 if (cvar("timelimit"))
609 myTl = cvar("timelimit");
611 myTl = timelimit_orig;
613 local float lastPossibleTimeout;
614 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
616 if (lastPossibleTimeout < time)
617 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
620 //player may not call a timeout if he has no calls left
621 if (self.allowedTimeouts < 1)
622 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
623 //now all required checks are passed
624 self.allowedTimeouts -= 1;
625 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)
626 remainingTimeoutTime = cvar("sv_timeout_length");
627 remainingLeadTime = cvar("sv_timeout_leadtime");
628 timeoutInitiator = self;
629 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
631 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
632 timeoutHandler = spawn();
633 timeoutHandler.think = timeoutHandler_Think;
635 timeoutHandler.nextthink = time; //always let the entity think asap
637 //inform all connected clients about the timeout call
638 play2all("announcer/robotic/timeoutcalled.wav");
642 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
643 * and the lead time for the timeout is still active, this countdown just will be aborted (the
644 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
645 * value of the cvar sv_timeout_resumetime.
647 * This function is called when a player issues the resumegame command.
649 void evaluateResumeGame() {
651 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
652 if (self != timeoutInitiator)
653 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
654 if (timeoutStatus == 1) {
655 remainingTimeoutTime = timeoutStatus = 0;
656 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
657 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
659 else if (timeoutStatus == 2) {
660 //only shorten the remainingTimeoutTime if it makes sense
661 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
662 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
663 remainingTimeoutTime = cvar("sv_timeout_resumetime");
664 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
667 sprint(self, "^7Error: Your resumegame call was discarded!\n");