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 command = strzone(command);
41 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " issued command '", command, "'"), TRUE);
42 localcmd(strcat(command, "\n"));
45 sprint(self, "You don't have remote admin status.\n");
47 sprint(self, "Clientside commands NOT allowed.\n");
49 } else if(argv(0) == "vote") {
50 if(argv(1) == "help") {
51 local string vmasterdis;
52 if(!cvar("sv_vote_master")) {
53 vmasterdis = " ^1(disabled)";
55 local string vcalldis;
56 if(!cvar("sv_vote_call")) {
57 vcalldis = " ^1(disabled)";
59 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");
60 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");
61 sprint(self, "^7\"^2help^7\" shows this info.\n");
62 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
63 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
64 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
65 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
66 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");
67 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
68 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
69 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
70 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
71 sprint(self, "^7You can call a vote for or execute these commands:\n");
72 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
73 } else if(argv(1) == "status") {
75 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
77 sprint(self, "^1No vote called.\n");
79 } else if(argv(1) == "call") {
80 if(cvar("sv_vote_call")) {
82 sprint(self, "^1There is already a vote called.\n");
87 sprint(self, "^1Your vote is empty. See help for more info.\n");
88 } else if(time < self.vote_next) {
89 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
90 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
91 if(!ValidateMap(vote))
94 votecalledmaster = FALSE;
95 votecalledvote = strzone(vote);
96 votecaller = self; // remember who called the vote
97 votefinished = time + cvar("sv_vote_timeout");
98 votecaller.vote_vote = 1; // of course you vote yes
99 votecaller.vote_next = time + cvar("sv_vote_wait");
100 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
101 VoteCount(); // needed if you are the only one
103 sprint(self, "^1This vote is not ok. See help for more info.\n");
107 sprint(self, "^1Vote calling is NOT allowed.\n");
109 } else if(argv(1) == "stop") {
111 sprint(self, "^1No vote called.\n");
112 } else if(self == votecaller
113 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
116 sprint(self, "^1You are not allowed to stop that Vote.\n");
118 } else if(argv(1) == "master") {
119 if(cvar("sv_vote_master")) {
121 sprint(self, "^1There is already a vote called.\n");
124 votecalledmaster = TRUE;
125 votecalledvote = strzone("^3master");
126 votecaller = self; // remember who called the vote
127 votefinished = time + cvar("sv_vote_timeout");
128 votecaller.vote_vote = 1; // of course you vote yes
129 votecaller.vote_next = time + cvar("sv_vote_wait");
130 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
131 VoteCount(); // needed if you are the only one
134 sprint(self, "^1Vote to become master is NOT allowed.\n");
136 } else if(argv(1) == "do") {
137 if(self.vote_master) {
139 dovote = VoteParse();
141 sprint(self, "^1Your command was empty. See help for more info.\n");
142 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
143 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
144 localcmd(strcat(dovote, "\n"));
146 sprint(self, "^1This command is not ok. See help for more info.\n");
149 sprint(self, "^1You are NOT a master.\n");
151 } else if(argv(1) == "yes") {
153 sprint(self, "^1No vote called.\n");
154 } else if(self.vote_vote == 0
155 || cvar("sv_vote_change")) {
156 sprint(self, "^1You accepted the vote.\n");
158 if(!cvar("sv_vote_singlecount")) {
162 sprint(self, "^1You have already voted.\n");
164 } else if(argv(1) == "no") {
166 sprint(self, "^1No vote called.\n");
167 } else if(self.vote_vote == 0
168 || cvar("sv_vote_change")) {
169 sprint(self, "^1You rejected the vote.\n");
171 if(!cvar("sv_vote_singlecount")) {
175 sprint(self, "^1You have already voted.\n");
179 sprint(self, "^1Unknown vote command.\n");
181 } else if(argv(0) == "autoswitch") {
182 // be backwards compatible with older clients (enabled)
183 self.autoswitch = ("0" != argv(1));
184 local string autoswitchmsg;
185 if (self.autoswitch) {
186 autoswitchmsg = "on";
188 autoswitchmsg = "off";
190 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
191 } else if(argv(0) == "clientversion") {
192 if (argv(1) == "$gameversion") {
193 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
194 // either that or someone wants to be funny
197 self.version = stof(argv(1));
199 if(self.version != cvar("gameversion"))
201 self.classname = "observer";
204 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
205 //JoinBestTeam(self, 0);
206 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
207 self.classname = "observer";
208 stuffcmd(self,"menu_showteamselect\n");
210 } else if(argv(0) == "reportcvar") {
212 } else if(argv(0) == "spectate") {
213 if(cvar("g_lms") || cvar("g_arena"))
214 return; // don't allow spectating in lms, unless player runs out of lives
215 if(self.classname == "player" && cvar("sv_spectate") == 1) {
216 self.classname = "observer";
219 } else if(argv(0) == "join") {
221 if (self.classname != "player")
223 self.classname = "player";
225 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
228 } else if( argv(0) == "selectteam" ) {
229 if( !cvar("teamplay") ) {
230 sprint( self, "selecteam can only be used in teamgames\n");
231 } else if(cvar("g_campaign")) {
232 //JoinBestTeam(self, 0);
233 } else if( argv(1) == "none" ) {
235 } else if( argv(1) == "red" ) {
236 SV_ChangeTeam( COLOR_TEAM1 - 1 );
237 } else if( argv(1) == "blue" ) {
238 SV_ChangeTeam( COLOR_TEAM2 - 1 );
239 } else if( argv(1) == "pink" ) {
240 SV_ChangeTeam( COLOR_TEAM3 - 1 );
241 } else if( argv(1) == "yellow" ) {
242 SV_ChangeTeam( COLOR_TEAM4 - 1 );
243 } else if( argv(1) == "auto" ) {
245 JoinBestTeam( self, 0 );
247 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
249 } else if(argv(0) == "ready") {
250 if(cvar("sv_ready_restart"))
253 bprint(self.netname, "^2 is ready\n");
256 } else if(argv(0) == "say") {
257 clientcommand(self, formatmessage(s));
258 } else if(argv(0) == "say_team") {
259 clientcommand(self, formatmessage(s));
261 clientcommand(self,s);
265 float ValidateMap(string vote)
270 if(argv(0) == "map" || argv(0) == "changelevel")
272 else if(argv(0) == "chmap")
277 if(!TryFile(strcat("maps/", argv(1), ext)))
279 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
287 if(votefinished > 0 // a vote was called
288 && time > votefinished) // time is up
299 while(argv(index) != "") {
300 vote = strcat(vote, " ", argv(index));
304 // necessary for some of the string operations
305 vote = strzone(vote);
307 // now we remove some things that could be misused
311 local float votelength;
312 votelength = strlen(vote);
313 while(!found && index < votelength)
315 local string badchar;
316 badchar = substring(vote, index, 1);
326 return substring(vote, 0, index);
329 float VoteAllowed(string votecommand) {
330 tokenize(cvar_string("sv_vote_commands"));
333 while(argv(index) != "") {
334 local string allowed;
335 allowed = argv(index);
336 if(votecommand == allowed) {
345 local string searchclass;
346 searchclass = "player";
351 player = find(player, classname, searchclass);
354 player.vote_vote = 0;
355 player = find(player, classname, searchclass);
358 if("player" == searchclass) {
359 searchclass = "observer";
360 } else if("observer" == searchclass) {
361 searchclass = "spectator";
368 votecalledmaster = FALSE;
373 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
376 votecaller.vote_master = 1;
378 localcmd(strcat(votecalledvote, "\n"));
380 votecaller.vote_next = 0; // people like your votes, no wait for next vote
385 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
390 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
394 void VoteStop(entity stopper) {
395 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
396 if(stopper == votecaller) {
397 // no wait for next vote so you can correct your vote
398 votecaller.vote_next = 0;
404 local float playercount;
406 local float yescount;
410 local string searchclass;
411 searchclass = "player";
416 player = find(player, classname, searchclass);
420 if(clienttype(player) != CLIENTTYPE_BOT) {
421 if(player.vote_vote < 0) {
423 } else if(player.vote_vote > 0) {
428 player = find(player, classname, searchclass);
431 if("player" == searchclass) {
432 searchclass = "observer";
433 } else if("observer" == searchclass) {
434 searchclass = "specator";
440 if((playercount == 1) && votecalledmaster) {
441 // if only one player is on the server becoming vote
442 // master is not allowed. This could be used for
443 // trolling or worse. 'self' is the user who has
444 // called the vote because this function is called
445 // by SV_ParseClientCommand. Maybe all voting should
446 // be disabled for a single player?
447 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
448 votecaller.vote_next = 0;
450 } else if((playercount / 2) < yescount) { // vote accepted
452 } else if((playercount / 2) < nocount) { // vote rejected
454 } else if(time > votefinished) { // vote timedout
456 } // else still running
465 e = find(world, classname, "player");
469 if(clienttype(e) == CLIENTTYPE_REAL)
474 e = find(e, classname, "player");
479 bprint("^1Server is restarting...\n");
480 localcmd("restart\n");