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, "^1You can use voting with \"^2cmd vote help^1\" \"^2cmd vote status^1\" \"^2cmd vote call ^3COMMAND ARGUMENTS^1\" \"^2cmd vote stop^1\" \"^2cmd vote yes^1\" \"^2cmd vote no^1\".\n");
42 sprint(self, "^1Or if your version is up to date you can use these aliases \"^2vhelp^1\" \"^2vstatus^1\" \"^2vcall ^3COMMAND ARGUMENTS^1\" \"^2vstop^1\" \"^2vyes^1\" \"^2vno^1\".\n");
43 sprint(self, "^1\"^2help^1\" shows this info.\n");
44 sprint(self, "^1\"^2status^1\" shows if there is a vote called and who called it.\n");
45 sprint(self, "^1\"^2call^1\" is used to call a vote. See the list of allowed commands.\n");
46 sprint(self, "^1If more then 50% of the players vote yes the vote is executed.\n");
47 sprint(self, "^1If more then 50% of the players vote no the vote fails.\n");
48 sprint(self, "^1\"^2stop^1\" can be used by the vote caller to stop a vote and maybe correct it.\n");
49 sprint(self, "^1\"^2yes^1\" and \"^2no^1\" to make your vote.\n");
50 sprint(self, "^1You can call a vote with these commands:\n");
51 sprint(self, strcat("^1\"^2vcall^1\" ^3", cvar_string("sv_vote_allowed"), "^1 and further ^3arguments^1\n"));
52 } else if(argv(1) == "status") {
53 if(votecalled == "") {
54 sprint(self, "^1No vote called.\n");
56 sprint(self, strcat("^7Vote for \"^1", votecalled, "^7\" called by \"", votecaller.netname, "^7\".\n"));
58 } else if(argv(1) == "call") {
59 if(votecalled == "") {
63 while(argv(index) != "") {
64 vote = strcat(vote, " ", argv(index));
68 // necessary for some of the string operations
71 // now we remove some things that could be misused
75 local float votelength;
76 votelength = strlen(vote);
77 while(!found && index < votelength)
80 badchar = substring(vote, index, 1);
89 vote = substring(vote, 0, index);
92 sprint(self, "^1You have to vote for something.\n");
93 } else if(time < self.vote_next) {
94 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
95 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
96 votecalled = strzone(vote);
97 votecaller = self; // remember who called the vote
98 self.vote_vote = 1; // of course you vote yes
99 self.vote_finished = time + cvar("sv_vote_timeout");
100 self.vote_next = time + cvar("sv_vote_wait");
101 bprint(strcat("^3Vote for \"^1", votecalled, "^3\" called by \"", self.netname, "^3\".\n"));
102 VoteCount(); // needed if you are the only one
104 sprint(self, "^1This vote is not ok. See help for more info.\n");
107 sprint(self, "^1There is already a vote called.\n");
109 } else if(argv(1) == "stop") {
110 if(votecalled == "") {
111 sprint(self, "^1No vote called.\n");
112 } else if(votecaller == self
113 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
114 if(votecaller == self) {
115 // disable next votetimer so you can correct your vote
118 VoteTimeout(votecaller);
120 sprint(self, "^1You are not allowed to stop that Vote.\n");
122 } else if(argv(1) == "yes") {
123 if(votecalled == "") {
124 sprint(self, "^1No vote called.\n");
125 } else if(self.vote_vote == 0
126 || cvar("sv_vote_change")) {
128 if(!cvar("sv_vote_singlecount")) {
132 sprint(self, "^1You have already voted.\n");
134 } else if(argv(1) == "no") {
135 if(votecalled == "") {
136 sprint(self, "^1No vote called.\n");
137 } else if(self.vote_vote == 0
138 || cvar("sv_vote_change")) {
140 if(!cvar("sv_vote_singlecount")) {
144 sprint(self, "^1You have already voted.\n");
148 sprint(self, "^1Unknown vote command.\n");
150 } else if(argv(0) == "autoswitch") {
151 // be backwards compatible with older clients (enabled)
152 self.autoswitch = ("0" != argv(1));
153 local string autoswitchmsg;
154 if (self.autoswitch) {
155 autoswitchmsg = "on";
157 autoswitchmsg = "off";
159 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
160 } else if(argv(0) == "clientversion") {
161 local string versionmsg;
162 if (argv(1) == "$g_nexuizversion_major") {
163 versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
164 // either that or someone wants to be funny
165 } else if (stof(argv(1)) != cvar("g_nexuizversion_major")) {
166 if(stof(argv(1)) < cvar("g_nexuizversion_major")) {
167 versionmsg = "^3Your client version is outdated.\nPlease update!!!^8";
169 versionmsg = "^3This server is using an outdated Nexuiz version.\nThis can lead to problems.^8";
173 versionmsg = "^2client version and server version are the same.^8";
175 self.versionmessage = strzone(versionmsg);
176 } else if(argv(0) == "spectate") {
178 return; // don't allow spectating in lms, unless player runs out of lives
179 if(self.classname == "player" && cvar("sv_spectate") == 1) {
180 self.classname = "observer";
183 } else if(argv(0) == "join") {
184 self.classname = "player";
186 // TODO: I have no idea whether this is needed or not
188 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
191 } else if( argv(0) == "selectteam" ) {
192 if( argv(1) == "none" ) {
195 } else if( argv(1) == "red" ) {
196 SV_ChangeTeam( COLOR_TEAM1 - 1 );
197 } else if( argv(1) == "blue" ) {
198 SV_ChangeTeam( COLOR_TEAM2 - 1 );
199 } else if( argv(1) == "green" || argv(1) == "pink" ) {
200 SV_ChangeTeam( COLOR_TEAM3 - 1 );
201 } else if( argv(1) == "yellow" ) {
202 SV_ChangeTeam( COLOR_TEAM4 - 1 );
203 } else if( argv(1) == "auto" ) {
204 JoinBestTeam( self, 0 );
206 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
209 clientcommand(self,s);
213 float VoteAllowed(string votecommand) {
214 tokenize(cvar_string("sv_vote_allowed"));
217 while(argv(index) != "") {
218 local string allowed;
219 allowed = argv(index);
220 if(votecommand == allowed) {
229 local float playercount;
231 local float yescount;
237 player = find(player, classname, "player");
240 if(player.vote_vote < 0) {
242 } else if(player.vote_vote > 0) {
246 if(self.vote_finished > 0) {
251 player = find(player, classname, "player");
254 if((playercount / 2) < yescount) { // vote passed
256 } else if((playercount / 2) < nocount) { // vote rejected
258 } // else still running
261 void VoteDo(entity voter) {
262 bprint(strcat("^2The vote for \"^1", votecalled, "^2\" from \"", voter.netname, "^2\" DID PASS.\n"));
263 localcmd(votecalled);
267 void VoteTimeout(entity voter) {
268 bprint(strcat("^5The vote for \"^1", votecalled, "^5\" from \"", voter.netname, "^5\" did NOT pass.\n"));
274 player = find(player, classname, "player");
277 player.vote_vote = 0;
278 player.vote_finished = 0;
279 player = find(player, classname, "player");