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");
17 sprint(self, "Wrong password.\n");
18 // use of -- produces compiler warning in the if() line???
19 self.adminstatus = self.adminstatus - 1;
20 if(self.adminstatus == 0)
21 sprint(self, "You lost remote admin status.\n");
24 sprint(self, "Clientside commands NOT allowed.\n");
26 } else if(argv(0) == "ccmd") {
27 if(cvar("sv_clientcommands")) {
28 if(self.adminstatus > 0) {
32 while(argv(index) != "") {
33 command = strcat(command, " ", argv(index));
38 sprint(self, "You don't have remote admin status.\n");
40 sprint(self, "Clientside commands NOT allowed.\n");
42 } else if(argv(0) == "vote") {
43 if(argv(1) == "help") {
44 local string vmasterdis;
45 if(!cvar("sv_vote_master")) {
46 vmasterdis = " ^1(disabled)";
48 local string vcalldis;
49 if(!cvar("sv_vote_call")) {
50 vcalldis = " ^1(disabled)";
52 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");
53 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");
54 sprint(self, "^7\"^2help^7\" shows this info.\n");
55 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
56 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
57 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
58 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
59 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");
60 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
61 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
62 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
63 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
64 sprint(self, "^7You can call a vote for or execute these commands:\n");
65 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
66 } else if(argv(1) == "status") {
68 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
70 sprint(self, "^1No vote called.\n");
72 } else if(argv(1) == "call") {
73 if(cvar("sv_vote_call")) {
75 sprint(self, "^1There is already a vote called.\n");
80 sprint(self, "^1Your vote is empty. See help for more info.\n");
81 } else if(time < self.vote_next) {
82 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
83 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
84 if(!ValidateMap(vote))
87 votecalledmaster = FALSE;
88 votecalledvote = strzone(vote);
89 votecaller = self; // remember who called the vote
90 votefinished = time + cvar("sv_vote_timeout");
91 votecaller.vote_vote = 1; // of course you vote yes
92 votecaller.vote_next = time + cvar("sv_vote_wait");
93 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
94 VoteCount(); // needed if you are the only one
96 sprint(self, "^1This vote is not ok. See help for more info.\n");
100 sprint(self, "^1Vote calling is NOT allowed.\n");
102 } else if(argv(1) == "stop") {
104 sprint(self, "^1No vote called.\n");
105 } else if(self == votecaller
106 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
109 sprint(self, "^1You are not allowed to stop that Vote.\n");
111 } else if(argv(1) == "master") {
112 if(cvar("sv_vote_master")) {
114 sprint(self, "^1There is already a vote called.\n");
117 votecalledmaster = TRUE;
118 votecalledvote = strzone("^3master");
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("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
124 VoteCount(); // needed if you are the only one
127 sprint(self, "^1Vote to become master is NOT allowed.\n");
129 } else if(argv(1) == "do") {
130 if(self.vote_master) {
132 dovote = VoteParse();
134 sprint(self, "^1Your command was empty. See help for more info.\n");
135 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
136 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
139 sprint(self, "^1This command is not ok. See help for more info.\n");
142 sprint(self, "^1You are NOT a master.\n");
144 } else if(argv(1) == "yes") {
146 sprint(self, "^1No vote called.\n");
147 } else if(self.vote_vote == 0
148 || cvar("sv_vote_change")) {
149 sprint(self, "^1You accepted the vote.\n");
151 if(!cvar("sv_vote_singlecount")) {
155 sprint(self, "^1You have already voted.\n");
157 } else if(argv(1) == "no") {
159 sprint(self, "^1No vote called.\n");
160 } else if(self.vote_vote == 0
161 || cvar("sv_vote_change")) {
162 sprint(self, "^1You rejected the vote.\n");
164 if(!cvar("sv_vote_singlecount")) {
168 sprint(self, "^1You have already voted.\n");
172 sprint(self, "^1Unknown vote command.\n");
174 } else if(argv(0) == "autoswitch") {
175 // be backwards compatible with older clients (enabled)
176 self.autoswitch = ("0" != argv(1));
177 local string autoswitchmsg;
178 if (self.autoswitch) {
179 autoswitchmsg = "on";
181 autoswitchmsg = "off";
183 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
184 } else if(argv(0) == "clientversion") {
185 if (argv(1) == "$gameversion") {
186 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
187 // either that or someone wants to be funny
190 self.version = stof(argv(1));
192 if(self.version != cvar("gameversion"))
194 self.classname = "observer";
197 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
198 self.classname = "observer";
199 stuffcmd(self,"menu_showteamselect\n");
201 } else if(argv(0) == "spectate") {
203 return; // don't allow spectating in lms, unless player runs out of lives
204 if(self.classname == "player" && cvar("sv_spectate") == 1) {
205 self.classname = "observer";
208 } else if(argv(0) == "join") {
209 if (self.classname != "player")
211 self.classname = "player";
213 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
216 } else if( argv(0) == "selectteam" ) {
217 if( !cvar("teamplay") ) {
218 sprint( self, "selecteam can only be used in teamgames\n");
219 } else if( argv(1) == "none" ) {
221 } else if( argv(1) == "red" ) {
222 SV_ChangeTeam( COLOR_TEAM1 - 1 );
223 } else if( argv(1) == "blue" ) {
224 SV_ChangeTeam( COLOR_TEAM2 - 1 );
225 } else if( argv(1) == "pink" ) {
226 SV_ChangeTeam( COLOR_TEAM3 - 1 );
227 } else if( argv(1) == "yellow" ) {
228 SV_ChangeTeam( COLOR_TEAM4 - 1 );
229 } else if( argv(1) == "auto" ) {
230 JoinBestTeam( self, 0 );
232 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
234 } else if(argv(0) == "ready") {
235 if(cvar("sv_ready_restart"))
238 bprint(self.netname, "^2 is ready\n");
242 clientcommand(self,s);
246 float ValidateMap(string vote)
253 else if(argv(0) == "chmap")
258 if(!TryFile(strcat("maps/", argv(1), ext)))
260 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
268 if(votefinished > 0 // a vote was called
269 && time > votefinished) // time is up
280 while(argv(index) != "") {
281 vote = strcat(vote, " ", argv(index));
285 // necessary for some of the string operations
286 vote = strzone(vote);
288 // now we remove some things that could be misused
292 local float votelength;
293 votelength = strlen(vote);
294 while(!found && index < votelength)
296 local string badchar;
297 badchar = substring(vote, index, 1);
307 return substring(vote, 0, index);
310 float VoteAllowed(string votecommand) {
311 tokenize(cvar_string("sv_vote_commands"));
314 while(argv(index) != "") {
315 local string allowed;
316 allowed = argv(index);
317 if(votecommand == allowed) {
326 local string searchclass;
327 searchclass = "player";
332 player = find(player, classname, searchclass);
335 player.vote_vote = 0;
336 player = find(player, classname, searchclass);
339 if("player" == searchclass) {
340 searchclass = "observer";
341 } else if("observer" == searchclass) {
342 searchclass = "spectator";
349 votecalledmaster = FALSE;
354 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
357 votecaller.vote_master = 1;
359 localcmd(votecalledvote);
361 votecaller.vote_next = 0; // people like your votes, no wait for next vote
366 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
371 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
375 void VoteStop(entity stopper) {
376 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
377 if(stopper == votecaller) {
378 // no wait for next vote so you can correct your vote
379 votecaller.vote_next = 0;
385 local float playercount;
387 local float yescount;
391 local string searchclass;
392 searchclass = "player";
397 player = find(player, classname, searchclass);
401 if(clienttype(player) != CLIENTTYPE_BOT) {
402 if(player.vote_vote < 0) {
404 } else if(player.vote_vote > 0) {
409 player = find(player, classname, searchclass);
412 if("player" == searchclass) {
413 searchclass = "observer";
414 } else if("observer" == searchclass) {
415 searchclass = "specator";
421 if((playercount == 1) && votecalledmaster) {
422 // if only one player is on the server becoming vote
423 // master is not allowed. This could be used for
424 // trolling or worse. 'self' is the user who has
425 // called the vote because this function is called
426 // by SV_ParseClientCommand. Maybe all voting should
427 // be disabled for a single player?
428 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
429 votecaller.vote_next = 0;
431 } else if((playercount / 2) < yescount) { // vote accepted
433 } else if((playercount / 2) < nocount) { // vote rejected
435 } else if(time > votefinished) { // vote timedout
437 } // else still running
446 e = find(world, classname, "player");
450 if(clienttype(e) == CLIENTTYPE_REAL)
455 e = find(e, classname, "player");
460 bprint("^1Server is restarting...\n");
461 localcmd("restart\n");