2 float ValidateMap(string vote);
4 void Say(entity source, float teamsay, string msgin)
6 string msgstr, colorstr;
9 msgin = formatmessage(msgin);
11 if(source.team == COLOR_TEAM1)
13 else if(source.team == COLOR_TEAM2)
15 else if(source.team == COLOR_TEAM3)
17 else if(source.team == COLOR_TEAM4)
25 if(source.classname != "player") // observers can't
28 // how can we prevent the message from appearing in a listen server?
29 // for now, just give "say" back and only handle say_team
32 clientcommand(self, strcat("say ", msgin));
37 msgstr = strcat(colorstr, "(^3", source.netname, colorstr, ") ^7", msgin, "\n");
39 msgstr = strcat("^3", source.netname, "^7: ", msgin, "\n");
41 head = find(world, classname, "player");
44 if(clienttype(head) == CLIENTTYPE_REAL)
45 if(!teamsay || (head.team == source.team))
48 sound(head, CHAN_VOICE, "misc/talk.wav", 1, ATTN_NORM);
50 head = find(head, classname, "player");
55 head = find(world, classname, "observer");
58 if(clienttype(head) == CLIENTTYPE_REAL)
61 sound(head, CHAN_VOICE, "misc/talk.wav", 1, ATTN_NORM);
63 head = find(head, classname, "observer");
65 head = find(world, classname, "spectator");
68 if(clienttype(head) == CLIENTTYPE_REAL)
71 sound(head, CHAN_VOICE, "misc/talk.wav", 1, ATTN_NORM);
73 head = find(head, classname, "spectator");
75 ServerConsoleEcho(substring(msgstr, 0, strlen(msgstr) - 1), TRUE);
79 void SV_ParseClientCommand(string s) {
84 if(argv(0) == "clogin") {
85 if(cvar("sv_clientcommands")) {
86 if(self.adminstatus < -5) {
87 sprint(self, "Too many unsuccessful tries.\n");
88 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
90 sprint(self, "You now have remote admin status.\n");
91 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " received admin status"), TRUE);
93 sprint(self, "Wrong password.\n");
94 // use of -- produces compiler warning in the if() line???
95 self.adminstatus = self.adminstatus - 1;
96 if(self.adminstatus == 0)
98 sprint(self, "You lost remote admin status.\n");
99 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " lost admin status"), TRUE);
103 sprint(self, "Clientside commands NOT allowed.\n");
105 } else if(argv(0) == "ccmd") {
106 if(cvar("sv_clientcommands")) {
107 if(self.adminstatus > 0) {
108 local string command;
111 while(argv(index) != "") {
112 command = strcat(command, " ", argv(index));
115 command = strzone(command);
116 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " issued command '", command, "'"), TRUE);
117 localcmd(strcat(command, "\n"));
120 sprint(self, "You don't have remote admin status.\n");
122 sprint(self, "Clientside commands NOT allowed.\n");
124 } else if(argv(0) == "vote") {
125 if(argv(1) == "help") {
126 local string vmasterdis;
127 if(!cvar("sv_vote_master")) {
128 vmasterdis = " ^1(disabled)";
130 local string vcalldis;
131 if(!cvar("sv_vote_call")) {
132 vcalldis = " ^1(disabled)";
134 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");
135 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");
136 sprint(self, "^7\"^2help^7\" shows this info.\n");
137 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
138 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
139 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
140 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
141 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");
142 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
143 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
144 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
145 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
146 sprint(self, "^7You can call a vote for or execute these commands:\n");
147 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
148 } else if(argv(1) == "status") {
150 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
152 sprint(self, "^1No vote called.\n");
154 } else if(argv(1) == "call") {
155 if(cvar("sv_vote_call")) {
157 sprint(self, "^1There is already a vote called.\n");
162 sprint(self, "^1Your vote is empty. See help for more info.\n");
163 } else if(time < self.vote_next) {
164 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
165 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
166 if(!ValidateMap(vote))
169 votecalledmaster = FALSE;
170 // remap chmap to gomap (forces intermission)
171 if(strlen(vote) >= 6)
172 if(substring(vote, 0, 6) == "chmap ")
173 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
174 votecalledvote = strzone(vote);
175 votecaller = self; // remember who called the vote
176 votefinished = time + cvar("sv_vote_timeout");
177 votecaller.vote_vote = 1; // of course you vote yes
178 votecaller.vote_next = time + cvar("sv_vote_wait");
179 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
180 VoteCount(); // needed if you are the only one
182 sprint(self, "^1This vote is not ok. See help for more info.\n");
186 sprint(self, "^1Vote calling is NOT allowed.\n");
188 } else if(argv(1) == "stop") {
190 sprint(self, "^1No vote called.\n");
191 } else if(self == votecaller
192 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
195 sprint(self, "^1You are not allowed to stop that Vote.\n");
197 } else if(argv(1) == "master") {
198 if(cvar("sv_vote_master")) {
200 sprint(self, "^1There is already a vote called.\n");
203 votecalledmaster = TRUE;
204 votecalledvote = strzone("^3master");
205 votecaller = self; // remember who called the vote
206 votefinished = time + cvar("sv_vote_timeout");
207 votecaller.vote_vote = 1; // of course you vote yes
208 votecaller.vote_next = time + cvar("sv_vote_wait");
209 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
210 VoteCount(); // needed if you are the only one
213 sprint(self, "^1Vote to become master is NOT allowed.\n");
215 } else if(argv(1) == "do") {
216 if(self.vote_master) {
218 dovote = VoteParse();
220 sprint(self, "^1Your command was empty. See help for more info.\n");
221 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
222 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
223 localcmd(strcat(dovote, "\n"));
225 sprint(self, "^1This command is not ok. See help for more info.\n");
228 sprint(self, "^1You are NOT a master.\n");
230 } else if(argv(1) == "yes") {
232 sprint(self, "^1No vote called.\n");
233 } else if(self.vote_vote == 0
234 || cvar("sv_vote_change")) {
235 sprint(self, "^1You accepted the vote.\n");
237 if(!cvar("sv_vote_singlecount")) {
241 sprint(self, "^1You have already voted.\n");
243 } else if(argv(1) == "no") {
245 sprint(self, "^1No vote called.\n");
246 } else if(self.vote_vote == 0
247 || cvar("sv_vote_change")) {
248 sprint(self, "^1You rejected the vote.\n");
250 if(!cvar("sv_vote_singlecount")) {
254 sprint(self, "^1You have already voted.\n");
258 sprint(self, "^1Unknown vote command.\n");
260 } else if(argv(0) == "autoswitch") {
261 // be backwards compatible with older clients (enabled)
262 self.autoswitch = ("0" != argv(1));
263 local string autoswitchmsg;
264 if (self.autoswitch) {
265 autoswitchmsg = "on";
267 autoswitchmsg = "off";
269 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
270 } else if(argv(0) == "clientversion") {
271 if (argv(1) == "$gameversion") {
272 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
273 // either that or someone wants to be funny
276 self.version = stof(argv(1));
278 if(self.version != cvar("gameversion"))
280 self.classname = "observer";
283 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
284 //JoinBestTeam(self, 0);
285 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
286 self.classname = "observer";
287 stuffcmd(self,"menu_showteamselect\n");
289 } else if(argv(0) == "reportcvar") {
291 } else if(argv(0) == "spectate") {
292 if(cvar("g_lms") || cvar("g_arena"))
293 return; // don't allow spectating in lms, unless player runs out of lives
294 if(self.classname == "player" && cvar("sv_spectate") == 1) {
295 self.classname = "observer";
298 } else if(argv(0) == "join") {
300 if (self.classname != "player")
302 self.classname = "player";
304 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
307 } else if( argv(0) == "selectteam" ) {
308 if( !cvar("teamplay") ) {
309 sprint( self, "selecteam can only be used in teamgames\n");
310 } else if(cvar("g_campaign")) {
311 //JoinBestTeam(self, 0);
312 } else if( argv(1) == "none" ) {
314 } else if( argv(1) == "red" ) {
315 SV_ChangeTeam( COLOR_TEAM1 - 1 );
316 } else if( argv(1) == "blue" ) {
317 SV_ChangeTeam( COLOR_TEAM2 - 1 );
318 } else if( argv(1) == "pink" ) {
319 SV_ChangeTeam( COLOR_TEAM3 - 1 );
320 } else if( argv(1) == "yellow" ) {
321 SV_ChangeTeam( COLOR_TEAM4 - 1 );
322 } else if( argv(1) == "auto" ) {
324 JoinBestTeam( self, 0 );
326 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
328 } else if(argv(0) == "ready") {
329 if(cvar("sv_ready_restart"))
332 bprint(self.netname, "^2 is ready\n");
335 } else if(argv(0) == "say") {
336 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
337 //clientcommand(self, formatmessage(s));
338 } else if(argv(0) == "say_team") {
339 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
340 //clientcommand(self, formatmessage(s));
342 clientcommand(self,s);
346 float ValidateMap(string vote)
351 if(argv(0) == "map" || argv(0) == "changelevel")
353 else if(argv(0) == "chmap")
355 else if(argv(0) == "gotomap")
360 if(!TryFile(strcat("maps/", argv(1), ext)))
362 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
370 if(votefinished > 0 // a vote was called
371 && time > votefinished) // time is up
382 while(argv(index) != "") {
383 vote = strcat(vote, " ", argv(index));
387 // necessary for some of the string operations
388 vote = strzone(vote);
390 // now we remove some things that could be misused
394 local float votelength;
395 votelength = strlen(vote);
396 while(!found && index < votelength)
398 local string badchar;
399 badchar = substring(vote, index, 1);
409 return substring(vote, 0, index);
412 float VoteAllowed(string votecommand) {
413 tokenize(cvar_string("sv_vote_commands"));
416 while(argv(index) != "") {
417 local string allowed;
418 allowed = argv(index);
419 if(votecommand == allowed) {
428 local string searchclass;
429 searchclass = "player";
434 player = find(player, classname, searchclass);
437 player.vote_vote = 0;
438 player = find(player, classname, searchclass);
441 if("player" == searchclass) {
442 searchclass = "observer";
443 } else if("observer" == searchclass) {
444 searchclass = "spectator";
451 votecalledmaster = FALSE;
456 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
459 votecaller.vote_master = 1;
461 localcmd(strcat(votecalledvote, "\n"));
463 votecaller.vote_next = 0; // people like your votes, no wait for next vote
468 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
473 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
477 void VoteStop(entity stopper) {
478 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
479 if(stopper == votecaller) {
480 // no wait for next vote so you can correct your vote
481 votecaller.vote_next = 0;
487 local float playercount;
489 local float yescount;
493 local string searchclass;
494 searchclass = "player";
499 player = find(player, classname, searchclass);
503 if(clienttype(player) != CLIENTTYPE_BOT) {
504 if(player.vote_vote < 0) {
506 } else if(player.vote_vote > 0) {
511 player = find(player, classname, searchclass);
514 if("player" == searchclass) {
515 searchclass = "observer";
516 } else if("observer" == searchclass) {
517 searchclass = "specator";
523 if((playercount == 1) && votecalledmaster) {
524 // if only one player is on the server becoming vote
525 // master is not allowed. This could be used for
526 // trolling or worse. 'self' is the user who has
527 // called the vote because this function is called
528 // by SV_ParseClientCommand. Maybe all voting should
529 // be disabled for a single player?
530 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
531 votecaller.vote_next = 0;
533 } else if((playercount / 2) < yescount) { // vote accepted
535 } else if((playercount / 2) < nocount) { // vote rejected
537 } else if(time > votefinished) { // vote timedout
539 } // else still running
548 e = find(world, classname, "player");
552 if(clienttype(e) == CLIENTTYPE_REAL)
557 e = find(e, classname, "player");
562 bprint("^1Server is restarting...\n");
563 localcmd("restart\n");