2 float ValidateMap(string vote);
3 void(entity e) DropFlag;
4 string MapVote_Suggest(string m);
6 void Say(entity source, float teamsay, string msgin)
8 string msgstr, colorstr, cmsgstr;
11 msgin = formatmessage(msgin);
16 colorstr = Team_ColorCode(source.team);
21 if(intermission_running)
24 if(source.classname != "player") // observers can't
27 // how can we prevent the message from appearing in a listen server?
28 // for now, just give "say" back and only handle say_team
31 clientcommand(self, strcat("say ", msgin));
37 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", source.netname, colorstr, ") ^7", msgin, "\n"));
38 cmsgstr = strcat(colorstr, "(^3", source.netname, colorstr, ")\n^7", wordwrap(msgin, 50));
41 msgstr = strzone(strcat("\{1}^3", source.netname, "^7: ", msgin, "\n"));
45 FOR_EACH_REALPLAYER(head)
47 if(head.team == source.team)
50 centerprint(head, cmsgstr);
57 //ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
63 void SV_ParseClientCommand(string s) {
68 if(argv(0) == "vote") {
69 if(argv(1) == "help") {
70 local string vmasterdis;
71 if(!cvar("sv_vote_master")) {
72 vmasterdis = " ^1(disabled)";
74 local string vcalldis;
75 if(!cvar("sv_vote_call")) {
76 vcalldis = " ^1(disabled)";
78 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");
79 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");
80 sprint(self, "^7\"^2help^7\" shows this info.\n");
81 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
82 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
83 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
84 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
85 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");
86 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
87 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
88 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
89 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
90 sprint(self, "^7You can call a vote for or execute these commands:\n");
91 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
92 } else if(argv(1) == "status") {
94 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
96 sprint(self, "^1No vote called.\n");
98 } else if(argv(1) == "call") {
99 if(cvar("sv_vote_call")) {
101 sprint(self, "^1There is already a vote called.\n");
106 sprint(self, "^1Your vote is empty. See help for more info.\n");
107 } else if(time < self.vote_next) {
108 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
109 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
110 if(!ValidateMap(vote))
113 votecalledmaster = FALSE;
114 // remap chmap to gotomap (forces intermission)
115 if(strlen(vote) >= 6)
116 if(substring(vote, 0, 6) == "chmap ")
117 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
118 votecalledvote = strzone(vote);
119 votecaller = self; // remember who called the vote
120 votefinished = time + cvar("sv_vote_timeout");
121 votecaller.vote_vote = 1; // of course you vote yes
122 votecaller.vote_next = time + cvar("sv_vote_wait");
123 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ^1", votecalledvote, "\n"));
124 VoteCount(); // needed if you are the only one
126 sprint(self, "^1This vote is not ok. See help for more info.\n");
130 sprint(self, "^1Vote calling is NOT allowed.\n");
132 } else if(argv(1) == "stop") {
134 sprint(self, "^1No vote called.\n");
135 } else if(self == votecaller) { // the votecaller can stop a vote
138 sprint(self, "^1You are not allowed to stop that Vote.\n");
140 } else if(argv(1) == "master") {
141 if(cvar("sv_vote_master")) {
143 sprint(self, "^1There is already a vote called.\n");
146 votecalledmaster = TRUE;
147 votecalledvote = strzone("^3master");
148 votecaller = self; // remember who called the vote
149 votefinished = time + cvar("sv_vote_timeout");
150 votecaller.vote_vote = 1; // of course you vote yes
151 votecaller.vote_next = time + cvar("sv_vote_wait");
152 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n"));
153 VoteCount(); // needed if you are the only one
156 sprint(self, "^1Vote to become master is NOT allowed.\n");
158 } else if(argv(1) == "do") {
159 if(argv(2) == "login") {
160 local string masterpwd;
161 masterpwd = cvar_string("sv_vote_master_password");
162 if(masterpwd != "") {
163 self.vote_master = (masterpwd == argv(3));
164 if(self.vote_master) {
165 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
166 bprint(strcat("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n"));
169 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
172 sprint(self, "^1You are NOT a master.\n");
173 } else if(self.vote_master) {
175 dovote = VoteParse();
177 sprint(self, "^1Your command was empty. See help for more info.\n");
178 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
179 if(!ValidateMap(dovote))
181 // remap chmap to gotomap (forces intermission)
182 if(strlen(dovote) >= 6)
183 if(substring(dovote, 0, 6) == "chmap ")
184 vote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
185 bprint("\{1}^2* ^3", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
186 localcmd(strcat(dovote, "\n"));
188 sprint(self, "^1This command is not ok. See help for more info.\n");
191 sprint(self, "^1You are NOT a master.\n");
193 } else if(argv(1) == "yes") {
195 sprint(self, "^1No vote called.\n");
196 } else if(self.vote_vote == 0
197 || cvar("sv_vote_change")) {
198 sprint(self, "^1You accepted the vote.\n");
200 if(!cvar("sv_vote_singlecount")) {
204 sprint(self, "^1You have already voted.\n");
206 } else if(argv(1) == "no") {
208 sprint(self, "^1No vote called.\n");
209 } else if(self.vote_vote == 0
210 || cvar("sv_vote_change")) {
211 sprint(self, "^1You rejected the vote.\n");
213 if(!cvar("sv_vote_singlecount")) {
217 sprint(self, "^1You have already voted.\n");
221 sprint(self, "^1Unknown vote command.\n");
223 } else if(argv(0) == "autoswitch") {
224 // be backwards compatible with older clients (enabled)
225 self.autoswitch = ("0" != argv(1));
226 local string autoswitchmsg;
227 if (self.autoswitch) {
228 autoswitchmsg = "on";
230 autoswitchmsg = "off";
232 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
233 } else if(argv(0) == "clientversion") {
234 if (argv(1) == "$gameversion") {
235 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
236 // either that or someone wants to be funny
239 self.version = stof(argv(1));
241 if(self.version != cvar("gameversion"))
243 self.classname = "observer";
246 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
247 //JoinBestTeam(self, 0);
248 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
249 self.classname = "observer";
250 stuffcmd(self,"menu_showteamselect\n");
252 } else if(argv(0) == "reportcvar") {
254 } else if(argv(0) == "spectate") {
255 if(cvar("g_lms") || cvar("g_arena"))
256 return; // don't allow spectating in lms, unless player runs out of lives
257 if(self.classname == "player" && cvar("sv_spectate") == 1) {
259 DropFlag(self.flagcarried);
260 DistributeFragsAmongTeam(self, self.team, 1.0);
261 self.classname = "observer";
264 } else if(argv(0) == "join") {
266 if (self.classname != "player")
268 self.classname = "player";
270 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
273 } else if( argv(0) == "selectteam" ) {
274 if( !cvar("teamplay") ) {
275 sprint( self, "selecteam can only be used in teamgames\n");
276 } else if(cvar("g_campaign")) {
277 //JoinBestTeam(self, 0);
278 } else if( argv(1) == "none" ) {
280 } else if( argv(1) == "red" ) {
281 SV_ChangeTeam( COLOR_TEAM1 - 1 );
282 } else if( argv(1) == "blue" ) {
283 SV_ChangeTeam( COLOR_TEAM2 - 1 );
284 } else if( argv(1) == "pink" ) {
285 SV_ChangeTeam( COLOR_TEAM3 - 1 );
286 } else if( argv(1) == "yellow" ) {
287 SV_ChangeTeam( COLOR_TEAM4 - 1 );
288 } else if( argv(1) == "auto" ) {
290 JoinBestTeam( self, 0 );
292 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
294 } else if(argv(0) == "ready") {
295 if(cvar("sv_ready_restart"))
298 bprint(self.netname, "^2 is ready\n");
301 } else if(argv(0) == "maplist") {
304 n = tokenize(cvar_string("g_maplist"));
305 sprint(self, "^7Maps in list: ");
306 for(i = 0; i < n; ++i)
312 sprint(self, strcat(col, argv(i), " "));
315 } else if(argv(0) == "teamstatus") {
316 PrintScoreboard(self);
317 } else if(argv(0) == "say") {
318 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
319 //clientcommand(self, formatmessage(s));
320 } else if(argv(0) == "say_team") {
321 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
322 //clientcommand(self, formatmessage(s));
323 } else if(argv(0) == "info") {
324 cmd = cvar_string(strcat("sv_info_", argv(1)));
326 sprint(self, "ERROR: unsupported info command\n");
328 wordwrap_sprint(cmd, 1111);
329 } else if(argv(0) == "suggestmap") {
330 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
333 /* checks not needed any more since DP has separated clientcommands and regular commands
336 //if(cmd != "say") // handled above
337 //if(cmd != "say_team") // handled above
348 if(cmd != "playermodel")
349 if(cmd != "playerskin")
350 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
352 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
356 clientcommand(self,s);
360 float ValidateMap(string vote)
365 if(argv(0) == "map" || argv(0) == "changelevel")
367 else if(argv(0) == "chmap")
369 else if(argv(0) == "gotomap")
374 if(!TryFile(strcat("maps/", argv(1), ext)))
376 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
384 if(votefinished > 0 // a vote was called
385 && time > votefinished) // time is up
396 while(argv(index) != "") {
397 vote = strcat(vote, " ", argv(index));
401 // necessary for some of the string operations
402 vote = strzone(vote);
404 // now we remove some things that could be misused
408 local float votelength;
409 votelength = strlen(vote);
410 while(!found && index < votelength)
412 local string badchar;
413 badchar = substring(vote, index, 1);
423 return substring(vote, 0, index);
426 float VoteAllowed(string votecommand) {
427 tokenize(cvar_string("sv_vote_commands"));
430 while(argv(index) != "") {
431 local string allowed;
432 allowed = argv(index);
433 if(votecommand == allowed) {
444 FOR_EACH_CLIENT(player)
446 player.vote_vote = 0;
447 centerprint_expire(player, CENTERPRIO_VOTE);
451 votecalledmaster = FALSE;
456 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was accepted\n"));
459 votecaller.vote_master = 1;
461 localcmd(strcat(votecalledvote, "\n"));
463 votecaller.vote_next = 0; // people like your votes, no wait for next vote
468 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was rejected\n"));
473 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 timed out\n"));
477 void VoteStop(entity stopper) {
478 bprint(strcat("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n"));
479 if(stopper == votecaller) {
480 // no wait for next vote so you can correct your vote
481 votecaller.vote_next = 0;
488 if(self.vote_vote == 0)
489 centerprint_atprio(self, CENTERPRIO_VOTE, strcat("^7^3", votecaller.netname, "^2 called a vote for:\n^1", votecalledvote, "\n\n^2You have not voted yet!\n^2HINT: By default, F1 is yes and F2 is no."));
493 local float playercount;
495 local float yescount;
501 FOR_EACH_REALCLIENT(player)
503 if(player.vote_vote < 0) {
505 } else if(player.vote_vote > 0) {
511 if((playercount == 1) && votecalledmaster) {
512 // if only one player is on the server becoming vote
513 // master is not allowed. This could be used for
514 // trolling or worse. 'self' is the user who has
515 // called the vote because this function is called
516 // by SV_ParseClientCommand. Maybe all voting should
517 // be disabled for a single player?
518 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
519 votecaller.vote_next = 0;
521 } else if((playercount / 2) < yescount) { // vote accepted
523 } else if((playercount / 2) < nocount) { // vote rejected
525 } else if(time > votefinished) { // vote timedout
526 if(cvar("sv_vote_simple_majority"))
527 if(yescount > nocount)
529 else if(nocount > yescount)
535 } // else still running
544 FOR_EACH_REALPLAYER(e)
553 bprint("^1Server is restarting...\n");
554 localcmd("restart\n");