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