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