1 void SV_ParseClientCommand(string s) {
4 if(argv(0) == "clogin") {
5 if(cvar("sv_clientcommands")) {
6 if(self.adminstatus < -5) {
7 sprint(self, "Too many unsuccessful tries.\n");
8 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
10 sprint(self, "You now have remote admin status.\n");
12 sprint(self, "Wrong password.\n");
14 if(self.adminstatus == 0)
15 sprint(self, "You lost remote admin status.\n");
18 sprint(self, "Clientside commands NOT allowed.\n");
20 } else if(argv(0) == "ccmd") {
21 if(cvar("sv_clientcommands")) {
22 if(self.adminstatus > 0) {
27 while(argv(index) != "") {
28 command = strcat(command, " ", argv(index));
33 sprint(self, "You don't have remote admin status.\n");
35 sprint(self, "Clientside commands NOT allowed.\n");
37 } else if(argv(0) == "vote") {
38 if(argv(1) == "help") {
39 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");
40 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");
41 sprint(self, "^1\"^2help^1\" shows this info.\n");
42 sprint(self, "^1\"^2status^1\" shows if there is a vote called and who called it.\n");
43 sprint(self, "^1\"^2call^1\" is used to call a vote. See the list of allowed commands.\n");
44 sprint(self, "^1If more then 50% of the players vote yes the vote is executed.\n");
45 sprint(self, "^1If more then 50% of the players vote no the vote fails.\n");
46 sprint(self, "^1\"^2stop^1\" can be used by the vote caller to stop a vote and maybe correct it.\n");
47 sprint(self, "^1\"^2yes^1\" and \"^2no^1\" to make your vote.\n");
48 sprint(self, "^1You can call a vote with these commands:\n");
49 sprint(self, strcat("^1\"^2vcall^1\" ^3", cvar_string("sv_vote_allowed"), "^1 and further ^3arguments^1\n"));
50 } else if(argv(1) == "status") {
51 if(votecalled == "") {
52 sprint(self, "^1No vote called.\n");
54 sprint(self, strcat("^7Vote for \"^1", votecalled, "^7\" called by \"", votecaller.netname, "^7\".\n"));
56 } else if(argv(1) == "call") {
57 if(votecalled == "") {
62 while(argv(index) != "") {
63 vote = strcat(vote, " ", argv(index));
67 // necessary for some of the string operations
70 // now we remove some things that could be misused
74 local float votelength;
75 votelength = strlen(vote);
76 while(!found && index < votelength)
79 badchar = substring(vote, index, 1);
88 vote = substring(vote, 0, index);
91 sprint(self, "^1You have to vote for something.\n");
92 } else if(time < self.vote_next) {
93 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
94 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
95 votecalled = strzone(vote);
96 votecaller = self; // remember who called the vote
97 self.vote_vote = 1; // of course you vote yes
98 self.vote_finished = time + cvar("sv_vote_timeout");
99 self.vote_next = time + cvar("sv_vote_wait");
100 bprint(strcat("^3Vote for \"^1", votecalled, "^3\" called by \"", self.netname, "^3\".\n"));
101 VoteCount(); // needed if you are the only one
103 sprint(self, "^1This vote is not ok. See help for more info.\n");
106 sprint(self, "^1There is already a vote called.\n");
108 } else if(argv(1) == "stop") {
109 if(votecalled == "") {
110 sprint(self, "^1No vote called.\n");
111 } else if(votecaller == self
112 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
113 if(votecaller == self) {
114 // disable next votetimer so you can correct your vote
117 VoteTimeout(votecaller);
119 sprint(self, "^1You are not allowed to stop that Vote.\n");
121 } else if(argv(1) == "yes") {
122 if(votecalled == "") {
123 sprint(self, "^1No vote called.\n");
124 } else if(self.vote_vote == 0
125 || cvar("sv_vote_change")) {
127 if(!cvar("sv_vote_singlecount")) {
131 sprint(self, "^1You have already voted.\n");
133 } else if(argv(1) == "no") {
134 if(votecalled == "") {
135 sprint(self, "^1No vote called.\n");
136 } else if(self.vote_vote == 0
137 || cvar("sv_vote_change")) {
139 if(!cvar("sv_vote_singlecount")) {
143 sprint(self, "^1You have already voted.\n");
147 sprint(self, "^1Unknown vote command.\n");
150 clientcommand(self,s);
154 float VoteAllowed(string votecommand) {
155 tokenize(cvar_string("sv_vote_allowed"));
158 while(argv(index) != "") {
159 local string allowed;
160 allowed = argv(index);
161 if(votecommand == allowed) {
170 local float playercount;
172 local float yescount;
178 player = find(player, classname, "player");
181 if(player.vote_vote < 0) {
183 } else if(player.vote_vote > 0) {
187 if(self.vote_finished > 0) {
192 player = find(player, classname, "player");
195 if((playercount / 2) < yescount) { // vote passed
197 } else if((playercount / 2) < nocount) { // vote rejected
199 } // else still running
202 void VoteDo(entity voter) {
203 bprint(strcat("^2The vote for \"^1", votecalled, "^2\" from \"", voter.netname, "^2\" DID PASS.\n"));
204 localcmd(votecalled);
208 void VoteTimeout(entity voter) {
209 bprint(strcat("^5The vote for \"^1", votecalled, "^5\" from \"", voter.netname, "^5\" did NOT pass.\n"));
215 player = find(player, classname, "player");
218 player.vote_vote = 0;
219 player.vote_finished = 0;
220 player = find(player, classname, "player");