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;
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 colorstr = Team_ColorCode(source.team);
28 if(intermission_running)
31 if(source.classname != "player") // observers can't
35 * using bprint solves this... me stupid
36 // how can we prevent the message from appearing in a listen server?
37 // for now, just give "say" back and only handle say_team
40 clientcommand(self, strcat("say ", msgin));
45 if(cvar("g_chat_teamcolors"))
46 namestr = playername(source);
48 namestr = source.netname;
51 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin, "\n"));
52 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", wordwrap(msgin, 50));
55 msgstr = strzone(strcat("\{1}", namestr, "^7: ", msgin, "\n"));
63 var .float flood_field;
67 flood_spl = cvar("g_chat_flood_spl_team");
68 flood_burst = cvar("g_chat_flood_burst_team");
69 flood_lmax = cvar("g_chat_flood_lmax_team");
70 flood_field = floodcontrol_team;
74 flood_spl = cvar("g_chat_flood_spl");
75 flood_burst = cvar("g_chat_flood_burst");
76 flood_lmax = cvar("g_chat_flood_lmax");
77 flood_field = floodcontrol_chat;
79 flood_burst = max(0, flood_burst - 1);
80 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
81 lines = ceil(strlennocol(msgstr) / 75);
82 if(flood_lmax && lines > flood_lmax)
84 else if(time >= self.flood_field)
85 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
92 if(cvar("g_chat_flood_notify_flooder"))
95 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
97 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
100 sprint(self, msgstr);
101 ServerConsoleEcho(strcat("NOTE: ", playername(self), "^7 is flooding."), TRUE);
105 FOR_EACH_REALPLAYER(head)
107 if(head.team == source.team)
109 sprint(head, msgstr);
110 centerprint(head, cmsgstr);
117 //ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
123 void SV_ParseClientCommand(string s) {
128 if(argv(0) == "vote") {
129 if(argv(1) == "help") {
130 local string vmasterdis;
131 if(!cvar("sv_vote_master")) {
132 vmasterdis = " ^1(disabled)";
134 local string vcalldis;
135 if(!cvar("sv_vote_call")) {
136 vcalldis = " ^1(disabled)";
138 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");
139 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");
140 sprint(self, "^7\"^2help^7\" shows this info.\n");
141 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
142 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
143 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
144 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
145 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");
146 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
147 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
148 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
149 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
150 sprint(self, "^7You can call a vote for or execute these commands:\n");
151 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
152 } else if(argv(1) == "status") {
154 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
156 sprint(self, "^1No vote called.\n");
158 } else if(argv(1) == "call") {
159 if(cvar("sv_vote_call")) {
161 sprint(self, "^1There is already a vote called.\n");
166 sprint(self, "^1Your vote is empty. See help for more info.\n");
167 } else if(time < self.vote_next) {
168 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
169 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
170 if(!ValidateMap(vote))
173 votecalledmaster = FALSE;
174 // remap chmap to gotomap (forces intermission)
175 if(strlen(vote) >= 6)
176 if(substring(vote, 0, 6) == "chmap ")
177 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
178 votecalledvote = strzone(vote);
179 votecaller = self; // remember who called the vote
180 votefinished = time + cvar("sv_vote_timeout");
181 votecaller.vote_vote = 1; // of course you vote yes
182 votecaller.vote_next = time + cvar("sv_vote_wait");
183 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ^1", votecalledvote, "\n");
184 VoteCount(); // needed if you are the only one
186 sprint(self, "^1This vote is not ok. See help for more info.\n");
190 sprint(self, "^1Vote calling is NOT allowed.\n");
192 } else if(argv(1) == "stop") {
194 sprint(self, "^1No vote called.\n");
195 } else if(self == votecaller) { // the votecaller can stop a vote
198 sprint(self, "^1You are not allowed to stop that Vote.\n");
200 } else if(argv(1) == "master") {
201 if(cvar("sv_vote_master")) {
203 sprint(self, "^1There is already a vote called.\n");
206 votecalledmaster = TRUE;
207 votecalledvote = strzone("^3master");
208 votecaller = self; // remember who called the vote
209 votefinished = time + cvar("sv_vote_timeout");
210 votecaller.vote_vote = 1; // of course you vote yes
211 votecaller.vote_next = time + cvar("sv_vote_wait");
212 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n");
213 VoteCount(); // needed if you are the only one
216 sprint(self, "^1Vote to become master is NOT allowed.\n");
218 } else if(argv(1) == "do") {
219 if(argv(2) == "login") {
220 local string masterpwd;
221 masterpwd = cvar_string("sv_vote_master_password");
222 if(masterpwd != "") {
223 self.vote_master = (masterpwd == argv(3));
224 if(self.vote_master) {
225 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
226 bprint("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n");
229 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
232 sprint(self, "^1You are NOT a master.\n");
233 } else if(self.vote_master) {
235 dovote = VoteParse();
237 sprint(self, "^1Your command was empty. See help for more info.\n");
238 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
239 if(!ValidateMap(dovote))
241 // remap chmap to gotomap (forces intermission)
242 if(strlen(dovote) >= 6)
243 if(substring(dovote, 0, 6) == "chmap ")
244 vote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
245 bprint("\{1}^2* ^3", self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n");
246 localcmd(strcat(dovote, "\n"));
248 sprint(self, "^1This command is not ok. See help for more info.\n");
251 sprint(self, "^1You are NOT a master.\n");
253 } else if(argv(1) == "yes") {
255 sprint(self, "^1No vote called.\n");
256 } else if(self.vote_vote == 0
257 || cvar("sv_vote_change")) {
258 sprint(self, "^1You accepted the vote.\n");
260 if(!cvar("sv_vote_singlecount")) {
264 sprint(self, "^1You have already voted.\n");
266 } else if(argv(1) == "no") {
268 sprint(self, "^1No vote called.\n");
269 } else if(self.vote_vote == 0
270 || cvar("sv_vote_change")) {
271 sprint(self, "^1You rejected the vote.\n");
273 if(!cvar("sv_vote_singlecount")) {
277 sprint(self, "^1You have already voted.\n");
281 sprint(self, "^1Unknown vote command.\n");
283 } else if(argv(0) == "autoswitch") {
284 // be backwards compatible with older clients (enabled)
285 self.autoswitch = ("0" != argv(1));
286 local string autoswitchmsg;
287 if (self.autoswitch) {
288 autoswitchmsg = "on";
290 autoswitchmsg = "off";
292 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
293 } else if(argv(0) == "clientversion") {
294 if (argv(1) == "$gameversion") {
295 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
296 // either that or someone wants to be funny
299 self.version = stof(argv(1));
301 if(self.version != cvar("gameversion"))
303 self.classname = "observer";
306 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
307 //JoinBestTeam(self, 0);
308 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
309 self.classname = "observer";
310 stuffcmd(self,"menu_showteamselect\n");
312 } else if(argv(0) == "reportcvar") { // old system
314 } else if(argv(0) == "sentcvar") { // new system
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 kh_Key_DropAll(self, TRUE);
323 WaypointSprite_PlayerDead();
324 DistributeFragsAmongTeam(self, self.team, 1.0);
325 self.classname = "observer";
328 } else if(argv(0) == "join") {
330 if (self.classname != "player")
332 self.classname = "player";
334 bprint ("^4", self.netname, "^4 is playing now\n");
337 } else if( argv(0) == "selectteam" ) {
338 if( !cvar("teamplay") ) {
339 sprint( self, "selecteam can only be used in teamgames\n");
340 } else if(cvar("g_campaign")) {
341 //JoinBestTeam(self, 0);
342 } else if( argv(1) == "none" ) {
344 } else if( argv(1) == "red" ) {
345 SV_ChangeTeam( COLOR_TEAM1 - 1 );
346 } else if( argv(1) == "blue" ) {
347 SV_ChangeTeam( COLOR_TEAM2 - 1 );
348 } else if( argv(1) == "yellow" ) {
349 SV_ChangeTeam( COLOR_TEAM3 - 1 );
350 } else if( argv(1) == "pink" ) {
351 SV_ChangeTeam( COLOR_TEAM4 - 1 );
352 } else if( argv(1) == "auto" ) {
354 JoinBestTeam( self, 0 );
356 sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
358 } else if(argv(0) == "ready") {
359 if(cvar("sv_ready_restart"))
362 bprint(self.netname, "^2 is ready\n");
365 } else if(argv(0) == "maplist") {
368 n = tokenize(cvar_string("g_maplist"));
369 sprint(self, "^7Maps in list: ");
370 for(i = 0; i < n; ++i)
376 sprint(self, strcat(col, argv(i), " "));
379 } else if(argv(0) == "teamstatus") {
380 PrintScoreboard(self);
381 } else if(argv(0) == "say") {
382 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
383 //clientcommand(self, formatmessage(s));
384 } else if(argv(0) == "say_team") {
385 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
386 //clientcommand(self, formatmessage(s));
387 } else if(argv(0) == "info") {
388 cmd = cvar_string(strcat("sv_info_", argv(1)));
390 sprint(self, "ERROR: unsupported info command\n");
392 wordwrap_sprint(cmd, 1111);
393 } else if(argv(0) == "suggestmap") {
394 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
397 /* checks not needed any more since DP has separated clientcommands and regular commands
400 //if(cmd != "say") // handled above
401 //if(cmd != "say_team") // handled above
412 if(cmd != "playermodel")
413 if(cmd != "playerskin")
414 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
416 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
420 clientcommand(self,s);
424 float ValidateMap(string vote)
429 if(argv(0) == "map" || argv(0) == "changelevel")
431 else if(argv(0) == "chmap")
433 else if(argv(0) == "gotomap")
438 if(!TryFile(strcat("maps/", argv(1), ext)))
440 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
448 if(votefinished > 0 // a vote was called
449 && time > votefinished) // time is up
460 while(argv(index) != "") {
461 vote = strcat(vote, " ", argv(index));
465 // necessary for some of the string operations
466 vote = strzone(vote);
468 // now we remove some things that could be misused
472 local float votelength;
473 votelength = strlen(vote);
474 while(!found && index < votelength)
476 local string badchar;
477 badchar = substring(vote, index, 1);
487 return substring(vote, 0, index);
490 float VoteAllowed(string votecommand) {
491 tokenize(cvar_string("sv_vote_commands"));
494 while(argv(index) != "") {
495 local string allowed;
496 allowed = argv(index);
497 if(votecommand == allowed) {
508 FOR_EACH_CLIENT(player)
510 player.vote_vote = 0;
511 centerprint_expire(player, CENTERPRIO_VOTE);
515 votecalledmaster = FALSE;
520 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was accepted\n");
523 votecaller.vote_master = 1;
525 localcmd(strcat(votecalledvote, "\n"));
527 votecaller.vote_next = 0; // people like your votes, no wait for next vote
532 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was rejected\n");
537 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 timed out\n");
541 void VoteStop(entity stopper) {
542 bprint("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n");
543 if(stopper == votecaller) {
544 // no wait for next vote so you can correct your vote
545 votecaller.vote_next = 0;
552 if(self.vote_vote == 0)
553 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."));
557 local float playercount;
559 local float yescount;
565 FOR_EACH_REALCLIENT(player)
567 if(player.vote_vote < 0) {
569 } else if(player.vote_vote > 0) {
575 if((playercount == 1) && votecalledmaster) {
576 // if only one player is on the server becoming vote
577 // master is not allowed. This could be used for
578 // trolling or worse. 'self' is the user who has
579 // called the vote because this function is called
580 // by SV_ParseClientCommand. Maybe all voting should
581 // be disabled for a single player?
582 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
583 votecaller.vote_next = 0;
585 } else if((playercount / 2) < yescount) { // vote accepted
587 } else if((playercount / 2) < nocount) { // vote rejected
589 } else if(time > votefinished) { // vote timedout
590 if(cvar("sv_vote_simple_majority"))
591 if(yescount > nocount)
593 else if(nocount > yescount)
599 } // else still running
608 FOR_EACH_REALPLAYER(e)
617 bprint("^1Server is restarting...\n");
618 localcmd("restart\n");