2 string MapVote_Suggest(string m);
4 .float floodcontrol_chat;
5 .float floodcontrol_team;
6 void Say(entity source, float teamsay, string msgin)
8 string msgstr, colorstr, cmsgstr, namestr;
12 if(Ban_MaybeEnforceBan(source))
16 if(substring(msgin, 0, 1) == " ")
17 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
19 msgin = formatmessage(msgin);
24 if(source.classname != "player")
25 colorstr = "^0"; // black for spectators
27 colorstr = Team_ColorCode(source.team);
31 if(intermission_running)
35 * using bprint solves this... me stupid
36 // how can we prevent the message from appearing in a listen server?
37 // for now, just give "say" back and only handle say_team
40 clientcommand(self, strcat("say ", msgin));
45 if(cvar("g_chat_teamcolors"))
46 namestr = playername(source);
48 namestr = source.netname;
51 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin, "\n"));
52 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", wordwrap(msgin, 50));
55 msgstr = strzone(strcat("\{1}", namestr, "^7: ", msgin, "\n"));
63 var .float flood_field;
67 flood_spl = cvar("g_chat_flood_spl_team");
68 flood_burst = cvar("g_chat_flood_burst_team");
69 flood_lmax = cvar("g_chat_flood_lmax_team");
70 flood_field = floodcontrol_team;
74 flood_spl = cvar("g_chat_flood_spl");
75 flood_burst = cvar("g_chat_flood_burst");
76 flood_lmax = cvar("g_chat_flood_lmax");
77 flood_field = floodcontrol_chat;
79 flood_burst = max(0, flood_burst - 1);
80 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
81 lines = ceil(strlennocol(msgstr) / 75);
82 if(flood_lmax && lines > flood_lmax)
84 else if(time >= self.flood_field)
85 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
92 if(cvar("g_chat_flood_notify_flooder"))
95 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
97 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
100 sprint(self, msgstr);
101 print("NOTE: ", playername(self), "^7 is flooding.\n");
105 if(source.classname == "player")
107 FOR_EACH_REALPLAYER(head)
109 if(head.team == source.team)
111 sprint(head, msgstr);
112 centerprint(head, cmsgstr);
118 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
120 sprint(head, msgstr);
121 centerprint(head, cmsgstr);
127 if(cvar("g_chat_nospectators") && source.classname != "player") {
128 FOR_EACH_REALCLIENT(head) if(head.classname != "player") {
129 sprint(head, msgstr);
139 entity GetPlayer(string name)
145 if(substring(name, 0, 1) == "#") {
146 num = stof(substring(name, 1, 999));
147 if(num >= 1 && num <= maxclients) {
148 for((e = world); num > 0; --num, (e = nextent(e)))
150 //if(clienttype(e) == CLIENTTYPE_REAL)
151 if(e.classname == "player")
155 ns = strdecolorize(name);
156 FOR_EACH_REALPLAYER(e) {
157 if(!strcasecmp(strdecolorize(e.netname), ns)) {
165 //float ctf_clientcommand();
166 void SV_ParseClientCommand(string s) {
172 if(GameCommand_Vote(s, self)) {
174 } else if(GameCommand_MapVote(argv(0))) {
176 } else if(argv(0) == "autoswitch") {
177 // be backwards compatible with older clients (enabled)
178 self.autoswitch = ("0" != argv(1));
179 local string autoswitchmsg;
180 if (self.autoswitch) {
181 autoswitchmsg = "on";
183 autoswitchmsg = "off";
185 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
186 } else if(argv(0) == "clientversion") {
187 if not(self.flags & FL_CLIENT)
189 if (argv(1) == "$gameversion") {
190 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
191 // either that or someone wants to be funny
194 self.version = stof(argv(1));
196 if(self.version != cvar("gameversion"))
198 self.classname = "observer";
199 self.version_mismatch = 1;
201 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
202 //JoinBestTeam(self, FALSE, TRUE);
203 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
204 self.classname = "observer";
205 stuffcmd(self,"menu_showteamselect\n");
207 } else if(argv(0) == "reportcvar") { // old system
209 } else if(argv(0) == "sentcvar") { // new system
211 } else if(argv(0) == "spectate") {
212 if not(self.flags & FL_CLIENT)
215 return; // don't allow spectating in lms, unless player runs out of lives
216 if(self.classname == "player" && cvar("sv_spectate") == 1) {
218 DropFlag(self.flagcarried, 0);
219 kh_Key_DropAll(self, TRUE);
220 WaypointSprite_PlayerDead();
221 self.classname = "observer";
223 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"));
226 } else if(argv(0) == "join") {
227 if not(self.flags & FL_CLIENT)
230 if (self.classname != "player" && !lockteams)
232 if(isJoinAllowed()) {
233 self.classname = "player";
234 PlayerScore_Clear(self);
235 bprint ("^4", self.netname, "^4 is playing now\n");
239 //player may not join because of g_maxplayers is set
240 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
243 } else if( argv(0) == "selectteam" ) {
244 if not(self.flags & FL_CLIENT)
246 if( !cvar("teamplay") ) {
247 sprint( self, "selecteam can only be used in teamgames\n");
248 } else if(cvar("g_campaign")) {
249 //JoinBestTeam(self, 0);
250 } else if(lockteams) {
251 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
252 } else if( argv(1) == "red" ) {
253 DoTeamChange(COLOR_TEAM1);
254 } else if( argv(1) == "blue" ) {
255 DoTeamChange(COLOR_TEAM2);
256 } else if( argv(1) == "yellow" ) {
257 DoTeamChange(COLOR_TEAM3);
258 } else if( argv(1) == "pink" ) {
259 DoTeamChange(COLOR_TEAM4);
260 } else if( argv(1) == "auto" ) {
263 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
265 } else if(argv(0) == "ready") {
266 if not(self.flags & FL_CLIENT)
268 if((inWarmupStage && 0 < g_warmup_limit) // with unlimited warmup players have to be able to restart
269 || cvar("sv_ready_restart"))
272 return sprint(self, "^1You cannot reset the game while a timeout is active!\n");
275 if(!restart_countdown || cvar("sv_ready_restart_repeatable"))
278 bprint(self.netname, "^2 is ready\n");
281 sprint(self, "^1game has already been restarted\n");
284 } else if(argv(0) == "maplist") {
287 n = tokenize(cvar_string("g_maplist"));
288 sprint(self, "^7Maps in list: ");
289 for(i = 0, j = 0; i < n; ++i)
291 if(MapInfo_CheckMap(argv(i)))
297 sprint(self, strcat(col, argv(i), " "));
302 } else if(argv(0) == "lsmaps") {
303 sprint(self, "^7Maps available: ");
304 for(i = 0; i < MapInfo_count; ++i)
310 sprint(self, strcat(col, MapInfo_BSPName_ByID(i), " "));
313 } else if(argv(0) == "voice") {
314 VoiceMessage(argv(1));
315 } else if(argv(0) == "say") {
316 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
317 //clientcommand(self, formatmessage(s));
318 } else if(argv(0) == "say_team") {
319 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
320 //clientcommand(self, formatmessage(s));
321 } else if(argv(0) == "info") {
322 cmd = cvar_string(strcat("sv_info_", argv(1)));
324 sprint(self, "ERROR: unsupported info command\n");
326 wordwrap_sprint(cmd, 1111);
327 } else if(argv(0) == "suggestmap") {
328 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
329 } else if(argv(0) == "calltimeout") {
330 if not(self.flags & FL_CLIENT)
332 if(cvar("sv_timeout")) {
333 if(self.classname == "player") {
335 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
337 evaluateTimeoutCall();
340 sprint(self, "^7Error: only players can call a timeout!\n");
342 } else if(argv(0) == "resumegame") {
343 if not(self.flags & FL_CLIENT)
345 if(cvar("sv_timeout")) {
346 evaluateResumeGame();
348 } else if(argv(0) == "teamstatus") {
349 Score_NicePrint(self);
351 //if(ctf_clientcommand())
354 /* checks not needed any more since DP has separated clientcommands and regular commands
357 //if(cmd != "say") // handled above
358 //if(cmd != "say_team") // handled above
369 if(cmd != "playermodel")
370 if(cmd != "playerskin")
371 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
373 print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
377 clientcommand(self,s);
385 bprint("^1Server is restarting...\n");
389 // no arena, assault support yet...
390 if(g_arena | g_assault | gameover | intermission_running | race_completing)
391 localcmd("restart\n");
394 if(checkrules_overtimeend)
395 checkrules_overtimeend = 0;
397 if(readyNagActive) { //if every player is ready, remove the ready-nagger again
402 restart_countdown = time + RESTART_COUNTDOWN;
403 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
404 if(0 < cvar("timelimit") || inWarmupStage)
406 // remember original timelimit on first restart
408 timelimit_orig = cvar("timelimit");
409 //only set the new timelimit if, when loading the map, a timelimit was really set
411 cvar_set("timelimit", ftos(timelimit_orig + ceil(restart_countdown)/60));
414 inWarmupStage = 0; //once the game is restarted the game is in match stage
416 //reset the .ready status of all players (also spectators)
417 FOR_EACH_CLIENTSLOT(e)
419 FOR_EACH_REALCLIENT(e)
422 WriteByte(MSG_ONE, SVC_TEMPENTITY);
423 WriteByte(MSG_ONE, TE_CSQC_WARMUP);
424 WriteByte(MSG_ONE, 0);
427 if(cvar("teamplay_lockonrestart") && teams_matter) {
429 bprint("^1The teams are now locked.\n");
432 //initiate the restart-countdown-announcer entity
433 restartAnnouncer = spawn();
434 restartAnnouncer.think = restartAnnouncer_Think;
435 restartAnnouncer.nextthink = time;
436 restartAnnouncer.cnt = RESTART_COUNTDOWN;
438 //after a restart every players number of allowed timeouts gets reset, too
439 if(cvar("sv_timeout"))
441 FOR_EACH_REALPLAYER(e)
442 e.allowedTimeouts = cvar("sv_timeout_number");
445 //play the prepareforbattle sound to everyone
446 play2all("announcer/robotic/prepareforbattle.wav");
448 //reset map immediately if this cvar is not set
449 if (!cvar("sv_ready_restart_after_countdown"))
455 if(cvar("sv_eventlog"))
456 GameLogEcho(":restart");
460 * Counts how many players are ready. If not enough players are ready, the function
461 * does nothing. If all players are ready, the timelimit will be extended and the
462 * restart_countdown variable is set to allow other functions like PlayerPostThink
463 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
464 * is not set the map will be resetted.
466 * Function is called after the server receives a 'ready' sign from a player.
475 FOR_EACH_REALPLAYER(e)
483 return; // NOTE: this also excludes !p, as r <= p
485 if(cvar("sv_ready_restart_nag")) {
486 if(!readyNagActive) {
487 readyNagger = spawn();
488 readyNagger.think = readyNagger_Think;
489 readyNagger.cnt = cvar("sv_ready_restart_nag_duration");
490 readyNagger.nextthink = time;
502 * Centerprints the information to all players who didn't ready up yet to do so.
504 void readyNagger_Think() {
506 if(self.cnt <= 0) { //have a break showing the ready nag
507 //make sure that the old ready-nag-centerprint isn't shown too long:
508 FOR_EACH_REALCLIENT(plr) {
509 if(plr.classname == "player") {
511 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
514 self.cnt = cvar("sv_ready_restart_nag_duration");
515 self.nextthink = time + cvar("sv_ready_restart_nag_interval");
518 //show the ready nagging to all players who aren't ready yet
519 FOR_EACH_REALCLIENT(plr) {
520 if(plr.classname == "player") {
522 centerprint_atprio(plr, CENTERPRIO_SPAM, "^2Please ready up (F4 by default)!");
523 //play reminder sound once the centerprint appears for the first time after the pause:
524 if (self.cnt == cvar("sv_ready_restart_nag_duration"))
525 play2(plr, "misc/talk2.wav");
530 self.nextthink = time + 1;
536 * Shows the restart countdown for all players.
537 * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
538 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
541 void restartAnnouncer_Think() {
544 if(self.cnt <= 0) { //show the "Begin" message and
545 if (cvar("sv_ready_restart_after_countdown")) {
546 restart_mapalreadyrestarted = 1;
550 FOR_EACH_REALCLIENT(plr) {
551 if(plr.classname == "player") {
552 s = strcat(NEWLINES, "^1Begin!");
556 play2all("announcer/robotic/begin.wav");
562 FOR_EACH_REALCLIENT(plr) {
563 if(plr.classname == "player") {
564 s = strcat(NEWLINES, "^1Game starts in ", ftos(self.cnt), " seconds");
570 play2all(strcat("announcer/robotic/", ftos(self.cnt), ".ogg"));
572 self.nextthink = time + 1;
578 * Checks whether the player who calls the timeout is allowed to do so.
579 * If so, it initializes the timeout countdown. It also checks whether another
580 * timeout was already running at this time and reacts correspondingly.
582 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
583 * timeoutInitiator, timeoutStatus, timeoutHandler
585 * This function is called when a player issues the calltimeout command.
587 void evaluateTimeoutCall() {
588 if (inWarmupStage && !g_warmup_allow_timeout)
589 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
590 if (time < restart_countdown )
591 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
592 if (timeoutStatus != 2) {
593 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
594 if (cvar("timelimit")) {
595 //a timelimit was used
597 if (cvar("timelimit"))
598 myTl = cvar("timelimit");
600 myTl = timelimit_orig;
602 local float lastPossibleTimeout;
603 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
605 if (lastPossibleTimeout < time)
606 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
609 //player may not call a timeout if he has no calls left
610 if (self.allowedTimeouts < 1)
611 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
612 //now all required checks are passed
613 self.allowedTimeouts -= 1;
614 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)
615 remainingTimeoutTime = cvar("sv_timeout_length");
616 remainingLeadTime = cvar("sv_timeout_leadtime");
617 timeoutInitiator = self;
618 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
620 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
621 timeoutHandler = spawn();
622 timeoutHandler.think = timeoutHandler_Think;
624 timeoutHandler.nextthink = time; //always let the entity think asap
626 //inform all connected clients about the timeout call
627 play2all("announcer/robotic/timeoutcalled.wav");
631 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
632 * and the lead time for the timeout is still active, this countdown just will be aborted (the
633 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
634 * value of the cvar sv_timeout_resumetime.
636 * This function is called when a player issues the resumegame command.
638 void evaluateResumeGame() {
640 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
641 if (self != timeoutInitiator)
642 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
643 if (timeoutStatus == 1) {
644 remainingTimeoutTime = timeoutStatus = 0;
645 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
646 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
648 else if (timeoutStatus == 2) {
649 //only shorten the remainingTimeoutTime if it makes sense
650 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
651 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
652 remainingTimeoutTime = cvar("sv_timeout_resumetime");
653 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
656 sprint(self, "^7Error: Your resumegame call was discarded!\n");