]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/clientcommands.qc
- changed sv_ready_restart to use a qc based restart function as suggested by nifrek...
[divverent/nexuiz.git] / data / qcsrc / server / clientcommands.qc
1 void ReadyCount();
2 string ValidateMap(string vote);
3 void(entity e) DropFlag;
4 string MapVote_Suggest(string m);
5
6 .float floodcontrol_chat;
7 .float floodcontrol_team;
8 void Say(entity source, float teamsay, string msgin)
9 {
10         string msgstr, colorstr, cmsgstr, namestr;
11         float flood;
12         entity head;
13
14         if(!teamsay)
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!)
17
18         msgin = formatmessage(msgin);
19
20         if(msgin == "")
21                 return;
22
23         colorstr = Team_ColorCode(source.team);
24
25         if(!teams_matter)
26                 teamsay = FALSE;
27
28         if(intermission_running)
29                 teamsay = FALSE;
30
31         if(source.classname != "player") // observers can't
32                 teamsay = FALSE;
33
34         /*
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
38         if(!teamsay)
39         {
40                 clientcommand(self, strcat("say ", msgin));
41                 return;
42         }
43         */
44
45         if(cvar("g_chat_teamcolors"))
46                 namestr = playername(source);
47         else
48                 namestr = source.netname;
49         if(teamsay)
50         {
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));
53         }
54         else
55                 msgstr = strzone(strcat("\{1}", namestr, "^7: ", msgin, "\n"));
56
57         // FLOOD CONTROL
58         flood = 0;
59         {
60                 float flood_spl;
61                 float flood_burst;
62                 float flood_lmax;
63                 var .float flood_field;
64                 float lines;
65                 if(teamsay)
66                 {
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;
71                 }
72                 else
73                 {
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;
78                 }
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)
83                         flood = 2;
84                 else if(time >= self.flood_field)
85                         self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
86                 else
87                         flood = 1;
88         }
89
90         if(flood)
91         {
92                 if(cvar("g_chat_flood_notify_flooder"))
93                 {
94                         if(flood == 1)
95                                 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
96                         else if(flood == 2)
97                                 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
98                 }
99                 else
100                         sprint(self, msgstr);
101                 ServerConsoleEcho(strcat("NOTE: ", playername(self), "^7 is flooding."), TRUE);
102         }
103         else if(teamsay)
104         {
105                 FOR_EACH_REALPLAYER(head)
106                 {
107                         if(head.team == source.team)
108                         {
109                                 sprint(head, msgstr);
110                                 centerprint(head, cmsgstr);
111                         }
112                 }
113         }
114         else
115         {
116                 bprint(msgstr);
117                 //ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
118         }
119
120         strunzone(msgstr);
121 }
122
123 string GetKickVoteVictim_newcommand;
124 entity GetKickVoteVictim(string vote, string cmd)
125 {
126         float tokens;
127         float i, n;
128         string ns;
129         entity e;
130
131         tokens = tokenize(vote);
132         ns = "";
133
134         if(tokens == 2)
135                 if(substring(argv(1), 0, 1) == "#")
136                         ns = substring(argv(1), 1, 999);
137         
138         if(tokens == 3)
139                 if(argv(1) == "#")
140                         ns = argv(2);
141
142         if(ns != "")
143         {
144                 n = stof(ns);
145                 if(ns == ftos(n)) if(n >= 1) if(n <= maxclients)
146                 {
147                         for((e = world), (i = 0); i < n; ++i, (e = nextent(e)))
148                                 ;
149                         if(clienttype(e) == CLIENTTYPE_REAL)
150                         {
151                                 GetKickVoteVictim_newcommand = strcat(argv(0), " # ", ns);
152                                 return e;
153                         }
154                 }
155         }
156
157         sprint(self, strcat("Usage: ", cmd, " ", argv(0), " #playernumber (as in \"status\")\n"));
158         return world;
159 }
160
161 void SV_ParseClientCommand(string s) {
162         local string cmd;
163         local entity e;
164
165         tokenize(s);
166
167         if(argv(0) == "vote") {
168                 if(argv(1) == "help") {
169                         local string vmasterdis;
170                         if(!cvar("sv_vote_master")) {
171                                 vmasterdis = " ^1(disabled)";
172                         }
173                         local string vcalldis;
174                         if(!cvar("sv_vote_call")) {
175                                 vcalldis = " ^1(disabled)";
176                         }
177                         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\".\n");
178                         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\".\n");
179                         sprint(self, "^7\"^2help^7\" shows this info.\n");
180                         sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
181                         sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
182                         sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
183                         sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
184                         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");
185                         sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
186                         sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
187                         sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
188                         sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
189                         sprint(self, "^7You can call a vote for or execute these commands:\n");
190                         sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
191                 } else if(argv(1) == "status") {
192                         if(votecalled) {
193                                 sprint(self, strcat("^7Vote for ", votecalledvote_display, "^7 called by ^7", votecaller.netname, "^7.\n"));
194                         } else {
195                                 sprint(self, "^1No vote called.\n");
196                         }
197                 } else if(argv(1) == "call") {
198                         if(cvar("sv_vote_call")) {
199                                 if(votecalled) {
200                                         sprint(self, "^1There is already a vote called.\n");
201                                 } else {
202                                         local string vote;
203                                         vote = VoteParse();
204                                         if(vote == "") {
205                                                 sprint(self, "^1Your vote is empty. See help for more info.\n");
206                                         } else if(time < self.vote_next) {
207                                                 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
208                                         } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
209                                                 // remap chmap to gotomap (forces intermission)
210                                                 if(substring(vote, 0, 6) == "chmap ")
211                                                         vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
212                                                 if(substring(vote, 0, 8) == "gotomap ")
213                                                 {
214                                                         if(!(vote = ValidateMap(substring(vote, 8, strlen(vote) - 8))))
215                                                                 return;
216                                                         vote = strcat("gotomap ", vote);
217                                                 }
218
219                                                 // make kick and kickban votes a bit nicer (and reject them if formatted badly)
220                                                 if(substring(vote, 0, 5) == "kick " || substring(vote, 0, 8) == "kickban ")
221                                                 {
222                                                         if(!(e = GetKickVoteVictim(vote, "vcall")))
223                                                                 return;
224                                                         votecalledvote_display = strzone(strcat("^1", vote, " (^7", e.netname, "^1)"));
225                                                         vote = GetKickVoteVictim_newcommand;
226                                                 }
227                                                 else
228                                                 {
229                                                         votecalledvote_display = strzone(strcat("^1", vote));
230                                                 }
231                                                 votecalledvote = strzone(vote);
232                                                 votecalled = TRUE;
233                                                 votecalledmaster = FALSE;
234                                                 votecaller = self; // remember who called the vote
235                                                 votefinished = time + cvar("sv_vote_timeout");
236                                                 votecaller.vote_vote = 1; // of course you vote yes
237                                                 votecaller.vote_next = time + cvar("sv_vote_wait");
238                                                 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ", votecalledvote_display, "\n");
239                                                 VoteCount(); // needed if you are the only one
240                                         } else {
241                                                 sprint(self, "^1This vote is not ok. See help for more info.\n");
242                                         }
243                                 }
244                         } else {
245                                 sprint(self, "^1Vote calling is NOT allowed.\n");
246                         }
247                 } else if(argv(1) == "stop") {
248                         if(!votecalled) {
249                                 sprint(self, "^1No vote called.\n");
250                         } else if(self == votecaller) { // the votecaller can stop a vote
251                                 VoteStop(self);
252                         } else if(self.vote_master) { // masters can, too
253                                 VoteStop(self);
254                         } else {
255                                 sprint(self, "^1You are not allowed to stop that Vote.\n");
256                         }
257                 } else if(argv(1) == "master") {
258                         if(cvar("sv_vote_master")) {
259                                 if(votecalled) {
260                                         sprint(self, "^1There is already a vote called.\n");
261                                 } else {
262                                         votecalled = TRUE;
263                                         votecalledmaster = TRUE;
264                                         votecalledvote = strzone("XXX");
265                                         votecalledvote_display = strzone("^3master");
266                                         votecaller = self; // remember who called the vote
267                                         votefinished = time + cvar("sv_vote_timeout");
268                                         votecaller.vote_vote = 1; // of course you vote yes
269                                         votecaller.vote_next = time + cvar("sv_vote_wait");
270                                         bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n");
271                                         VoteCount(); // needed if you are the only one
272                                 }
273                         } else {
274                                 sprint(self, "^1Vote to become master is NOT allowed.\n");
275                         }
276                 } else if(argv(1) == "do") {
277                         if(argv(2) == "login") {
278                                 local string masterpwd;
279                                 masterpwd = cvar_string("sv_vote_master_password");
280                                 if(masterpwd != "") {
281                                         self.vote_master = (masterpwd == argv(3));
282                                         if(self.vote_master) {
283                                                 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
284                                                 bprint("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n");
285                                         }
286                                         else
287                                                 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
288                                 }
289                                 else
290                                         sprint(self, "^1You are NOT a master.\n");
291                         } else if(self.vote_master) {
292                                 local string dovote, dovote_display;
293                                 dovote = VoteParse();
294                                 if(dovote == "") {
295                                         sprint(self, "^1Your command was empty. See help for more info.\n");
296                                 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
297                                         if(substring(dovote, 0, 6) == "chmap ")
298                                                 dovote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
299                                         if(substring(dovote, 0, 8) == "gotomap ")
300                                         {
301                                                 if(!(dovote = ValidateMap(substring(dovote, 8, strlen(dovote) - 8))))
302                                                         return;
303                                                 dovote = strcat("gotomap ", dovote);
304                                         }
305
306                                         dovote_display = dovote;
307                                         if(substring(dovote, 0, 5) == "kick " || substring(dovote, 0, 8) == "kickban ")
308                                         {
309                                                 if(!(e = GetKickVoteVictim(dovote, "vdo")))
310                                                         return;
311                                                 dovote_display = strzone(strcat("^1", dovote, " (^7", e.netname, "^1)"));
312                                                 dovote = GetKickVoteVictim_newcommand;
313                                         }
314                                         bprint("\{1}^2* ^3", self.netname, "^2 used his ^3master^2 status to do \"^2", dovote_display, "^2\".\n");
315                                         localcmd(strcat(dovote, "\n"));
316                                 } else {
317                                         sprint(self, "^1This command is not ok. See help for more info.\n");
318                                 }
319                         } else {
320                                 sprint(self, "^1You are NOT a master.\n");
321                         }
322                 } else if(argv(1) == "yes") {
323                         if(!votecalled) {
324                                 sprint(self, "^1No vote called.\n");
325                         } else if(self.vote_vote == 0
326                                   || cvar("sv_vote_change")) {
327                                 sprint(self, "^1You accepted the vote.\n");
328                                 self.vote_vote = 1;
329                                 if(!cvar("sv_vote_singlecount")) {
330                                         VoteCount();
331                                 }
332                         } else {
333                                 sprint(self, "^1You have already voted.\n");
334                         }
335                 } else if(argv(1) == "no") {
336                         if(!votecalled) {
337                                 sprint(self, "^1No vote called.\n");
338                         } else if(self.vote_vote == 0
339                                   || cvar("sv_vote_change")) {
340                                 sprint(self, "^1You rejected the vote.\n");
341                                 self.vote_vote = -1;
342                                 if(!cvar("sv_vote_singlecount")) {
343                                         VoteCount();
344                                 }
345                         } else {
346                                 sprint(self, "^1You have already voted.\n");
347                         }
348                 } else {
349                         // ignore this?
350                         sprint(self, "^1Unknown vote command.\n");
351                 }
352         } else if(argv(0) == "autoswitch") {
353                 // be backwards compatible with older clients (enabled)
354                 self.autoswitch = ("0" != argv(1));
355                 local string autoswitchmsg;
356                 if (self.autoswitch) {
357                         autoswitchmsg = "on";
358                 } else {
359                         autoswitchmsg = "off";
360                 }
361                 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
362         } else if(argv(0) == "clientversion") {
363                 if (argv(1) == "$gameversion") {
364                         //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
365                         // either that or someone wants to be funny
366                         self.version = 1;
367                 } else {
368                         self.version = stof(argv(1));
369                 }
370                 if(self.version != cvar("gameversion")) 
371                 {
372                         self.classname = "observer";
373                         self.frags = -2;
374                         PutClientInServer();
375                 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
376                         //JoinBestTeam(self, 0);
377                 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
378                         self.classname = "observer";
379                         stuffcmd(self,"menu_showteamselect\n");
380                 }
381         } else if(argv(0) == "reportcvar") { // old system
382                 GetCvars(1);
383         } else if(argv(0) == "sentcvar") { // new system
384                 GetCvars(1);
385         } else if(argv(0) == "spectate") {
386                 if(g_lms || g_arena)
387                         return; // don't allow spectating in lms, unless player runs out of lives
388                 if(self.classname == "player" && cvar("sv_spectate") == 1) {
389                         if(self.flagcarried)
390                                 DropFlag(self.flagcarried);
391                         kh_Key_DropAll(self, TRUE);
392                         WaypointSprite_PlayerDead();
393                         DistributeFragsAmongTeam(self, self.team, 1.0);
394                         self.classname = "observer";
395                         PutClientInServer();
396                 }
397         } else if(argv(0) == "join") {
398                 if(!g_arena)
399                 if (self.classname != "player")
400                 {
401                         self.classname = "player";
402                         self.frags = 0;
403                         bprint ("^4", self.netname, "^4 is playing now\n");
404                         PutClientInServer();
405                 }
406         } else if( argv(0) == "selectteam" ) {
407                 if( !cvar("teamplay") ) {
408                         sprint( self, "selecteam can only be used in teamgames\n");
409                 } else if(cvar("g_campaign")) {
410                         //JoinBestTeam(self, 0);
411                 } else if( argv(1) == "none" ) {
412                         SV_ChangeTeam( 0 );
413                 } else if( argv(1) == "red" ) {
414                         SV_ChangeTeam( COLOR_TEAM1 - 1 );
415                 } else if( argv(1) == "blue" ) {
416                         SV_ChangeTeam( COLOR_TEAM2 - 1 );
417                 } else if( argv(1) == "yellow" ) {
418                         SV_ChangeTeam( COLOR_TEAM3 - 1 );
419                 } else if( argv(1) == "pink" ) {
420                         SV_ChangeTeam( COLOR_TEAM4 - 1 );
421                 } else if( argv(1) == "auto" ) {
422                         self.team = -1;
423                         JoinBestTeam( self, 0 );
424                 } else {
425                         sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
426                 }
427         } else if(argv(0) == "ready") {
428                 if(cvar("sv_ready_restart"))
429                 {
430                         if(!restart_countdown)
431                         {
432                                 self.ready = TRUE;
433                                 bprint(self.netname, "^2 is ready\n");
434                                 ReadyCount();
435                         } else {
436                                 sprint(self, "^1game has already been restarted\n");
437                         }
438                 }
439         } else if(argv(0) == "maplist") {
440                 local float i, n;
441                 local string col;
442                 n = tokenize(cvar_string("g_maplist"));
443                 sprint(self, "^7Maps in list: ");
444                 for(i = 0; i < n; ++i)
445                 {
446                         if(math_mod(i, 2))
447                                 col = "^2";
448                         else
449                                 col = "^3";
450                         sprint(self, strcat(col, argv(i), " "));
451                 }
452                 sprint(self, "\n");
453         } else if(argv(0) == "teamstatus") {
454                 PrintScoreboard(self);
455         } else if(argv(0) == "say") {
456                 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
457                 //clientcommand(self, formatmessage(s));
458         } else if(argv(0) == "say_team") {
459                 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
460                 //clientcommand(self, formatmessage(s));
461         } else if(argv(0) == "info") {
462                 cmd = cvar_string(strcat("sv_info_", argv(1)));
463                 if(cmd == "")
464                         sprint(self, "ERROR: unsupported info command\n");
465                 else
466                         wordwrap_sprint(cmd, 1111);
467         } else if(argv(0) == "suggestmap") {
468                 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
469         } else {
470                 cmd = argv(0);
471                 /* checks not needed any more since DP has separated clientcommands and regular commands
472                 if(cmd != "status")
473                 if(cmd != "name")
474                 //if(cmd != "say") // handled above
475                 //if(cmd != "say_team") // handled above
476                 if(cmd != "tell")
477                 if(cmd != "color")
478                 if(cmd != "kill")
479                 if(cmd != "pause")
480                 if(cmd != "kick")
481                 if(cmd != "ping")
482                 if(cmd != "pings")
483                 if(cmd != "ban")
484                 if(cmd != "pmodel")
485                 if(cmd != "rate")
486                 if(cmd != "playermodel")
487                 if(cmd != "playerskin")
488                 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
489                 {
490                         ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
491                         return;
492                 }
493                 */
494                 clientcommand(self,s);
495         }
496 }
497
498 string ValidateMap(string m)
499 {
500 #ifdef MAPINFO
501         m = MapInfo_FixName(m);
502         if(!m)
503         {
504                 sprint(self, "This map is not available on this server.\n");
505                 return string_null;
506         }
507 #endif
508         if(!cvar("sv_vote_change_gametype"))
509                 if(!IsSameGametype(m))
510                 {
511                         sprint(self, "This server does not allow changing the game type by map votes.\n");
512                         return string_null;
513                 }
514         if(!cvar("sv_vote_override_mostrecent"))
515                 if(Map_IsRecent(m))
516                 {
517                         sprint(self, "This server does not allow for recent maps to be played again. Please be patient for some rounds.\n");
518                         return string_null;
519                 }
520 #ifdef MAPINFO
521         if(!MapInfo_CheckMap(m))
522         {
523                 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not support the current game mode.\n"));
524                 return string_null;
525         }
526 #else
527         if(!TryFile(strcat("maps/", m, ".mapcfg")))
528         {
529                 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not exist on this server.\n"));
530                 return string_null;
531         }
532 #endif
533
534         return m;
535 }
536
537
538 void VoteThink() {
539         if(votefinished > 0 // a vote was called
540             && time > votefinished) // time is up
541         {
542                 VoteCount();
543         }
544 }
545
546 string VoteParse() {
547         local float index;
548         index = 3;
549         local string vote;
550         vote = argv(2);
551         while(argv(index) != "") {
552                 vote = strcat(vote, " ", argv(index));
553                 index++;
554         }
555
556         // necessary for some of the string operations
557         vote = strzone(vote);
558
559         // now we remove some things that could be misused
560         index = 0;
561         local float found;
562         found = FALSE;
563         local float votelength;
564         votelength = strlen(vote);
565         while(!found && index < votelength)
566         {
567                 local string badchar;
568                 badchar = substring(vote, index, 1);
569                 if(badchar == ";"
570                    || badchar == "\r"
571                    || badchar == "\n")
572                 {
573                         found = TRUE;
574                 } else {
575                         index++;
576                 }
577         }
578         return substring(vote, 0, index);
579 }
580
581 float VoteAllowed(string votecommand) {
582         tokenize(cvar_string("sv_vote_commands"));
583         local float index;
584         index = 0;
585         while(argv(index) != "") {
586                 local string allowed;
587                 allowed = argv(index);
588                 if(votecommand == allowed) {
589                         return TRUE;
590                 }
591                 index++;
592         }
593         return FALSE;
594 }
595
596 void VoteReset() {
597         local entity player;
598
599         FOR_EACH_CLIENT(player)
600         {
601                 player.vote_vote = 0;
602                 centerprint_expire(player, CENTERPRIO_VOTE);
603         }
604
605         if(votecalled)
606         {
607                 strunzone(votecalledvote);
608                 strunzone(votecalledvote_display);
609         }
610
611         votecalled = FALSE;
612         votecalledmaster = FALSE;
613         votefinished = 0;
614 }
615
616 void VoteAccept() {
617         bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote_display, "^2 was accepted\n");
618         if(votecalledmaster)
619         {
620                 votecaller.vote_master = 1;
621         } else {
622                 localcmd(strcat(votecalledvote, "\n"));
623         }
624         votecaller.vote_next = 0; // people like your votes, no wait for next vote
625         VoteReset();
626 }
627
628 void VoteReject() {
629         bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 was rejected\n");
630         VoteReset();
631 }
632
633 void VoteTimeout() {
634         bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 timed out\n");
635         VoteReset();
636 }
637
638 void VoteStop(entity stopper) {
639         bprint("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n");
640         if(stopper == votecaller) {
641                 // no wait for next vote so you can correct your vote
642                 votecaller.vote_next = 0;
643         }
644         VoteReset();
645 }
646
647 void VoteNag() {
648         if(votecalled)
649                 if(self.vote_vote == 0)
650                         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."));
651 }
652
653 void VoteCount() {
654         local float playercount;
655         playercount = 0;
656         local float yescount;
657         yescount = 0;
658         local float nocount;
659         nocount = 0;
660         local entity player;
661
662         FOR_EACH_REALCLIENT(player)
663         {
664                 if(player.vote_vote < 0) {
665                         nocount++;
666                 } else if(player.vote_vote > 0) {
667                         yescount++;
668                 }
669                 playercount++;
670         }
671
672         if((playercount == 1) && votecalledmaster) {
673                 // if only one player is on the server becoming vote
674                 // master is not allowed.  This could be used for
675                 // trolling or worse. 'self' is the user who has
676                 // called the vote because this function is called
677                 // by SV_ParseClientCommand. Maybe all voting should
678                 // be disabled for a single player?
679                 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
680                 votecaller.vote_next = 0;
681                 VoteReset();
682         } else if((playercount / 2) < yescount) { // vote accepted
683                 VoteAccept();
684         } else if((playercount / 2) < nocount) { // vote rejected
685                 VoteReject();
686         } else if(time > votefinished) { // vote timedout
687                 if(cvar("sv_vote_simple_majority"))
688                         if(yescount > nocount)
689                                 VoteAccept();
690                         else if(nocount > yescount)
691                                 VoteReject();
692                         else
693                                 VoteTimeout();
694                 else
695                         VoteTimeout();
696         } // else still running
697 }
698
699 float timelimit_orig;
700
701 void ReadyCount()
702 {
703         local entity e;
704         local float r, p;
705
706         FOR_EACH_REALPLAYER(e)
707         {
708                 p += 1;
709                 if(e.ready)
710                         r += 1;
711         }
712
713         if(!p || r < p)
714                 return;
715
716         bprint("^1Server is restarting...\n");
717         
718         // no arena, assault & onslaught support yet...
719         if(g_arena | g_assault | g_onslaught | gameover | intermission_running)
720                 localcmd("restart\n");
721
722         restart_countdown = time + RESTART_COUNTDOWN;
723         if(0<cvar("timelimit"))
724         {
725                 // remember original timelimit on first restart
726                 if(!timelimit_orig)
727                         timelimit_orig = cvar("timelimit");
728                 cvar_set("timelimit", ftos(timelimit_orig + ceil(restart_countdown)/60));
729         }
730
731         reset_map();
732         
733         if(cvar("sv_eventlog"))
734                 GameLogEcho(":restart", FALSE);
735 }