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