2 void(entity e) DropFlag;
3 string MapVote_Suggest(string m);
5 .float floodcontrol_chat;
6 .float floodcontrol_team;
7 void Say(entity source, float teamsay, string msgin)
9 string msgstr, colorstr, cmsgstr, namestr;
14 if(substring(msgin, 0, 1) == " ")
15 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
17 msgin = formatmessage(msgin);
22 if(source.classname != "player")
23 colorstr = "^0"; // black for spectators
25 colorstr = Team_ColorCode(source.team);
29 if(intermission_running)
33 * using bprint solves this... me stupid
34 // how can we prevent the message from appearing in a listen server?
35 // for now, just give "say" back and only handle say_team
38 clientcommand(self, strcat("say ", msgin));
43 if(cvar("g_chat_teamcolors"))
44 namestr = playername(source);
46 namestr = source.netname;
49 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin, "\n"));
50 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", wordwrap(msgin, 50));
53 msgstr = strzone(strcat("\{1}", namestr, "^7: ", msgin, "\n"));
61 var .float flood_field;
65 flood_spl = cvar("g_chat_flood_spl_team");
66 flood_burst = cvar("g_chat_flood_burst_team");
67 flood_lmax = cvar("g_chat_flood_lmax_team");
68 flood_field = floodcontrol_team;
72 flood_spl = cvar("g_chat_flood_spl");
73 flood_burst = cvar("g_chat_flood_burst");
74 flood_lmax = cvar("g_chat_flood_lmax");
75 flood_field = floodcontrol_chat;
77 flood_burst = max(0, flood_burst - 1);
78 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
79 lines = ceil(strlennocol(msgstr) / 75);
80 if(flood_lmax && lines > flood_lmax)
82 else if(time >= self.flood_field)
83 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
90 if(cvar("g_chat_flood_notify_flooder"))
93 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
95 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
99 ServerConsoleEcho(strcat("NOTE: ", playername(self), "^7 is flooding."), TRUE);
103 if(source.classname == "player")
105 FOR_EACH_REALPLAYER(head)
107 if(head.team == source.team)
109 sprint(head, msgstr);
110 centerprint(head, cmsgstr);
116 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
118 sprint(head, msgstr);
119 centerprint(head, cmsgstr);
125 //when g_tourney is active and g_tourney_disable_spec_chat is set and game is in matchstage
126 //don't print the text from specs/observers to the players but only the other spectators
127 if(g_tourney && cvar("g_tourney_disable_spec_chat") && tourneyInMatchStage && source.classname != "player") {
128 FOR_EACH_REALCLIENT(head) if(head.classname != "player") {
129 sprint(head, msgstr);
134 //ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
140 entity GetPlayer(string name)
146 if(substring(name, 0, 1) == "#") {
147 num = stof(substring(name, 1, 999));
148 if(num >= 1 && num <= maxclients) {
149 for((e = world); num > 0; --num, (e = nextent(e)))
151 //if(clienttype(e) == CLIENTTYPE_REAL)
152 if(e.classname == "player")
156 ns = strdecolorize(name);
157 FOR_EACH_REALPLAYER(e) {
158 if(!strcasecmp(strdecolorize(e.netname), ns)) {
166 //float ctf_clientcommand();
167 void SV_ParseClientCommand(string s) {
173 if(GameCommand_Vote(s, self)) {
175 } else if(GameCommand_MapVote(argv(0))) {
177 } else if(argv(0) == "autoswitch") {
178 // be backwards compatible with older clients (enabled)
179 self.autoswitch = ("0" != argv(1));
180 local string autoswitchmsg;
181 if (self.autoswitch) {
182 autoswitchmsg = "on";
184 autoswitchmsg = "off";
186 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
187 } else if(argv(0) == "clientversion") {
188 if not(self.flags & FL_CLIENT)
190 if (argv(1) == "$gameversion") {
191 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
192 // either that or someone wants to be funny
195 self.version = stof(argv(1));
197 if(self.version != cvar("gameversion"))
199 self.classname = "observer";
202 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
203 //JoinBestTeam(self, FALSE, TRUE);
204 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
205 self.classname = "observer";
206 stuffcmd(self,"menu_showteamselect\n");
208 } else if(argv(0) == "reportcvar") { // old system
210 } else if(argv(0) == "sentcvar") { // new system
212 } else if(argv(0) == "spectate") {
213 if not(self.flags & FL_CLIENT)
216 return; // don't allow spectating in lms, unless player runs out of lives
217 if(self.classname == "player" && cvar("sv_spectate") == 1) {
219 DropFlag(self.flagcarried);
220 kh_Key_DropAll(self, TRUE);
221 WaypointSprite_PlayerDead();
222 self.classname = "observer";
224 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"));
227 } else if(argv(0) == "join") {
228 if not(self.flags & FL_CLIENT)
231 if (self.classname != "player" && !lockteams)
233 if(isJoinAllowed()) {
234 self.classname = "player";
235 PlayerScore_Clear(self);
236 bprint ("^4", self.netname, "^4 is playing now\n");
240 //player may not join because of g_maxplayers is set
241 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
244 } else if( argv(0) == "selectteam" ) {
245 if not(self.flags & FL_CLIENT)
247 if( !cvar("teamplay") ) {
248 sprint( self, "selecteam can only be used in teamgames\n");
249 } else if(cvar("g_campaign")) {
250 //JoinBestTeam(self, 0);
251 } else if(lockteams) {
252 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
253 } else if( argv(1) == "red" ) {
254 DoTeamChange(COLOR_TEAM1);
255 } else if( argv(1) == "blue" ) {
256 DoTeamChange(COLOR_TEAM2);
257 } else if( argv(1) == "yellow" ) {
258 DoTeamChange(COLOR_TEAM3);
259 } else if( argv(1) == "pink" ) {
260 DoTeamChange(COLOR_TEAM4);
261 } else if( argv(1) == "auto" ) {
264 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
266 } else if(argv(0) == "ready") {
267 if not(self.flags & FL_CLIENT)
269 if(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), " "));
303 } else if(argv(0) == "lsmaps") {
304 sprint(self, "^7Maps available: ");
305 for(i = 0; i < MapInfo_count; ++i)
311 sprint(self, strcat(col, MapInfo_BSPName_ByID(i), " "));
315 } else if(argv(0) == "voice") {
316 VoiceMessage(argv(1));
317 } else if(argv(0) == "say") {
318 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
319 //clientcommand(self, formatmessage(s));
320 } else if(argv(0) == "say_team") {
321 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
322 //clientcommand(self, formatmessage(s));
323 } else if(argv(0) == "info") {
324 cmd = cvar_string(strcat("sv_info_", argv(1)));
326 sprint(self, "ERROR: unsupported info command\n");
328 wordwrap_sprint(cmd, 1111);
329 } else if(argv(0) == "suggestmap") {
330 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
331 } else if(argv(0) == "calltimeout") {
332 if not(self.flags & FL_CLIENT)
334 if(cvar("sv_timeout")) {
335 if(self.classname == "player") {
337 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
339 evaluateTimeoutCall();
342 sprint(self, "^7Error: only players can call a timeout!\n");
344 } else if(argv(0) == "resumegame") {
345 if not(self.flags & FL_CLIENT)
347 if(cvar("sv_timeout")) {
348 evaluateResumeGame();
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 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
377 clientcommand(self,s);
382 * Counts how many players are ready. If not enough players are ready, the function
383 * does nothing. If all players are ready, the timelimit will be extended and the
384 * restart_countdown variable is set to allow other functions like PlayerPostThink
385 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
386 * is not set the map will be resetted.
388 * Function is called after the server receives a 'ready' sign from a player.
395 FOR_EACH_REALPLAYER(e)
402 if(cvar("sv_ready_restart_nag")) {
403 if(!readyNagActive) {
404 readyNagger = spawn();
405 readyNagger.think = readyNagger_Think;
406 readyNagger.cnt = cvar("sv_ready_restart_nag_duration");
407 readyNagger.nextthink = time;
415 bprint("^1Server is restarting...\n");
417 // no arena, assault support yet...
418 if(g_arena | g_assault | gameover | intermission_running)
419 localcmd("restart\n");
421 if(readyNagActive) { //if every player is ready, remove the ready-nagger again
427 tourneyInMatchStage = 1; //once the game is restarted the game is in match stage
428 //reset weapons and ammo, health and armor to default:
429 start_items = IT_LASER | IT_SHOTGUN;
430 start_switchweapon = WEP_SHOTGUN;
431 start_ammo_shells = cvar("g_start_ammo_shells");
432 start_ammo_nails = cvar("g_start_ammo_nails");
433 start_ammo_rockets = cvar("g_start_ammo_rockets");
434 start_ammo_cells = cvar("g_start_ammo_cells");
435 start_health = cvar("g_balance_health_start");
436 start_armorvalue = cvar("g_balance_armor_start");
439 restart_countdown = time + RESTART_COUNTDOWN;
440 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
441 //reset the .ready status of all players (also spectators)
446 if(0<cvar("timelimit") || (g_tourney && cvar("g_tourney_warmup_unlimited_time")) )
448 // remember original timelimit on first restart
450 timelimit_orig = cvar("timelimit");
451 //only set the new timelimit if, when loading the map, a timelimit was really set
453 cvar_set("timelimit", ftos(timelimit_orig + ceil(restart_countdown)/60));
455 if(cvar("teamplay_lockonrestart") && teams_matter) {
457 bprint("^1The teams are now locked.\n");
460 //initiate the restart-countdown-announcer entity
461 restartAnnouncer = spawn();
462 restartAnnouncer.think = restartAnnouncer_Think;
463 restartAnnouncer.nextthink = time;
464 restartAnnouncer.cnt = RESTART_COUNTDOWN;
466 //after a restart every players number of allowed timeouts gets reset, too
467 if(cvar("sv_timeout"))
469 FOR_EACH_REALPLAYER(e)
471 e.allowedTimeouts = cvar("sv_timeout_number");
475 //play the prepareforbattle sound to everyone
476 sound(world, CHAN_AUTO, "announcer/robotic/prepareforbattle.wav", 1, ATTN_NONE);
478 //reset map immediately if this cvar is not set
479 if (!cvar("sv_ready_restart_after_countdown"))
485 if(cvar("sv_eventlog"))
486 GameLogEcho(":restart", FALSE);
490 * Centerprints the information to all players who didn't ready up yet to do so.
492 void readyNagger_Think() {
494 if(self.cnt <= 0) { //have a break showing the ready nag
495 //make sure that the old ready-nag-centerprint isn't shown too long:
496 FOR_EACH_REALCLIENT(plr) {
497 if(plr.classname == "player") {
499 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
502 self.cnt = cvar("sv_ready_restart_nag_duration");
503 self.nextthink = time + cvar("sv_ready_restart_nag_interval");
506 //show the ready nagging to all players who aren't ready yet
507 FOR_EACH_REALCLIENT(plr) {
508 if(plr.classname == "player") {
510 centerprint_atprio(plr, CENTERPRIO_SPAM, "^2Please ready up (F4 by default)!");
511 //play reminder sound once the centerprint appears for the first time after the pause:
512 if (self.cnt == cvar("sv_ready_restart_nag_duration"))
513 play2(plr, "misc/talk2.wav");
518 self.nextthink = time + 1;
524 * Shows the restart countdown for all players.
525 * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
526 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
529 void restartAnnouncer_Think() {
532 if(self.cnt <= 0) { //show the "Begin" message and
533 if (cvar("sv_ready_restart_after_countdown")) {
534 restart_mapalreadyrestarted = 1;
538 FOR_EACH_REALCLIENT(plr) {
539 if(plr.classname == "player") {
540 s = strcat(NEWLINES, "^1Begin!");
544 sound(world, CHAN_AUTO, "announcer/robotic/begin.wav", 1, ATTN_NONE);
550 FOR_EACH_REALCLIENT(plr) {
551 if(plr.classname == "player") {
552 s = strcat(NEWLINES, "^1Game starts in ", ftos(self.cnt), " seconds");
558 sound(world, CHAN_AUTO, strcat("announcer/robotic/", ftos(self.cnt), ".ogg"), 1, ATTN_NONE);
560 self.nextthink = time + 1;
566 * Checks whether the player who calls the timeout is allowed to do so.
567 * If so, it initializes the timeout countdown. It also checks whether another
568 * timeout was already running at this time and reacts correspondingly.
570 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
571 * timeoutInitiator, timeoutStatus, timeoutHandler
573 * This function is called when a player issues the calltimeout command.
575 void evaluateTimeoutCall() {
576 if (g_tourney && !tourneyInMatchStage && !cvar("g_tourney_warmup_allow_timeout"))
577 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
578 if (time < restart_countdown )
579 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
580 if (timeoutStatus != 2) {
581 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
582 if (cvar("timelimit")) {
583 //a timelimit was used
585 if (cvar("timelimit"))
586 myTl = cvar("timelimit");
588 myTl = timelimit_orig;
590 local float lastPossibleTimeout;
591 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
593 if (lastPossibleTimeout < time)
594 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
597 //player may not call a timeout if he has no calls left
598 if (self.allowedTimeouts < 1)
599 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
600 //now all required checks are passed
601 self.allowedTimeouts -= 1;
602 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)
603 remainingTimeoutTime = cvar("sv_timeout_length");
604 remainingLeadTime = cvar("sv_timeout_leadtime");
605 timeoutInitiator = self;
606 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
608 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
609 timeoutHandler = spawn();
610 timeoutHandler.think = timeoutHandler_Think;
612 timeoutHandler.nextthink = time; //always let the entity think asap
614 //inform all connected clients about the timeout call
615 sound(world, CHAN_AUTO, "announcer/robotic/timeoutcalled.wav", 1, ATTN_NONE);
619 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
620 * and the lead time for the timeout is still active, this countdown just will be aborted (the
621 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
622 * value of the cvar sv_timeout_resumetime.
624 * This function is called when a player issues the resumegame command.
626 void evaluateResumeGame() {
628 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
629 if (self != timeoutInitiator)
630 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
631 if (timeoutStatus == 1) {
632 remainingTimeoutTime = timeoutStatus = 0;
633 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
634 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
636 else if (timeoutStatus == 2) {
637 //only shorten the remainingTimeoutTime if it makes sense
638 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
639 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
640 remainingTimeoutTime = cvar("sv_timeout_resumetime");
641 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
644 sprint(self, "^7Error: Your resumegame call was discarded!\n");