2 float 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;
14 msgin = formatmessage(msgin);
19 colorstr = Team_ColorCode(source.team);
24 if(intermission_running)
27 if(source.classname != "player") // observers can't
31 * using bprint solves this... me stupid
32 // how can we prevent the message from appearing in a listen server?
33 // for now, just give "say" back and only handle say_team
36 clientcommand(self, strcat("say ", msgin));
42 if(substring(msgin, 0, 1) == " ")
43 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
45 if(cvar("g_chat_teamcolors"))
46 namestr = playername(source);
48 namestr = source.netname;
49 if(substring(namestr, strlen(namestr) - 1, 1) == "^")
50 namestr = strdecolorize(namestr); // BROKEN!
53 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin, "\n"));
54 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", wordwrap(msgin, 50));
57 msgstr = strzone(strcat("\{1}^3", namestr, "^7: ", msgin, "\n"));
65 var .float flood_field;
69 flood_spl = cvar("g_chat_flood_spl_team");
70 flood_burst = cvar("g_chat_flood_burst_team");
71 flood_lmax = cvar("g_chat_flood_lmax_team");
72 flood_field = floodcontrol_team;
76 flood_spl = cvar("g_chat_flood_spl");
77 flood_burst = cvar("g_chat_flood_burst");
78 flood_lmax = cvar("g_chat_flood_lmax");
79 flood_field = floodcontrol_chat;
81 flood_burst = max(0, flood_burst - 1);
82 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
83 lines = ceil(strlennocol(msgstr) / 75);
84 if(flood_lmax && lines > flood_lmax)
86 else if(time >= self.flood_field)
87 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
94 if(cvar("g_chat_flood_notify_flooder"))
97 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
99 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
102 sprint(self, msgstr);
103 ServerConsoleEcho(strcat("NOTE: ", playername(self), "^7 is flooding."), TRUE);
107 FOR_EACH_REALPLAYER(head)
109 if(head.team == source.team)
111 sprint(head, msgstr);
112 centerprint(head, cmsgstr);
119 //ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
125 void SV_ParseClientCommand(string s) {
130 if(argv(0) == "vote") {
131 if(argv(1) == "help") {
132 local string vmasterdis;
133 if(!cvar("sv_vote_master")) {
134 vmasterdis = " ^1(disabled)";
136 local string vcalldis;
137 if(!cvar("sv_vote_call")) {
138 vcalldis = " ^1(disabled)";
140 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");
141 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");
142 sprint(self, "^7\"^2help^7\" shows this info.\n");
143 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
144 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
145 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
146 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
147 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");
148 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
149 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
150 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
151 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
152 sprint(self, "^7You can call a vote for or execute these commands:\n");
153 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
154 } else if(argv(1) == "status") {
156 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
158 sprint(self, "^1No vote called.\n");
160 } else if(argv(1) == "call") {
161 if(cvar("sv_vote_call")) {
163 sprint(self, "^1There is already a vote called.\n");
168 sprint(self, "^1Your vote is empty. See help for more info.\n");
169 } else if(time < self.vote_next) {
170 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
171 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
172 if(!ValidateMap(vote))
175 votecalledmaster = FALSE;
176 // remap chmap to gotomap (forces intermission)
177 if(strlen(vote) >= 6)
178 if(substring(vote, 0, 6) == "chmap ")
179 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
180 votecalledvote = strzone(vote);
181 votecaller = self; // remember who called the vote
182 votefinished = time + cvar("sv_vote_timeout");
183 votecaller.vote_vote = 1; // of course you vote yes
184 votecaller.vote_next = time + cvar("sv_vote_wait");
185 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ^1", votecalledvote, "\n");
186 VoteCount(); // needed if you are the only one
188 sprint(self, "^1This vote is not ok. See help for more info.\n");
192 sprint(self, "^1Vote calling is NOT allowed.\n");
194 } else if(argv(1) == "stop") {
196 sprint(self, "^1No vote called.\n");
197 } else if(self == votecaller) { // the votecaller can stop a vote
200 sprint(self, "^1You are not allowed to stop that Vote.\n");
202 } else if(argv(1) == "master") {
203 if(cvar("sv_vote_master")) {
205 sprint(self, "^1There is already a vote called.\n");
208 votecalledmaster = TRUE;
209 votecalledvote = strzone("^3master");
210 votecaller = self; // remember who called the vote
211 votefinished = time + cvar("sv_vote_timeout");
212 votecaller.vote_vote = 1; // of course you vote yes
213 votecaller.vote_next = time + cvar("sv_vote_wait");
214 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n");
215 VoteCount(); // needed if you are the only one
218 sprint(self, "^1Vote to become master is NOT allowed.\n");
220 } else if(argv(1) == "do") {
221 if(argv(2) == "login") {
222 local string masterpwd;
223 masterpwd = cvar_string("sv_vote_master_password");
224 if(masterpwd != "") {
225 self.vote_master = (masterpwd == argv(3));
226 if(self.vote_master) {
227 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
228 bprint("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n");
231 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
234 sprint(self, "^1You are NOT a master.\n");
235 } else if(self.vote_master) {
237 dovote = VoteParse();
239 sprint(self, "^1Your command was empty. See help for more info.\n");
240 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
241 if(!ValidateMap(dovote))
243 // remap chmap to gotomap (forces intermission)
244 if(strlen(dovote) >= 6)
245 if(substring(dovote, 0, 6) == "chmap ")
246 vote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
247 bprint("\{1}^2* ^3", self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n");
248 localcmd(strcat(dovote, "\n"));
250 sprint(self, "^1This command is not ok. See help for more info.\n");
253 sprint(self, "^1You are NOT a master.\n");
255 } else if(argv(1) == "yes") {
257 sprint(self, "^1No vote called.\n");
258 } else if(self.vote_vote == 0
259 || cvar("sv_vote_change")) {
260 sprint(self, "^1You accepted the vote.\n");
262 if(!cvar("sv_vote_singlecount")) {
266 sprint(self, "^1You have already voted.\n");
268 } else if(argv(1) == "no") {
270 sprint(self, "^1No vote called.\n");
271 } else if(self.vote_vote == 0
272 || cvar("sv_vote_change")) {
273 sprint(self, "^1You rejected the vote.\n");
275 if(!cvar("sv_vote_singlecount")) {
279 sprint(self, "^1You have already voted.\n");
283 sprint(self, "^1Unknown vote command.\n");
285 } else if(argv(0) == "autoswitch") {
286 // be backwards compatible with older clients (enabled)
287 self.autoswitch = ("0" != argv(1));
288 local string autoswitchmsg;
289 if (self.autoswitch) {
290 autoswitchmsg = "on";
292 autoswitchmsg = "off";
294 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
295 } else if(argv(0) == "clientversion") {
296 if (argv(1) == "$gameversion") {
297 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
298 // either that or someone wants to be funny
301 self.version = stof(argv(1));
303 if(self.version != cvar("gameversion"))
305 self.classname = "observer";
308 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
309 //JoinBestTeam(self, 0);
310 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
311 self.classname = "observer";
312 stuffcmd(self,"menu_showteamselect\n");
314 } else if(argv(0) == "reportcvar") {
316 } else if(argv(0) == "spectate") {
317 if(cvar("g_lms") || cvar("g_arena"))
318 return; // don't allow spectating in lms, unless player runs out of lives
319 if(self.classname == "player" && cvar("sv_spectate") == 1) {
321 DropFlag(self.flagcarried);
322 DistributeFragsAmongTeam(self, self.team, 1.0);
323 self.classname = "observer";
326 } else if(argv(0) == "join") {
328 if (self.classname != "player")
330 self.classname = "player";
332 bprint ("^4", self.netname, "^4 is playing now\n");
335 } else if( argv(0) == "selectteam" ) {
336 if( !cvar("teamplay") ) {
337 sprint( self, "selecteam can only be used in teamgames\n");
338 } else if(cvar("g_campaign")) {
339 //JoinBestTeam(self, 0);
340 } else if( argv(1) == "none" ) {
342 } else if( argv(1) == "red" ) {
343 SV_ChangeTeam( COLOR_TEAM1 - 1 );
344 } else if( argv(1) == "blue" ) {
345 SV_ChangeTeam( COLOR_TEAM2 - 1 );
346 } else if( argv(1) == "pink" ) {
347 SV_ChangeTeam( COLOR_TEAM3 - 1 );
348 } else if( argv(1) == "yellow" ) {
349 SV_ChangeTeam( COLOR_TEAM4 - 1 );
350 } else if( argv(1) == "auto" ) {
352 JoinBestTeam( self, 0 );
354 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
356 } else if(argv(0) == "ready") {
357 if(cvar("sv_ready_restart"))
360 bprint(self.netname, "^2 is ready\n");
363 } else if(argv(0) == "maplist") {
366 n = tokenize(cvar_string("g_maplist"));
367 sprint(self, "^7Maps in list: ");
368 for(i = 0; i < n; ++i)
374 sprint(self, strcat(col, argv(i), " "));
377 } else if(argv(0) == "teamstatus") {
378 PrintScoreboard(self);
379 } else if(argv(0) == "say") {
380 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
381 //clientcommand(self, formatmessage(s));
382 } else if(argv(0) == "say_team") {
383 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
384 //clientcommand(self, formatmessage(s));
385 } else if(argv(0) == "info") {
386 cmd = cvar_string(strcat("sv_info_", argv(1)));
388 sprint(self, "ERROR: unsupported info command\n");
390 wordwrap_sprint(cmd, 1111);
391 } else if(argv(0) == "suggestmap") {
392 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
395 /* checks not needed any more since DP has separated clientcommands and regular commands
398 //if(cmd != "say") // handled above
399 //if(cmd != "say_team") // handled above
410 if(cmd != "playermodel")
411 if(cmd != "playerskin")
412 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
414 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
418 clientcommand(self,s);
422 float ValidateMap(string vote)
427 if(argv(0) == "map" || argv(0) == "changelevel")
429 else if(argv(0) == "chmap")
431 else if(argv(0) == "gotomap")
436 if(!TryFile(strcat("maps/", argv(1), ext)))
438 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
446 if(votefinished > 0 // a vote was called
447 && time > votefinished) // time is up
458 while(argv(index) != "") {
459 vote = strcat(vote, " ", argv(index));
463 // necessary for some of the string operations
464 vote = strzone(vote);
466 // now we remove some things that could be misused
470 local float votelength;
471 votelength = strlen(vote);
472 while(!found && index < votelength)
474 local string badchar;
475 badchar = substring(vote, index, 1);
485 return substring(vote, 0, index);
488 float VoteAllowed(string votecommand) {
489 tokenize(cvar_string("sv_vote_commands"));
492 while(argv(index) != "") {
493 local string allowed;
494 allowed = argv(index);
495 if(votecommand == allowed) {
506 FOR_EACH_CLIENT(player)
508 player.vote_vote = 0;
509 centerprint_expire(player, CENTERPRIO_VOTE);
513 votecalledmaster = FALSE;
518 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was accepted\n");
521 votecaller.vote_master = 1;
523 localcmd(strcat(votecalledvote, "\n"));
525 votecaller.vote_next = 0; // people like your votes, no wait for next vote
530 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was rejected\n");
535 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 timed out\n");
539 void VoteStop(entity stopper) {
540 bprint("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n");
541 if(stopper == votecaller) {
542 // no wait for next vote so you can correct your vote
543 votecaller.vote_next = 0;
550 if(self.vote_vote == 0)
551 centerprint_atprio(self, CENTERPRIO_VOTE, strcat("^7^3", votecaller.netname, "^2 called a vote for ^1", votecalledvote, "\n\n^2You have not voted yet!\n^2HINT: By default, F1 is yes and F2 is no."));
555 local float playercount;
557 local float yescount;
563 FOR_EACH_REALCLIENT(player)
565 if(player.vote_vote < 0) {
567 } else if(player.vote_vote > 0) {
573 if((playercount == 1) && votecalledmaster) {
574 // if only one player is on the server becoming vote
575 // master is not allowed. This could be used for
576 // trolling or worse. 'self' is the user who has
577 // called the vote because this function is called
578 // by SV_ParseClientCommand. Maybe all voting should
579 // be disabled for a single player?
580 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
581 votecaller.vote_next = 0;
583 } else if((playercount / 2) < yescount) { // vote accepted
585 } else if((playercount / 2) < nocount) { // vote rejected
587 } else if(time > votefinished) { // vote timedout
588 if(cvar("sv_vote_simple_majority"))
589 if(yescount > nocount)
591 else if(nocount > yescount)
597 } // else still running
606 FOR_EACH_REALPLAYER(e)
615 bprint("^1Server is restarting...\n");
616 localcmd("restart\n");