3 void SV_ParseClientCommand(string s) {
8 if(argv(0) == "clogin") {
9 if(cvar("sv_clientcommands")) {
10 if(self.adminstatus < -5) {
11 sprint(self, "Too many unsuccessful tries.\n");
12 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
14 sprint(self, "You now have remote admin status.\n");
16 sprint(self, "Wrong password.\n");
17 // use of -- produces compiler warning in the if() line???
18 self.adminstatus = self.adminstatus - 1;
19 if(self.adminstatus == 0)
20 sprint(self, "You lost remote admin status.\n");
23 sprint(self, "Clientside commands NOT allowed.\n");
25 } else if(argv(0) == "ccmd") {
26 if(cvar("sv_clientcommands")) {
27 if(self.adminstatus > 0) {
31 while(argv(index) != "") {
32 command = strcat(command, " ", argv(index));
37 sprint(self, "You don't have remote admin status.\n");
39 sprint(self, "Clientside commands NOT allowed.\n");
41 } else if(argv(0) == "vote") {
42 if(argv(1) == "help") {
43 local string vmasterdis;
44 if(!cvar("sv_vote_master")) {
45 vmasterdis = " ^1(disabled)";
47 local string vcalldis;
48 if(!cvar("sv_vote_call")) {
49 vcalldis = " ^1(disabled)";
51 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");
52 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");
53 sprint(self, "^7\"^2help^7\" shows this info.\n");
54 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
55 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
56 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
57 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
58 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");
59 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
60 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
61 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
62 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
63 sprint(self, "^7You can call a vote for or execute these commands:\n");
64 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
65 } else if(argv(1) == "status") {
67 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
69 sprint(self, "^1No vote called.\n");
71 } else if(argv(1) == "call") {
72 if(cvar("sv_vote_call")) {
74 sprint(self, "^1There is already a vote called.\n");
79 sprint(self, "^1Your vote is empty. See help for more info.\n");
80 } else if(time < self.vote_next) {
81 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
82 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
84 votecalledmaster = FALSE;
85 votecalledvote = strzone(vote);
86 votecaller = self; // remember who called the vote
87 votefinished = time + cvar("sv_vote_timeout");
88 votecaller.vote_vote = 1; // of course you vote yes
89 votecaller.vote_next = time + cvar("sv_vote_wait");
90 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
91 VoteCount(); // needed if you are the only one
93 sprint(self, "^1This vote is not ok. See help for more info.\n");
97 sprint(self, "^1Vote calling is NOT allowed.\n");
99 } else if(argv(1) == "stop") {
101 sprint(self, "^1No vote called.\n");
102 } else if(self == votecaller
103 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
106 sprint(self, "^1You are not allowed to stop that Vote.\n");
108 } else if(argv(1) == "master") {
109 if(cvar("sv_vote_master")) {
111 sprint(self, "^1There is already a vote called.\n");
114 votecalledmaster = TRUE;
115 votecalledvote = strzone("^3master");
116 votecaller = self; // remember who called the vote
117 votefinished = time + cvar("sv_vote_timeout");
118 votecaller.vote_vote = 1; // of course you vote yes
119 votecaller.vote_next = time + cvar("sv_vote_wait");
120 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
121 VoteCount(); // needed if you are the only one
124 sprint(self, "^1Vote to become master is NOT allowed.\n");
126 } else if(argv(1) == "do") {
127 if(self.vote_master) {
129 dovote = VoteParse();
131 sprint(self, "^1Your command was empty. See help for more info.\n");
132 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
133 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
136 sprint(self, "^1This command is not ok. See help for more info.\n");
139 sprint(self, "^1You are NOT a master.\n");
141 } else if(argv(1) == "yes") {
143 sprint(self, "^1No vote called.\n");
144 } else if(self.vote_vote == 0
145 || cvar("sv_vote_change")) {
146 sprint(self, "^1You accepted the vote.\n");
148 if(!cvar("sv_vote_singlecount")) {
152 sprint(self, "^1You have already voted.\n");
154 } else if(argv(1) == "no") {
156 sprint(self, "^1No vote called.\n");
157 } else if(self.vote_vote == 0
158 || cvar("sv_vote_change")) {
159 sprint(self, "^1You rejected the vote.\n");
161 if(!cvar("sv_vote_singlecount")) {
165 sprint(self, "^1You have already voted.\n");
169 sprint(self, "^1Unknown vote command.\n");
171 } else if(argv(0) == "autoswitch") {
172 // be backwards compatible with older clients (enabled)
173 self.autoswitch = ("0" != argv(1));
174 local string autoswitchmsg;
175 if (self.autoswitch) {
176 autoswitchmsg = "on";
178 autoswitchmsg = "off";
180 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
181 } else if(argv(0) == "clientversion") {
182 if (argv(1) == "$gameversion") {
183 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
184 // either that or someone wants to be funny
187 self.version = stof(argv(1));
189 } else if(argv(0) == "spectate") {
191 return; // don't allow spectating in lms, unless player runs out of lives
192 if(self.classname == "player" && cvar("sv_spectate") == 1) {
193 self.classname = "observer";
196 } else if(argv(0) == "join") {
197 if (self.classname != "player")
199 self.classname = "player";
201 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
204 } else if( argv(0) == "selectteam" ) {
205 if( !cvar("teamplay") ) {
206 sprint( self, "selecteam can only be used in teamgames\n");
207 } else if( argv(1) == "none" ) {
209 } else if( argv(1) == "red" ) {
210 SV_ChangeTeam( COLOR_TEAM1 - 1 );
211 } else if( argv(1) == "blue" ) {
212 SV_ChangeTeam( COLOR_TEAM2 - 1 );
213 } else if( argv(1) == "pink" ) {
214 SV_ChangeTeam( COLOR_TEAM3 - 1 );
215 } else if( argv(1) == "yellow" ) {
216 SV_ChangeTeam( COLOR_TEAM4 - 1 );
217 } else if( argv(1) == "auto" ) {
218 JoinBestTeam( self, 0 );
220 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
222 } else if(argv(0) == "ready") {
223 if(cvar("sv_ready_restart"))
226 bprint(self.netname, "^2 is ready\n");
230 clientcommand(self,s);
235 if(votefinished > 0 // a vote was called
236 && time > votefinished) // time is up
247 while(argv(index) != "") {
248 vote = strcat(vote, " ", argv(index));
252 // necessary for some of the string operations
253 vote = strzone(vote);
255 // now we remove some things that could be misused
259 local float votelength;
260 votelength = strlen(vote);
261 while(!found && index < votelength)
263 local string badchar;
264 badchar = substring(vote, index, 1);
274 return substring(vote, 0, index);
277 float VoteAllowed(string votecommand) {
278 tokenize(cvar_string("sv_vote_commands"));
281 while(argv(index) != "") {
282 local string allowed;
283 allowed = argv(index);
284 if(votecommand == allowed) {
293 local string searchclass;
294 searchclass = "player";
299 player = find(player, classname, searchclass);
302 player.vote_vote = 0;
303 player = find(player, classname, searchclass);
306 if("player" == searchclass) {
307 searchclass = "observer";
308 } else if("observer" == searchclass) {
309 searchclass = "spectator";
316 votecalledmaster = FALSE;
321 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
324 votecaller.vote_master = 1;
326 localcmd(votecalledvote);
328 votecaller.vote_next = 0; // people like your votes, no wait for next vote
333 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
338 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
342 void VoteStop(entity stopper) {
343 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
344 if(stopper == votecaller) {
345 // no wait for next vote so you can correct your vote
346 votecaller.vote_next = 0;
352 local float playercount;
354 local float yescount;
358 local string searchclass;
359 searchclass = "player";
364 player = find(player, classname, searchclass);
368 if(clienttype(player) != CLIENTTYPE_BOT) {
369 if(player.vote_vote < 0) {
371 } else if(player.vote_vote > 0) {
376 player = find(player, classname, searchclass);
379 if("player" == searchclass) {
380 searchclass = "observer";
381 } else if("observer" == searchclass) {
382 searchclass = "specator";
388 if((playercount == 1) && votecalledmaster) {
389 // if only one player is on the server becoming vote
390 // master is not allowed. This could be used for
391 // trolling or worse. 'self' is the user who has
392 // called the vote because this function is called
393 // by SV_ParseClientCommand. Maybe all voting should
394 // be disabled for a single player?
395 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
396 votecaller.vote_next = 0;
398 } else if((playercount / 2) < yescount) { // vote accepted
400 } else if((playercount / 2) < nocount) { // vote rejected
402 } else if(time > votefinished) { // vote timedout
404 } // else still running
413 e = find(world, classname, "player");
417 if(clienttype(e) == CLIENTTYPE_REAL)
422 e = find(e, classname, "player");
427 bprint("^1Server is restarting...\n");
428 localcmd("restart\n");