2 float ValidateMap(string vote);
4 void Say(entity source, float teamsay, string msgin)
6 string msgstr, colorstr, cmsgstr;
9 msgin = formatmessage(msgin);
14 if(source.team == COLOR_TEAM1)
16 else if(source.team == COLOR_TEAM2)
18 else if(source.team == COLOR_TEAM3)
20 else if(source.team == COLOR_TEAM4)
28 if(source.classname != "player") // observers can't
31 // how can we prevent the message from appearing in a listen server?
32 // for now, just give "say" back and only handle say_team
35 clientcommand(self, strcat("say ", msgin));
41 msgstr = strzone(strcat(colorstr, "(^3", source.netname, colorstr, ") ^7", msgin, "\n"));
42 cmsgstr = strcat(colorstr, "(^3", source.netname, colorstr, ")\n^7", wordwrap(msgin, 50));
45 msgstr = strzone(strcat("^3", source.netname, "^7: ", msgin, "\n"));
47 head = find(world, classname, "player");
50 if(clienttype(head) == CLIENTTYPE_REAL)
51 if(!teamsay || (head.team == source.team))
55 centermsg_setfor(head, CENTERMSG_TEAMSAY, cmsgstr);
56 stuffcmd(head, "play2 misc/talk.wav\n");
58 head = find(head, classname, "player");
63 head = find(world, classname, "observer");
66 if(clienttype(head) == CLIENTTYPE_REAL)
69 stuffcmd(head, "play2 misc/talk.wav\n");
71 head = find(head, classname, "observer");
73 head = find(world, classname, "spectator");
76 if(clienttype(head) == CLIENTTYPE_REAL)
79 stuffcmd(head, "play2 misc/talk.wav\n");
81 head = find(head, classname, "spectator");
83 ServerConsoleEcho(substring(msgstr, 0, strlen(msgstr) - 1), TRUE);
89 void SV_ParseClientCommand(string s) {
94 if(argv(0) == "clogin") {
95 if(cvar("sv_clientcommands")) {
96 if(self.adminstatus < -5) {
97 sprint(self, "Too many unsuccessful tries.\n");
98 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
100 sprint(self, "You now have remote admin status.\n");
101 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " received admin status"), TRUE);
103 sprint(self, "Wrong password.\n");
104 // use of -- produces compiler warning in the if() line???
105 self.adminstatus = self.adminstatus - 1;
106 if(self.adminstatus == 0)
108 sprint(self, "You lost remote admin status.\n");
109 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " lost admin status"), TRUE);
113 sprint(self, "Clientside commands NOT allowed.\n");
115 } else if(argv(0) == "ccmd") {
116 if(cvar("sv_clientcommands")) {
117 if(self.adminstatus > 0) {
118 local string command;
121 while(argv(index) != "") {
122 command = strcat(command, " ", argv(index));
125 command = strzone(command);
126 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " issued command '", command, "'"), TRUE);
127 localcmd(strcat(command, "\n"));
130 sprint(self, "You don't have remote admin status.\n");
132 sprint(self, "Clientside commands NOT allowed.\n");
134 } else if(argv(0) == "vote") {
135 if(argv(1) == "help") {
136 local string vmasterdis;
137 if(!cvar("sv_vote_master")) {
138 vmasterdis = " ^1(disabled)";
140 local string vcalldis;
141 if(!cvar("sv_vote_call")) {
142 vcalldis = " ^1(disabled)";
144 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");
145 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");
146 sprint(self, "^7\"^2help^7\" shows this info.\n");
147 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
148 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
149 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
150 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
151 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");
152 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
153 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
154 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
155 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
156 sprint(self, "^7You can call a vote for or execute these commands:\n");
157 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
158 } else if(argv(1) == "status") {
160 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
162 sprint(self, "^1No vote called.\n");
164 } else if(argv(1) == "call") {
165 if(cvar("sv_vote_call")) {
167 sprint(self, "^1There is already a vote called.\n");
172 sprint(self, "^1Your vote is empty. See help for more info.\n");
173 } else if(time < self.vote_next) {
174 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
175 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
176 if(!ValidateMap(vote))
179 votecalledmaster = FALSE;
180 // remap chmap to gomap (forces intermission)
181 if(strlen(vote) >= 6)
182 if(substring(vote, 0, 6) == "chmap ")
183 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
184 votecalledvote = strzone(vote);
185 votecaller = self; // remember who called the vote
186 votefinished = time + cvar("sv_vote_timeout");
187 votecaller.vote_vote = 1; // of course you vote yes
188 votecaller.vote_next = time + cvar("sv_vote_wait");
189 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
190 VoteCount(); // needed if you are the only one
192 sprint(self, "^1This vote is not ok. See help for more info.\n");
196 sprint(self, "^1Vote calling is NOT allowed.\n");
198 } else if(argv(1) == "stop") {
200 sprint(self, "^1No vote called.\n");
201 } else if(self == votecaller
202 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
205 sprint(self, "^1You are not allowed to stop that Vote.\n");
207 } else if(argv(1) == "master") {
208 if(cvar("sv_vote_master")) {
210 sprint(self, "^1There is already a vote called.\n");
213 votecalledmaster = TRUE;
214 votecalledvote = strzone("^3master");
215 votecaller = self; // remember who called the vote
216 votefinished = time + cvar("sv_vote_timeout");
217 votecaller.vote_vote = 1; // of course you vote yes
218 votecaller.vote_next = time + cvar("sv_vote_wait");
219 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
220 VoteCount(); // needed if you are the only one
223 sprint(self, "^1Vote to become master is NOT allowed.\n");
225 } else if(argv(1) == "do") {
226 if(self.vote_master) {
228 dovote = VoteParse();
230 sprint(self, "^1Your command was empty. See help for more info.\n");
231 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
232 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
233 localcmd(strcat(dovote, "\n"));
235 sprint(self, "^1This command is not ok. See help for more info.\n");
238 sprint(self, "^1You are NOT a master.\n");
240 } else if(argv(1) == "yes") {
242 sprint(self, "^1No vote called.\n");
243 } else if(self.vote_vote == 0
244 || cvar("sv_vote_change")) {
245 sprint(self, "^1You accepted the vote.\n");
247 if(!cvar("sv_vote_singlecount")) {
251 sprint(self, "^1You have already voted.\n");
253 } else if(argv(1) == "no") {
255 sprint(self, "^1No vote called.\n");
256 } else if(self.vote_vote == 0
257 || cvar("sv_vote_change")) {
258 sprint(self, "^1You rejected the vote.\n");
260 if(!cvar("sv_vote_singlecount")) {
264 sprint(self, "^1You have already voted.\n");
268 sprint(self, "^1Unknown vote command.\n");
270 } else if(argv(0) == "autoswitch") {
271 // be backwards compatible with older clients (enabled)
272 self.autoswitch = ("0" != argv(1));
273 local string autoswitchmsg;
274 if (self.autoswitch) {
275 autoswitchmsg = "on";
277 autoswitchmsg = "off";
279 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
280 } else if(argv(0) == "clientversion") {
281 if (argv(1) == "$gameversion") {
282 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
283 // either that or someone wants to be funny
286 self.version = stof(argv(1));
288 if(self.version != cvar("gameversion"))
290 self.classname = "observer";
293 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
294 //JoinBestTeam(self, 0);
295 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
296 self.classname = "observer";
297 stuffcmd(self,"menu_showteamselect\n");
299 } else if(argv(0) == "reportcvar") {
301 } else if(argv(0) == "spectate") {
302 if(cvar("g_lms") || cvar("g_arena"))
303 return; // don't allow spectating in lms, unless player runs out of lives
304 if(self.classname == "player" && cvar("sv_spectate") == 1) {
305 self.classname = "observer";
308 } else if(argv(0) == "join") {
310 if (self.classname != "player")
312 self.classname = "player";
314 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
317 } else if( argv(0) == "selectteam" ) {
318 if( !cvar("teamplay") ) {
319 sprint( self, "selecteam can only be used in teamgames\n");
320 } else if(cvar("g_campaign")) {
321 //JoinBestTeam(self, 0);
322 } else if( argv(1) == "none" ) {
324 } else if( argv(1) == "red" ) {
325 SV_ChangeTeam( COLOR_TEAM1 - 1 );
326 } else if( argv(1) == "blue" ) {
327 SV_ChangeTeam( COLOR_TEAM2 - 1 );
328 } else if( argv(1) == "pink" ) {
329 SV_ChangeTeam( COLOR_TEAM3 - 1 );
330 } else if( argv(1) == "yellow" ) {
331 SV_ChangeTeam( COLOR_TEAM4 - 1 );
332 } else if( argv(1) == "auto" ) {
334 JoinBestTeam( self, 0 );
336 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
338 } else if(argv(0) == "ready") {
339 if(cvar("sv_ready_restart"))
342 bprint(self.netname, "^2 is ready\n");
345 } else if(argv(0) == "say") {
346 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
347 //clientcommand(self, formatmessage(s));
348 } else if(argv(0) == "say_team") {
349 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
350 //clientcommand(self, formatmessage(s));
352 clientcommand(self,s);
356 float ValidateMap(string vote)
361 if(argv(0) == "map" || argv(0) == "changelevel")
363 else if(argv(0) == "chmap")
365 else if(argv(0) == "gotomap")
370 if(!TryFile(strcat("maps/", argv(1), ext)))
372 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
380 if(votefinished > 0 // a vote was called
381 && time > votefinished) // time is up
392 while(argv(index) != "") {
393 vote = strcat(vote, " ", argv(index));
397 // necessary for some of the string operations
398 vote = strzone(vote);
400 // now we remove some things that could be misused
404 local float votelength;
405 votelength = strlen(vote);
406 while(!found && index < votelength)
408 local string badchar;
409 badchar = substring(vote, index, 1);
419 return substring(vote, 0, index);
422 float VoteAllowed(string votecommand) {
423 tokenize(cvar_string("sv_vote_commands"));
426 while(argv(index) != "") {
427 local string allowed;
428 allowed = argv(index);
429 if(votecommand == allowed) {
438 local string searchclass;
439 searchclass = "player";
444 player = find(player, classname, searchclass);
447 player.vote_vote = 0;
448 player = find(player, classname, searchclass);
451 if("player" == searchclass) {
452 searchclass = "observer";
453 } else if("observer" == searchclass) {
454 searchclass = "spectator";
461 votecalledmaster = FALSE;
466 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
469 votecaller.vote_master = 1;
471 localcmd(strcat(votecalledvote, "\n"));
473 votecaller.vote_next = 0; // people like your votes, no wait for next vote
478 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
483 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
487 void VoteStop(entity stopper) {
488 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
489 if(stopper == votecaller) {
490 // no wait for next vote so you can correct your vote
491 votecaller.vote_next = 0;
497 local float playercount;
499 local float yescount;
503 local string searchclass;
504 searchclass = "player";
509 player = find(player, classname, searchclass);
513 if(clienttype(player) != CLIENTTYPE_BOT) {
514 if(player.vote_vote < 0) {
516 } else if(player.vote_vote > 0) {
521 player = find(player, classname, searchclass);
524 if("player" == searchclass) {
525 searchclass = "observer";
526 } else if("observer" == searchclass) {
527 searchclass = "specator";
533 if((playercount == 1) && votecalledmaster) {
534 // if only one player is on the server becoming vote
535 // master is not allowed. This could be used for
536 // trolling or worse. 'self' is the user who has
537 // called the vote because this function is called
538 // by SV_ParseClientCommand. Maybe all voting should
539 // be disabled for a single player?
540 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
541 votecaller.vote_next = 0;
543 } else if((playercount / 2) < yescount) { // vote accepted
545 } else if((playercount / 2) < nocount) { // vote rejected
547 } else if(time > votefinished) { // vote timedout
549 } // else still running
558 e = find(world, classname, "player");
562 if(clienttype(e) == CLIENTTYPE_REAL)
567 e = find(e, classname, "player");
572 bprint("^1Server is restarting...\n");
573 localcmd("restart\n");