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