1 void SV_ParseClientCommand(string s) {
6 if(argv(0) == "clogin") {
7 if(cvar("sv_clientcommands")) {
8 if(self.adminstatus < -5) {
9 sprint(self, "Too many unsuccessful tries.\n");
10 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
12 sprint(self, "You now have remote admin status.\n");
14 sprint(self, "Wrong password.\n");
15 // use of -- produces compiler warning in the if() line???
16 self.adminstatus = self.adminstatus - 1;
17 if(self.adminstatus == 0)
18 sprint(self, "You lost remote admin status.\n");
21 sprint(self, "Clientside commands NOT allowed.\n");
23 } else if(argv(0) == "ccmd") {
24 if(cvar("sv_clientcommands")) {
25 if(self.adminstatus > 0) {
29 while(argv(index) != "") {
30 command = strcat(command, " ", argv(index));
35 sprint(self, "You don't have remote admin status.\n");
37 sprint(self, "Clientside commands NOT allowed.\n");
39 } else if(argv(0) == "vote") {
40 if(argv(1) == "help") {
41 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");
42 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");
43 sprint(self, "^7\"^2help^7\" shows this info.\n");
44 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
45 sprint(self, "^7\"^2call^7\" is used to call a vote. See the list of allowed commands.\n");
46 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
47 sprint(self, "^7\"^2master^7\" is used to call a vote to become a master.\n");
48 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");
49 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
50 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
51 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
52 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
53 sprint(self, "^7You can call a vote for or execute these commands:\n");
54 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
55 } else if(argv(1) == "status") {
57 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
59 sprint(self, "^1No vote called.\n");
61 } else if(argv(1) == "call") {
62 if(cvar("sv_vote_call")) {
64 sprint(self, "^1There is already a vote called.\n");
69 sprint(self, "^1Your vote is empty. See help for more info.\n");
70 } else if(time < self.vote_next) {
71 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
72 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
74 votecalledmaster = FALSE;
75 votecalledvote = strzone(vote);
76 votecaller = self; // remember who called the vote
77 votecaller.vote_vote = 1; // of course you vote yes
78 votecaller.vote_finished = time + cvar("sv_vote_timeout");
79 votecaller.vote_next = time + cvar("sv_vote_wait");
80 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
81 VoteCount(); // needed if you are the only one
83 sprint(self, "^1This vote is not ok. See help for more info.\n");
87 sprint(self, "^1Vote calling is NOT allowed.\n");
89 } else if(argv(1) == "stop") {
91 sprint(self, "^1No vote called.\n");
92 } else if(self == votecaller
93 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
96 sprint(self, "^1You are not allowed to stop that Vote.\n");
98 } else if(argv(1) == "master") {
99 if(cvar("sv_vote_master")) {
101 sprint(self, "^1There is already a vote called.\n");
104 votecalledmaster = TRUE;
105 votecalledvote = strzone("^3master");
106 votecaller = self; // remember who called the vote
107 votecaller.vote_vote = 1; // of course you vote yes
108 votecaller.vote_finished = time + cvar("sv_vote_timeout");
109 votecaller.vote_next = time + cvar("sv_vote_wait");
110 bprint(strcat("\"^7", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
111 VoteCount(); // needed if you are the only one
114 sprint(self, "^1Vote to become master is NOT allowed.\n");
116 } else if(argv(1) == "do") {
117 if(self.vote_master) {
119 dovote = VoteParse();
121 sprint(self, "^1Your command was empty. See help for more info.\n");
122 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
123 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
126 sprint(self, "^1This command is not ok. See help for more info.\n");
129 sprint(self, "^1You are NOT a master.\n");
131 } else if(argv(1) == "yes") {
133 sprint(self, "^1No vote called.\n");
134 } else if(self.vote_vote == 0
135 || cvar("sv_vote_change")) {
136 sprint(self, "^1You accepted the vote.\n");
138 if(!cvar("sv_vote_singlecount")) {
142 sprint(self, "^1You have already voted.\n");
144 } else if(argv(1) == "no") {
146 sprint(self, "^1No vote called.\n");
147 } else if(self.vote_vote == 0
148 || cvar("sv_vote_change")) {
149 sprint(self, "^1You rejected the vote.\n");
151 if(!cvar("sv_vote_singlecount")) {
155 sprint(self, "^1You have already voted.\n");
159 sprint(self, "^1Unknown vote command.\n");
161 } else if(argv(0) == "autoswitch") {
162 // be backwards compatible with older clients (enabled)
163 self.autoswitch = ("0" != argv(1));
164 local string autoswitchmsg;
165 if (self.autoswitch) {
166 autoswitchmsg = "on";
168 autoswitchmsg = "off";
170 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
171 } else if(argv(0) == "clientversion") {
172 local string versionmsg;
173 if (argv(1) == "$g_nexuizversion_major") {
174 versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
175 // either that or someone wants to be funny
176 } else if (stof(argv(1)) != cvar("g_nexuizversion_major")) {
177 if(stof(argv(1)) < cvar("g_nexuizversion_major")) {
178 versionmsg = "^3Your client version is outdated.\nPlease update!!!^8";
180 versionmsg = "^3This server is using an outdated Nexuiz version.\nThis can lead to problems.^8";
184 versionmsg = "^2client version and server version are the same.^8";
186 self.versionmessage = strzone(versionmsg);
187 } else if(argv(0) == "spectate") {
189 return; // don't allow spectating in lms, unless player runs out of lives
190 if(self.classname == "player" && cvar("sv_spectate") == 1) {
191 self.classname = "observer";
194 } else if(argv(0) == "join") {
195 self.classname = "player";
197 // TODO: I have no idea whether this is needed or not
199 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
202 } else if( argv(0) == "selectteam" ) {
203 if( argv(1) == "none" ) {
205 } else if( argv(1) == "red" ) {
206 SV_ChangeTeam( COLOR_TEAM1 - 1 );
207 } else if( argv(1) == "blue" ) {
208 SV_ChangeTeam( COLOR_TEAM2 - 1 );
209 } else if( argv(1) == "pink" ) {
210 SV_ChangeTeam( COLOR_TEAM3 - 1 );
211 } else if( argv(1) == "yellow" ) {
212 SV_ChangeTeam( COLOR_TEAM4 - 1 );
213 } else if( argv(1) == "auto" ) {
214 JoinBestTeam( self, 0 );
216 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
219 clientcommand(self,s);
224 if(self.vote_finished > 0 // this player has called a vote
225 && time > self.vote_finished) // time is up
236 while(argv(index) != "") {
237 vote = strcat(vote, " ", argv(index));
241 // necessary for some of the string operations
242 vote = strzone(vote);
244 // now we remove some things that could be misused
248 local float votelength;
249 votelength = strlen(vote);
250 while(!found && index < votelength)
252 local string badchar;
253 badchar = substring(vote, index, 1);
262 return substring(vote, 0, index);
265 float VoteAllowed(string votecommand) {
266 tokenize(cvar_string("sv_vote_commands"));
269 while(argv(index) != "") {
270 local string allowed;
271 allowed = argv(index);
272 if(votecommand == allowed) {
281 local string searchclass;
282 searchclass = "player";
287 player = find(player, classname, searchclass);
290 player.vote_vote = 0;
291 player.vote_finished = 0;
292 player = find(player, classname, searchclass);
295 if("player" == searchclass) {
296 searchclass = "observer";
297 } else if("observer" == searchclass) {
298 searchclass = "spectator";
305 votecalledmaster = FALSE;
309 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
312 votecaller.vote_master = 1;
314 localcmd(votecalledvote);
316 votecaller.vote_next = 0; // people like your votes, no wait for next vote
321 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
326 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
330 void VoteStop(entity stopper) {
331 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
332 if(stopper == votecaller) {
333 // no wait for next vote so you can correct your vote
334 votecaller.vote_next = 0;
340 local float playercount;
342 local float yescount;
346 local string searchclass;
347 searchclass = "player";
352 player = find(player, classname, searchclass);
356 if(clienttype(player) != CLIENTTYPE_BOT) {
357 if(player.vote_vote < 0) {
359 } else if(player.vote_vote > 0) {
364 player = find(player, classname, searchclass);
367 if("player" == searchclass) {
368 searchclass = "observer";
369 } else if("observer" == searchclass) {
370 searchclass = "specator";
376 if((playercount / 2) < yescount) { // vote accepted
378 } else if((playercount / 2) < nocount) { // vote rejected
380 } else if(time > votecaller.vote_finished) { // vote timedout
382 } // else still running