]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/clientcommands.qc
new feature: g_tourney
[divverent/nexuiz.git] / data / qcsrc / server / clientcommands.qc
1 void ReadyCount();
2 string ValidateMap(string vote);
3 void(entity e) DropFlag;
4 string MapVote_Suggest(string m);
5
6 .float floodcontrol_chat;
7 .float floodcontrol_team;
8 void Say(entity source, float teamsay, string msgin)
9 {
10         string msgstr, colorstr, cmsgstr, namestr;
11         float flood;
12         entity head;
13
14         if(!teamsay)
15                 if(substring(msgin, 0, 1) == " ")
16                         msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
17
18         msgin = formatmessage(msgin);
19
20         if(msgin == "")
21                 return;
22
23         if(source.classname != "player")
24                 colorstr = "^0"; // black for spectators
25         else if(teams_matter)
26                 colorstr = Team_ColorCode(source.team);
27         else
28                 teamsay = FALSE;
29
30         if(intermission_running)
31                 teamsay = FALSE;
32
33         /*
34          * using bprint solves this... me stupid
35         // how can we prevent the message from appearing in a listen server?
36         // for now, just give "say" back and only handle say_team
37         if(!teamsay)
38         {
39                 clientcommand(self, strcat("say ", msgin));
40                 return;
41         }
42         */
43
44         if(cvar("g_chat_teamcolors"))
45                 namestr = playername(source);
46         else
47                 namestr = source.netname;
48         if(teamsay)
49         {
50                 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin, "\n"));
51                 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", wordwrap(msgin, 50));
52         }
53         else
54                 msgstr = strzone(strcat("\{1}", namestr, "^7: ", msgin, "\n"));
55
56         // FLOOD CONTROL
57         flood = 0;
58         {
59                 float flood_spl;
60                 float flood_burst;
61                 float flood_lmax;
62                 var .float flood_field;
63                 float lines;
64                 if(teamsay)
65                 {
66                         flood_spl = cvar("g_chat_flood_spl_team");
67                         flood_burst = cvar("g_chat_flood_burst_team");
68                         flood_lmax = cvar("g_chat_flood_lmax_team");
69                         flood_field = floodcontrol_team;
70                 }
71                 else
72                 {
73                         flood_spl = cvar("g_chat_flood_spl");
74                         flood_burst = cvar("g_chat_flood_burst");
75                         flood_lmax = cvar("g_chat_flood_lmax");
76                         flood_field = floodcontrol_chat;
77                 }
78                 flood_burst = max(0, flood_burst - 1);
79                 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
80                 lines = ceil(strlennocol(msgstr) / 75);
81                 if(flood_lmax && lines > flood_lmax)
82                         flood = 2;
83                 else if(time >= self.flood_field)
84                         self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
85                 else
86                         flood = 1;
87         }
88
89         if(flood)
90         {
91                 if(cvar("g_chat_flood_notify_flooder"))
92                 {
93                         if(flood == 1)
94                                 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
95                         else if(flood == 2)
96                                 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
97                 }
98                 else
99                         sprint(self, msgstr);
100                 ServerConsoleEcho(strcat("NOTE: ", playername(self), "^7 is flooding."), TRUE);
101         }
102         else if(teamsay)
103         {
104                 if(source.classname == "player")
105                 {
106                         FOR_EACH_REALPLAYER(head)
107                         {
108                                 if(head.team == source.team)
109                                 {
110                                         sprint(head, msgstr);
111                                         centerprint(head, cmsgstr);
112                                 }
113                         }
114                 }
115                 else
116                 {
117                         FOR_EACH_REALCLIENT(head) if(head.classname != "player")
118                         {
119                                 sprint(head, msgstr);
120                                 centerprint(head, cmsgstr);
121                         }
122                 }
123         }
124         else
125         {
126                 //when g_tourney is active and g_tourney_disable_spec_chat is set and game is in matchstage
127                 //don't print the text from specs/observers to the players but only the other spectators
128                 if(g_tourney && cvar("g_tourney_disable_spec_chat") && tourneyInMatchStage && source.classname != "player") {
129                         FOR_EACH_REALCLIENT(head) if(head.classname != "player") {
130                                 sprint(head, msgstr);
131                         }
132                 }
133                 else
134                         bprint(msgstr);
135                 //ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
136         }
137
138         strunzone(msgstr);
139 }
140
141 float VoteCheckNasty(string cmd)
142 {
143         if(strstrofs(cmd, ";", 0) >= 0)
144                 return TRUE;
145         if(strstrofs(cmd, "\n", 0) >= 0)
146                 return TRUE;
147         if(strstrofs(cmd, "\r", 0) >= 0)
148                 return TRUE;
149         if(strstrofs(cmd, "$", 0) >= 0)
150                 return TRUE;
151         return FALSE;
152 }
153
154 string GetKickVoteVictim_newcommand;
155 string GetKickVoteVictim_reason;
156 entity GetKickVoteVictim(string vote, string cmd)
157 {
158         float tokens;
159         float i, n, t;
160         string ns;
161         entity e;
162
163         tokens = tokenize(vote);
164         ns = "";
165
166         if(tokens >= 2)
167                 if(substring(argv(1), 0, 1) == "#")
168                 {
169                         ns = substring(argv(1), 1, 999);
170                         t = 2;
171                 }
172
173         if(tokens >= 3)
174                 if(argv(1) == "#")
175                 {
176                         ns = argv(2);
177                         t = 3;
178                 }
179
180         if(ns != "")
181         {
182                 GetKickVoteVictim_reason = "";
183                 for(i = t; i < tokens; ++i)
184                         GetKickVoteVictim_reason = strcat(GetKickVoteVictim_reason, argv(i), " ");
185                 GetKickVoteVictim_reason = substring(GetKickVoteVictim_reason, 0, strlen(GetKickVoteVictim_reason) - 1);
186
187                 n = stof(ns);
188                 if(ns == ftos(n)) if(n >= 1) if(n <= maxclients)
189                 {
190                         e = edict_num(n);
191                         if(clienttype(e) == CLIENTTYPE_REAL)
192                         {
193                                 GetKickVoteVictim_newcommand = strcat(argv(0), " # ", ns);
194                                 return e;
195                         }
196                 }
197         }
198
199         sprint(self, strcat("Usage: ", cmd, " ", argv(0), " #playernumber (as in \"status\")\n"));
200         return world;
201 }
202
203 void SV_ParseClientCommand(string s) {
204         local string cmd;
205         local entity e;
206         local float i;
207
208         tokenize(s);
209
210         if(argv(0) == "vote") {
211                 if(argv(1) == "help") {
212                         local string vmasterdis;
213                         if(!cvar("sv_vote_master")) {
214                                 vmasterdis = " ^1(disabled)";
215                         }
216                         local string vcalldis;
217                         if(!cvar("sv_vote_call")) {
218                                 vcalldis = " ^1(disabled)";
219                         }
220                         sprint(self, "^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 do ^3COMMAND ARGUMENTS^7\" \"^2cmd vote yes^7\" \"^2cmd vote no^7\" \"^2cmd vote dontcare^7\".\n");
221                         sprint(self, "^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\" \"^2vdo ^3COMMAND ARGUMENTS^7\" \"^2vyes^7\" \"^2vno^7\" \"^2vdontcare^7\".\n");
222                         sprint(self, "^7\"^2help^7\" shows this info.\n");
223                         sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
224                         sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
225                         sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
226                         sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
227                         sprint(self, "^7\"^2do^7\" If you are a master you can execute a command without a vote. See the list of allowed commands.\n");
228                         sprint(self, "^7\"^2yes^7\", \"^2no^7\" and \"^2dontcare^7\" to make your vote.\n");
229                         sprint(self, "^7If enough of the players vote yes the vote is accepted.\n");
230                         sprint(self, "^7If enough of the players vote no the vote is rejected.\n");
231                         sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
232                         sprint(self, "^7You can call a vote for or execute these commands:\n");
233                         sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
234                 } else if(argv(1) == "status") {
235                         if(votecalled) {
236                                 sprint(self, strcat("^7Vote for ", votecalledvote_display, "^7 called by ^7", votecaller.netname, "^7.\n"));
237                         } else {
238                                 sprint(self, "^1No vote called.\n");
239                         }
240                 } else if(argv(1) == "call") {
241                         if(cvar("sv_vote_call")) {
242                                 if(tourneyInMatchStage && cvar("g_tourney_disable_spec_vote") && self.classname != "player") {
243                                         sprint(self, "^1Error: Only players can call a vote during the match-stage.\n");
244                                 }
245                                 else if(votecalled) {
246                                         sprint(self, "^1There is already a vote called.\n");
247                                 } else {
248                                         local string vote;
249                                         vote = VoteParse();
250                                         if(vote == "") {
251                                                 sprint(self, "^1Your vote is empty. See help for more info.\n");
252                                         } else if(time < self.vote_next) {
253                                                 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
254                                         } else if(VoteCheckNasty(vote)) {
255                                                 sprint(self, "Syntax error in command.\n");
256                                         } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
257                                                 // remap chmap to gotomap (forces intermission)
258                                                 if(vote == "chmap" || vote == "gotomap") // won't work without arguments
259                                                         return;
260                                                 if(substring(vote, 0, 6) == "chmap ")
261                                                         vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
262                                                 if(substring(vote, 0, 8) == "gotomap ")
263                                                 {
264                                                         if(!(vote = ValidateMap(substring(vote, 8, strlen(vote) - 8))))
265                                                                 return;
266                                                         vote = strcat("gotomap ", vote);
267                                                 }
268
269                                                 // make kick and kickban votes a bit nicer (and reject them if formatted badly)
270                                                 if(substring(vote, 0, 5) == "kick " || substring(vote, 0, 8) == "kickban ")
271                                                 {
272                                                         if(!(e = GetKickVoteVictim(vote, "vcall")))
273                                                                 return;
274                                                         vote = GetKickVoteVictim_newcommand;
275                                                         votecalledvote_display = strzone(strcat("^1", vote, " (^7", e.netname, "^1): ", GetKickVoteVictim_reason));
276                                                 }
277                                                 else
278                                                 {
279                                                         votecalledvote_display = strzone(strcat("^1", vote));
280                                                 }
281                                                 votecalledvote = strzone(vote);
282                                                 votecalled = TRUE;
283                                                 votecalledmaster = FALSE;
284                                                 votecaller = self; // remember who called the vote
285                                                 votefinished = time + cvar("sv_vote_timeout");
286                                                 votecaller.vote_vote = 1; // of course you vote yes
287                                                 votecaller.vote_next = time + cvar("sv_vote_wait");
288                                                 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ", votecalledvote_display, "\n");
289                                                 VoteCount(); // needed if you are the only one
290                                         } else {
291                                                 sprint(self, "^1This vote is not ok. See help for more info.\n");
292                                         }
293                                 }
294                         } else {
295                                 sprint(self, "^1Vote calling is NOT allowed.\n");
296                         }
297                 } else if(argv(1) == "stop") {
298                         if(!votecalled) {
299                                 sprint(self, "^1No vote called.\n");
300                         } else if(self == votecaller) { // the votecaller can stop a vote
301                                 VoteStop(self);
302                         } else if(self.vote_master) { // masters can, too
303                                 VoteStop(self);
304                         } else {
305                                 sprint(self, "^1You are not allowed to stop that Vote.\n");
306                         }
307                 } else if(argv(1) == "master") {
308                         if(cvar("sv_vote_master")) {
309                                 if(votecalled) {
310                                         sprint(self, "^1There is already a vote called.\n");
311                                 } else {
312                                         votecalled = TRUE;
313                                         votecalledmaster = TRUE;
314                                         votecalledvote = strzone("XXX");
315                                         votecalledvote_display = strzone("^3master");
316                                         votecaller = self; // remember who called the vote
317                                         votefinished = time + cvar("sv_vote_timeout");
318                                         votecaller.vote_vote = 1; // of course you vote yes
319                                         votecaller.vote_next = time + cvar("sv_vote_wait");
320                                         bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n");
321                                         VoteCount(); // needed if you are the only one
322                                 }
323                         } else {
324                                 sprint(self, "^1Vote to become master is NOT allowed.\n");
325                         }
326                 } else if(argv(1) == "do") {
327                         if(argv(2) == "login") {
328                                 local string masterpwd;
329                                 masterpwd = cvar_string("sv_vote_master_password");
330                                 if(masterpwd != "") {
331                                         self.vote_master = (masterpwd == argv(3));
332                                         if(self.vote_master) {
333                                                 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
334                                                 bprint("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n");
335                                         }
336                                         else
337                                                 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
338                                 }
339                                 else
340                                         sprint(self, "^1You are NOT a master.\n");
341                         } else if(self.vote_master) {
342                                 local string dovote, dovote_display;
343                                 dovote = VoteParse();
344                                 if(dovote == "") {
345                                         sprint(self, "^1Your command was empty. See help for more info.\n");
346                                 } else if(VoteCheckNasty(dovote)) {
347                                         sprint(self, "Syntax error in command.\n");
348                                 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
349                                         if(dovote == "chmap" || dovote == "gotomap") // won't work without arguments
350                                                 return;
351                                         if(substring(dovote, 0, 6) == "chmap ")
352                                                 dovote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
353                                         if(substring(dovote, 0, 8) == "gotomap ")
354                                         {
355                                                 if(!(dovote = ValidateMap(substring(dovote, 8, strlen(dovote) - 8))))
356                                                         return;
357                                                 dovote = strcat("gotomap ", dovote);
358                                         }
359
360                                         dovote_display = dovote;
361                                         if(substring(dovote, 0, 5) == "kick " || substring(dovote, 0, 8) == "kickban ")
362                                         {
363                                                 if(!(e = GetKickVoteVictim(dovote, "vdo")))
364                                                         return;
365                                                 dovote = GetKickVoteVictim_newcommand;
366                                                 dovote_display = strcat("^1", dovote, " (^7", e.netname, "^1): ", GetKickVoteVictim_reason);
367                                         }
368                                         bprint("\{1}^2* ^3", self.netname, "^2 used his ^3master^2 status to do \"^2", dovote_display, "^2\".\n");
369                                         localcmd(strcat(dovote, "\n"));
370                                 } else {
371                                         sprint(self, "^1This command is not ok. See help for more info.\n");
372                                 }
373                         } else {
374                                 sprint(self, "^1You are NOT a master.\n");
375                         }
376                 } else if(argv(1) == "yes") {
377                         if(!votecalled) {
378                                 sprint(self, "^1No vote called.\n");
379                         } else if(self.vote_vote == 0
380                                   || cvar("sv_vote_change")) {
381                                 sprint(self, "^1You accepted the vote.\n");
382                                 self.vote_vote = 1;
383                                 centerprint_expire(self, CENTERPRIO_VOTE);
384                                 if(!cvar("sv_vote_singlecount")) {
385                                         VoteCount();
386                                 }
387                         } else {
388                                 sprint(self, "^1You have already voted.\n");
389                         }
390                 } else if(argv(1) == "no") {
391                         if(!votecalled) {
392                                 sprint(self, "^1No vote called.\n");
393                         } else if(self.vote_vote == 0
394                                   || cvar("sv_vote_change")) {
395                                 sprint(self, "^1You rejected the vote.\n");
396                                 self.vote_vote = -1;
397                                 centerprint_expire(self, CENTERPRIO_VOTE);
398                                 if(!cvar("sv_vote_singlecount")) {
399                                         VoteCount();
400                                 }
401                         } else {
402                                 sprint(self, "^1You have already voted.\n");
403                         }
404                 } else if(argv(1) == "abstain" || argv(1) == "dontcare") {
405                         if(!votecalled) {
406                                 sprint(self, "^1No vote called.\n");
407                         } else if(self.vote_vote == 0
408                                   || cvar("sv_vote_change")) {
409                                 sprint(self, "^1You abstained from your vote.\n");
410                                 self.vote_vote = -2;
411                                 centerprint_expire(self, CENTERPRIO_VOTE);
412                                 if(!cvar("sv_vote_singlecount")) {
413                                         VoteCount();
414                                 }
415                         } else {
416                                 sprint(self, "^1You have already voted.\n");
417                         }
418                 } else {
419                         // ignore this?
420                         sprint(self, "^1Unknown vote command.\n");
421                 }
422         } else if(argv(0) == "autoswitch") {
423                 // be backwards compatible with older clients (enabled)
424                 self.autoswitch = ("0" != argv(1));
425                 local string autoswitchmsg;
426                 if (self.autoswitch) {
427                         autoswitchmsg = "on";
428                 } else {
429                         autoswitchmsg = "off";
430                 }
431                 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
432         } else if(argv(0) == "clientversion") {
433                 if (argv(1) == "$gameversion") {
434                         //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
435                         // either that or someone wants to be funny
436                         self.version = 1;
437                 } else {
438                         self.version = stof(argv(1));
439                 }
440                 if(self.version != cvar("gameversion"))
441                 {
442                         self.classname = "observer";
443                         self.frags = -2;
444                         PutClientInServer();
445                 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
446                         //JoinBestTeam(self, FALSE, TRUE);
447                 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
448                         self.classname = "observer";
449                         stuffcmd(self,"menu_showteamselect\n");
450                 }
451         } else if(argv(0) == "reportcvar") { // old system
452                 GetCvars(1);
453         } else if(argv(0) == "sentcvar") { // new system
454                 GetCvars(1);
455         } else if(argv(0) == "spectate") {
456                 if(g_lms || g_arena)
457                         return; // don't allow spectating in lms, unless player runs out of lives
458                 if(self.classname == "player" && cvar("sv_spectate") == 1) {
459                         if(self.flagcarried)
460                                 DropFlag(self.flagcarried);
461                         kh_Key_DropAll(self, TRUE);
462                         WaypointSprite_PlayerDead();
463                         DistributeFragsAmongTeam(self, self.team, 1.0);
464                         self.classname = "observer";
465                         if(blockSpectators)
466                                 sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
467                         PutClientInServer();
468                 }
469         } else if(argv(0) == "join") {
470                 if(!g_arena)
471                 if (self.classname != "player" && !lockteams)
472                 {
473                         if(isJoinAllowed()) {
474                                 self.classname = "player";
475                                 self.frags = 0;
476                                 bprint ("^4", self.netname, "^4 is playing now\n");
477                                 PutClientInServer();
478                         }
479                         else {
480                                 //player may not join because of g_maxplayers is set
481                                 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
482                         }
483                 }
484         } else if( argv(0) == "selectteam" ) {
485                 if( !cvar("teamplay") ) {
486                         sprint( self, "selecteam can only be used in teamgames\n");
487                 } else if(cvar("g_campaign")) {
488                         //JoinBestTeam(self, 0);
489                 } else if(lockteams) {
490                         sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
491                 } else if( argv(1) == "red" ) {
492                         DoTeamChange(COLOR_TEAM1);
493                 } else if( argv(1) == "blue" ) {
494                         DoTeamChange(COLOR_TEAM2);
495                 } else if( argv(1) == "yellow" ) {
496                         DoTeamChange(COLOR_TEAM3);
497                 } else if( argv(1) == "pink" ) {
498                         DoTeamChange(COLOR_TEAM4);
499                 } else if( argv(1) == "auto" ) {
500                         DoTeamChange(-1);
501                 } else {
502                         sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
503                 }
504         } else if(argv(0) == "ready") {
505                 if(cvar("sv_ready_restart"))
506                 {
507                         if(!restart_countdown || cvar("sv_ready_restart_repeatable"))
508                         {
509                                 self.ready = TRUE;
510                                 bprint(self.netname, "^2 is ready\n");
511                                 ReadyCount();
512                         } else {
513                                 sprint(self, "^1game has already been restarted\n");
514                         }
515                 }
516         } else if(argv(0) == "maplist") {
517                 local float n;
518                 local string col;
519                 n = tokenize(cvar_string("g_maplist"));
520                 sprint(self, "^7Maps in list: ");
521                 for(i = 0; i < n; ++i)
522                 {
523                         if(mod(i, 2))
524                                 col = "^2";
525                         else
526                                 col = "^3";
527                         sprint(self, strcat(col, argv(i), " "));
528                 }
529                 sprint(self, "\n");
530 #ifdef MAPINFO
531         } else if(argv(0) == "lsmaps") {
532                 sprint(self, "^7Maps available: ");
533                 for(i = 0; i < MapInfo_count; ++i)
534                 {
535                         if(mod(i, 2))
536                                 col = "^2";
537                         else
538                                 col = "^3";
539                         sprint(self, strcat(col, MapInfo_BSPName_ByID(i), " "));
540                 }
541                 sprint(self, "\n");
542 #endif
543         } else if(argv(0) == "teamstatus") {
544                 PrintScoreboard(self);
545         } else if(argv(0) == "voice") {
546                 VoiceMessage(argv(1));
547         } else if(argv(0) == "say") {
548                 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
549                 //clientcommand(self, formatmessage(s));
550         } else if(argv(0) == "say_team") {
551                 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
552                 //clientcommand(self, formatmessage(s));
553         } else if(argv(0) == "info") {
554                 cmd = cvar_string(strcat("sv_info_", argv(1)));
555                 if(cmd == "")
556                         sprint(self, "ERROR: unsupported info command\n");
557                 else
558                         wordwrap_sprint(cmd, 1111);
559         } else if(argv(0) == "suggestmap") {
560                 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
561         } else {
562                 cmd = argv(0);
563                 /* checks not needed any more since DP has separated clientcommands and regular commands
564                 if(cmd != "status")
565                 if(cmd != "name")
566                 //if(cmd != "say") // handled above
567                 //if(cmd != "say_team") // handled above
568                 if(cmd != "tell")
569                 if(cmd != "color")
570                 if(cmd != "kill")
571                 if(cmd != "pause")
572                 if(cmd != "kick")
573                 if(cmd != "ping")
574                 if(cmd != "pings")
575                 if(cmd != "ban")
576                 if(cmd != "pmodel")
577                 if(cmd != "rate")
578                 if(cmd != "playermodel")
579                 if(cmd != "playerskin")
580                 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
581                 {
582                         ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
583                         return;
584                 }
585                 */
586                 clientcommand(self,s);
587         }
588 }
589
590 string ValidateMap(string m)
591 {
592 #ifdef MAPINFO
593         m = MapInfo_FixName(m);
594         if(!m)
595         {
596                 sprint(self, "This map is not available on this server.\n");
597                 return string_null;
598         }
599 #else
600         if(!cvar("sv_vote_change_gametype"))
601                 if(!IsSameGametype(m))
602                 {
603                         sprint(self, "This server does not allow changing the game type by map votes.\n");
604                         return string_null;
605                 }
606 #endif
607         if(!cvar("sv_vote_override_mostrecent"))
608                 if(Map_IsRecent(m))
609                 {
610                         sprint(self, "This server does not allow for recent maps to be played again. Please be patient for some rounds.\n");
611                         return string_null;
612                 }
613 #ifdef MAPINFO
614         if(!MapInfo_CheckMap(m))
615         {
616                 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not support the current game mode.\n"));
617                 return string_null;
618         }
619 #else
620         if(!TryFile(strcat("maps/", m, ".mapcfg")))
621         {
622                 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not exist on this server.\n"));
623                 return string_null;
624         }
625 #endif
626
627         return m;
628 }
629
630
631 void VoteThink() {
632         if(votefinished > 0 // a vote was called
633             && time > votefinished) // time is up
634         {
635                 VoteCount();
636         }
637 }
638
639 string VoteParse() {
640         local float index;
641         index = 3;
642         local string vote;
643         vote = argv(2);
644         while(argv(index) != "") {
645                 vote = strcat(vote, " ", argv(index));
646                 index++;
647         }
648
649         // necessary for some of the string operations
650         vote = strzone(vote);
651
652         // now we remove some things that could be misused
653         index = 0;
654         local float found;
655         found = FALSE;
656         local float votelength;
657         votelength = strlen(vote);
658         while(!found && index < votelength)
659         {
660                 local string badchar;
661                 badchar = substring(vote, index, 1);
662                 if(badchar == ";"
663                    || badchar == "\r"
664                    || badchar == "\n")
665                 {
666                         found = TRUE;
667                 } else {
668                         index++;
669                 }
670         }
671         return substring(vote, 0, index);
672 }
673
674 float VoteAllowed(string votecommand) {
675         tokenize(cvar_string("sv_vote_commands"));
676         local float index;
677         index = 0;
678         while(argv(index) != "") {
679                 local string allowed;
680                 allowed = argv(index);
681                 if(votecommand == allowed) {
682                         return TRUE;
683                 }
684                 index++;
685         }
686         return FALSE;
687 }
688
689 void VoteReset() {
690         local entity player;
691
692         FOR_EACH_CLIENT(player)
693         {
694                 player.vote_vote = 0;
695                 centerprint_expire(player, CENTERPRIO_VOTE);
696         }
697
698         if(votecalled)
699         {
700                 strunzone(votecalledvote);
701                 strunzone(votecalledvote_display);
702         }
703
704         votecalled = FALSE;
705         votecalledmaster = FALSE;
706         votefinished = 0;
707 }
708
709 void VoteAccept() {
710         bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote_display, "^2 was accepted\n");
711         if(votecalledmaster)
712         {
713                 votecaller.vote_master = 1;
714         } else {
715                 //in g_tourney mode and if the vote is a timelimit-change, don't change it immediately but after restart
716                 if(cvar("g_tourney") && substring(votecalledvote, 0, 10) == "timelimit ") {
717                         if( stof(substring(votecalledvote, 10, strlen(votecalledvote) - 10)) > 0 ) {
718                                 timelimit_orig = stof(substring(votecalledvote, 10, strlen(votecalledvote) - 10));
719                                 bprint(strcat("The timelimit will be set to ", ftos(timelimit_orig), " minutes after the next restart!\n"));
720                         }
721                         else //calls like "timelimit -1" can pass immediately
722                                 localcmd(strcat(votecalledvote, "\n"));
723                 }
724                 else
725                         localcmd(strcat(votecalledvote, "\n"));
726         }
727         votecaller.vote_next = 0; // people like your votes, no wait for next vote
728         VoteReset();
729 }
730
731 void VoteReject() {
732         bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 was rejected\n");
733         VoteReset();
734 }
735
736 void VoteTimeout() {
737         bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 timed out\n");
738         VoteReset();
739 }
740
741 void VoteStop(entity stopper) {
742         bprint("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n");
743         if(stopper == votecaller) {
744                 // no wait for next vote so you can correct your vote
745                 votecaller.vote_next = 0;
746         }
747         VoteReset();
748 }
749
750 void VoteNag() {
751         if(votecalled)
752                 if(self.vote_vote == 0)
753                         centerprint_atprio(self, CENTERPRIO_VOTE, strcat("^7^3", votecaller.netname, "^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."));
754 }
755
756 void VoteSpam(float yescount, float nocount, float abstaincount, float notvoters, float mincount)
757 {
758         string s;
759         if(mincount >= 0)
760         {
761                 s = strcat("\{1}^2* vote results: ^1", ftos(yescount), "^2:^1");
762                 s = strcat(s, ftos(nocount), "^2 (^1");
763                 s = strcat(s, ftos(mincount), "^2 needed), ^1");
764                 s = strcat(s, ftos(abstaincount), "^2 didn't care, ^1");
765                 s = strcat(s, ftos(notvoters), "^2 didn't vote\n");
766         }
767         else
768         {
769                 s = strcat("\{1}^2* vote results: ^1", ftos(yescount), "^2:^1");
770                 s = strcat(s, ftos(nocount), "^2 (^1");
771                 s = strcat(s, ftos(abstaincount), "^2 didn't care, ^1");
772                 s = strcat(s, ftos(notvoters), "^2 didn't have to vote\n");
773         }
774         bprint(s);
775 }
776
777 void VoteCount() {
778         local float playercount;
779         playercount = 0;
780         local float yescount;
781         yescount = 0;
782         local float nocount;
783         nocount = 0;
784         local float abstaincount;
785         abstaincount = 0;
786         local entity player;
787         //same for real players
788         local float realplayercount;
789         local float realplayeryescount;
790         local float realplayernocount;
791         local float realplayerabstaincount;
792         realplayercount = realplayernocount = realplayerabstaincount = realplayeryescount = 0;
793
794         FOR_EACH_REALCLIENT(player)
795         {
796                 if(player.vote_vote == -1) {
797                         nocount++;
798                 } else if(player.vote_vote == 1) {
799                         yescount++;
800                 } else if(player.vote_vote == -2) {
801                         abstaincount++;
802                 }
803                 playercount++;
804                 //do the same for real players
805                 if(player.classname == "player") {
806                         if(player.vote_vote == -1) {
807                                 realplayernocount++;
808                         } else if(player.vote_vote == 1) {
809                                 realplayeryescount++;
810                         } else if(player.vote_vote == -2) {
811                                 realplayerabstaincount++;
812                         }
813                         realplayercount++;
814                 }
815         }
816
817         //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)
818         if( cvar("g_tourney") && (realplayercount > 0) ) {
819                 yescount = realplayeryescount;
820                 nocount = realplayernocount;
821                 abstaincount = realplayerabstaincount;
822                 playercount = realplayercount;
823         }
824
825
826         if((playercount == 1) && votecalledmaster) {
827                 // if only one player is on the server becoming vote
828                 // master is not allowed.  This could be used for
829                 // trolling or worse. 'self' is the user who has
830                 // called the vote because this function is called
831                 // by SV_ParseClientCommand. Maybe all voting should
832                 // be disabled for a single player?
833                 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
834                 votecaller.vote_next = 0;
835                 VoteReset();
836         } else {
837                 float votefactor;
838                 votefactor = bound(0.5, cvar("sv_vote_majority_factor"), 0.999);
839                 if(yescount > (playercount - abstaincount) * votefactor)
840                 {
841                         VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, -1);
842                         VoteAccept();
843                 }
844                 else if(nocount >= (playercount - abstaincount) * (1 - votefactor)) // that means, yescount cannot reach minyes any more
845                 {
846                         VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, -1);
847                         VoteReject();
848                 }
849                 else if(time > votefinished)
850                 {
851                         if(cvar("sv_vote_simple_majority"))
852                         {
853                                 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor((yescount + nocount) * votefactor) + 1);
854                                 if(yescount > (yescount + nocount) * votefactor)
855                                         VoteAccept();
856                                 else if(yescount + nocount > 0)
857                                         VoteReject();
858                                 else
859                                         VoteTimeout();
860                         }
861                         else
862                         {
863                                 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor((playercount - abstaincount) * votefactor) + 1);
864                                 VoteTimeout();
865                         }
866                 }
867         }
868 }
869
870 /**
871  * Counts how many players are ready. If not enough players are ready, the function
872  * does nothing. If all players are ready, the timelimit will be extended and the
873  * restart_countdown variable is set to allow other functions like PlayerPostThink
874  * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
875  * is not set the map will be resetted.
876  * 
877  * Function is called after the server receives a 'ready' sign from a player.
878  */
879 void ReadyCount()
880 {
881         local entity e;
882         local float r, p;
883
884         FOR_EACH_REALPLAYER(e)
885         {
886                 p += 1;
887                 if(e.ready)
888                         r += 1;
889         }
890
891         if(cvar("sv_ready_restart_nag")) {
892                 if(!readyNagActive) {
893                         readyNagger = spawn();
894                         readyNagger.think = readyNagger_Think;
895                         readyNagger.cnt = cvar("sv_ready_restart_nag_duration");
896                         readyNagger.nextthink = time;
897                         readyNagActive = 1;
898                 }
899         }
900
901         if(!p || r < p)
902                 return;
903
904         bprint("^1Server is restarting...\n");
905
906         // no arena, assault support yet...
907         if(g_arena | g_assault | gameover | intermission_running)
908                 localcmd("restart\n");
909
910         if(readyNagActive) { //if every player is ready, remove the ready-nagger again
911                 readyNagActive = 0;
912                 remove(readyNagger);
913         }
914
915         if(g_tourney) {
916                 tourneyInMatchStage = 1; //once the game is restarted the game is in match stage
917                 //reset weapons and ammo, health and armor to default:
918                 start_items = IT_LASER | IT_SHOTGUN;
919                 start_switchweapon = WEP_SHOTGUN;
920                 start_ammo_shells = cvar("g_start_ammo_shells");
921                 start_ammo_nails = cvar("g_start_ammo_nails");
922                 start_ammo_rockets = cvar("g_start_ammo_rockets");
923                 start_ammo_cells = cvar("g_start_ammo_cells");
924                 start_health = cvar("g_balance_health_start");
925                 start_armorvalue = cvar("g_balance_armor_start");
926         }
927
928         restart_countdown = time + RESTART_COUNTDOWN;
929         restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
930         //reset the .ready status of all players (also spectators)
931         FOR_EACH_CLIENT(e)
932         {
933                 e.ready = 0;
934         }
935         if(0<cvar("timelimit") || (g_tourney && cvar("g_tourney_warmup_unlimited_time")) )
936         {
937                 // remember original timelimit on first restart
938                 if(!timelimit_orig)
939                         timelimit_orig = cvar("timelimit");
940                 //only set the new timelimit if, when loading the map, a timelimit was really set
941                 if(timelimit_orig)
942                         cvar_set("timelimit", ftos(timelimit_orig + ceil(restart_countdown)/60));
943         }
944         if(cvar("teamplay_lockonrestart") && teams_matter) {
945                 lockteams = 1;
946                 bprint("^1The teams are now locked.\n");
947         }
948         
949         //initiate the restart-countdown-announcer entity
950         restartAnnouncer = spawn();
951         restartAnnouncer.think = restartAnnouncer_Think;
952         restartAnnouncer.nextthink = time;
953         restartAnnouncer.cnt = RESTART_COUNTDOWN;
954
955         //play the prepareforbattle sound to everyone
956         sound(world, CHAN_AUTO, "announcer/robotic/prepareforbattle.wav", 1, ATTN_NONE);
957
958         //reset map immediately if this cvar is not set
959         if (!cvar("sv_ready_restart_after_countdown"))
960                 reset_map();
961         
962         if(cvar("sv_eventlog"))
963                 GameLogEcho(":restart", FALSE);
964 }
965
966 /**
967  * Centerprints the information to all players who didn't ready up yet to do so.
968  */
969 void readyNagger_Think() {
970         local entity plr;
971         if(self.cnt <= 0) { //have a break showing the ready nag
972                 //make sure that the old ready-nag-centerprint isn't shown too long:
973                 FOR_EACH_REALCLIENT(plr) {
974                         if(plr.classname == "player") {
975                                 if (!plr.ready)
976                                         centerprint_atprio(plr, CENTERPRIO_SPAM, "");
977                         }
978                 }
979                 self.cnt = cvar("sv_ready_restart_nag_duration");
980                 self.nextthink = time + cvar("sv_ready_restart_nag_interval");
981         }
982         else {
983                 //show the ready nagging to all players who aren't ready yet
984                 FOR_EACH_REALCLIENT(plr) {
985                         if(plr.classname == "player") {
986                                 if (!plr.ready) {
987                                         centerprint_atprio(plr, CENTERPRIO_SPAM, "^2Please ready up (F4 by default)!");
988                                         //play reminder sound once the centerprint appears for the first time after the pause:
989                                         if (self.cnt == cvar("sv_ready_restart_nag_duration"))
990                                                 play2(plr, "misc/talk2.wav");
991                                 }
992                         }
993                 }
994
995                 self.nextthink = time + 1;
996                 self.cnt -= 1;
997         }
998 }
999
1000 /**
1001  * Shows the restart countdown for all players.
1002  * Plays the countdown sounds for the seconds 3, 2 1, begin for everyone.
1003  * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
1004  * is set to 1).
1005  */
1006 void restartAnnouncer_Think() {
1007         local entity plr;
1008         local string s;
1009         if(self.cnt <= 0) { //show the "Begin" message and
1010                 if (cvar("sv_ready_restart_after_countdown")) {
1011                         restart_mapalreadyrestarted = 1;
1012                         reset_map();
1013                 }
1014
1015                 FOR_EACH_REALCLIENT(plr) {
1016                         if(plr.classname == "player") {
1017                                 s = strcat(NEWLINES, "^1Begin!");
1018                                 centerprint(plr, s);
1019                         }
1020                 }
1021                 sound(world, CHAN_AUTO, "announcer/robotic/begin.wav", 1, ATTN_NONE);
1022
1023                 remove(self);
1024                 return;
1025         }
1026         else {
1027                 FOR_EACH_REALCLIENT(plr) {
1028                         if(plr.classname == "player") {
1029                                 s = strcat(NEWLINES, "^1Game starts in ", ftos(self.cnt), " seconds");
1030                                 centerprint(plr, s);
1031                         }
1032                 }
1033
1034                 if(self.cnt <= 3) {
1035                         sound(world, CHAN_AUTO, strcat("announcer/robotic/", ftos(self.cnt), ".ogg"), 1, ATTN_NONE);
1036                 }
1037                 self.nextthink = time + 1;
1038                 self.cnt -= 1;
1039         }
1040 }