2 float ValidateMap(string vote);
4 void SV_ParseClientCommand(string s) {
9 if(argv(0) == "clogin") {
10 if(cvar("sv_clientcommands")) {
11 if(self.adminstatus < -5) {
12 sprint(self, "Too many unsuccessful tries.\n");
13 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
15 sprint(self, "You now have remote admin status.\n");
16 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " received admin status"), TRUE);
18 sprint(self, "Wrong password.\n");
19 // use of -- produces compiler warning in the if() line???
20 self.adminstatus = self.adminstatus - 1;
21 if(self.adminstatus == 0)
23 sprint(self, "You lost remote admin status.\n");
24 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " lost admin status"), TRUE);
28 sprint(self, "Clientside commands NOT allowed.\n");
30 } else if(argv(0) == "ccmd") {
31 if(cvar("sv_clientcommands")) {
32 if(self.adminstatus > 0) {
36 while(argv(index) != "") {
37 command = strcat(command, " ", argv(index));
40 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " issued command '", command, "'"), TRUE);
43 sprint(self, "You don't have remote admin status.\n");
45 sprint(self, "Clientside commands NOT allowed.\n");
47 } else if(argv(0) == "vote") {
48 if(argv(1) == "help") {
49 local string vmasterdis;
50 if(!cvar("sv_vote_master")) {
51 vmasterdis = " ^1(disabled)";
53 local string vcalldis;
54 if(!cvar("sv_vote_call")) {
55 vcalldis = " ^1(disabled)";
57 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");
58 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");
59 sprint(self, "^7\"^2help^7\" shows this info.\n");
60 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
61 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
62 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
63 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
64 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");
65 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
66 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
67 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
68 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
69 sprint(self, "^7You can call a vote for or execute these commands:\n");
70 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
71 } else if(argv(1) == "status") {
73 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
75 sprint(self, "^1No vote called.\n");
77 } else if(argv(1) == "call") {
78 if(cvar("sv_vote_call")) {
80 sprint(self, "^1There is already a vote called.\n");
85 sprint(self, "^1Your vote is empty. See help for more info.\n");
86 } else if(time < self.vote_next) {
87 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
88 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
89 if(!ValidateMap(vote))
92 votecalledmaster = FALSE;
93 votecalledvote = strzone(vote);
94 votecaller = self; // remember who called the vote
95 votefinished = time + cvar("sv_vote_timeout");
96 votecaller.vote_vote = 1; // of course you vote yes
97 votecaller.vote_next = time + cvar("sv_vote_wait");
98 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
99 VoteCount(); // needed if you are the only one
101 sprint(self, "^1This vote is not ok. See help for more info.\n");
105 sprint(self, "^1Vote calling is NOT allowed.\n");
107 } else if(argv(1) == "stop") {
109 sprint(self, "^1No vote called.\n");
110 } else if(self == votecaller
111 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
114 sprint(self, "^1You are not allowed to stop that Vote.\n");
116 } else if(argv(1) == "master") {
117 if(cvar("sv_vote_master")) {
119 sprint(self, "^1There is already a vote called.\n");
122 votecalledmaster = TRUE;
123 votecalledvote = strzone("^3master");
124 votecaller = self; // remember who called the vote
125 votefinished = time + cvar("sv_vote_timeout");
126 votecaller.vote_vote = 1; // of course you vote yes
127 votecaller.vote_next = time + cvar("sv_vote_wait");
128 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
129 VoteCount(); // needed if you are the only one
132 sprint(self, "^1Vote to become master is NOT allowed.\n");
134 } else if(argv(1) == "do") {
135 if(self.vote_master) {
137 dovote = VoteParse();
139 sprint(self, "^1Your command was empty. See help for more info.\n");
140 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
141 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
144 sprint(self, "^1This command is not ok. See help for more info.\n");
147 sprint(self, "^1You are NOT a master.\n");
149 } else if(argv(1) == "yes") {
151 sprint(self, "^1No vote called.\n");
152 } else if(self.vote_vote == 0
153 || cvar("sv_vote_change")) {
154 sprint(self, "^1You accepted the vote.\n");
156 if(!cvar("sv_vote_singlecount")) {
160 sprint(self, "^1You have already voted.\n");
162 } else if(argv(1) == "no") {
164 sprint(self, "^1No vote called.\n");
165 } else if(self.vote_vote == 0
166 || cvar("sv_vote_change")) {
167 sprint(self, "^1You rejected the vote.\n");
169 if(!cvar("sv_vote_singlecount")) {
173 sprint(self, "^1You have already voted.\n");
177 sprint(self, "^1Unknown vote command.\n");
179 } else if(argv(0) == "autoswitch") {
180 // be backwards compatible with older clients (enabled)
181 self.autoswitch = ("0" != argv(1));
182 local string autoswitchmsg;
183 if (self.autoswitch) {
184 autoswitchmsg = "on";
186 autoswitchmsg = "off";
188 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
189 } else if(argv(0) == "clientversion") {
190 if (argv(1) == "$gameversion") {
191 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
192 // either that or someone wants to be funny
195 self.version = stof(argv(1));
197 if(self.version != cvar("gameversion"))
199 self.classname = "observer";
202 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
203 self.classname = "observer";
204 stuffcmd(self,"menu_showteamselect\n");
206 } else if(argv(0) == "spectate") {
208 return; // don't allow spectating in lms, unless player runs out of lives
209 if(self.classname == "player" && cvar("sv_spectate") == 1) {
210 self.classname = "observer";
213 } else if(argv(0) == "join") {
214 if (self.classname != "player")
216 self.classname = "player";
218 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
221 } else if( argv(0) == "selectteam" ) {
222 if( !cvar("teamplay") ) {
223 sprint( self, "selecteam can only be used in teamgames\n");
224 } else if( argv(1) == "none" ) {
226 } else if( argv(1) == "red" ) {
227 SV_ChangeTeam( COLOR_TEAM1 - 1 );
228 } else if( argv(1) == "blue" ) {
229 SV_ChangeTeam( COLOR_TEAM2 - 1 );
230 } else if( argv(1) == "pink" ) {
231 SV_ChangeTeam( COLOR_TEAM3 - 1 );
232 } else if( argv(1) == "yellow" ) {
233 SV_ChangeTeam( COLOR_TEAM4 - 1 );
234 } else if( argv(1) == "auto" ) {
235 JoinBestTeam( self, 0 );
237 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
239 } else if(argv(0) == "ready") {
240 if(cvar("sv_ready_restart"))
243 bprint(self.netname, "^2 is ready\n");
246 } else if(argv(0) == "say") {
247 clientcommand(self, formatmessage(s));
248 } else if(argv(0) == "say_team") {
249 clientcommand(self, formatmessage(s));
251 clientcommand(self,s);
255 float ValidateMap(string vote)
260 if(argv(0) == "map" || argv(0) == "changelevel")
262 else if(argv(0) == "chmap")
267 if(!TryFile(strcat("maps/", argv(1), ext)))
269 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
277 if(votefinished > 0 // a vote was called
278 && time > votefinished) // time is up
289 while(argv(index) != "") {
290 vote = strcat(vote, " ", argv(index));
294 // necessary for some of the string operations
295 vote = strzone(vote);
297 // now we remove some things that could be misused
301 local float votelength;
302 votelength = strlen(vote);
303 while(!found && index < votelength)
305 local string badchar;
306 badchar = substring(vote, index, 1);
316 return substring(vote, 0, index);
319 float VoteAllowed(string votecommand) {
320 tokenize(cvar_string("sv_vote_commands"));
323 while(argv(index) != "") {
324 local string allowed;
325 allowed = argv(index);
326 if(votecommand == allowed) {
335 local string searchclass;
336 searchclass = "player";
341 player = find(player, classname, searchclass);
344 player.vote_vote = 0;
345 player = find(player, classname, searchclass);
348 if("player" == searchclass) {
349 searchclass = "observer";
350 } else if("observer" == searchclass) {
351 searchclass = "spectator";
358 votecalledmaster = FALSE;
363 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
366 votecaller.vote_master = 1;
368 localcmd(votecalledvote);
370 votecaller.vote_next = 0; // people like your votes, no wait for next vote
375 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
380 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
384 void VoteStop(entity stopper) {
385 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
386 if(stopper == votecaller) {
387 // no wait for next vote so you can correct your vote
388 votecaller.vote_next = 0;
394 local float playercount;
396 local float yescount;
400 local string searchclass;
401 searchclass = "player";
406 player = find(player, classname, searchclass);
410 if(clienttype(player) != CLIENTTYPE_BOT) {
411 if(player.vote_vote < 0) {
413 } else if(player.vote_vote > 0) {
418 player = find(player, classname, searchclass);
421 if("player" == searchclass) {
422 searchclass = "observer";
423 } else if("observer" == searchclass) {
424 searchclass = "specator";
430 if((playercount == 1) && votecalledmaster) {
431 // if only one player is on the server becoming vote
432 // master is not allowed. This could be used for
433 // trolling or worse. 'self' is the user who has
434 // called the vote because this function is called
435 // by SV_ParseClientCommand. Maybe all voting should
436 // be disabled for a single player?
437 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
438 votecaller.vote_next = 0;
440 } else if((playercount / 2) < yescount) { // vote accepted
442 } else if((playercount / 2) < nocount) { // vote rejected
444 } else if(time > votefinished) { // vote timedout
446 } // else still running
455 e = find(world, classname, "player");
459 if(clienttype(e) == CLIENTTYPE_REAL)
464 e = find(e, classname, "player");
469 bprint("^1Server is restarting...\n");
470 localcmd("restart\n");