]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/vote.qc
Merge remote branch 'remotes/origin/terencehill/newpanelhud' into terencehill/newpanelhud
[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, " ", cvar_string("g_ban_default_bantime"), " ", cvar_string("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 void VoteDialog_UpdateHighlight(float selected) {
120         WriteByte(MSG_ONE, SVC_TEMPENTITY);
121         WriteByte(MSG_ONE, TE_CSQC_VOTE);
122         WriteByte(MSG_ONE, 1);
123         WriteByte(MSG_ONE, selected);
124 }
125
126 void VoteDialog_Reset() {
127         WriteByte(MSG_ALL, SVC_TEMPENTITY);
128         WriteByte(MSG_ALL, TE_CSQC_VOTERESET);
129 }
130
131 float GameCommand_Vote(string s, entity e) {
132         float argc;
133         argc = tokenize_console(s);
134         if(argv(0) == "help") {
135                 print_to(e, "  vote COMMANDS ARGUMENTS. See 'vhelp' for more info.");
136                 return TRUE;
137         } else if(argv(0) == "vote") {
138                 if(argv(1) == "") {
139                         print_to(e, "^1You have to supply a vote command. See 'vhelp' for more info.");
140                 } else if(argv(1) == "help") {
141                         VoteHelp(e);
142                 } else if(argv(1) == "status") {
143                         if(votecalled) {
144                                 print_to(e, strcat("^7Vote for ", votecalledvote_display, "^7 called by ^7", VoteNetname(votecaller), "^7."));
145                         } else {
146                                 print_to(e, "^1No vote called.");
147                         }
148                 } else if(argv(1) == "call") {
149                         if(!e || cvar("sv_vote_call")) {
150                                 if(cvar("sv_vote_nospectators") && e && e.classname != "player") {
151                                         print_to(e, "^1Error: Only players can call a vote."); // TODO invent a cvar name for allowing votes by spectators during warmup anyway
152                                 }
153                                 else if(timeoutStatus) { //don't allow a vote call during a timeout
154                                         print_to(e, "^1Error: You can not call a vote while a timeout is active.");
155                                 }
156                                 else if(votecalled) {
157                                         print_to(e, "^1There is already a vote called.");
158                                 } else {
159                                         local string vote;
160                                         vote = VoteParse(s, argc);
161                                         if(vote == "") {
162                                                 print_to(e, "^1Your vote is empty. See 'vhelp' for more info.");
163                                         } else if(e
164                                                 && time < e.vote_next) {
165                                                         print_to(e, strcat("^1You have to wait ^2", ftos(ceil(e.vote_next - time)), "^1 seconds before you can again call a vote."));
166                                         } else if(VoteCheckNasty(vote)) {
167                                                 print_to(e, "Syntax error in command. See 'vhelp' for more info.");
168                                         } else if(RemapVote(vote, "vcall", e)) {
169                                                 votecalledvote = strzone(RemapVote_vote);
170                                                 votecalledvote_display = strzone(RemapVote_display);
171                                                 votecalled = TRUE;
172                                                 votecalledmaster = FALSE;
173                                                 votefinished = time + cvar("sv_vote_timeout");
174                                                 votecaller = e; // remember who called the vote
175                                                 if(e) {
176                                                         e.vote_vote = 1; // of course you vote yes
177                                                         e.vote_next = time + cvar("sv_vote_wait");
178                                                 }
179                                                 bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2 calls a vote for ", votecalledvote_display, "\n");
180                                                 if(cvar("sv_eventlog"))
181                                                         GameLogEcho(strcat(":vote:vcall:", ftos(votecaller.playerid), ":", votecalledvote_display));
182                                                 VoteCount(); // needed if you are the only one
183                                                 Nagger_VoteChanged();
184                                                 msg_entity = e;
185                                                 VoteDialog_UpdateHighlight(1);
186                                         } else {
187                                                 print_to(e, "^1This vote is not ok. See 'vhelp' for more info.");
188                                         }
189                                 }
190                         } else {
191                                 print_to(e, "^1Vote calling is NOT allowed.");
192                         }
193                 } else if(argv(1) == "stop") {
194                         if(!votecalled) {
195                                 print_to(e, "^1No vote called.");
196                         } else if(e == votecaller) { // the votecaller can stop a vote
197                                 VoteDialog_Reset();
198                                 VoteStop(e);
199                         } else if(!e) { // server admin / console can too
200                                 VoteDialog_Reset();
201                                 VoteStop(e);
202                         } else if(e.vote_master) { // masters can too
203                                 VoteDialog_Reset();
204                                 VoteStop(e);
205                         } else {
206                                 print_to(e, "^1You are not allowed to stop that Vote.");
207                         }
208                 } else if(argv(1) == "master") {
209                         if(cvar("sv_vote_master")) {
210                                 if(votecalled) {
211                                         print_to(e, "^1There is already a vote called.");
212                                 } else {
213                                         votecalled = TRUE;
214                                         votecalledmaster = TRUE;
215                                         votecalledvote = strzone("XXX");
216                                         votecalledvote_display = strzone("^3master");
217                                         votefinished = time + cvar("sv_vote_timeout");
218                                         votecaller = e; // remember who called the vote
219                                         if(e) {
220                                                 e.vote_vote = 1; // of course you vote yes
221                                                 e.vote_next = time + cvar("sv_vote_wait");
222                                         }
223                                         bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2 calls a vote to become ^3master^2.\n");
224                                         if(cvar("sv_eventlog"))
225                                                 GameLogEcho(strcat(":vote:vcall:", ftos(votecaller.playerid), ":", votecalledvote_display));
226                                         VoteCount(); // needed if you are the only one
227                                         Nagger_VoteChanged();
228                                 }
229                         } else {
230                                 print_to(e, "^1Vote to become master is NOT allowed.");
231                         }
232                 } else if(argv(1) == "do") {
233                         if(!e || e.vote_master) {
234                                 local string dovote;
235                                 dovote = VoteParse(s, argc);
236                                 if(dovote == "") {
237                                         print_to(e, "^1Your command was empty. See 'vhelp' for more info.");
238                                 } else if(VoteCheckNasty(dovote)) {
239                                         print_to(e, "Syntax error in command. See 'vhelp' for more info.");
240                                 } else if(RemapVote(dovote, "vdo", e)) { // strcat seems to be necessary
241                                         bprint("\{1}^2* ^3", VoteNetname(e), "^2 used their ^3master^2 status to do \"^2", RemapVote_display, "^2\".\n");
242                                         if(cvar("sv_eventlog"))
243                                                 GameLogEcho(strcat(":vote:vdo:", ftos(e.playerid), ":", RemapVote_display));
244                                         localcmd(strcat(RemapVote_vote, "\n"));
245                                 } else {
246                                         print_to(e, "^1This command is not ok. See 'vhelp' for more info.");
247                                 }
248                         } else {
249                                 print_to(e, "^1You are NOT a master.  You might need to login or vote to become master first. See 'vhelp' for more info.");
250                         }
251                 } else if(argv(1) == "login") {
252                         local string masterpwd;
253                         masterpwd = cvar_string("sv_vote_master_password");
254                         if(masterpwd != "") {
255                                 local float granted;
256                                 granted = (masterpwd == argv(2));
257                                 if (e)
258                                         e.vote_master = granted;
259                                 if(granted) {
260                                         print("Accepted master login from ", VoteNetname(e), "\n");
261                                         bprint("\{1}^2* ^3", VoteNetname(e), "^2 logged in as ^3master^2\n");
262                                         if(cvar("sv_eventlog"))
263                                                 GameLogEcho(strcat(":vote:vlogin:", ftos(e.playerid)));
264                                 }
265                                 else
266                                         print("REJECTED master login from ", VoteNetname(e), "\n");
267                         }
268                         else
269                                 print_to(e, "^1Login to become master is NOT allowed.");
270                 } else if(argv(1) == "yes") {
271                         if(!votecalled) {
272                                 print_to(e, "^1No vote called.");
273                         } else if (!e) {
274                                 print_to(e, "^1You can't vote from the server console.");
275                         } else if(e.vote_vote == 0
276                                   || cvar("sv_vote_change")) {
277                                 msg_entity = e;
278                                 VoteDialog_UpdateHighlight(1);
279                                 print_to(e, "^1You accepted the vote.");
280                                 e.vote_vote = 1;
281                                 centerprint_expire(e, CENTERPRIO_VOTE);
282                                 if(!cvar("sv_vote_singlecount")) {
283                                         VoteCount();
284                                 }
285                         } else {
286                                 print_to(e, "^1You have already voted.");
287                         }
288                 } else if(argv(1) == "no") {
289                         if(!votecalled) {
290                                 print_to(e, "^1No vote called.");
291                         } else if (!e) {
292                                 print_to(e, "^1You can't vote from the server console.");
293                         } else if(e.vote_vote == 0
294                                   || cvar("sv_vote_change")) {
295                                 msg_entity = e;
296                                 VoteDialog_UpdateHighlight(2);
297                                 print_to(e, "^1You rejected the vote.");
298                                 e.vote_vote = -1;
299                                 centerprint_expire(e, CENTERPRIO_VOTE);
300                                 if(!cvar("sv_vote_singlecount")) {
301                                         VoteCount();
302                                 }
303                         } else {
304                                 print_to(e, "^1You have already voted.");
305                         }
306                 } else if(argv(1) == "abstain" || argv(1) == "dontcare") {
307                         if(!votecalled) {
308                                 print_to(e, "^1No vote called.");
309                         } else if (!e) {
310                                 print_to(e, "^1You can't vote from the server console.");
311                         } else if(e.vote_vote == 0
312                                   || cvar("sv_vote_change")) {
313                                 msg_entity = e;
314                                 VoteDialog_UpdateHighlight(3);
315                                 print_to(e, "^1You abstained from your vote.");
316                                 e.vote_vote = -2;
317                                 centerprint_expire(e, CENTERPRIO_VOTE);
318                                 if(!cvar("sv_vote_singlecount")) {
319                                         VoteCount();
320                                 }
321                         } else {
322                                 print_to(e, "^1You have already voted.");
323                         }
324                 } else {
325                         // ignore this?
326                         print_to(e, "^1Unknown vote command.");
327                 }
328                 return TRUE;
329         }
330         return FALSE;
331 }
332
333 void VoteHelp(entity e) {
334         local string vmasterdis;
335         if(!cvar("sv_vote_master")) {
336                 vmasterdis = " ^1(disabled)";
337         }
338
339         local string vlogindis;
340         if("" == cvar_string("sv_vote_master_password")) {
341                 vlogindis = " ^1(disabled)";
342         }
343
344         local string vcalldis;
345         if(!cvar("sv_vote_call")) {
346                 vcalldis = " ^1(disabled)";
347         }
348
349         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\".");
350         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\".");
351         print_to(e, "^7\"^2help^7\" shows this info.");
352         print_to(e, "^7\"^2status^7\" shows if there is a vote called and who called it.");
353         print_to(e, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7"));
354         print_to(e, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.");
355         print_to(e, strcat("^7\"^2master^7\" call a vote to become master who can execute commands without a vote", vmasterdis, "^7"));
356         print_to(e, strcat("^7\"^2login^7\" login to become master who can execute commands without a vote.", vlogindis, "^7"));
357         print_to(e, "^7\"^2do^7\" executes a command if you are a master. See the list of allowed commands.");
358         print_to(e, "^7\"^2yes^7\", \"^2no^7\", \"^2abstain^7\" and \"^2dontcare^7\" to make your vote.");
359         print_to(e, "^7If enough of the players vote yes the vote is accepted.");
360         print_to(e, "^7If enough of the players vote no the vote is rejected.");
361         print_to(e, strcat("^7If neither the vote will timeout after ", cvar_string("sv_vote_timeout"), "^7 seconds."));
362         print_to(e, "^7You can call a vote for or execute these commands:");
363         print_to(e, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7"));
364 }
365
366 string VoteNetname(entity e)
367 {
368         if(e) {
369                 return e.netname;
370         } else {
371                 if(cvar_string("sv_adminnick") != "") {
372                         return cvar_string("sv_adminnick");
373                 } else {
374                         return cvar_string("hostname");
375                 }
376         }
377 }
378
379 string ValidateMap(string m, entity e)
380 {
381         m = MapInfo_FixName(m);
382         if(!m)
383         {
384                 print_to(e, "This map is not available on this server.");
385                 return string_null;
386         }
387         if(!cvar("sv_vote_override_mostrecent"))
388                 if(Map_IsRecent(m))
389                 {
390                         print_to(e, "This server does not allow for recent maps to be played again. Please be patient for some rounds.");
391                         return string_null;
392                 }
393         if(!MapInfo_CheckMap(m))
394         {
395                 print_to(e, strcat("^1Invalid mapname, \"^3", m, "^1\" does not support the current game mode."));
396                 return string_null;
397         }
398
399         return m;
400 }
401
402
403 void VoteThink() {
404         if(votefinished > 0) // a vote was called
405         if(time > votefinished) // time is up
406         {
407                 VoteCount();
408         }
409 }
410
411 string VoteParse(string all, float argc) {
412         if(argc < 3)
413                 return "";
414         return substring(all, argv_start_index(2), argv_end_index(-1) - argv_start_index(2));
415 }
416
417 float VoteCommandInList(string votecommand, string list)
418 {
419         string l;
420         l = strcat(" ", list, " ");
421         
422         if(strstrofs(l, strcat(" ", votecommand, " "), 0) >= 0)
423                 return TRUE;
424         
425         // if gotomap is allowed, chmap is too, and vice versa
426         if(votecommand == "gotomap")
427                 if(strstrofs(l, " chmap ", 0) >= 0)
428                         return TRUE;
429         if(votecommand == "chmap")
430                 if(strstrofs(l, " gotomap ", 0) >= 0)
431                         return TRUE;
432         
433         return FALSE;
434 }
435
436 float VoteAllowed(string votecommand, string cmd) {
437         if(VoteCommandInList(votecommand, cvar_string("sv_vote_commands")))
438                 return TRUE;
439
440         if(cmd == "vdo")
441         {
442                 if(VoteCommandInList(votecommand, cvar_string("sv_vote_master_commands")))
443                         return TRUE;
444         }
445         else
446         {
447                 if(VoteCommandInList(votecommand, cvar_string("sv_vote_only_commands")))
448                         return TRUE;
449         }
450
451         return FALSE;
452 }
453
454 void VoteReset() {
455         local entity player;
456
457         FOR_EACH_CLIENT(player)
458         {
459                 player.vote_vote = 0;
460                 centerprint_expire(player, CENTERPRIO_VOTE);
461         }
462
463         if(votecalled)
464         {
465                 strunzone(votecalledvote);
466                 strunzone(votecalledvote_display);
467         }
468
469         votecalled = FALSE;
470         votecalledmaster = FALSE;
471         votefinished = 0;
472 }
473
474 void VoteAccept() {
475         bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2's vote for ^1", votecalledvote_display, "^2 was accepted\n");
476         if(votecalledmaster)
477         {
478                 if(votecaller) {
479                         votecaller.vote_master = 1;
480                 }
481         } else {
482                 localcmd(strcat(votecalledvote, "\n"));
483         }
484         if(votecaller) {
485                 votecaller.vote_next = 0; // people like your votes,
486                                           // no wait for next vote
487         }
488         VoteReset();
489 }
490
491 void VoteReject() {
492         bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2's vote for ", votecalledvote_display, "^2 was rejected\n");
493         VoteReset();
494 }
495
496 void VoteTimeout() {
497         bprint("\{1}^2* ^3", VoteNetname(votecaller), "^2's vote for ", votecalledvote_display, "^2 timed out\n");
498         VoteReset();
499 }
500
501 void VoteStop(entity stopper) {
502         bprint("\{1}^2* ^3", VoteNetname(stopper), "^2 stopped ^3", VoteNetname(votecaller), "^2's vote\n");
503         if(cvar("sv_eventlog"))
504                 GameLogEcho(strcat(":vote:vstop:", ftos(stopper.playerid)));
505         if(stopper == votecaller) {
506                 // no wait for next vote so you can correct your vote
507                 if(votecaller) {
508                         votecaller.vote_next = time + cvar("sv_vote_stop");
509                 }
510         }
511         VoteReset();
512 }
513
514 void VoteSpam(float yescount, float nocount, float abstaincount, float notvoters, float mincount, string result)
515 {
516         string s;
517         if(mincount >= 0)
518         {
519                 s = strcat("\{1}^2* vote results: ^1", ftos(yescount), "^2:^1");
520                 s = strcat(s, ftos(nocount), "^2 (^1");
521                 s = strcat(s, ftos(mincount), "^2 needed), ^1");
522                 s = strcat(s, ftos(abstaincount), "^2 didn't care, ^1");
523                 s = strcat(s, ftos(notvoters), "^2 didn't vote\n");
524         }
525         else
526         {
527                 s = strcat("\{1}^2* vote results: ^1", ftos(yescount), "^2:^1");
528                 s = strcat(s, ftos(nocount), "^2, ^1");
529                 s = strcat(s, ftos(abstaincount), "^2 didn't care, ^1");
530                 s = strcat(s, ftos(notvoters), "^2 didn't have to vote\n");
531         }
532         bprint(s);
533         if(cvar("sv_eventlog"))
534         {
535                 s = strcat(":vote:v", result, ":", ftos(yescount));
536                 s = strcat(s, ":", ftos(nocount));
537                 s = strcat(s, ":", ftos(abstaincount));
538                 s = strcat(s, ":", ftos(notvoters));
539                 s = strcat(s, ":", ftos(mincount));
540                 GameLogEcho(s);
541         }
542 }
543
544 void VoteDialog_Update(float msg, float vyes, float vno, float needed) {
545         WriteByte(msg, SVC_TEMPENTITY);
546         WriteByte(msg, TE_CSQC_VOTE);
547         WriteByte(msg, 0);
548         WriteByte(msg, vyes);
549         WriteByte(msg, vno);
550         WriteByte(msg, needed);
551 }
552
553 void VoteCount() {
554         local float playercount;
555         playercount = 0;
556         local float yescount;
557         yescount = 0;
558         local float nocount;
559         nocount = 0;
560         local float abstaincount;
561         abstaincount = 0;
562         local entity player;
563         //same for real players
564         local float realplayercount;
565         local float realplayeryescount;
566         local float realplayernocount;
567         local float realplayerabstaincount;
568         realplayercount = realplayernocount = realplayerabstaincount = realplayeryescount = 0;
569
570         FOR_EACH_REALCLIENT(player)
571         {
572                 if(player.vote_vote == -1) {
573                         ++nocount;
574                 } else if(player.vote_vote == 1) {
575                         ++yescount;
576                 } else if(player.vote_vote == -2) {
577                         ++abstaincount;
578                 }
579                 ++playercount;
580                 //do the same for real players
581                 if(player.classname == "player") {
582                         if(player.vote_vote == -1) {
583                                 ++realplayernocount;
584                         } else if(player.vote_vote == 1) {
585                                 ++realplayeryescount;
586                         } else if(player.vote_vote == -2) {
587                                 ++realplayerabstaincount;
588                         }
589                         ++realplayercount;
590                 }
591         }
592
593         //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)
594         if(cvar("sv_vote_nospectators"))
595         if(realplayercount > 0) {
596                 yescount = realplayeryescount;
597                 nocount = realplayernocount;
598                 abstaincount = realplayerabstaincount;
599                 playercount = realplayercount;
600         }
601
602         float votefactor, simplevotefactor;
603         votefactor = bound(0.5, cvar("sv_vote_majority_factor"), 0.999);
604         simplevotefactor = cvar("sv_vote_simple_majority_factor");
605         float needed;
606         needed = floor((playercount - abstaincount) * max(votefactor, simplevotefactor)) + 1;
607         VoteDialog_Update(MSG_ALL, yescount, nocount, needed);
608
609         if(votecalledmaster
610            && playercount == 1) {
611                 // if only one player is on the server becoming vote
612                 // master is not allowed.  This could be used for
613                 // trolling or worse. 'self' is the user who has
614                 // called the vote because this function is called
615                 // by SV_ParseClientCommand. Maybe all voting should
616                 // be disabled for a single player?
617                 print_to(votecaller, "^1You are the only player on this server so you can not become vote master.");
618                 if(votecaller) {
619                         votecaller.vote_next = 0;
620                 }
621                 VoteReset();
622         } else {
623                 if(yescount > (playercount - abstaincount) * votefactor)
624                 {
625                         VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, -1, "yes");
626                         VoteAccept();
627                         VoteDialog_Reset();
628                 }
629                 else if(nocount >= (playercount - abstaincount) * (1 - votefactor)) // that means, yescount cannot reach minyes any more
630                 {
631                         VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, -1, "no");
632                         VoteReject();
633                         VoteDialog_Reset();
634                 }
635                 else if(time > votefinished)
636                 {
637                         if(simplevotefactor)
638                         {
639                                 string result;
640                                 simplevotefactor = bound(votefactor, simplevotefactor, 0.999);
641                                 if(yescount > (yescount + nocount) * simplevotefactor)
642                                         result = "yes";
643                                 else if(yescount + nocount > 0)
644                                         result = "no";
645                                 else
646                                         result = "timeout";
647                                 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor(min((playercount - abstaincount) * votefactor, (yescount + nocount) * simplevotefactor)) + 1, result);
648                                 if(result == "yes")
649                                         VoteAccept();
650                                 else if(result == "no")
651                                         VoteReject();
652                                 else
653                                         VoteTimeout();
654                         }
655                         else
656                         {
657                                 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor((playercount - abstaincount) * votefactor) + 1, "timeout");
658                                 VoteTimeout();
659                         }
660                 VoteDialog_Reset();
661                 }
662         }
663 }