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));
41 if(cvar("g_teamcolors_chat"))
42 namestr = playername(source);
44 namestr = source.netname;
47 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin, "\n"));
48 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", wordwrap(msgin, 50));
51 msgstr = strzone(strcat("\{1}^3", namestr, "^7: ", msgin, "\n"));
59 var .float flood_field;
63 flood_spl = cvar("g_chat_flood_spl_team");
64 flood_burst = cvar("g_chat_flood_burst_team");
65 flood_lmax = cvar("g_chat_flood_lmax_team");
66 flood_field = floodcontrol_team;
70 flood_spl = cvar("g_chat_flood_spl");
71 flood_burst = cvar("g_chat_flood_burst");
72 flood_lmax = cvar("g_chat_flood_lmax");
73 flood_field = floodcontrol_chat;
75 lines = ceil(strlennocol(msgstr) / 50);
76 if(flood_lmax && lines > flood_lmax)
78 else if(time >= self.flood_field)
79 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
86 if(cvar("g_chat_flood_notify_flooder"))
89 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
91 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
95 ServerConsoleEcho(strcat("NOTE: ", playername(self), "^7 is flooding."), TRUE);
99 FOR_EACH_REALPLAYER(head)
101 if(head.team == source.team)
103 sprint(head, msgstr);
104 centerprint(head, cmsgstr);
111 //ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
117 void SV_ParseClientCommand(string s) {
122 if(argv(0) == "vote") {
123 if(argv(1) == "help") {
124 local string vmasterdis;
125 if(!cvar("sv_vote_master")) {
126 vmasterdis = " ^1(disabled)";
128 local string vcalldis;
129 if(!cvar("sv_vote_call")) {
130 vcalldis = " ^1(disabled)";
132 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");
133 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");
134 sprint(self, "^7\"^2help^7\" shows this info.\n");
135 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
136 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
137 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
138 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
139 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");
140 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
141 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
142 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
143 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
144 sprint(self, "^7You can call a vote for or execute these commands:\n");
145 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
146 } else if(argv(1) == "status") {
148 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
150 sprint(self, "^1No vote called.\n");
152 } else if(argv(1) == "call") {
153 if(cvar("sv_vote_call")) {
155 sprint(self, "^1There is already a vote called.\n");
160 sprint(self, "^1Your vote is empty. See help for more info.\n");
161 } else if(time < self.vote_next) {
162 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
163 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
164 if(!ValidateMap(vote))
167 votecalledmaster = FALSE;
168 // remap chmap to gotomap (forces intermission)
169 if(strlen(vote) >= 6)
170 if(substring(vote, 0, 6) == "chmap ")
171 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
172 votecalledvote = strzone(vote);
173 votecaller = self; // remember who called the vote
174 votefinished = time + cvar("sv_vote_timeout");
175 votecaller.vote_vote = 1; // of course you vote yes
176 votecaller.vote_next = time + cvar("sv_vote_wait");
177 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ^1", votecalledvote, "\n");
178 VoteCount(); // needed if you are the only one
180 sprint(self, "^1This vote is not ok. See help for more info.\n");
184 sprint(self, "^1Vote calling is NOT allowed.\n");
186 } else if(argv(1) == "stop") {
188 sprint(self, "^1No vote called.\n");
189 } else if(self == votecaller) { // the votecaller can stop a vote
192 sprint(self, "^1You are not allowed to stop that Vote.\n");
194 } else if(argv(1) == "master") {
195 if(cvar("sv_vote_master")) {
197 sprint(self, "^1There is already a vote called.\n");
200 votecalledmaster = TRUE;
201 votecalledvote = strzone("^3master");
202 votecaller = self; // remember who called the vote
203 votefinished = time + cvar("sv_vote_timeout");
204 votecaller.vote_vote = 1; // of course you vote yes
205 votecaller.vote_next = time + cvar("sv_vote_wait");
206 bprint("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n");
207 VoteCount(); // needed if you are the only one
210 sprint(self, "^1Vote to become master is NOT allowed.\n");
212 } else if(argv(1) == "do") {
213 if(argv(2) == "login") {
214 local string masterpwd;
215 masterpwd = cvar_string("sv_vote_master_password");
216 if(masterpwd != "") {
217 self.vote_master = (masterpwd == argv(3));
218 if(self.vote_master) {
219 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
220 bprint("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n");
223 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
226 sprint(self, "^1You are NOT a master.\n");
227 } else if(self.vote_master) {
229 dovote = VoteParse();
231 sprint(self, "^1Your command was empty. See help for more info.\n");
232 } else if(VoteAllowed(strcat1(argv(2)))) { // strcat seems to be necessary
233 if(!ValidateMap(dovote))
235 // remap chmap to gotomap (forces intermission)
236 if(strlen(dovote) >= 6)
237 if(substring(dovote, 0, 6) == "chmap ")
238 vote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
239 bprint("\{1}^2* ^3", self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n");
240 localcmd(strcat(dovote, "\n"));
242 sprint(self, "^1This command is not ok. See help for more info.\n");
245 sprint(self, "^1You are NOT a master.\n");
247 } else if(argv(1) == "yes") {
249 sprint(self, "^1No vote called.\n");
250 } else if(self.vote_vote == 0
251 || cvar("sv_vote_change")) {
252 sprint(self, "^1You accepted the vote.\n");
254 if(!cvar("sv_vote_singlecount")) {
258 sprint(self, "^1You have already voted.\n");
260 } else if(argv(1) == "no") {
262 sprint(self, "^1No vote called.\n");
263 } else if(self.vote_vote == 0
264 || cvar("sv_vote_change")) {
265 sprint(self, "^1You rejected the vote.\n");
267 if(!cvar("sv_vote_singlecount")) {
271 sprint(self, "^1You have already voted.\n");
275 sprint(self, "^1Unknown vote command.\n");
277 } else if(argv(0) == "autoswitch") {
278 // be backwards compatible with older clients (enabled)
279 self.autoswitch = ("0" != argv(1));
280 local string autoswitchmsg;
281 if (self.autoswitch) {
282 autoswitchmsg = "on";
284 autoswitchmsg = "off";
286 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
287 } else if(argv(0) == "clientversion") {
288 if (argv(1) == "$gameversion") {
289 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
290 // either that or someone wants to be funny
293 self.version = stof(argv(1));
295 if(self.version != cvar("gameversion"))
297 self.classname = "observer";
300 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
301 //JoinBestTeam(self, 0);
302 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
303 self.classname = "observer";
304 stuffcmd(self,"menu_showteamselect\n");
306 } else if(argv(0) == "reportcvar") {
308 } else if(argv(0) == "spectate") {
309 if(cvar("g_lms") || cvar("g_arena"))
310 return; // don't allow spectating in lms, unless player runs out of lives
311 if(self.classname == "player" && cvar("sv_spectate") == 1) {
313 DropFlag(self.flagcarried);
314 DistributeFragsAmongTeam(self, self.team, 1.0);
315 self.classname = "observer";
318 } else if(argv(0) == "join") {
320 if (self.classname != "player")
322 self.classname = "player";
324 bprint ("^4", self.netname, "^4 is playing now\n");
327 } else if( argv(0) == "selectteam" ) {
328 if( !cvar("teamplay") ) {
329 sprint( self, "selecteam can only be used in teamgames\n");
330 } else if(cvar("g_campaign")) {
331 //JoinBestTeam(self, 0);
332 } else if( argv(1) == "none" ) {
334 } else if( argv(1) == "red" ) {
335 SV_ChangeTeam( COLOR_TEAM1 - 1 );
336 } else if( argv(1) == "blue" ) {
337 SV_ChangeTeam( COLOR_TEAM2 - 1 );
338 } else if( argv(1) == "pink" ) {
339 SV_ChangeTeam( COLOR_TEAM3 - 1 );
340 } else if( argv(1) == "yellow" ) {
341 SV_ChangeTeam( COLOR_TEAM4 - 1 );
342 } else if( argv(1) == "auto" ) {
344 JoinBestTeam( self, 0 );
346 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
348 } else if(argv(0) == "ready") {
349 if(cvar("sv_ready_restart"))
352 bprint(self.netname, "^2 is ready\n");
355 } else if(argv(0) == "maplist") {
358 n = tokenize(cvar_string("g_maplist"));
359 sprint(self, "^7Maps in list: ");
360 for(i = 0; i < n; ++i)
366 sprint(self, strcat(col, argv(i), " "));
369 } else if(argv(0) == "teamstatus") {
370 PrintScoreboard(self);
371 } else if(argv(0) == "say") {
372 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
373 //clientcommand(self, formatmessage(s));
374 } else if(argv(0) == "say_team") {
375 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
376 //clientcommand(self, formatmessage(s));
377 } else if(argv(0) == "info") {
378 cmd = cvar_string(strcat("sv_info_", argv(1)));
380 sprint(self, "ERROR: unsupported info command\n");
382 wordwrap_sprint(cmd, 1111);
383 } else if(argv(0) == "suggestmap") {
384 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
387 /* checks not needed any more since DP has separated clientcommands and regular commands
390 //if(cmd != "say") // handled above
391 //if(cmd != "say_team") // handled above
402 if(cmd != "playermodel")
403 if(cmd != "playerskin")
404 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
406 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
410 clientcommand(self,s);
414 float ValidateMap(string vote)
419 if(argv(0) == "map" || argv(0) == "changelevel")
421 else if(argv(0) == "chmap")
423 else if(argv(0) == "gotomap")
428 if(!TryFile(strcat("maps/", argv(1), ext)))
430 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
438 if(votefinished > 0 // a vote was called
439 && time > votefinished) // time is up
450 while(argv(index) != "") {
451 vote = strcat(vote, " ", argv(index));
455 // necessary for some of the string operations
456 vote = strzone(vote);
458 // now we remove some things that could be misused
462 local float votelength;
463 votelength = strlen(vote);
464 while(!found && index < votelength)
466 local string badchar;
467 badchar = substring(vote, index, 1);
477 return substring(vote, 0, index);
480 float VoteAllowed(string votecommand) {
481 tokenize(cvar_string("sv_vote_commands"));
484 while(argv(index) != "") {
485 local string allowed;
486 allowed = argv(index);
487 if(votecommand == allowed) {
498 FOR_EACH_CLIENT(player)
500 player.vote_vote = 0;
501 centerprint_expire(player, CENTERPRIO_VOTE);
505 votecalledmaster = FALSE;
510 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was accepted\n");
513 votecaller.vote_master = 1;
515 localcmd(strcat(votecalledvote, "\n"));
517 votecaller.vote_next = 0; // people like your votes, no wait for next vote
522 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was rejected\n");
527 bprint("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 timed out\n");
531 void VoteStop(entity stopper) {
532 bprint("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n");
533 if(stopper == votecaller) {
534 // no wait for next vote so you can correct your vote
535 votecaller.vote_next = 0;
542 if(self.vote_vote == 0)
543 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."));
547 local float playercount;
549 local float yescount;
555 FOR_EACH_REALCLIENT(player)
557 if(player.vote_vote < 0) {
559 } else if(player.vote_vote > 0) {
565 if((playercount == 1) && votecalledmaster) {
566 // if only one player is on the server becoming vote
567 // master is not allowed. This could be used for
568 // trolling or worse. 'self' is the user who has
569 // called the vote because this function is called
570 // by SV_ParseClientCommand. Maybe all voting should
571 // be disabled for a single player?
572 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
573 votecaller.vote_next = 0;
575 } else if((playercount / 2) < yescount) { // vote accepted
577 } else if((playercount / 2) < nocount) { // vote rejected
579 } else if(time > votefinished) { // vote timedout
580 if(cvar("sv_vote_simple_majority"))
581 if(yescount > nocount)
583 else if(nocount > yescount)
589 } // else still running
598 FOR_EACH_REALPLAYER(e)
607 bprint("^1Server is restarting...\n");
608 localcmd("restart\n");