2 string ValidateMap(string vote);
3 void(entity e) DropFlag;
4 string MapVote_Suggest(string m);
6 .float floodcontrol_chat;
7 .float floodcontrol_team;
8 void Say(entity source, float teamsay, string msgin)
10 string msgstr, colorstr, cmsgstr, namestr;
15 if(substring(msgin, 0, 1) == " ")
16 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
18 msgin = formatmessage(msgin);
23 if(source.classname != "player")
24 colorstr = "^0"; // black for spectators
26 colorstr = Team_ColorCode(source.team);
30 if(intermission_running)
34 * using bprint solves this... me stupid
35 // how can we prevent the message from appearing in a listen server?
36 // for now, just give "say" back and only handle say_team
39 clientcommand(self, strcat("say ", msgin));
44 if(cvar("g_chat_teamcolors"))
45 namestr = playername(source);
47 namestr = source.netname;
50 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin, "\n"));
51 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", wordwrap(msgin, 50));
54 msgstr = strzone(strcat("\{1}", namestr, "^7: ", msgin, "\n"));
62 var .float flood_field;
66 flood_spl = cvar("g_chat_flood_spl_team");
67 flood_burst = cvar("g_chat_flood_burst_team");
68 flood_lmax = cvar("g_chat_flood_lmax_team");
69 flood_field = floodcontrol_team;
73 flood_spl = cvar("g_chat_flood_spl");
74 flood_burst = cvar("g_chat_flood_burst");
75 flood_lmax = cvar("g_chat_flood_lmax");
76 flood_field = floodcontrol_chat;
78 flood_burst = max(0, flood_burst - 1);
79 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
80 lines = ceil(strlennocol(msgstr) / 75);
81 if(flood_lmax && lines > flood_lmax)
83 else if(time >= self.flood_field)
84 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
91 if(cvar("g_chat_flood_notify_flooder"))
94 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
96 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
100 ServerConsoleEcho(strcat("NOTE: ", playername(self), "^7 is flooding."), TRUE);
104 if(source.classname == "player")
106 FOR_EACH_REALPLAYER(head)
108 if(head.team == source.team)
110 sprint(head, msgstr);
111 centerprint(head, cmsgstr);
117 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
119 sprint(head, msgstr);
120 centerprint(head, cmsgstr);
126 //when g_tourney is active and g_tourney_disable_spec_chat is set and game is in matchstage
127 //don't print the text from specs/observers to the players but only the other spectators
128 if(g_tourney && cvar("g_tourney_disable_spec_chat") && tourneyInMatchStage && source.classname != "player") {
129 FOR_EACH_REALCLIENT(head) if(head.classname != "player") {
130 sprint(head, msgstr);
135 //ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
141 float VoteCheckNasty(string cmd)
143 if(strstrofs(cmd, ";", 0) >= 0)
145 if(strstrofs(cmd, "\n", 0) >= 0)
147 if(strstrofs(cmd, "\r", 0) >= 0)
149 if(strstrofs(cmd, "$", 0) >= 0)
154 string GetKickVoteVictim_newcommand;
155 string GetKickVoteVictim_reason;
156 entity GetKickVoteVictim(string vote, string cmd)
163 tokens = tokenize(vote);
167 if(substring(argv(1), 0, 1) == "#")
169 ns = substring(argv(1), 1, 999);
182 GetKickVoteVictim_reason = "";
183 for(i = t; i < tokens; ++i)
184 GetKickVoteVictim_reason = strcat(GetKickVoteVictim_reason, argv(i), " ");
185 GetKickVoteVictim_reason = substring(GetKickVoteVictim_reason, 0, strlen(GetKickVoteVictim_reason) - 1);
188 if(ns == ftos(n)) if(n >= 1) if(n <= maxclients)
191 if(clienttype(e) == CLIENTTYPE_REAL)
193 GetKickVoteVictim_newcommand = strcat(argv(0), " # ", ns);
199 sprint(self, strcat("Usage: ", cmd, " ", argv(0), " #playernumber (as in \"status\")\n"));
203 void SV_ParseClientCommand(string s) {
210 if(argv(0) == "vote") {
211 if(argv(1) == "help") {
212 local string vmasterdis;
213 if(!cvar("sv_vote_master")) {
214 vmasterdis = " ^1(disabled)";
216 local string vcalldis;
217 if(!cvar("sv_vote_call")) {
218 vcalldis = " ^1(disabled)";
220 sprint(self, "^7You can use voting with \"^2cmd vote help^7\" \"^2cmd vote status^7\" \"^2cmd vote call ^3COMMAND ARGUMENTS^7\" \"^2cmd vote stop^7\" \"^2cmd vote master^7\" \"^2cmd vote do ^3COMMAND ARGUMENTS^7\" \"^2cmd vote yes^7\" \"^2cmd vote no^7\" \"^2cmd vote dontcare^7\".\n");
221 sprint(self, "^7Or if your version is up to date you can use these aliases \"^2vhelp^7\" \"^2vstatus^7\" \"^2vcall ^3COMMAND ARGUMENTS^7\" \"^2vstop^7\" \"^2vmaster^7\" \"^2vdo ^3COMMAND ARGUMENTS^7\" \"^2vyes^7\" \"^2vno^7\" \"^2vdontcare^7\".\n");
222 sprint(self, "^7\"^2help^7\" shows this info.\n");
223 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
224 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
225 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
226 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
227 sprint(self, "^7\"^2do^7\" If you are a master you can execute a command without a vote. See the list of allowed commands.\n");
228 sprint(self, "^7\"^2yes^7\", \"^2no^7\" and \"^2dontcare^7\" to make your vote.\n");
229 sprint(self, "^7If enough of the players vote yes the vote is accepted.\n");
230 sprint(self, "^7If enough of the players vote no the vote is rejected.\n");
231 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
232 sprint(self, "^7You can call a vote for or execute these commands:\n");
233 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
234 } else if(argv(1) == "status") {
236 sprint(self, strcat("^7Vote for ", votecalledvote_display, "^7 called by ^7", votecaller.netname, "^7.\n"));
238 sprint(self, "^1No vote called.\n");
240 } else if(argv(1) == "call") {
241 if(cvar("sv_vote_call")) {
242 if(tourneyInMatchStage && cvar("g_tourney_disable_spec_vote") && self.classname != "player") {
243 sprint(self, "^1Error: Only players can call a vote during the match-stage.\n");
245 else if(timeoutStatus) { //don't allow a vote call during a timeout
246 sprint(self, "^1Error: You can not call a vote while a timeout is active.\n");
248 else if(votecalled) {
249 sprint(self, "^1There is already a vote called.\n");
254 sprint(self, "^1Your vote is empty. See help for more info.\n");
255 } else if(time < self.vote_next) {
256 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
257 } else if(VoteCheckNasty(vote)) {
258 sprint(self, "Syntax error in command.\n");
259 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
260 // remap chmap to gotomap (forces intermission)
261 if(vote == "chmap" || vote == "gotomap") // won't work without arguments
263 if(substring(vote, 0, 6) == "chmap ")
264 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
265 if(substring(vote, 0, 8) == "gotomap ")
267 if(!(vote = ValidateMap(substring(vote, 8, strlen(vote) - 8))))
269 vote = strcat("gotomap ", vote);
272 // make kick and kickban votes a bit nicer (and reject them if formatted badly)
273 if(substring(vote, 0, 5) == "kick " || substring(vote, 0, 8) == "kickban ")
275 if(!(e = GetKickVoteVictim(vote, "vcall")))
277 vote = GetKickVoteVictim_newcommand;
278 votecalledvote_display = strzone(strcat("^1", vote, " (^7", e.netname, "^1): ", GetKickVoteVictim_reason));
282 votecalledvote_display = strzone(strcat("^1", vote));
284 votecalledvote = strzone(vote);
286 votecalledmaster = FALSE;
287 votecaller = self; // remember who called the vote
288 votefinished = time + cvar("sv_vote_timeout");
289 votecaller.vote_vote = 1; // of course you vote yes
290 votecaller.vote_next = time + cvar("sv_vote_wait");
291 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ", votecalledvote_display, "\n");
292 VoteCount(); // needed if you are the only one
294 sprint(self, "^1This vote is not ok. See help for more info.\n");
298 sprint(self, "^1Vote calling is NOT allowed.\n");
300 } else if(argv(1) == "stop") {
302 sprint(self, "^1No vote called.\n");
303 } else if(self == votecaller) { // the votecaller can stop a vote
305 } else if(self.vote_master) { // masters can, too
308 sprint(self, "^1You are not allowed to stop that Vote.\n");
310 } else if(argv(1) == "master") {
311 if(cvar("sv_vote_master")) {
313 sprint(self, "^1There is already a vote called.\n");
316 votecalledmaster = TRUE;
317 votecalledvote = strzone("XXX");
318 votecalledvote_display = strzone("^3master");
319 votecaller = self; // remember who called the vote
320 votefinished = time + cvar("sv_vote_timeout");
321 votecaller.vote_vote = 1; // of course you vote yes
322 votecaller.vote_next = time + cvar("sv_vote_wait");
323 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n");
324 VoteCount(); // needed if you are the only one
327 sprint(self, "^1Vote to become master is NOT allowed.\n");
329 } else if(argv(1) == "do") {
330 if(argv(2) == "login") {
331 local string masterpwd;
332 masterpwd = cvar_string("sv_vote_master_password");
333 if(masterpwd != "") {
334 self.vote_master = (masterpwd == argv(3));
335 if(self.vote_master) {
336 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
337 bprint("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n");
340 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
343 sprint(self, "^1You are NOT a master.\n");
344 } else if(self.vote_master) {
345 local string dovote, dovote_display;
346 dovote = VoteParse();
348 sprint(self, "^1Your command was empty. See help for more info.\n");
349 } else if(VoteCheckNasty(dovote)) {
350 sprint(self, "Syntax error in command.\n");
351 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
352 if(dovote == "chmap" || dovote == "gotomap") // won't work without arguments
354 if(substring(dovote, 0, 6) == "chmap ")
355 dovote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
356 if(substring(dovote, 0, 8) == "gotomap ")
358 if(!(dovote = ValidateMap(substring(dovote, 8, strlen(dovote) - 8))))
360 dovote = strcat("gotomap ", dovote);
363 dovote_display = dovote;
364 if(substring(dovote, 0, 5) == "kick " || substring(dovote, 0, 8) == "kickban ")
366 if(!(e = GetKickVoteVictim(dovote, "vdo")))
368 dovote = GetKickVoteVictim_newcommand;
369 dovote_display = strcat("^1", dovote, " (^7", e.netname, "^1): ", GetKickVoteVictim_reason);
371 bprint("\{1}^2* ^3", self.netname, "^2 used his ^3master^2 status to do \"^2", dovote_display, "^2\".\n");
372 localcmd(strcat(dovote, "\n"));
374 sprint(self, "^1This command is not ok. See help for more info.\n");
377 sprint(self, "^1You are NOT a master.\n");
379 } else if(argv(1) == "yes") {
381 sprint(self, "^1No vote called.\n");
382 } else if(self.vote_vote == 0
383 || cvar("sv_vote_change")) {
384 sprint(self, "^1You accepted the vote.\n");
386 centerprint_expire(self, CENTERPRIO_VOTE);
387 if(!cvar("sv_vote_singlecount")) {
391 sprint(self, "^1You have already voted.\n");
393 } else if(argv(1) == "no") {
395 sprint(self, "^1No vote called.\n");
396 } else if(self.vote_vote == 0
397 || cvar("sv_vote_change")) {
398 sprint(self, "^1You rejected the vote.\n");
400 centerprint_expire(self, CENTERPRIO_VOTE);
401 if(!cvar("sv_vote_singlecount")) {
405 sprint(self, "^1You have already voted.\n");
407 } else if(argv(1) == "abstain" || argv(1) == "dontcare") {
409 sprint(self, "^1No vote called.\n");
410 } else if(self.vote_vote == 0
411 || cvar("sv_vote_change")) {
412 sprint(self, "^1You abstained from your vote.\n");
414 centerprint_expire(self, CENTERPRIO_VOTE);
415 if(!cvar("sv_vote_singlecount")) {
419 sprint(self, "^1You have already voted.\n");
423 sprint(self, "^1Unknown vote command.\n");
425 } else if(argv(0) == "autoswitch") {
426 // be backwards compatible with older clients (enabled)
427 self.autoswitch = ("0" != argv(1));
428 local string autoswitchmsg;
429 if (self.autoswitch) {
430 autoswitchmsg = "on";
432 autoswitchmsg = "off";
434 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
435 } else if(argv(0) == "clientversion") {
436 if (argv(1) == "$gameversion") {
437 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
438 // either that or someone wants to be funny
441 self.version = stof(argv(1));
443 if(self.version != cvar("gameversion"))
445 self.classname = "observer";
448 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
449 //JoinBestTeam(self, FALSE, TRUE);
450 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
451 self.classname = "observer";
452 stuffcmd(self,"menu_showteamselect\n");
454 } else if(argv(0) == "reportcvar") { // old system
456 } else if(argv(0) == "sentcvar") { // new system
458 } else if(argv(0) == "spectate") {
460 return; // don't allow spectating in lms, unless player runs out of lives
461 if(self.classname == "player" && cvar("sv_spectate") == 1) {
463 DropFlag(self.flagcarried);
464 kh_Key_DropAll(self, TRUE);
465 WaypointSprite_PlayerDead();
466 DistributeFragsAmongTeam(self, self.team, 1.0);
467 self.classname = "observer";
469 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"));
472 } else if(argv(0) == "join") {
474 if (self.classname != "player" && !lockteams)
476 if(isJoinAllowed()) {
477 self.classname = "player";
479 bprint ("^4", self.netname, "^4 is playing now\n");
483 //player may not join because of g_maxplayers is set
484 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
487 } else if( argv(0) == "selectteam" ) {
488 if( !cvar("teamplay") ) {
489 sprint( self, "selecteam can only be used in teamgames\n");
490 } else if(cvar("g_campaign")) {
491 //JoinBestTeam(self, 0);
492 } else if(lockteams) {
493 sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
494 } else if( argv(1) == "red" ) {
495 DoTeamChange(COLOR_TEAM1);
496 } else if( argv(1) == "blue" ) {
497 DoTeamChange(COLOR_TEAM2);
498 } else if( argv(1) == "yellow" ) {
499 DoTeamChange(COLOR_TEAM3);
500 } else if( argv(1) == "pink" ) {
501 DoTeamChange(COLOR_TEAM4);
502 } else if( argv(1) == "auto" ) {
505 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
507 } else if(argv(0) == "ready") {
508 if(cvar("sv_ready_restart"))
511 return sprint(self, "^1You cannot reset the game while a timeout is active!\n");
514 if(!restart_countdown || cvar("sv_ready_restart_repeatable"))
517 bprint(self.netname, "^2 is ready\n");
520 sprint(self, "^1game has already been restarted\n");
523 } else if(argv(0) == "maplist") {
526 n = tokenize(cvar_string("g_maplist"));
527 sprint(self, "^7Maps in list: ");
528 for(i = 0; i < n; ++i)
534 sprint(self, strcat(col, argv(i), " "));
538 } else if(argv(0) == "lsmaps") {
539 sprint(self, "^7Maps available: ");
540 for(i = 0; i < MapInfo_count; ++i)
546 sprint(self, strcat(col, MapInfo_BSPName_ByID(i), " "));
550 } else if(argv(0) == "teamstatus") {
551 PrintScoreboard(self);
552 } else if(argv(0) == "voice") {
553 VoiceMessage(argv(1));
554 } else if(argv(0) == "say") {
555 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
556 //clientcommand(self, formatmessage(s));
557 } else if(argv(0) == "say_team") {
558 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
559 //clientcommand(self, formatmessage(s));
560 } else if(argv(0) == "info") {
561 cmd = cvar_string(strcat("sv_info_", argv(1)));
563 sprint(self, "ERROR: unsupported info command\n");
565 wordwrap_sprint(cmd, 1111);
566 } else if(argv(0) == "suggestmap") {
567 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
568 } else if(argv(0) == "calltimeout") {
569 if(cvar("sv_timeout")) {
570 if(self.classname == "player") {
572 sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
574 evaluateTimeoutCall();
577 sprint(self, "^7Error: only players can call a timeout!\n");
579 } else if(argv(0) == "resumegame") {
580 if(cvar("sv_timeout")) {
581 evaluateResumeGame();
585 /* checks not needed any more since DP has separated clientcommands and regular commands
588 //if(cmd != "say") // handled above
589 //if(cmd != "say_team") // handled above
600 if(cmd != "playermodel")
601 if(cmd != "playerskin")
602 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
604 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
608 clientcommand(self,s);
612 string ValidateMap(string m)
615 m = MapInfo_FixName(m);
618 sprint(self, "This map is not available on this server.\n");
622 if(!cvar("sv_vote_change_gametype"))
623 if(!IsSameGametype(m))
625 sprint(self, "This server does not allow changing the game type by map votes.\n");
629 if(!cvar("sv_vote_override_mostrecent"))
632 sprint(self, "This server does not allow for recent maps to be played again. Please be patient for some rounds.\n");
636 if(!MapInfo_CheckMap(m))
638 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not support the current game mode.\n"));
642 if(!TryFile(strcat("maps/", m, ".mapcfg")))
644 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not exist on this server.\n"));
654 if(votefinished > 0 // a vote was called
655 && time > votefinished) // time is up
666 while(argv(index) != "") {
667 vote = strcat(vote, " ", argv(index));
671 // necessary for some of the string operations
672 vote = strzone(vote);
674 // now we remove some things that could be misused
678 local float votelength;
679 votelength = strlen(vote);
680 while(!found && index < votelength)
682 local string badchar;
683 badchar = substring(vote, index, 1);
693 return substring(vote, 0, index);
696 float VoteAllowed(string votecommand) {
697 tokenize(cvar_string("sv_vote_commands"));
700 while(argv(index) != "") {
701 local string allowed;
702 allowed = argv(index);
703 if(votecommand == allowed) {
714 FOR_EACH_CLIENT(player)
716 player.vote_vote = 0;
717 centerprint_expire(player, CENTERPRIO_VOTE);
722 strunzone(votecalledvote);
723 strunzone(votecalledvote_display);
727 votecalledmaster = FALSE;
732 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote_display, "^2 was accepted\n");
735 votecaller.vote_master = 1;
737 //in g_tourney mode and if the vote is a timelimit-change, don't change it immediately but after restart
738 if(cvar("g_tourney") && substring(votecalledvote, 0, 10) == "timelimit ") {
739 if( stof(substring(votecalledvote, 10, strlen(votecalledvote) - 10)) > 0 ) {
740 timelimit_orig = stof(substring(votecalledvote, 10, strlen(votecalledvote) - 10));
741 bprint(strcat("The timelimit will be set to ", ftos(timelimit_orig), " minutes after the next restart!\n"));
743 else //calls like "timelimit -1" can pass immediately
744 localcmd(strcat(votecalledvote, "\n"));
747 localcmd(strcat(votecalledvote, "\n"));
749 votecaller.vote_next = 0; // people like your votes, no wait for next vote
754 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 was rejected\n");
759 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 timed out\n");
763 void VoteStop(entity stopper) {
764 bprint("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n");
765 if(stopper == votecaller) {
766 // no wait for next vote so you can correct your vote
767 votecaller.vote_next = 0;
774 if(self.vote_vote == 0)
775 centerprint_atprio(self, CENTERPRIO_VOTE, strcat("^7^3", votecaller.netname, "^2 called a vote for ", votecalledvote_display, "\n\n^2You have not voted yet!\n^2HINT: By default, F1 is yes and F2 is no."));
778 void VoteSpam(float yescount, float nocount, float abstaincount, float notvoters, float mincount)
783 s = strcat("\{1}^2* vote results: ^1", ftos(yescount), "^2:^1");
784 s = strcat(s, ftos(nocount), "^2 (^1");
785 s = strcat(s, ftos(mincount), "^2 needed), ^1");
786 s = strcat(s, ftos(abstaincount), "^2 didn't care, ^1");
787 s = strcat(s, ftos(notvoters), "^2 didn't vote\n");
791 s = strcat("\{1}^2* vote results: ^1", ftos(yescount), "^2:^1");
792 s = strcat(s, ftos(nocount), "^2 (^1");
793 s = strcat(s, ftos(abstaincount), "^2 didn't care, ^1");
794 s = strcat(s, ftos(notvoters), "^2 didn't have to vote\n");
800 local float playercount;
802 local float yescount;
806 local float abstaincount;
809 //same for real players
810 local float realplayercount;
811 local float realplayeryescount;
812 local float realplayernocount;
813 local float realplayerabstaincount;
814 realplayercount = realplayernocount = realplayerabstaincount = realplayeryescount = 0;
816 FOR_EACH_REALCLIENT(player)
818 if(player.vote_vote == -1) {
820 } else if(player.vote_vote == 1) {
822 } else if(player.vote_vote == -2) {
826 //do the same for real players
827 if(player.classname == "player") {
828 if(player.vote_vote == -1) {
830 } else if(player.vote_vote == 1) {
831 realplayeryescount++;
832 } else if(player.vote_vote == -2) {
833 realplayerabstaincount++;
839 //in tournament mode, if we have at least one player then don't make the vote dependent on spectators (so specs don't have to press F1)
840 if( cvar("g_tourney") && (realplayercount > 0) ) {
841 yescount = realplayeryescount;
842 nocount = realplayernocount;
843 abstaincount = realplayerabstaincount;
844 playercount = realplayercount;
848 if((playercount == 1) && votecalledmaster) {
849 // if only one player is on the server becoming vote
850 // master is not allowed. This could be used for
851 // trolling or worse. 'self' is the user who has
852 // called the vote because this function is called
853 // by SV_ParseClientCommand. Maybe all voting should
854 // be disabled for a single player?
855 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
856 votecaller.vote_next = 0;
860 votefactor = bound(0.5, cvar("sv_vote_majority_factor"), 0.999);
861 if(yescount > (playercount - abstaincount) * votefactor)
863 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, -1);
866 else if(nocount >= (playercount - abstaincount) * (1 - votefactor)) // that means, yescount cannot reach minyes any more
868 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, -1);
871 else if(time > votefinished)
873 if(cvar("sv_vote_simple_majority"))
875 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor((yescount + nocount) * votefactor) + 1);
876 if(yescount > (yescount + nocount) * votefactor)
878 else if(yescount + nocount > 0)
885 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor((playercount - abstaincount) * votefactor) + 1);
893 * Counts how many players are ready. If not enough players are ready, the function
894 * does nothing. If all players are ready, the timelimit will be extended and the
895 * restart_countdown variable is set to allow other functions like PlayerPostThink
896 * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
897 * is not set the map will be resetted.
899 * Function is called after the server receives a 'ready' sign from a player.
906 FOR_EACH_REALPLAYER(e)
913 if(cvar("sv_ready_restart_nag")) {
914 if(!readyNagActive) {
915 readyNagger = spawn();
916 readyNagger.think = readyNagger_Think;
917 readyNagger.cnt = cvar("sv_ready_restart_nag_duration");
918 readyNagger.nextthink = time;
926 bprint("^1Server is restarting...\n");
928 // no arena, assault support yet...
929 if(g_arena | g_assault | gameover | intermission_running)
930 localcmd("restart\n");
932 if(readyNagActive) { //if every player is ready, remove the ready-nagger again
938 tourneyInMatchStage = 1; //once the game is restarted the game is in match stage
939 //reset weapons and ammo, health and armor to default:
940 start_items = IT_LASER | IT_SHOTGUN;
941 start_switchweapon = WEP_SHOTGUN;
942 start_ammo_shells = cvar("g_start_ammo_shells");
943 start_ammo_nails = cvar("g_start_ammo_nails");
944 start_ammo_rockets = cvar("g_start_ammo_rockets");
945 start_ammo_cells = cvar("g_start_ammo_cells");
946 start_health = cvar("g_balance_health_start");
947 start_armorvalue = cvar("g_balance_armor_start");
950 restart_countdown = time + RESTART_COUNTDOWN;
951 restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
952 //reset the .ready status of all players (also spectators)
957 if(0<cvar("timelimit") || (g_tourney && cvar("g_tourney_warmup_unlimited_time")) )
959 // remember original timelimit on first restart
961 timelimit_orig = cvar("timelimit");
962 //only set the new timelimit if, when loading the map, a timelimit was really set
964 cvar_set("timelimit", ftos(timelimit_orig + ceil(restart_countdown)/60));
966 if(cvar("teamplay_lockonrestart") && teams_matter) {
968 bprint("^1The teams are now locked.\n");
971 //initiate the restart-countdown-announcer entity
972 restartAnnouncer = spawn();
973 restartAnnouncer.think = restartAnnouncer_Think;
974 restartAnnouncer.nextthink = time;
975 restartAnnouncer.cnt = RESTART_COUNTDOWN;
977 //after a restart every players number of allowed timeouts gets reset, too
978 if(cvar("sv_timeout"))
980 FOR_EACH_REALPLAYER(e)
982 e.allowedTimeouts = cvar("sv_timeout_number");
986 //play the prepareforbattle sound to everyone
987 sound(world, CHAN_AUTO, "announcer/robotic/prepareforbattle.wav", 1, ATTN_NONE);
989 //reset map immediately if this cvar is not set
990 if (!cvar("sv_ready_restart_after_countdown"))
993 if(cvar("sv_eventlog"))
994 GameLogEcho(":restart", FALSE);
998 * Centerprints the information to all players who didn't ready up yet to do so.
1000 void readyNagger_Think() {
1002 if(self.cnt <= 0) { //have a break showing the ready nag
1003 //make sure that the old ready-nag-centerprint isn't shown too long:
1004 FOR_EACH_REALCLIENT(plr) {
1005 if(plr.classname == "player") {
1007 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
1010 self.cnt = cvar("sv_ready_restart_nag_duration");
1011 self.nextthink = time + cvar("sv_ready_restart_nag_interval");
1014 //show the ready nagging to all players who aren't ready yet
1015 FOR_EACH_REALCLIENT(plr) {
1016 if(plr.classname == "player") {
1018 centerprint_atprio(plr, CENTERPRIO_SPAM, "^2Please ready up (F4 by default)!");
1019 //play reminder sound once the centerprint appears for the first time after the pause:
1020 if (self.cnt == cvar("sv_ready_restart_nag_duration"))
1021 play2(plr, "misc/talk2.wav");
1026 self.nextthink = time + 1;
1032 * Shows the restart countdown for all players.
1033 * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
1034 * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
1037 void restartAnnouncer_Think() {
1040 if(self.cnt <= 0) { //show the "Begin" message and
1041 if (cvar("sv_ready_restart_after_countdown")) {
1042 restart_mapalreadyrestarted = 1;
1046 FOR_EACH_REALCLIENT(plr) {
1047 if(plr.classname == "player") {
1048 s = strcat(NEWLINES, "^1Begin!");
1049 centerprint(plr, s);
1052 sound(world, CHAN_AUTO, "announcer/robotic/begin.wav", 1, ATTN_NONE);
1058 FOR_EACH_REALCLIENT(plr) {
1059 if(plr.classname == "player") {
1060 s = strcat(NEWLINES, "^1Game starts in ", ftos(self.cnt), " seconds");
1061 centerprint(plr, s);
1066 sound(world, CHAN_AUTO, strcat("announcer/robotic/", ftos(self.cnt), ".ogg"), 1, ATTN_NONE);
1068 self.nextthink = time + 1;
1074 * Checks whether the player who calls the timeout is allowed to do so.
1075 * If so, it initializes the timeout countdown. It also checks whether another
1076 * timeout was already running at this time and reacts correspondingly.
1078 * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
1079 * timeoutInitiator, timeoutStatus, timeoutHandler
1081 * This function is called when a player issues the calltimeout command.
1083 void evaluateTimeoutCall() {
1084 if (g_tourney && !tourneyInMatchStage && !cvar("g_tourney_warmup_allow_timeout"))
1085 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
1086 if (time < restart_countdown )
1087 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
1088 if (timeoutStatus != 2) {
1089 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
1090 if (cvar("timelimit")) {
1091 //a timelimit was used
1093 if (cvar("timelimit"))
1094 myTl = cvar("timelimit");
1096 myTl = timelimit_orig;
1098 local float lastPossibleTimeout;
1099 lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
1101 if (lastPossibleTimeout < time)
1102 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
1105 //player may not call a timeout if he has no calls left
1106 if (self.allowedTimeouts < 1)
1107 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
1108 //now all required checks are passed
1109 self.allowedTimeouts -= 1;
1110 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)
1111 remainingTimeoutTime = cvar("sv_timeout_length");
1112 remainingLeadTime = cvar("sv_timeout_leadtime");
1113 timeoutInitiator = self;
1114 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
1116 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
1117 timeoutHandler = spawn();
1118 timeoutHandler.think = timeoutHandler_Think;
1120 timeoutHandler.nextthink = time; //always let the entity think asap
1122 //inform all connected clients about the timeout call
1123 sound(world, CHAN_AUTO, "announcer/robotic/timeoutcalled.wav", 1, ATTN_NONE);
1127 * Checks whether a player is allowed to resume the game. If he is allowed to do it,
1128 * and the lead time for the timeout is still active, this countdown just will be aborted (the
1129 * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
1130 * value of the cvar sv_timeout_resumetime.
1132 * This function is called when a player issues the resumegame command.
1134 void evaluateResumeGame() {
1136 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
1137 if (self != timeoutInitiator)
1138 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
1139 if (timeoutStatus == 1) {
1140 remainingTimeoutTime = timeoutStatus = 0;
1141 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
1142 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
1144 else if (timeoutStatus == 2) {
1145 //only shorten the remainingTimeoutTime if it makes sense
1146 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
1147 bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
1148 remainingTimeoutTime = cvar("sv_timeout_resumetime");
1149 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
1152 sprint(self, "^7Error: Your resumegame call was discarded!\n");