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