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 string GetKickVoteVictim_newcommand;
134 entity GetKickVoteVictim(string vote, string cmd)
141 tokens = tokenize(vote);
145 if(substring(argv(1), 0, 1) == "#")
146 ns = substring(argv(1), 1, 999);
155 if(ns == ftos(n)) if(n >= 1) if(n <= maxclients)
157 for((e = world), (i = 0); i < n; ++i, (e = nextent(e)))
159 if(clienttype(e) == CLIENTTYPE_REAL)
161 GetKickVoteVictim_newcommand = strcat(argv(0), " # ", ns);
167 sprint(self, strcat("Usage: ", cmd, " ", argv(0), " #playernumber (as in \"status\")\n"));
171 void SV_ParseClientCommand(string s) {
178 if(argv(0) == "vote") {
179 if(argv(1) == "help") {
180 local string vmasterdis;
181 if(!cvar("sv_vote_master")) {
182 vmasterdis = " ^1(disabled)";
184 local string vcalldis;
185 if(!cvar("sv_vote_call")) {
186 vcalldis = " ^1(disabled)";
188 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\".\n");
189 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\".\n");
190 sprint(self, "^7\"^2help^7\" shows this info.\n");
191 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
192 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
193 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
194 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
195 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");
196 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
197 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
198 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
199 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
200 sprint(self, "^7You can call a vote for or execute these commands:\n");
201 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
202 } else if(argv(1) == "status") {
204 sprint(self, strcat("^7Vote for ", votecalledvote_display, "^7 called by ^7", votecaller.netname, "^7.\n"));
206 sprint(self, "^1No vote called.\n");
208 } else if(argv(1) == "call") {
209 if(cvar("sv_vote_call")) {
211 sprint(self, "^1There is already a vote called.\n");
216 sprint(self, "^1Your vote is empty. See help for more info.\n");
217 } else if(time < self.vote_next) {
218 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
219 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
220 // remap chmap to gotomap (forces intermission)
221 if(vote == "chmap" || vote == "gotomap") // won't work without arguments
223 if(substring(vote, 0, 6) == "chmap ")
224 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
225 if(substring(vote, 0, 8) == "gotomap ")
227 if(!(vote = ValidateMap(substring(vote, 8, strlen(vote) - 8))))
229 vote = strcat("gotomap ", vote);
232 // make kick and kickban votes a bit nicer (and reject them if formatted badly)
233 if(substring(vote, 0, 5) == "kick " || substring(vote, 0, 8) == "kickban ")
235 if(!(e = GetKickVoteVictim(vote, "vcall")))
237 votecalledvote_display = strzone(strcat("^1", vote, " (^7", e.netname, "^1)"));
238 vote = GetKickVoteVictim_newcommand;
242 votecalledvote_display = strzone(strcat("^1", vote));
244 votecalledvote = strzone(vote);
246 votecalledmaster = FALSE;
247 votecaller = self; // remember who called the vote
248 votefinished = time + cvar("sv_vote_timeout");
249 votecaller.vote_vote = 1; // of course you vote yes
250 votecaller.vote_next = time + cvar("sv_vote_wait");
251 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ", votecalledvote_display, "\n");
252 VoteCount(); // needed if you are the only one
254 sprint(self, "^1This vote is not ok. See help for more info.\n");
258 sprint(self, "^1Vote calling is NOT allowed.\n");
260 } else if(argv(1) == "stop") {
262 sprint(self, "^1No vote called.\n");
263 } else if(self == votecaller) { // the votecaller can stop a vote
265 } else if(self.vote_master) { // masters can, too
268 sprint(self, "^1You are not allowed to stop that Vote.\n");
270 } else if(argv(1) == "master") {
271 if(cvar("sv_vote_master")) {
273 sprint(self, "^1There is already a vote called.\n");
276 votecalledmaster = TRUE;
277 votecalledvote = strzone("XXX");
278 votecalledvote_display = strzone("^3master");
279 votecaller = self; // remember who called the vote
280 votefinished = time + cvar("sv_vote_timeout");
281 votecaller.vote_vote = 1; // of course you vote yes
282 votecaller.vote_next = time + cvar("sv_vote_wait");
283 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n");
284 VoteCount(); // needed if you are the only one
287 sprint(self, "^1Vote to become master is NOT allowed.\n");
289 } else if(argv(1) == "do") {
290 if(argv(2) == "login") {
291 local string masterpwd;
292 masterpwd = cvar_string("sv_vote_master_password");
293 if(masterpwd != "") {
294 self.vote_master = (masterpwd == argv(3));
295 if(self.vote_master) {
296 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
297 bprint("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n");
300 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
303 sprint(self, "^1You are NOT a master.\n");
304 } else if(self.vote_master) {
305 local string dovote, dovote_display;
306 dovote = VoteParse();
308 sprint(self, "^1Your command was empty. See help for more info.\n");
309 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
310 if(dovote == "chmap" || dovote == "gotomap") // won't work without arguments
312 if(substring(dovote, 0, 6) == "chmap ")
313 dovote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
314 if(substring(dovote, 0, 8) == "gotomap ")
316 if(!(dovote = ValidateMap(substring(dovote, 8, strlen(dovote) - 8))))
318 dovote = strcat("gotomap ", dovote);
321 dovote_display = dovote;
322 if(substring(dovote, 0, 5) == "kick " || substring(dovote, 0, 8) == "kickban ")
324 if(!(e = GetKickVoteVictim(dovote, "vdo")))
326 dovote_display = strzone(strcat("^1", dovote, " (^7", e.netname, "^1)"));
327 dovote = GetKickVoteVictim_newcommand;
329 bprint("\{1}^2* ^3", self.netname, "^2 used his ^3master^2 status to do \"^2", dovote_display, "^2\".\n");
330 localcmd(strcat(dovote, "\n"));
332 sprint(self, "^1This command is not ok. See help for more info.\n");
335 sprint(self, "^1You are NOT a master.\n");
337 } else if(argv(1) == "yes") {
339 sprint(self, "^1No vote called.\n");
340 } else if(self.vote_vote == 0
341 || cvar("sv_vote_change")) {
342 sprint(self, "^1You accepted the vote.\n");
344 if(!cvar("sv_vote_singlecount")) {
348 sprint(self, "^1You have already voted.\n");
350 } else if(argv(1) == "no") {
352 sprint(self, "^1No vote called.\n");
353 } else if(self.vote_vote == 0
354 || cvar("sv_vote_change")) {
355 sprint(self, "^1You rejected the vote.\n");
357 if(!cvar("sv_vote_singlecount")) {
361 sprint(self, "^1You have already voted.\n");
365 sprint(self, "^1Unknown vote command.\n");
367 } else if(argv(0) == "autoswitch") {
368 // be backwards compatible with older clients (enabled)
369 self.autoswitch = ("0" != argv(1));
370 local string autoswitchmsg;
371 if (self.autoswitch) {
372 autoswitchmsg = "on";
374 autoswitchmsg = "off";
376 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
377 } else if(argv(0) == "clientversion") {
378 if (argv(1) == "$gameversion") {
379 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
380 // either that or someone wants to be funny
383 self.version = stof(argv(1));
385 if(self.version != cvar("gameversion"))
387 self.classname = "observer";
390 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
391 //JoinBestTeam(self, 0);
392 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
393 self.classname = "observer";
394 stuffcmd(self,"menu_showteamselect\n");
396 } else if(argv(0) == "reportcvar") { // old system
398 } else if(argv(0) == "sentcvar") { // new system
400 } else if(argv(0) == "spectate") {
402 return; // don't allow spectating in lms, unless player runs out of lives
403 if(self.classname == "player" && cvar("sv_spectate") == 1) {
405 DropFlag(self.flagcarried);
406 kh_Key_DropAll(self, TRUE);
407 WaypointSprite_PlayerDead();
408 DistributeFragsAmongTeam(self, self.team, 1.0);
409 self.classname = "observer";
412 } else if(argv(0) == "join") {
414 if (self.classname != "player")
416 self.classname = "player";
418 bprint ("^4", self.netname, "^4 is playing now\n");
421 } else if( argv(0) == "selectteam" ) {
422 if( !cvar("teamplay") ) {
423 sprint( self, "selecteam can only be used in teamgames\n");
424 } else if(cvar("g_campaign")) {
425 //JoinBestTeam(self, 0);
426 } else if( argv(1) == "none" ) {
428 } else if( argv(1) == "red" ) {
429 SV_ChangeTeam( COLOR_TEAM1 - 1 );
430 } else if( argv(1) == "blue" ) {
431 SV_ChangeTeam( COLOR_TEAM2 - 1 );
432 } else if( argv(1) == "yellow" ) {
433 SV_ChangeTeam( COLOR_TEAM3 - 1 );
434 } else if( argv(1) == "pink" ) {
435 SV_ChangeTeam( COLOR_TEAM4 - 1 );
436 } else if( argv(1) == "auto" ) {
438 JoinBestTeam( self, 0 );
440 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
442 } else if(argv(0) == "ready") {
443 if(cvar("sv_ready_restart"))
445 if(!restart_countdown)
448 bprint(self.netname, "^2 is ready\n");
451 sprint(self, "^1game has already been restarted\n");
454 } else if(argv(0) == "maplist") {
457 n = tokenize(cvar_string("g_maplist"));
458 sprint(self, "^7Maps in list: ");
459 for(i = 0; i < n; ++i)
465 sprint(self, strcat(col, argv(i), " "));
469 } else if(argv(0) == "lsmaps") {
470 sprint(self, "^7Maps available: ");
471 for(i = 0; i < MapInfo_count; ++i)
477 sprint(self, strcat(col, MapInfo_BSPName_ByID(i), " "));
481 } else if(argv(0) == "teamstatus") {
482 PrintScoreboard(self);
483 } else if(argv(0) == "voice") {
484 VoiceMessage(argv(1));
485 } else if(argv(0) == "say") {
486 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
487 //clientcommand(self, formatmessage(s));
488 } else if(argv(0) == "say_team") {
489 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
490 //clientcommand(self, formatmessage(s));
491 } else if(argv(0) == "info") {
492 cmd = cvar_string(strcat("sv_info_", argv(1)));
494 sprint(self, "ERROR: unsupported info command\n");
496 wordwrap_sprint(cmd, 1111);
497 } else if(argv(0) == "suggestmap") {
498 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
501 /* checks not needed any more since DP has separated clientcommands and regular commands
504 //if(cmd != "say") // handled above
505 //if(cmd != "say_team") // handled above
516 if(cmd != "playermodel")
517 if(cmd != "playerskin")
518 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
520 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
524 clientcommand(self,s);
528 string ValidateMap(string m)
531 m = MapInfo_FixName(m);
534 sprint(self, "This map is not available on this server.\n");
538 if(!cvar("sv_vote_change_gametype"))
539 if(!IsSameGametype(m))
541 sprint(self, "This server does not allow changing the game type by map votes.\n");
544 if(!cvar("sv_vote_override_mostrecent"))
547 sprint(self, "This server does not allow for recent maps to be played again. Please be patient for some rounds.\n");
551 if(!MapInfo_CheckMap(m))
553 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not support the current game mode.\n"));
557 if(!TryFile(strcat("maps/", m, ".mapcfg")))
559 sprint(self, strcat("^1Invalid mapname, \"^3", m, "^1\" does not exist on this server.\n"));
569 if(votefinished > 0 // a vote was called
570 && time > votefinished) // time is up
581 while(argv(index) != "") {
582 vote = strcat(vote, " ", argv(index));
586 // necessary for some of the string operations
587 vote = strzone(vote);
589 // now we remove some things that could be misused
593 local float votelength;
594 votelength = strlen(vote);
595 while(!found && index < votelength)
597 local string badchar;
598 badchar = substring(vote, index, 1);
608 return substring(vote, 0, index);
611 float VoteAllowed(string votecommand) {
612 tokenize(cvar_string("sv_vote_commands"));
615 while(argv(index) != "") {
616 local string allowed;
617 allowed = argv(index);
618 if(votecommand == allowed) {
629 FOR_EACH_CLIENT(player)
631 player.vote_vote = 0;
632 centerprint_expire(player, CENTERPRIO_VOTE);
637 strunzone(votecalledvote);
638 strunzone(votecalledvote_display);
642 votecalledmaster = FALSE;
647 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote_display, "^2 was accepted\n");
650 votecaller.vote_master = 1;
652 localcmd(strcat(votecalledvote, "\n"));
654 votecaller.vote_next = 0; // people like your votes, no wait for next vote
659 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 was rejected\n");
664 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ", votecalledvote_display, "^2 timed out\n");
668 void VoteStop(entity stopper) {
669 bprint("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n");
670 if(stopper == votecaller) {
671 // no wait for next vote so you can correct your vote
672 votecaller.vote_next = 0;
679 if(self.vote_vote == 0)
680 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."));
684 local float playercount;
686 local float yescount;
692 FOR_EACH_REALCLIENT(player)
694 if(player.vote_vote < 0) {
696 } else if(player.vote_vote > 0) {
702 if((playercount == 1) && votecalledmaster) {
703 // if only one player is on the server becoming vote
704 // master is not allowed. This could be used for
705 // trolling or worse. 'self' is the user who has
706 // called the vote because this function is called
707 // by SV_ParseClientCommand. Maybe all voting should
708 // be disabled for a single player?
709 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
710 votecaller.vote_next = 0;
712 } else if((playercount / 2) < yescount) { // vote accepted
714 } else if((playercount / 2) < nocount) { // vote rejected
716 } else if(time > votefinished) { // vote timedout
717 if(cvar("sv_vote_simple_majority"))
718 if(yescount > nocount)
720 else if(nocount > yescount)
726 } // else still running
729 float timelimit_orig;
736 FOR_EACH_REALPLAYER(e)
746 bprint("^1Server is restarting...\n");
748 // no arena, assault & onslaught support yet...
749 if(g_arena | g_assault | g_onslaught | gameover | intermission_running)
750 localcmd("restart\n");
752 restart_countdown = time + RESTART_COUNTDOWN;
753 if(0<cvar("timelimit"))
755 // remember original timelimit on first restart
757 timelimit_orig = cvar("timelimit");
758 cvar_set("timelimit", ftos(timelimit_orig + ceil(restart_countdown)/60));
763 if(cvar("sv_eventlog"))
764 GameLogEcho(":restart", FALSE);