2 float ValidateMap(string vote);
3 void(entity e) DropFlag;
5 void Say(entity source, float teamsay, string msgin)
7 string msgstr, colorstr, cmsgstr;
10 msgin = formatmessage(msgin);
15 if(source.team == COLOR_TEAM1)
17 else if(source.team == COLOR_TEAM2)
19 else if(source.team == COLOR_TEAM3)
21 else if(source.team == COLOR_TEAM4)
29 if(source.classname != "player") // observers can't
32 // how can we prevent the message from appearing in a listen server?
33 // for now, just give "say" back and only handle say_team
36 clientcommand(self, strcat("say ", msgin));
42 msgstr = strzone(strcat("\{1}", colorstr, "(^3", source.netname, colorstr, ") ^7", msgin, "\n"));
43 cmsgstr = strcat(colorstr, "(^3", source.netname, colorstr, ")\n^7", wordwrap(msgin, 50));
46 msgstr = strzone(strcat("\{1}^3", source.netname, "^7: ", msgin, "\n"));
48 head = find(world, classname, "player");
51 if(clienttype(head) == CLIENTTYPE_REAL)
52 if(!teamsay || (head.team == source.team))
56 centerprint(head, cmsgstr);
57 //stuffcmd(head, "play2 misc/talk.wav\n");
59 head = find(head, classname, "player");
64 head = find(world, classname, "observer");
67 if(clienttype(head) == CLIENTTYPE_REAL)
70 //stuffcmd(head, "play2 misc/talk.wav\n");
72 head = find(head, classname, "observer");
74 head = find(world, classname, "spectator");
77 if(clienttype(head) == CLIENTTYPE_REAL)
80 //stuffcmd(head, "play2 misc/talk.wav\n");
82 head = find(head, classname, "spectator");
84 ServerConsoleEcho(substring(msgstr, 1, strlen(msgstr) - 2), TRUE);
90 void SV_ParseClientCommand(string s) {
95 if(argv(0) == "clogin") {
96 if(cvar("sv_clientcommands")) {
97 if(self.adminstatus < -5) {
98 sprint(self, "Too many unsuccessful tries.\n");
99 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
100 self.adminstatus = 1;
101 sprint(self, "You now have remote admin status.\n");
102 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " received admin status"), TRUE);
104 sprint(self, "Wrong password.\n");
105 // use of -- produces compiler warning in the if() line???
106 self.adminstatus = self.adminstatus - 1;
107 if(self.adminstatus == 0)
109 sprint(self, "You lost remote admin status.\n");
110 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " lost admin status"), TRUE);
114 sprint(self, "Clientside commands NOT allowed.\n");
116 } else if(argv(0) == "ccmd") {
117 if(cvar("sv_clientcommands")) {
118 if(self.adminstatus > 0) {
119 local string command;
122 while(argv(index) != "") {
123 command = strcat(command, " ", argv(index));
126 command = strzone(command);
127 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " issued command '", command, "'"), TRUE);
128 localcmd(strcat(command, "\n"));
131 sprint(self, "You don't have remote admin status.\n");
133 sprint(self, "Clientside commands NOT allowed.\n");
135 } else if(argv(0) == "vote") {
136 if(argv(1) == "help") {
137 local string vmasterdis;
138 if(!cvar("sv_vote_master")) {
139 vmasterdis = " ^1(disabled)";
141 local string vcalldis;
142 if(!cvar("sv_vote_call")) {
143 vcalldis = " ^1(disabled)";
145 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");
146 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");
147 sprint(self, "^7\"^2help^7\" shows this info.\n");
148 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
149 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
150 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
151 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
152 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");
153 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
154 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
155 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
156 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
157 sprint(self, "^7You can call a vote for or execute these commands:\n");
158 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
159 } else if(argv(1) == "status") {
161 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
163 sprint(self, "^1No vote called.\n");
165 } else if(argv(1) == "call") {
166 if(cvar("sv_vote_call")) {
168 sprint(self, "^1There is already a vote called.\n");
173 sprint(self, "^1Your vote is empty. See help for more info.\n");
174 } else if(time < self.vote_next) {
175 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
176 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
177 if(!ValidateMap(vote))
180 votecalledmaster = FALSE;
181 // remap chmap to gomap (forces intermission)
182 if(strlen(vote) >= 6)
183 if(substring(vote, 0, 6) == "chmap ")
184 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
185 votecalledvote = strzone(vote);
186 votecaller = self; // remember who called the vote
187 votefinished = time + cvar("sv_vote_timeout");
188 votecaller.vote_vote = 1; // of course you vote yes
189 votecaller.vote_next = time + cvar("sv_vote_wait");
190 // bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
191 bprint(strcat("\{1}^3* ^7", votecaller.netname, "^3 calls a vote for ^1", votecalledvote, "\n"));
192 VoteCount(); // needed if you are the only one
194 sprint(self, "^1This vote is not ok. See help for more info.\n");
198 sprint(self, "^1Vote calling is NOT allowed.\n");
200 } else if(argv(1) == "stop") {
202 sprint(self, "^1No vote called.\n");
203 } else if(self == votecaller
204 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
207 sprint(self, "^1You are not allowed to stop that Vote.\n");
209 } else if(argv(1) == "master") {
210 if(cvar("sv_vote_master")) {
212 sprint(self, "^1There is already a vote called.\n");
215 votecalledmaster = TRUE;
216 votecalledvote = strzone("^3master");
217 votecaller = self; // remember who called the vote
218 votefinished = time + cvar("sv_vote_timeout");
219 votecaller.vote_vote = 1; // of course you vote yes
220 votecaller.vote_next = time + cvar("sv_vote_wait");
221 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
222 VoteCount(); // needed if you are the only one
225 sprint(self, "^1Vote to become master is NOT allowed.\n");
227 } else if(argv(1) == "do") {
228 if(self.vote_master) {
230 dovote = VoteParse();
232 sprint(self, "^1Your command was empty. See help for more info.\n");
233 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
234 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
235 localcmd(strcat(dovote, "\n"));
237 sprint(self, "^1This command is not ok. See help for more info.\n");
240 sprint(self, "^1You are NOT a master.\n");
242 } else if(argv(1) == "yes") {
244 sprint(self, "^1No vote called.\n");
245 } else if(self.vote_vote == 0
246 || cvar("sv_vote_change")) {
247 sprint(self, "^1You accepted the vote.\n");
249 if(!cvar("sv_vote_singlecount")) {
253 sprint(self, "^1You have already voted.\n");
255 } else if(argv(1) == "no") {
257 sprint(self, "^1No vote called.\n");
258 } else if(self.vote_vote == 0
259 || cvar("sv_vote_change")) {
260 sprint(self, "^1You rejected the vote.\n");
262 if(!cvar("sv_vote_singlecount")) {
266 sprint(self, "^1You have already voted.\n");
270 sprint(self, "^1Unknown vote command.\n");
272 } else if(argv(0) == "autoswitch") {
273 // be backwards compatible with older clients (enabled)
274 self.autoswitch = ("0" != argv(1));
275 local string autoswitchmsg;
276 if (self.autoswitch) {
277 autoswitchmsg = "on";
279 autoswitchmsg = "off";
281 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
282 } else if(argv(0) == "clientversion") {
283 if (argv(1) == "$gameversion") {
284 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
285 // either that or someone wants to be funny
288 self.version = stof(argv(1));
290 if(self.version != cvar("gameversion"))
292 self.classname = "observer";
295 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
296 //JoinBestTeam(self, 0);
297 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
298 self.classname = "observer";
299 stuffcmd(self,"menu_showteamselect\n");
301 } else if(argv(0) == "reportcvar") {
303 } else if(argv(0) == "spectate") {
304 if(cvar("g_lms") || cvar("g_arena"))
305 return; // don't allow spectating in lms, unless player runs out of lives
306 if(self.classname == "player" && cvar("sv_spectate") == 1) {
308 DropFlag(self.flagcarried);
309 DistributeFragsAmongTeam(self, self.team, 1.0);
310 self.classname = "observer";
313 } else if(argv(0) == "join") {
315 if (self.classname != "player")
317 self.classname = "player";
319 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
322 } else if( argv(0) == "selectteam" ) {
323 if( !cvar("teamplay") ) {
324 sprint( self, "selecteam can only be used in teamgames\n");
325 } else if(cvar("g_campaign")) {
326 //JoinBestTeam(self, 0);
327 } else if( argv(1) == "none" ) {
329 } else if( argv(1) == "red" ) {
330 SV_ChangeTeam( COLOR_TEAM1 - 1 );
331 } else if( argv(1) == "blue" ) {
332 SV_ChangeTeam( COLOR_TEAM2 - 1 );
333 } else if( argv(1) == "pink" ) {
334 SV_ChangeTeam( COLOR_TEAM3 - 1 );
335 } else if( argv(1) == "yellow" ) {
336 SV_ChangeTeam( COLOR_TEAM4 - 1 );
337 } else if( argv(1) == "auto" ) {
339 JoinBestTeam( self, 0 );
341 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
343 } else if(argv(0) == "ready") {
344 if(cvar("sv_ready_restart"))
347 bprint(self.netname, "^2 is ready\n");
350 } else if(argv(0) == "maplist") {
353 n = tokenize(cvar_string("g_maplist"));
354 sprint(self, "^7Maps in list: ");
355 for(i = 0; i < n; ++i)
361 sprint(self, strcat(col, argv(i), " "));
364 } else if(argv(0) == "say") {
365 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
366 //clientcommand(self, formatmessage(s));
367 } else if(argv(0) == "say_team") {
368 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
369 //clientcommand(self, formatmessage(s));
375 //if(cmd != "say") // handled above
376 //if(cmd != "say_team") // handled above
387 if(cmd != "playermodel")
388 if(cmd != "playerskin")
389 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
391 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
394 clientcommand(self,s);
398 float ValidateMap(string vote)
403 if(argv(0) == "map" || argv(0) == "changelevel")
405 else if(argv(0) == "chmap")
407 else if(argv(0) == "gotomap")
412 if(!TryFile(strcat("maps/", argv(1), ext)))
414 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
422 if(votefinished > 0 // a vote was called
423 && time > votefinished) // time is up
434 while(argv(index) != "") {
435 vote = strcat(vote, " ", argv(index));
439 // necessary for some of the string operations
440 vote = strzone(vote);
442 // now we remove some things that could be misused
446 local float votelength;
447 votelength = strlen(vote);
448 while(!found && index < votelength)
450 local string badchar;
451 badchar = substring(vote, index, 1);
461 return substring(vote, 0, index);
464 float VoteAllowed(string votecommand) {
465 tokenize(cvar_string("sv_vote_commands"));
468 while(argv(index) != "") {
469 local string allowed;
470 allowed = argv(index);
471 if(votecommand == allowed) {
480 local string searchclass;
481 searchclass = "player";
486 player = find(player, classname, searchclass);
489 player.vote_vote = 0;
490 player = find(player, classname, searchclass);
493 if("player" == searchclass) {
494 searchclass = "observer";
495 } else if("observer" == searchclass) {
496 searchclass = "spectator";
503 votecalledmaster = FALSE;
508 // bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
509 bprint(strcat("\{1}^3* ^7", votecaller.netname, "^3's vote for ^1", votecalledvote, "^3 was accepted\n"));
512 votecaller.vote_master = 1;
514 localcmd(strcat(votecalledvote, "\n"));
516 votecaller.vote_next = 0; // people like your votes, no wait for next vote
521 // bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
522 bprint(strcat("\{1}^3* ^7", votecaller.netname, "^3's vote for ^1", votecalledvote, "^3 was rejected\n"));
527 // bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
528 bprint(strcat("\{1}^3* ^7", votecaller.netname, "^3's vote for ^1", votecalledvote, "^3 timed out\n"));
532 void VoteStop(entity stopper) {
533 // bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
534 bprint(strcat("\{1}^3* ^7", stopper.netname, "^3 stopped ^7", votecaller.netname, "^3's vote\n"));
535 if(stopper == votecaller) {
536 // no wait for next vote so you can correct your vote
537 votecaller.vote_next = 0;
543 local float playercount;
545 local float yescount;
549 local string searchclass;
550 searchclass = "player";
555 player = find(player, classname, searchclass);
559 if(clienttype(player) != CLIENTTYPE_BOT) {
560 if(player.vote_vote < 0) {
562 } else if(player.vote_vote > 0) {
567 player = find(player, classname, searchclass);
570 if("player" == searchclass) {
571 searchclass = "observer";
572 } else if("observer" == searchclass) {
573 searchclass = "specator";
579 if((playercount == 1) && votecalledmaster) {
580 // if only one player is on the server becoming vote
581 // master is not allowed. This could be used for
582 // trolling or worse. 'self' is the user who has
583 // called the vote because this function is called
584 // by SV_ParseClientCommand. Maybe all voting should
585 // be disabled for a single player?
586 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
587 votecaller.vote_next = 0;
589 } else if((playercount / 2) < yescount) { // vote accepted
591 } else if((playercount / 2) < nocount) { // vote rejected
593 } else if(time > votefinished) { // vote timedout
595 } // else still running
604 e = find(world, classname, "player");
608 if(clienttype(e) == CLIENTTYPE_REAL)
613 e = find(e, classname, "player");
618 bprint("^1Server is restarting...\n");
619 localcmd("restart\n");