2 string ValidateMap(string vote);
3 void(entity e) DropFlag;
4 string MapVote_Suggest(string m);
6 .float floodcontrol_chat;
7 .float floodcontrol_team;
8 void Say(entity source, float teamsay, string msgin)
10 string msgstr, colorstr, cmsgstr, namestr;
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!)
18 msgin = formatmessage(msgin);
23 if(source.classname != "player")
24 colorstr = "^0"; // black for spectators
26 colorstr = Team_ColorCode(source.team);
30 if(intermission_running)
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
39 clientcommand(self, strcat("say ", msgin));
44 if(cvar("g_chat_teamcolors"))
45 namestr = playername(source);
47 namestr = source.netname;
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));
54 msgstr = strzone(strcat("\{1}", namestr, "^7: ", msgin, "\n"));
62 var .float flood_field;
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;
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;
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)
83 else if(time >= self.flood_field)
84 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
91 if(cvar("g_chat_flood_notify_flooder"))
94 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
96 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
100 ServerConsoleEcho(strcat("NOTE: ", playername(self), "^7 is flooding."), TRUE);
104 if(source.classname == "player")
106 FOR_EACH_REALPLAYER(head)
108 if(head.team == source.team)
110 sprint(head, msgstr);
111 centerprint(head, cmsgstr);
117 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
119 sprint(head, msgstr);
120 centerprint(head, cmsgstr);
127 //ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
133 float VoteCheckNasty(string cmd)
135 if(strstrofs(cmd, ";", 0) >= 0)
137 if(strstrofs(cmd, "\n", 0) >= 0)
139 if(strstrofs(cmd, "\r", 0) >= 0)
144 string GetKickVoteVictim_newcommand;
145 entity GetKickVoteVictim(string vote, string cmd)
152 tokens = tokenize(vote);
156 if(substring(argv(1), 0, 1) == "#")
157 ns = substring(argv(1), 1, 999);
166 if(ns == ftos(n)) if(n >= 1) if(n <= maxclients)
168 for((e = world), (i = 0); i < n; ++i, (e = nextent(e)))
170 if(clienttype(e) == CLIENTTYPE_REAL)
172 GetKickVoteVictim_newcommand = strcat(argv(0), " # ", ns);
178 sprint(self, strcat("Usage: ", cmd, " ", argv(0), " #playernumber (as in \"status\")\n"));
182 void SV_ParseClientCommand(string s) {
189 if(argv(0) == "vote") {
190 if(argv(1) == "help") {
191 local string vmasterdis;
192 if(!cvar("sv_vote_master")) {
193 vmasterdis = " ^1(disabled)";
195 local string vcalldis;
196 if(!cvar("sv_vote_call")) {
197 vcalldis = " ^1(disabled)";
199 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");
200 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");
201 sprint(self, "^7\"^2help^7\" shows this info.\n");
202 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
203 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
204 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
205 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
206 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");
207 sprint(self, "^7\"^2yes^7\", \"^2no^7\" and \"^2dontcare^7\" to make your vote.\n");
208 sprint(self, "^7If enough of the players vote yes the vote is accepted.\n");
209 sprint(self, "^7If enough of the players vote no the vote is rejected.\n");
210 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
211 sprint(self, "^7You can call a vote for or execute these commands:\n");
212 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
213 } else if(argv(1) == "status") {
215 sprint(self, strcat("^7Vote for ", votecalledvote_display, "^7 called by ^7", votecaller.netname, "^7.\n"));
217 sprint(self, "^1No vote called.\n");
219 } else if(argv(1) == "call") {
220 if(cvar("sv_vote_call")) {
222 sprint(self, "^1There is already a vote called.\n");
227 sprint(self, "^1Your vote is empty. See help for more info.\n");
228 } else if(time < self.vote_next) {
229 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
230 } else if(VoteCheckNasty(vote)) {
231 sprint(self, "Syntax error in command.\n");
232 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
233 // remap chmap to gotomap (forces intermission)
234 if(vote == "chmap" || vote == "gotomap") // won't work without arguments
236 if(substring(vote, 0, 6) == "chmap ")
237 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
238 if(substring(vote, 0, 8) == "gotomap ")
240 if(!(vote = ValidateMap(substring(vote, 8, strlen(vote) - 8))))
242 vote = strcat("gotomap ", vote);
245 // make kick and kickban votes a bit nicer (and reject them if formatted badly)
246 if(substring(vote, 0, 5) == "kick " || substring(vote, 0, 8) == "kickban ")
248 if(!(e = GetKickVoteVictim(vote, "vcall")))
250 votecalledvote_display = strzone(strcat("^1", vote, " (^7", e.netname, "^1)"));
251 vote = GetKickVoteVictim_newcommand;
255 votecalledvote_display = strzone(strcat("^1", vote));
257 votecalledvote = strzone(vote);
259 votecalledmaster = FALSE;
260 votecaller = self; // remember who called the vote
261 votefinished = time + cvar("sv_vote_timeout");
262 votecaller.vote_vote = 1; // of course you vote yes
263 votecaller.vote_next = time + cvar("sv_vote_wait");
264 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ", votecalledvote_display, "\n");
265 VoteCount(); // needed if you are the only one
267 sprint(self, "^1This vote is not ok. See help for more info.\n");
271 sprint(self, "^1Vote calling is NOT allowed.\n");
273 } else if(argv(1) == "stop") {
275 sprint(self, "^1No vote called.\n");
276 } else if(self == votecaller) { // the votecaller can stop a vote
278 } else if(self.vote_master) { // masters can, too
281 sprint(self, "^1You are not allowed to stop that Vote.\n");
283 } else if(argv(1) == "master") {
284 if(cvar("sv_vote_master")) {
286 sprint(self, "^1There is already a vote called.\n");
289 votecalledmaster = TRUE;
290 votecalledvote = strzone("XXX");
291 votecalledvote_display = strzone("^3master");
292 votecaller = self; // remember who called the vote
293 votefinished = time + cvar("sv_vote_timeout");
294 votecaller.vote_vote = 1; // of course you vote yes
295 votecaller.vote_next = time + cvar("sv_vote_wait");
296 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n");
297 VoteCount(); // needed if you are the only one
300 sprint(self, "^1Vote to become master is NOT allowed.\n");
302 } else if(argv(1) == "do") {
303 if(argv(2) == "login") {
304 local string masterpwd;
305 masterpwd = cvar_string("sv_vote_master_password");
306 if(masterpwd != "") {
307 self.vote_master = (masterpwd == argv(3));
308 if(self.vote_master) {
309 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
310 bprint("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n");
313 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
316 sprint(self, "^1You are NOT a master.\n");
317 } else if(self.vote_master) {
318 local string dovote, dovote_display;
319 dovote = VoteParse();
321 sprint(self, "^1Your command was empty. See help for more info.\n");
322 } else if(VoteCheckNasty(dovote)) {
323 sprint(self, "Syntax error in command.\n");
324 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
325 if(dovote == "chmap" || dovote == "gotomap") // won't work without arguments
327 if(substring(dovote, 0, 6) == "chmap ")
328 dovote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
329 if(substring(dovote, 0, 8) == "gotomap ")
331 if(!(dovote = ValidateMap(substring(dovote, 8, strlen(dovote) - 8))))
333 dovote = strcat("gotomap ", dovote);
336 dovote_display = dovote;
337 if(substring(dovote, 0, 5) == "kick " || substring(dovote, 0, 8) == "kickban ")
339 if(!(e = GetKickVoteVictim(dovote, "vdo")))
341 dovote_display = strzone(strcat("^1", dovote, " (^7", e.netname, "^1)"));
342 dovote = GetKickVoteVictim_newcommand;
344 bprint("\{1}^2* ^3", self.netname, "^2 used his ^3master^2 status to do \"^2", dovote_display, "^2\".\n");
345 localcmd(strcat(dovote, "\n"));
347 sprint(self, "^1This command is not ok. See help for more info.\n");
350 sprint(self, "^1You are NOT a master.\n");
352 } else if(argv(1) == "yes") {
354 sprint(self, "^1No vote called.\n");
355 } else if(self.vote_vote == 0
356 || cvar("sv_vote_change")) {
357 sprint(self, "^1You accepted the vote.\n");
359 centerprint_expire(self, CENTERPRIO_VOTE);
360 if(!cvar("sv_vote_singlecount")) {
364 sprint(self, "^1You have already voted.\n");
366 } else if(argv(1) == "no") {
368 sprint(self, "^1No vote called.\n");
369 } else if(self.vote_vote == 0
370 || cvar("sv_vote_change")) {
371 sprint(self, "^1You rejected the vote.\n");
373 centerprint_expire(self, CENTERPRIO_VOTE);
374 if(!cvar("sv_vote_singlecount")) {
378 sprint(self, "^1You have already voted.\n");
380 } else if(argv(1) == "abstain" || argv(1) == "dontcare") {
382 sprint(self, "^1No vote called.\n");
383 } else if(self.vote_vote == 0
384 || cvar("sv_vote_change")) {
385 sprint(self, "^1You abstained from your vote.\n");
387 centerprint_expire(self, CENTERPRIO_VOTE);
388 if(!cvar("sv_vote_singlecount")) {
392 sprint(self, "^1You have already voted.\n");
396 sprint(self, "^1Unknown vote command.\n");
398 } else if(argv(0) == "autoswitch") {
399 // be backwards compatible with older clients (enabled)
400 self.autoswitch = ("0" != argv(1));
401 local string autoswitchmsg;
402 if (self.autoswitch) {
403 autoswitchmsg = "on";
405 autoswitchmsg = "off";
407 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
408 } else if(argv(0) == "clientversion") {
409 if (argv(1) == "$gameversion") {
410 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
411 // either that or someone wants to be funny
414 self.version = stof(argv(1));
416 if(self.version != cvar("gameversion"))
418 self.classname = "observer";
421 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
422 //JoinBestTeam(self, 0);
423 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
424 self.classname = "observer";
425 stuffcmd(self,"menu_showteamselect\n");
427 } else if(argv(0) == "reportcvar") { // old system
429 } else if(argv(0) == "sentcvar") { // new system
431 } else if(argv(0) == "spectate") {
433 return; // don't allow spectating in lms, unless player runs out of lives
434 if(self.classname == "player" && cvar("sv_spectate") == 1) {
436 DropFlag(self.flagcarried);
437 kh_Key_DropAll(self, TRUE);
438 WaypointSprite_PlayerDead();
439 DistributeFragsAmongTeam(self, self.team, 1.0);
440 self.classname = "observer";
443 } else if(argv(0) == "join") {
445 if (self.classname != "player")
447 self.classname = "player";
449 bprint ("^4", self.netname, "^4 is playing now\n");
452 } else if( argv(0) == "selectteam" ) {
453 if( !cvar("teamplay") ) {
454 sprint( self, "selecteam can only be used in teamgames\n");
455 } else if(cvar("g_campaign")) {
456 //JoinBestTeam(self, 0);
457 } else if( argv(1) == "none" ) {
459 } else if( argv(1) == "red" ) {
460 SV_ChangeTeam( COLOR_TEAM1 - 1 );
461 } else if( argv(1) == "blue" ) {
462 SV_ChangeTeam( COLOR_TEAM2 - 1 );
463 } else if( argv(1) == "yellow" ) {
464 SV_ChangeTeam( COLOR_TEAM3 - 1 );
465 } else if( argv(1) == "pink" ) {
466 SV_ChangeTeam( COLOR_TEAM4 - 1 );
467 } else if( argv(1) == "auto" ) {
469 JoinBestTeam( self, 0 );
471 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
473 } else if(argv(0) == "ready") {
474 if(cvar("sv_ready_restart"))
476 if(!restart_countdown)
479 bprint(self.netname, "^2 is ready\n");
482 sprint(self, "^1game has already been restarted\n");
485 } else if(argv(0) == "maplist") {
488 n = tokenize(cvar_string("g_maplist"));
489 sprint(self, "^7Maps in list: ");
490 for(i = 0; i < n; ++i)
496 sprint(self, strcat(col, argv(i), " "));
500 } else if(argv(0) == "lsmaps") {
501 sprint(self, "^7Maps available: ");
502 for(i = 0; i < MapInfo_count; ++i)
508 sprint(self, strcat(col, MapInfo_BSPName_ByID(i), " "));
512 } else if(argv(0) == "teamstatus") {
513 PrintScoreboard(self);
514 } else if(argv(0) == "voice") {
515 VoiceMessage(argv(1));
516 } else if(argv(0) == "say") {
517 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
518 //clientcommand(self, formatmessage(s));
519 } else if(argv(0) == "say_team") {
520 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
521 //clientcommand(self, formatmessage(s));
522 } else if(argv(0) == "info") {
523 cmd = cvar_string(strcat("sv_info_", argv(1)));
525 sprint(self, "ERROR: unsupported info command\n");
527 wordwrap_sprint(cmd, 1111);
528 } else if(argv(0) == "suggestmap") {
529 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
532 /* checks not needed any more since DP has separated clientcommands and regular commands
535 //if(cmd != "say") // handled above
536 //if(cmd != "say_team") // handled above
547 if(cmd != "playermodel")
548 if(cmd != "playerskin")
549 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
551 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
555 clientcommand(self,s);
559 string ValidateMap(string m)
562 m = MapInfo_FixName(m);
565 sprint(self, "This map is not available on this server.\n");
569 if(!cvar("sv_vote_change_gametype"))
570 if(!IsSameGametype(m))
572 sprint(self, "This server does not allow changing the game type by map votes.\n");
575 if(!cvar("sv_vote_override_mostrecent"))
578 sprint(self, "This server does not allow for recent maps to be played again. Please be patient for some rounds.\n");
582 if(!MapInfo_CheckMap(m))
584 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not support the current game mode.\n"));
588 if(!TryFile(strcat("maps/", m, ".mapcfg")))
590 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not exist on this server.\n"));
600 if(votefinished > 0 // a vote was called
601 && time > votefinished) // time is up
612 while(argv(index) != "") {
613 vote = strcat(vote, " ", argv(index));
617 // necessary for some of the string operations
618 vote = strzone(vote);
620 // now we remove some things that could be misused
624 local float votelength;
625 votelength = strlen(vote);
626 while(!found && index < votelength)
628 local string badchar;
629 badchar = substring(vote, index, 1);
639 return substring(vote, 0, index);
642 float VoteAllowed(string votecommand) {
643 tokenize(cvar_string("sv_vote_commands"));
646 while(argv(index) != "") {
647 local string allowed;
648 allowed = argv(index);
649 if(votecommand == allowed) {
660 FOR_EACH_CLIENT(player)
662 player.vote_vote = 0;
663 centerprint_expire(player, CENTERPRIO_VOTE);
668 strunzone(votecalledvote);
669 strunzone(votecalledvote_display);
673 votecalledmaster = FALSE;
678 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote_display, "^2 was accepted\n");
681 votecaller.vote_master = 1;
683 localcmd(strcat(votecalledvote, "\n"));
685 votecaller.vote_next = 0; // people like your votes, no wait for next vote
690 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 was rejected\n");
695 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 timed out\n");
699 void VoteStop(entity stopper) {
700 bprint("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n");
701 if(stopper == votecaller) {
702 // no wait for next vote so you can correct your vote
703 votecaller.vote_next = 0;
710 if(self.vote_vote == 0)
711 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."));
714 void VoteSpam(float yescount, float nocount, float abstaincount, float notvoters, float mincount)
717 s = strcat("\{1}^2* vote results: ^1", ftos(yescount), "^2:^1");
718 s = strcat(s, ftos(nocount), "^2 (^1");
719 s = strcat(s, ftos(mincount), "^2 needed), ^1");
720 s = strcat(s, ftos(abstaincount), "^2 didn't care, ^1");
721 s = strcat(s, ftos(notvoters), "^2 didn't vote\n");
726 local float playercount;
728 local float yescount;
732 local float abstaincount;
736 FOR_EACH_REALCLIENT(player)
738 if(player.vote_vote == -1) {
740 } else if(player.vote_vote == 1) {
742 } else if(player.vote_vote == -2) {
748 if((playercount == 1) && votecalledmaster) {
749 // if only one player is on the server becoming vote
750 // master is not allowed. This could be used for
751 // trolling or worse. 'self' is the user who has
752 // called the vote because this function is called
753 // by SV_ParseClientCommand. Maybe all voting should
754 // be disabled for a single player?
755 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
756 votecaller.vote_next = 0;
760 votefactor = bound(0.5, cvar("sv_vote_majority_factor"), 0.999);
761 if(yescount > (playercount - abstaincount) * votefactor)
763 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor((playercount - abstaincount) * votefactor) + 1);
766 else if(nocount >= (playercount - abstaincount) * (1 - votefactor)) // that means, yescount cannot reach minyes any more
768 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor((playercount - abstaincount) * votefactor) + 1);
771 else if(time > votefinished)
773 if(cvar("sv_vote_simple_majority"))
775 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor((yescount + nocount) * votefactor) + 1);
776 if(yescount > (yescount + nocount) * votefactor)
778 else if(yescount + nocount > 0)
785 VoteSpam(yescount, nocount, abstaincount, playercount - yescount - nocount - abstaincount, floor((playercount - abstaincount) * votefactor) + 1);
792 float timelimit_orig;
799 FOR_EACH_REALPLAYER(e)
809 bprint("^1Server is restarting...\n");
811 // no arena, assault & onslaught support yet...
812 if(g_arena | g_assault | g_onslaught | gameover | intermission_running)
813 localcmd("restart\n");
815 restart_countdown = time + RESTART_COUNTDOWN;
816 if(0<cvar("timelimit"))
818 // remember original timelimit on first restart
820 timelimit_orig = cvar("timelimit");
821 cvar_set("timelimit", ftos(timelimit_orig + ceil(restart_countdown)/60));
826 if(cvar("sv_eventlog"))
827 GameLogEcho(":restart", FALSE);