5 void SV_ParseClientCommand(string s) {
10 if(argv(0) == "clogin") {
11 if(cvar("sv_clientcommands")) {
12 if(self.adminstatus < -5) {
13 sprint(self, "Too many unsuccessful tries.\n");
14 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
16 sprint(self, "You now have remote admin status.\n");
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)
22 sprint(self, "You lost remote admin status.\n");
25 sprint(self, "Clientside commands NOT allowed.\n");
27 } else if(argv(0) == "ccmd") {
28 if(cvar("sv_clientcommands")) {
29 if(self.adminstatus > 0) {
33 while(argv(index) != "") {
34 command = strcat(command, " ", argv(index));
39 sprint(self, "You don't have remote admin status.\n");
41 sprint(self, "Clientside commands NOT allowed.\n");
43 } else if(argv(0) == "vote") {
44 if(argv(1) == "help") {
45 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");
46 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");
47 sprint(self, "^7\"^2help^7\" shows this info.\n");
48 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
49 sprint(self, "^7\"^2call^7\" is used to call a vote. See the list of allowed commands.\n");
50 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
51 sprint(self, "^7\"^2master^7\" is used to call a vote to become a master.\n");
52 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");
53 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
54 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
55 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
56 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
57 sprint(self, "^7You can call a vote for or execute these commands:\n");
58 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
59 } else if(argv(1) == "status") {
61 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
63 sprint(self, "^1No vote called.\n");
65 } else if(argv(1) == "call") {
66 if(cvar("sv_vote_call")) {
68 sprint(self, "^1There is already a vote called.\n");
73 sprint(self, "^1Your vote is empty. See help for more info.\n");
74 } else if(time < self.vote_next) {
75 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
76 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
78 votecalledmaster = FALSE;
79 votecalledvote = strzone(vote);
80 votecaller = self; // remember who called the vote
81 votecaller.vote_vote = 1; // of course you vote yes
82 votecaller.vote_finished = time + cvar("sv_vote_timeout");
83 votecaller.vote_next = time + cvar("sv_vote_wait");
84 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
85 VoteCount(); // needed if you are the only one
87 sprint(self, "^1This vote is not ok. See help for more info.\n");
91 sprint(self, "^1Vote calling is NOT allowed.\n");
93 } else if(argv(1) == "stop") {
95 sprint(self, "^1No vote called.\n");
96 } else if(self == votecaller
97 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
100 sprint(self, "^1You are not allowed to stop that Vote.\n");
102 } else if(argv(1) == "master") {
103 if(cvar("sv_vote_master")) {
105 sprint(self, "^1There is already a vote called.\n");
108 votecalledmaster = TRUE;
109 votecalledvote = strzone("^3master");
110 votecaller = self; // remember who called the vote
111 votecaller.vote_vote = 1; // of course you vote yes
112 votecaller.vote_finished = time + cvar("sv_vote_timeout");
113 votecaller.vote_next = time + cvar("sv_vote_wait");
114 bprint(strcat("\"^7", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
115 VoteCount(); // needed if you are the only one
118 sprint(self, "^1Vote to become master is NOT allowed.\n");
120 } else if(argv(1) == "do") {
121 if(self.vote_master) {
123 dovote = VoteParse();
125 sprint(self, "^1Your command was empty. See help for more info.\n");
126 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
127 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
130 sprint(self, "^1This command is not ok. See help for more info.\n");
133 sprint(self, "^1You are NOT a master.\n");
135 } else if(argv(1) == "yes") {
137 sprint(self, "^1No vote called.\n");
138 } else if(self.vote_vote == 0
139 || cvar("sv_vote_change")) {
140 sprint(self, "^1You accepted the vote.\n");
142 if(!cvar("sv_vote_singlecount")) {
146 sprint(self, "^1You have already voted.\n");
148 } else if(argv(1) == "no") {
150 sprint(self, "^1No vote called.\n");
151 } else if(self.vote_vote == 0
152 || cvar("sv_vote_change")) {
153 sprint(self, "^1You rejected the vote.\n");
155 if(!cvar("sv_vote_singlecount")) {
159 sprint(self, "^1You have already voted.\n");
163 sprint(self, "^1Unknown vote command.\n");
165 } else if(argv(0) == "autoswitch") {
166 // be backwards compatible with older clients (enabled)
167 self.autoswitch = ("0" != argv(1));
168 local string autoswitchmsg;
169 if (self.autoswitch) {
170 autoswitchmsg = "on";
172 autoswitchmsg = "off";
174 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
175 } else if(argv(0) == "clientversion") {
176 if (argv(1) == "$g_nexuizversion_major") {
177 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
178 // either that or someone wants to be funny
181 self.version = stof(argv(1));
183 } else if(argv(0) == "spectate") {
185 return; // don't allow spectating in lms, unless player runs out of lives
186 if(self.classname == "player" && cvar("sv_spectate") == 1) {
187 self.classname = "observer";
190 } else if(argv(0) == "join") {
191 self.classname = "player";
193 // TODO: I have no idea whether this is needed or not
195 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
198 } else if( argv(0) == "selectteam" ) {
199 if( argv(1) == "none" ) {
201 } else if( argv(1) == "red" ) {
202 SV_ChangeTeam( COLOR_TEAM1 - 1 );
203 } else if( argv(1) == "blue" ) {
204 SV_ChangeTeam( COLOR_TEAM2 - 1 );
205 } else if( argv(1) == "pink" ) {
206 SV_ChangeTeam( COLOR_TEAM3 - 1 );
207 } else if( argv(1) == "yellow" ) {
208 SV_ChangeTeam( COLOR_TEAM4 - 1 );
209 } else if( argv(1) == "auto" ) {
210 JoinBestTeam( self, 0 );
212 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
214 } else if(argv(0) == "ready") {
215 if(cvar("sv_ready_restart"))
221 clientcommand(self,s);
226 if(self.vote_finished > 0 // this player has called a vote
227 && time > self.vote_finished) // time is up
238 while(argv(index) != "") {
239 vote = strcat(vote, " ", argv(index));
243 // necessary for some of the string operations
244 vote = strzone(vote);
246 // now we remove some things that could be misused
250 local float votelength;
251 votelength = strlen(vote);
252 while(!found && index < votelength)
254 local string badchar;
255 badchar = substring(vote, index, 1);
264 return substring(vote, 0, index);
267 float VoteAllowed(string votecommand) {
268 tokenize(cvar_string("sv_vote_commands"));
271 while(argv(index) != "") {
272 local string allowed;
273 allowed = argv(index);
274 if(votecommand == allowed) {
283 local string searchclass;
284 searchclass = "player";
289 player = find(player, classname, searchclass);
292 player.vote_vote = 0;
293 player.vote_finished = 0;
294 player = find(player, classname, searchclass);
297 if("player" == searchclass) {
298 searchclass = "observer";
299 } else if("observer" == searchclass) {
300 searchclass = "spectator";
307 votecalledmaster = FALSE;
311 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
314 votecaller.vote_master = 1;
316 localcmd(votecalledvote);
318 votecaller.vote_next = 0; // people like your votes, no wait for next vote
323 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
328 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
332 void VoteStop(entity stopper) {
333 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
334 if(stopper == votecaller) {
335 // no wait for next vote so you can correct your vote
336 votecaller.vote_next = 0;
342 local float playercount;
344 local float yescount;
348 local string searchclass;
349 searchclass = "player";
354 player = find(player, classname, searchclass);
358 if(clienttype(player) != CLIENTTYPE_BOT) {
359 if(player.vote_vote < 0) {
361 } else if(player.vote_vote > 0) {
366 player = find(player, classname, searchclass);
369 if("player" == searchclass) {
370 searchclass = "observer";
371 } else if("observer" == searchclass) {
372 searchclass = "specator";
378 if((playercount / 2) < yescount) { // vote accepted
380 } else if((playercount / 2) < nocount) { // vote rejected
382 } else if(time > votecaller.vote_finished) { // vote timedout
384 } // else still running
393 e = find(world, classname, "player");
397 if(clienttype(e) == CLIENTTYPE_REAL)
402 e = find(e, classname, "player");
407 bprint("^1Server is restarting...\n");
408 localcmd("restart\n");