]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/vote.qc
Merge remote branch 'origin/terencehill/physics_panel_update'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vote.qc
1 float VoteCheckNasty(string cmd)
2 {
3         if(strstrofs(cmd, ";", 0) >= 0)
4                 return TRUE;
5         if(strstrofs(cmd, "\n", 0) >= 0)
6                 return TRUE;
7         if(strstrofs(cmd, "\r", 0) >= 0)
8                 return TRUE;
9         if(strstrofs(cmd, "$", 0) >= 0)
10                 return TRUE;
11         return FALSE;
12 }
13
14 string GetKickVoteVictim_newcommand;
15 string GetKickVoteVictim_reason;
16
17 entity GetKickVoteVictim(string vote, string cmd, entity caller)
18 {
19         float tokens;
20         string ns;
21         entity e;
22         string reason;
23
24         tokens = tokenize_console(vote);
25         ns = "";
26
27         e = GetCommandPlayerSlotTargetFromTokenizedCommand(tokens, 1);
28         if(e)
29         {
30                 if(ParseCommandPlayerSlotTarget_firsttoken < tokens)
31                         GetKickVoteVictim_reason = substring(vote, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken));
32                 else
33                         GetKickVoteVictim_reason = "";
34
35                 reason = "";
36                 if(cmd != "vdo" || GetKickVoteVictim_reason == "")
37                         reason = "~"; // by convention, ~ prefixes a "unverified" kickban which will not be networked
38
39                 if(substring(GetKickVoteVictim_reason, 0, 1) == "~")
40                 {
41                         reason = "~";
42                         GetKickVoteVictim_reason = substring(GetKickVoteVictim_reason, 1, strlen(GetKickVoteVictim_reason) - 1);
43                 }
44
45                 if(caller)
46                         reason = strcat(reason, "player ", strdecolorize(caller.netname));
47                 else
48                         reason = strcat(reason, "console vote");
49                 if(GetKickVoteVictim_reason != "")
50                         reason = strcat(reason, ": ", strdecolorize(GetKickVoteVictim_reason));
51
52                 if not(cvar_value_issafe(reason))
53                         reason = uri_escape(reason);
54
55                 GetKickVoteVictim_newcommand = strcat(argv(0), " # ", ftos(num_for_edict(e)));
56                 if(argv(0) == "kickban")
57                 {
58                         GetKickVoteVictim_newcommand = strcat(GetKickVoteVictim_newcommand, " ", ftos(autocvar_g_ban_default_bantime), " ", ftos(autocvar_g_ban_default_masksize), " ", reason);
59                 }
60                 else if(argv(0) == "kick")
61                 {
62                         GetKickVoteVictim_newcommand = strcat(GetKickVoteVictim_newcommand, " ", reason);
63                 }
64                 return e;
65         }
66
67         print_to(caller, strcat("Usage: ", cmd, " ", argv(0), " #playernumber (as in \"status\")\n"));
68         return world;
69 }
70
71 string RemapVote_display;
72 string RemapVote_vote;
73 float RemapVote(string vote, string cmd, entity e)
74 {
75         float vote_argc;
76         entity victim;
77         vote_argc = tokenize_console(vote);
78
79         if(!VoteAllowed(argv(0), cmd))
80                 return FALSE;
81
82         // VoteAllowed tokenizes!
83         vote_argc = tokenize_console(vote);
84
85         // remap chmap to gotomap (forces intermission)
86         if(vote_argc < 2)
87                 if(argv(0) == "chmap" || argv(0) == "gotomap" || argv(0) == "kick" || argv(0) == "kickban") // won't work without arguments
88                         return FALSE;
89         if(argv(0) == "chmap")
90         {
91                 vote = strcat("gotomap ", substring(vote, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
92                 vote_argc = tokenize_console(vote);
93         }
94         if(argv(0) == "gotomap")
95         {
96                 if(!(vote = ValidateMap(substring(vote, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), e)))
97                         return FALSE;
98                 vote = strcat("gotomap ", vote);
99                 vote_argc = tokenize_console(vote); // ValidateMap may have done some stuff to it
100         }
101
102         // make kick and kickban votes a bit nicer (and reject them if formatted badly)
103         if(argv(0) == "kick" || argv(0) == "kickban")
104         {
105                 if(!(victim = GetKickVoteVictim(vote, cmd, e)))
106                         return FALSE;
107                 RemapVote_vote = GetKickVoteVictim_newcommand;
108                 RemapVote_display = strcat("^1", vote, " (^7", victim.netname, "^1): ", GetKickVoteVictim_reason);
109         }
110         else
111         {
112                 RemapVote_vote = vote;
113                 RemapVote_display = strzone(strcat("^1", vote));
114         }
115
116         return TRUE;
117 }
118
119 float GameCommand_Vote(string s, entity e) {
120         local float playercount;
121         float argc;
122         argc = tokenize_console(s);
123         if(argv(0) == "help") {
124                 print_to(e, "  vote COMMANDS ARGUMENTS. See 'vhelp' for more info.");
125                 return TRUE;
126         } else if(argv(0) == "vote") {
127                 if(argv(1) == "") {
128                         print_to(e, "^1You have to supply a vote command. See 'vhelp' for more info.");
129                 } else if(argv(1) == "help") {
130                         VoteHelp(e);
131                 } else if(argv(1) == "status") {
132                         if(votecalled) {
133                                 print_to(e, strcat("^7Vote for ", votecalledvote_display, "^7 called by ^7", VoteNetname(votecaller), "^7."));
134                         } else {
135                                 print_to(e, "^1No vote called.");
136                         }
137                 } else if(argv(1) == "call") {
138                         if(!e || autocvar_sv_vote_call) {
139                                 if(autocvar_sv_vote_nospectators && e && e.classname != "player") {
140                                         print_to(e, "^1Error: Only players can call a vote."); // TODO invent a cvar name for allowing votes by spectators during warmup anyway
141                                 }
142                                 else if(timeoutStatus) { //don't allow a vote call during a timeout
143                                         print_to(e, "^1Error: You can not call a vote while a timeout is active.");
144                                 }
145                                 else if(votecalled) {
146                                         print_to(e, "^1There is already a vote called.");
147                                 } else {
148                                         local string vote;
149                                         vote = VoteParse(s, argc);
150                                         if(vote == "") {
151                                                 print_to(e, "^1Your vote is empty. See 'vhelp' for more info.");
152                                         } else if(e
153                                                         && time < e.vote_next) {
154                                                 print_to(e, strcat("^1You have to wait ^2", ftos(ceil(e.vote_next - time)), "^1 seconds before you can again call a vote."));
155                                         } else if(VoteCheckNasty(vote)) {
156                                                 print_to(e, "Syntax error in command. See 'vhelp' for more info.");
157                                         } else if(RemapVote(vote, "vcall", e)) {
158                                                 votecalledvote = strzone(RemapVote_vote);
159                                                 votecalledvote_display = strzone(RemapVote_display);
160                                                 votecalled = TRUE;
161                                                 votecalledmaster = FALSE;
162                                                 votefinished = time + autocvar_sv_vote_timeout;
163                                                 votecaller = e; // remember who called the vote
164                                                 if(e) {
165                                                         e.vote_vote = 1; // of course you vote yes
166                                                         e.vote_next = time + autocvar_sv_vote_wait;
167                                                 }
168                                                 bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2 calls a vote for ", votecalledvote_display, "\n");
169                                                 if(autocvar_sv_eventlog)
170                                                         GameLogEcho(strcat(":vote:vcall:", ftos(votecaller.playerid), ":", votecalledvote_display));
171                                                 Nagger_VoteChanged();
172                                                 VoteCount(); // needed if you are the only one
173                                                 msg_entity = e;
174
175                                                 local entity player;
176                                                 FOR_EACH_REALCLIENT(player)
177                                                 {
178                                                         ++playercount;
179                                                 }
180                                                 if(playercount > 1) // don't announce a "vote now" sound if player is alone
181                                                         Announce("votecall");
182                                         } else {
183                                                 print_to(e, "^1This vote is not ok. See 'vhelp' for more info.");
184                                         }
185                                 }
186                         } else {
187                                 print_to(e, "^1Vote calling is NOT allowed.");
188                         }
189                 } else if(argv(1) == "stop") {
190                         if(!votecalled) {
191                                 print_to(e, "^1No vote called.");
192                         } else if(e == votecaller) { // the votecaller can stop a vote
193                                 VoteStop(e);
194                         } else if(!e) { // server admin / console can too
195                                 VoteStop(e);
196                         } else if(e.vote_master) { // masters can too
197                                 VoteStop(e);
198                         } else {
199                                 print_to(e, "^1You are not allowed to stop that Vote.");
200                         }
201                 } else if(argv(1) == "master") {
202                         if(autocvar_sv_vote_master) {
203                                 if(votecalled) {
204                                         print_to(e, "^1There is already a vote called.");
205                                 } else {
206                                         votecalled = TRUE;
207                                         votecalledmaster = TRUE;
208                                         votecalledvote = strzone("XXX");
209                                         votecalledvote_display = strzone("^3master");
210                                         votefinished = time + autocvar_sv_vote_timeout;
211                                         votecaller = e; // remember who called the vote
212                                         if(e) {
213                                                 e.vote_vote = 1; // of course you vote yes
214                                                 e.vote_next = time + autocvar_sv_vote_wait;
215                                         }
216                                         bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2 calls a vote to become ^3master^2.\n");
217                                         if(autocvar_sv_eventlog)
218                                                 GameLogEcho(strcat(":vote:vcall:", ftos(votecaller.playerid), ":", votecalledvote_display));
219                                         Nagger_VoteChanged();
220                                         VoteCount(); // needed if you are the only one
221                                 }
222                         } else {
223                                 print_to(e, "^1Vote to become master is NOT allowed.");
224                         }
225                 } else if(argv(1) == "do") {
226                         if(!e || e.vote_master) {
227                                 local string dovote;
228                                 dovote = VoteParse(s, argc);
229                                 if(dovote == "") {
230                                         print_to(e, "^1Your command was empty. See 'vhelp' for more info.");
231                                 } else if(VoteCheckNasty(dovote)) {
232                                         print_to(e, "Syntax error in command. See 'vhelp' for more info.");
233                                 } else if(RemapVote(dovote, "vdo", e)) { // strcat seems to be necessary
234                                         bprint("\{1}^2* ^3", VoteNetname(e), "^2 used their ^3master^2 status to do \"^2", RemapVote_display, "^2\".\n");
235                                         if(autocvar_sv_eventlog)
236                                                 GameLogEcho(strcat(":vote:vdo:", ftos(e.playerid), ":", RemapVote_display));
237                                         localcmd(strcat(RemapVote_vote, "\n"));
238                                 } else {
239                                         print_to(e, "^1This command is not ok. See 'vhelp' for more info.");
240                                 }
241                         } else {
242                                 print_to(e, "^1You are NOT a master.  You might need to login or vote to become master first. See 'vhelp' for more info.");
243                         }
244                 } else if(argv(1) == "login") {
245                         local string masterpwd;
246                         masterpwd = autocvar_sv_vote_master_password;
247                         if(masterpwd != "") {
248                                 local float granted;
249                                 granted = (masterpwd == argv(2));
250                                 if (e)
251                                         e.vote_master = granted;
252                                 if(granted) {
253                                         print("Accepted master login from ", VoteNetname(e), "\n");
254                                         bprint("\{1}^2* ^3", VoteNetname(e), "^2 logged in as ^3master^2\n");
255                                         if(autocvar_sv_eventlog)
256                                                 GameLogEcho(strcat(":vote:vlogin:", ftos(e.playerid)));
257                                 }
258                                 else
259                                         print("REJECTED master login from ", VoteNetname(e), "\n");
260                         }
261                         else
262                                 print_to(e, "^1Login to become master is NOT allowed.");
263                 } else if(argv(1) == "yes") {
264                         if(!votecalled) {
265                                 print_to(e, "^1No vote called.");
266                         } else if (!e) {
267                                 print_to(e, "^1You can't vote from the server console.");
268                         } else if(e.vote_vote == 0
269                                   || autocvar_sv_vote_change) {
270                                 msg_entity = e;
271                                 print_to(e, "^1You accepted the vote.");
272                                 e.vote_vote = 1;
273                                 centerprint_expire(e, CENTERPRIO_VOTE);
274                                 if(!autocvar_sv_vote_singlecount) {
275                                         VoteCount();
276                                 }
277                         } else {
278                                 print_to(e, "^1You have already voted.");
279                         }
280                 } else if(argv(1) == "no") {
281                         if(!votecalled) {
282                                 print_to(e, "^1No vote called.");
283                         } else if (!e) {
284                                 print_to(e, "^1You can't vote from the server console.");
285                         } else if(e.vote_vote == 0
286                                   || autocvar_sv_vote_change) {
287                                 msg_entity = e;
288                                 print_to(e, "^1You rejected the vote.");
289                                 e.vote_vote = -1;
290                                 centerprint_expire(e, CENTERPRIO_VOTE);
291                                 if(!autocvar_sv_vote_singlecount) {
292                                         VoteCount();
293                                 }
294                         } else {
295                                 print_to(e, "^1You have already voted.");
296                         }
297                 } else if(argv(1) == "abstain" || argv(1) == "dontcare") {
298                         if(!votecalled) {
299                                 print_to(e, "^1No vote called.");
300                         } else if (!e) {
301                                 print_to(e, "^1You can't vote from the server console.");
302                         } else if(e.vote_vote == 0
303                                   || autocvar_sv_vote_change) {
304                                 msg_entity = e;
305                                 print_to(e, "^1You abstained from your vote.");
306                                 e.vote_vote = -2;
307                                 centerprint_expire(e, CENTERPRIO_VOTE);
308                                 if(!autocvar_sv_vote_singlecount) {
309                                         VoteCount();
310                                 }
311                         } else {
312                                 print_to(e, "^1You have already voted.");
313                         }
314                 } else {
315                         // ignore this?
316                         print_to(e, "^1Unknown vote command.");
317                 }
318                 return TRUE;
319         }
320         return FALSE;
321 }
322
323 void VoteHelp(entity e) {
324         local string vmasterdis;
325         if(!autocvar_sv_vote_master) {
326                 vmasterdis = " ^1(disabled)";
327         }
328
329         local string vlogindis;
330         if("" == autocvar_sv_vote_master_password) {
331                 vlogindis = " ^1(disabled)";
332         }
333
334         local string vcalldis;
335         if(!autocvar_sv_vote_call) {
336                 vcalldis = " ^1(disabled)";
337         }
338
339         print_to(e, "^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 login^7\" \"^2cmd vote do ^3COMMAND ARGUMENTS^7\" \"^2cmd vote yes^7\" \"^2cmd vote no^7\" \"^2cmd vote abstain^7\" \"^2cmd vote dontcare^7\".");
340         print_to(e, "^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\" \"^2vlogin^7\" \"^2vdo ^3COMMAND ARGUMENTS^7\" \"^2vyes^7\" \"^2vno^7\" \"^2abstain^7\" \"^2vdontcare^7\".");
341         print_to(e, "^7\"^2help^7\" shows this info.");
342         print_to(e, "^7\"^2status^7\" shows if there is a vote called and who called it.");
343         print_to(e, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7"));
344         print_to(e, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.");
345         print_to(e, strcat("^7\"^2master^7\" call a vote to become master who can execute commands without a vote", vmasterdis, "^7"));
346         print_to(e, strcat("^7\"^2login^7\" login to become master who can execute commands without a vote.", vlogindis, "^7"));
347         print_to(e, "^7\"^2do^7\" executes a command if you are a master. See the list of allowed commands.");
348         print_to(e, "^7\"^2yes^7\", \"^2no^7\", \"^2abstain^7\" and \"^2dontcare^7\" to make your vote.");
349         print_to(e, "^7If enough of the players vote yes the vote is accepted.");
350         print_to(e, "^7If enough of the players vote no the vote is rejected.");
351         print_to(e, strcat("^7If neither the vote will timeout after ", ftos(autocvar_sv_vote_timeout), "^7 seconds."));
352         print_to(e, "^7You can call a vote for or execute these commands:");
353         print_to(e, strcat("^3", autocvar_sv_vote_commands, "^7 and maybe further ^3arguments^7"));
354 }
355
356 string VoteNetname(entity e)
357 {
358         if(e) {
359                 return e.netname;
360         } else {
361                 if(autocvar_sv_adminnick != "") {
362                         return autocvar_sv_adminnick;
363                 } else {
364                         return autocvar_hostname;
365                 }
366         }
367 }
368
369 string ValidateMap(string m, entity e)
370 {
371         m = MapInfo_FixName(m);
372         if(!m)
373         {
374                 print_to(e, "This map is not available on this server.");
375                 return string_null;
376         }
377         if(!autocvar_sv_vote_override_mostrecent)
378                 if(Map_IsRecent(m))
379                 {
380                         print_to(e, "This server does not allow for recent maps to be played again. Please be patient for some rounds.");
381                         return string_null;
382                 }
383         if(!MapInfo_CheckMap(m))
384         {
385                 print_to(e, strcat("^1Invalid mapname, \"^3", m, "^1\" does not support the current game mode."));
386                 return string_null;
387         }
388
389         return m;
390 }
391
392
393 void VoteThink() {
394         if(votefinished > 0) // a vote was called
395         if(time > votefinished) // time is up
396         {
397                 VoteCount();
398         }
399 }
400
401 string VoteParse(string all, float argc) {
402         if(argc < 3)
403                 return "";
404         return substring(all, argv_start_index(2), argv_end_index(-1) - argv_start_index(2));
405 }
406
407 float VoteCommandInList(string votecommand, string list)
408 {
409         string l;
410         l = strcat(" ", list, " ");
411         
412         if(strstrofs(l, strcat(" ", votecommand, " "), 0) >= 0)
413                 return TRUE;
414         
415         // if gotomap is allowed, chmap is too, and vice versa
416         if(votecommand == "gotomap")
417                 if(strstrofs(l, " chmap ", 0) >= 0)
418                         return TRUE;
419         if(votecommand == "chmap")
420                 if(strstrofs(l, " gotomap ", 0) >= 0)
421                         return TRUE;
422         
423         return FALSE;
424 }
425
426 float VoteAllowed(string votecommand, string cmd) {
427         if(VoteCommandInList(votecommand, autocvar_sv_vote_commands))
428                 return TRUE;
429
430         if(cmd == "vdo")
431         {
432                 if(VoteCommandInList(votecommand, autocvar_sv_vote_master_commands))
433                         return TRUE;
434         }
435         else
436         {
437                 if(VoteCommandInList(votecommand, autocvar_sv_vote_only_commands))
438                         return TRUE;
439         }
440
441         return FALSE;
442 }
443
444 void VoteReset() {
445         local entity player;
446
447         FOR_EACH_CLIENT(player)
448         {
449                 player.vote_vote = 0;
450                 centerprint_expire(player, CENTERPRIO_VOTE);
451         }
452
453         if(votecalled)
454         {
455                 strunzone(votecalledvote);
456                 strunzone(votecalledvote_display);
457         }
458
459         votecalled = FALSE;
460         votecalledmaster = FALSE;
461         votefinished = 0;
462         votecalledvote = string_null;
463         votecalledvote_display = string_null;
464 }
465
466 void VoteAccept() {
467         bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2's vote for ^1", votecalledvote_display, "^2 was accepted\n");
468         if(votecalledmaster)
469         {
470                 if(votecaller) {
471                         votecaller.vote_master = 1;
472                 }
473         } else {
474                 localcmd(strcat(votecalledvote, "\n"));
475         }
476         if(votecaller) {
477                 votecaller.vote_next = 0; // people like your votes,
478                                           // no wait for next vote
479         }
480         VoteReset();
481         Announce("voteaccept");
482 }
483
484 void VoteReject() {
485         bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2's vote for ", votecalledvote_display, "^2 was rejected\n");
486         VoteReset();
487         Announce("votefail");
488 }
489
490 void VoteTimeout() {
491         bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2's vote for ", votecalledvote_display, "^2 timed out\n");
492         VoteReset();
493         Announce("votefail");
494 }
495
496 void VoteStop(entity stopper) {
497         bprint("\{1}^2* ^3", VoteNetname(stopper), "^2 stopped ^3", VoteNetname(votecaller), "^2's vote\n");
498         if(autocvar_sv_eventlog)
499                 GameLogEcho(strcat(":vote:vstop:", ftos(stopper.playerid)));
500         if(stopper == votecaller) {
501                 // no wait for next vote so you can correct your vote
502                 if(votecaller) {
503                         votecaller.vote_next = time + autocvar_sv_vote_stop;
504                 }
505         }
506         VoteReset();
507 }
508
509 void VoteSpam(float notvoters, float mincount, string result)
510 {
511         string s;
512         if(mincount >= 0)
513         {
514                 s = strcat("\{1}^2* vote results: ^1", ftos(vote_yescount), "^2:^1");
515                 s = strcat(s, ftos(vote_nocount), "^2 (^1");
516                 s = strcat(s, ftos(mincount), "^2 needed), ^1");
517                 s = strcat(s, ftos(vote_abstaincount), "^2 didn't care, ^1");
518                 s = strcat(s, ftos(notvoters), "^2 didn't vote\n");
519         }
520         else
521         {
522                 s = strcat("\{1}^2* vote results: ^1", ftos(vote_yescount), "^2:^1");
523                 s = strcat(s, ftos(vote_nocount), "^2, ^1");
524                 s = strcat(s, ftos(vote_abstaincount), "^2 didn't care, ^1");
525                 s = strcat(s, ftos(notvoters), "^2 didn't have to vote\n");
526         }
527         bprint(s);
528         if(autocvar_sv_eventlog)
529         {
530                 s = strcat(":vote:v", result, ":", ftos(vote_yescount));
531                 s = strcat(s, ":", ftos(vote_nocount));
532                 s = strcat(s, ":", ftos(vote_abstaincount));
533                 s = strcat(s, ":", ftos(notvoters));
534                 s = strcat(s, ":", ftos(mincount));
535                 GameLogEcho(s);
536         }
537 }
538
539 void VoteCount() {
540         local float playercount;
541         playercount = 0;
542         vote_yescount = 0;
543         vote_nocount = 0;
544         vote_abstaincount = 0;
545         local entity player;
546         //same for real players
547         local float realplayercount;
548         local float realplayeryescount;
549         local float realplayernocount;
550         local float realplayerabstaincount;
551         realplayercount = realplayernocount = realplayerabstaincount = realplayeryescount = 0;
552
553         Nagger_VoteCountChanged();
554
555         FOR_EACH_REALCLIENT(player)
556         {
557                 if(player.vote_vote == -1) {
558                         ++vote_nocount;
559                 } else if(player.vote_vote == 1) {
560                         ++vote_yescount;
561                 } else if(player.vote_vote == -2) {
562                         ++vote_abstaincount;
563                 }
564                 ++playercount;
565                 //do the same for real players
566                 if(player.classname == "player") {
567                         if(player.vote_vote == -1) {
568                                 ++realplayernocount;
569                         } else if(player.vote_vote == 1) {
570                                 ++realplayeryescount;
571                         } else if(player.vote_vote == -2) {
572                                 ++realplayerabstaincount;
573                         }
574                         ++realplayercount;
575                 }
576         }
577
578         //in tournament mode, if we have at least one player then don't make the vote dependent on spectators (so specs don't have to press F1)
579         if(autocvar_sv_vote_nospectators)
580         if(realplayercount > 0) {
581                 vote_yescount = realplayeryescount;
582                 vote_nocount = realplayernocount;
583                 vote_abstaincount = realplayerabstaincount;
584                 playercount = realplayercount;
585         }
586
587         float votefactor, simplevotefactor;
588         votefactor = bound(0.5, autocvar_sv_vote_majority_factor, 0.999);
589         simplevotefactor = autocvar_sv_vote_simple_majority_factor;
590
591         // FIXME this number is a guess
592         vote_needed_absolute = floor((playercount - vote_abstaincount) * votefactor) + 1;
593         if(simplevotefactor)
594         {
595                 simplevotefactor = bound(votefactor, simplevotefactor, 0.999);
596                 vote_needed_simple = floor((vote_yescount + vote_nocount) * simplevotefactor) + 1;
597         }
598         else
599                 vote_needed_simple = 0;
600
601         if(votecalledmaster
602            && playercount == 1) {
603                 // if only one player is on the server becoming vote
604                 // master is not allowed.  This could be used for
605                 // trolling or worse. 'self' is the user who has
606                 // called the vote because this function is called
607                 // by SV_ParseClientCommand. Maybe all voting should
608                 // be disabled for a single player?
609                 print_to(votecaller, "^1You are the only player on this server so you can not become vote master.");
610                 if(votecaller) {
611                         votecaller.vote_next = 0;
612                 }
613                 VoteReset();
614         } else {
615                 if(vote_yescount >= vote_needed_absolute)
616                 {
617                         VoteSpam(playercount - vote_yescount - vote_nocount - vote_abstaincount, -1, "yes");
618                         VoteAccept();
619                 }
620                 else if(vote_nocount > playercount - vote_abstaincount - vote_needed_absolute) // that means, vote_yescount cannot reach vote_needed_absolute any more
621                 {
622                         VoteSpam(playercount - vote_yescount - vote_nocount - vote_abstaincount, -1, "no");
623                         VoteReject();
624                 }
625                 else if(time > votefinished)
626                 {
627                         if(simplevotefactor)
628                         {
629                                 string result;
630                                 if(vote_yescount >= vote_needed_simple)
631                                         result = "yes";
632                                 else if(vote_yescount + vote_nocount > 0)
633                                         result = "no";
634                                 else
635                                         result = "timeout";
636                                 VoteSpam(playercount - vote_yescount - vote_nocount - vote_abstaincount, min(vote_needed_absolute, vote_needed_simple), result);
637                                 if(result == "yes")
638                                         VoteAccept();
639                                 else if(result == "no")
640                                         VoteReject();
641                                 else
642                                         VoteTimeout();
643                         }
644                         else
645                         {
646                                 VoteSpam(playercount - vote_yescount - vote_nocount - vote_abstaincount, vote_needed_absolute, "timeout");
647                                 VoteTimeout();
648                         }
649                 }
650         }
651 }