]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/gamec/clientcommands.c
new gamemode: "Last Man Standing" (g_lms)
[divverent/nexuiz.git] / data / qcsrc / gamec / clientcommands.c
1 void SV_ParseClientCommand(string s) {
2         local float index;
3
4         tokenize(s);
5
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")) {
11                                 self.adminstatus = 1;
12                                 sprint(self, "You now have remote admin status.\n");
13                         } else {
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");
19                         }
20                 } else {
21                         sprint(self, "Clientside commands NOT allowed.\n");
22                 }
23         } else if(argv(0) == "ccmd") {
24                 if(cvar("sv_clientcommands")) {
25                         if(self.adminstatus > 0) {
26                                 local string command;
27                                 command = argv(1);
28                                 index = 2;
29                                 while(argv(index) != "") {
30                                         command = strcat(command, " ", argv(index));
31                                         index++;
32                                 }
33                                 localcmd(command);
34                         } else
35                                 sprint(self, "You don't have remote admin status.\n");
36                 } else {
37                         sprint(self, "Clientside commands NOT allowed.\n");
38                 }
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");
55                         } else {
56                                 sprint(self, strcat("^7Vote for \"^1", votecalled, "^7\" called by \"", votecaller.netname, "^7\".\n"));
57                         }
58                 } else if(argv(1) == "call") {
59                         if(votecalled == "") {
60                                 local string vote;
61                                 vote = argv(2);
62                                 index = 3;
63                                 while(argv(index) != "") {
64                                         vote = strcat(vote, " ", argv(index));
65                                         index++;
66                                 }
67
68                                 // necessary for some of the string operations
69                                 vote = strzone(vote);
70
71                                 // now we remove some things that could be misused
72                                 index = 0;
73                                 local float found;
74                                 found = FALSE;
75                                 local float votelength;
76                                 votelength = strlen(vote);
77                                 while(!found && index < votelength)
78                                 {
79                                         local string badchar;
80                                         badchar = substring(vote, index, 1);
81                                         if(badchar == ";"
82                                            || badchar == "\n")
83                                         {
84                                                 found = TRUE;
85                                         } else {
86                                                 index++;
87                                         }
88                                 }
89                                 vote = substring(vote, 0, index);
90
91                                 if(vote == "") {
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
103                                 } else {
104                                         sprint(self, "^1This vote is not ok. See help for more info.\n");
105                                 }
106                         } else {
107                                 sprint(self, "^1There is already a vote called.\n");
108                         }
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
116                                         self.vote_next = 0;
117                                 }
118                                 VoteTimeout(votecaller);
119                         } else {
120                                 sprint(self, "^1You are not allowed to stop that Vote.\n");
121                         }
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")) {
127                                 self.vote_vote = 1;
128                                 if(!cvar("sv_vote_singlecount")) {
129                                         VoteCount();
130                                 }
131                         } else {
132                                 sprint(self, "^1You have already voted.\n");
133                         }
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")) {
139                                 self.vote_vote = -1;
140                                 if(!cvar("sv_vote_singlecount")) {
141                                         VoteCount();
142                                 }
143                         } else {
144                                 sprint(self, "^1You have already voted.\n");
145                         }
146                 } else {
147                         // ignore this?
148                         sprint(self, "^1Unknown vote command.\n");
149                 }
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";
156                 } else {
157                         autoswitchmsg = "off";
158                 }
159                 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
160         } else if(argv(0) == "clientversion") {
161                 local string versionmsg;
162                 if (argv(1) == "$g_nexuizversion") {
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 (argv(1) != cvar_string("g_nexuizversion")) {
166                         versionmsg = strcat("^3client version (", argv(1), ") and server version are different.\nYou might have to update!!!^8");
167                 } else {
168                         versionmsg = strcat("^2client version (", argv(1), ") and server version are the same.^8");
169                 }
170                 self.versionmessage = strzone(versionmsg);
171         } else if(argv(0) == "spectate") {
172                 if(cvar("g_lms"))
173                         return; // don't allow spectating in lms, unless player runs out of lives
174                 if(self.classname == "player" && cvar("sv_spectate") == 1) {
175                         self.classname = "observer";
176                         PutClientInServer();
177                 }
178         } else if(argv(0) == "crosshair") {
179                 self.crosshair_static = argv(1);
180         } else {
181                 clientcommand(self,s);
182         }
183 }
184
185 float VoteAllowed(string votecommand) {
186         tokenize(cvar_string("sv_vote_allowed"));
187         local float index;
188         index = 0;
189         while(argv(index) != "") {
190                 local string allowed;
191                 allowed = argv(index);
192                 if(votecommand == allowed) {
193                         return TRUE;
194                 }
195                 index++;
196         }
197         return FALSE;
198 }
199
200 void VoteCount() {
201         local float playercount;
202         playercount = 0;
203         local float yescount;
204         yescount = 0;
205         local float nocount;
206         nocount = 0;
207         local entity player;
208         local entity voter;
209         player = find(player, classname, "player");
210         while(player)
211         {
212                 if(player.vote_vote < 0) {
213                         nocount++;
214                 } else if(player.vote_vote > 0) {
215                         yescount++;
216                 }
217
218                 if(self.vote_finished > 0) {
219                         voter = player;
220                 }
221
222                 playercount++;
223                 player = find(player, classname, "player");
224         }
225
226         if((playercount / 2) < yescount) { // vote passed
227                 VoteDo(voter);
228         } else if((playercount / 2) < nocount) { // vote rejected
229                 VoteTimeout(voter);
230         } // else still running
231 }
232
233 void VoteDo(entity voter) {
234         bprint(strcat("^2The vote for \"^1", votecalled, "^2\" from \"", voter.netname, "^2\" DID PASS.\n"));
235         localcmd(votecalled);
236         VoteReset();
237 }
238
239 void VoteTimeout(entity voter) {
240         bprint(strcat("^5The vote for \"^1", votecalled, "^5\" from \"", voter.netname, "^5\" did NOT pass.\n"));
241         VoteReset();
242 }
243
244 void VoteReset() {
245         local entity player;
246         player = find(player, classname, "player");
247         while(player)
248         {
249                 player.vote_vote = 0;
250                 player.vote_finished = 0;
251                 player = find(player, classname, "player");
252         }
253         votecalled = "";
254 }