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