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