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 colorstr = Team_ColorCode(source.team);
20 if(source.classname != "player") // observers can't
23 // how can we prevent the message from appearing in a listen server?
24 // for now, just give "say" back and only handle say_team
27 clientcommand(self, strcat("say ", msgin));
33 msgstr = strzone(strcat(colorstr, "(^3", source.netname, colorstr, ") ^7", msgin, "\n"));
34 cmsgstr = strcat(colorstr, "(^3", source.netname, colorstr, ")\n^7", wordwrap(msgin, 50));
37 msgstr = strzone(strcat("^3", source.netname, "^7: ", msgin, "\n"));
39 head = find(world, classname, "player");
42 if(clienttype(head) == CLIENTTYPE_REAL)
43 if(!teamsay || (head.team == source.team))
47 centermsg_setfor(head, CENTERMSG_TEAMSAY, cmsgstr);
48 stuffcmd(head, "play2 misc/talk.wav\n");
50 head = find(head, classname, "player");
55 head = find(world, classname, "observer");
58 if(clienttype(head) == CLIENTTYPE_REAL)
61 stuffcmd(head, "play2 misc/talk.wav\n");
63 head = find(head, classname, "observer");
65 head = find(world, classname, "spectator");
68 if(clienttype(head) == CLIENTTYPE_REAL)
71 stuffcmd(head, "play2 misc/talk.wav\n");
73 head = find(head, classname, "spectator");
75 ServerConsoleEcho(substring(msgstr, 0, strlen(msgstr) - 1), TRUE);
81 void SV_ParseClientCommand(string s) {
86 if(argv(0) == "clogin") {
87 if(cvar("sv_clientcommands")) {
88 if(self.adminstatus < -5) {
89 sprint(self, "Too many unsuccessful tries.\n");
90 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
92 sprint(self, "You now have remote admin status.\n");
93 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " received admin status"), TRUE);
95 sprint(self, "Wrong password.\n");
96 // use of -- produces compiler warning in the if() line???
97 self.adminstatus = self.adminstatus - 1;
98 if(self.adminstatus == 0)
100 sprint(self, "You lost remote admin status.\n");
101 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " lost admin status"), TRUE);
105 sprint(self, "Clientside commands NOT allowed.\n");
107 } else if(argv(0) == "ccmd") {
108 if(cvar("sv_clientcommands")) {
109 if(self.adminstatus > 0) {
110 local string command;
113 while(argv(index) != "") {
114 command = strcat(command, " ", argv(index));
117 command = strzone(command);
118 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " issued command '", command, "'"), TRUE);
119 localcmd(strcat(command, "\n"));
122 sprint(self, "You don't have remote admin status.\n");
124 sprint(self, "Clientside commands NOT allowed.\n");
126 } else if(argv(0) == "vote") {
127 if(argv(1) == "help") {
128 local string vmasterdis;
129 if(!cvar("sv_vote_master")) {
130 vmasterdis = " ^1(disabled)";
132 local string vcalldis;
133 if(!cvar("sv_vote_call")) {
134 vcalldis = " ^1(disabled)";
136 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");
137 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");
138 sprint(self, "^7\"^2help^7\" shows this info.\n");
139 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
140 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
141 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
142 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
143 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");
144 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
145 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
146 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
147 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
148 sprint(self, "^7You can call a vote for or execute these commands:\n");
149 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
150 } else if(argv(1) == "status") {
152 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
154 sprint(self, "^1No vote called.\n");
156 } else if(argv(1) == "call") {
157 if(cvar("sv_vote_call")) {
159 sprint(self, "^1There is already a vote called.\n");
164 sprint(self, "^1Your vote is empty. See help for more info.\n");
165 } else if(time < self.vote_next) {
166 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
167 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
168 if(!ValidateMap(vote))
171 votecalledmaster = FALSE;
172 // remap chmap to gomap (forces intermission)
173 if(strlen(vote) >= 6)
174 if(substring(vote, 0, 6) == "chmap ")
175 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
176 votecalledvote = strzone(vote);
177 votecaller = self; // remember who called the vote
178 votefinished = time + cvar("sv_vote_timeout");
179 votecaller.vote_vote = 1; // of course you vote yes
180 votecaller.vote_next = time + cvar("sv_vote_wait");
181 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
182 VoteCount(); // needed if you are the only one
184 sprint(self, "^1This vote is not ok. See help for more info.\n");
188 sprint(self, "^1Vote calling is NOT allowed.\n");
190 } else if(argv(1) == "stop") {
192 sprint(self, "^1No vote called.\n");
193 } else if(self == votecaller
194 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
197 sprint(self, "^1You are not allowed to stop that Vote.\n");
199 } else if(argv(1) == "master") {
200 if(cvar("sv_vote_master")) {
202 sprint(self, "^1There is already a vote called.\n");
205 votecalledmaster = TRUE;
206 votecalledvote = strzone("^3master");
207 votecaller = self; // remember who called the vote
208 votefinished = time + cvar("sv_vote_timeout");
209 votecaller.vote_vote = 1; // of course you vote yes
210 votecaller.vote_next = time + cvar("sv_vote_wait");
211 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
212 VoteCount(); // needed if you are the only one
215 sprint(self, "^1Vote to become master is NOT allowed.\n");
217 } else if(argv(1) == "do") {
218 if(self.vote_master) {
220 dovote = VoteParse();
222 sprint(self, "^1Your command was empty. See help for more info.\n");
223 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
224 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
225 localcmd(strcat(dovote, "\n"));
227 sprint(self, "^1This command is not ok. See help for more info.\n");
230 sprint(self, "^1You are NOT a master.\n");
232 } else if(argv(1) == "yes") {
234 sprint(self, "^1No vote called.\n");
235 } else if(self.vote_vote == 0
236 || cvar("sv_vote_change")) {
237 sprint(self, "^1You accepted the vote.\n");
239 if(!cvar("sv_vote_singlecount")) {
243 sprint(self, "^1You have already voted.\n");
245 } else if(argv(1) == "no") {
247 sprint(self, "^1No vote called.\n");
248 } else if(self.vote_vote == 0
249 || cvar("sv_vote_change")) {
250 sprint(self, "^1You rejected the vote.\n");
252 if(!cvar("sv_vote_singlecount")) {
256 sprint(self, "^1You have already voted.\n");
260 sprint(self, "^1Unknown vote command.\n");
262 } else if(argv(0) == "autoswitch") {
263 // be backwards compatible with older clients (enabled)
264 self.autoswitch = ("0" != argv(1));
265 local string autoswitchmsg;
266 if (self.autoswitch) {
267 autoswitchmsg = "on";
269 autoswitchmsg = "off";
271 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
272 } else if(argv(0) == "clientversion") {
273 if (argv(1) == "$gameversion") {
274 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
275 // either that or someone wants to be funny
278 self.version = stof(argv(1));
280 if(self.version != cvar("gameversion"))
282 self.classname = "observer";
285 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
286 //JoinBestTeam(self, 0);
287 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
288 self.classname = "observer";
289 stuffcmd(self,"menu_showteamselect\n");
291 } else if(argv(0) == "reportcvar") {
293 } else if(argv(0) == "spectate") {
294 if(cvar("g_lms") || cvar("g_arena"))
295 return; // don't allow spectating in lms, unless player runs out of lives
296 if(self.classname == "player" && cvar("sv_spectate") == 1) {
298 DropFlag(self.flagcarried);
299 DistributeFragsAmongTeam(self, self.team, 1.0);
300 self.classname = "observer";
303 } else if(argv(0) == "join") {
305 if (self.classname != "player")
307 self.classname = "player";
309 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
312 } else if( argv(0) == "selectteam" ) {
313 if( !cvar("teamplay") ) {
314 sprint( self, "selecteam can only be used in teamgames\n");
315 } else if(cvar("g_campaign")) {
316 //JoinBestTeam(self, 0);
317 } else if( argv(1) == "none" ) {
319 } else if( argv(1) == "red" ) {
320 SV_ChangeTeam( COLOR_TEAM1 - 1 );
321 } else if( argv(1) == "blue" ) {
322 SV_ChangeTeam( COLOR_TEAM2 - 1 );
323 } else if( argv(1) == "pink" ) {
324 SV_ChangeTeam( COLOR_TEAM3 - 1 );
325 } else if( argv(1) == "yellow" ) {
326 SV_ChangeTeam( COLOR_TEAM4 - 1 );
327 } else if( argv(1) == "auto" ) {
329 JoinBestTeam( self, 0 );
331 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
333 } else if(argv(0) == "ready") {
334 if(cvar("sv_ready_restart"))
337 bprint(self.netname, "^2 is ready\n");
340 } else if(argv(0) == "say") {
341 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
342 //clientcommand(self, formatmessage(s));
343 } else if(argv(0) == "say_team") {
344 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
345 //clientcommand(self, formatmessage(s));
347 clientcommand(self,s);
351 float ValidateMap(string vote)
356 if(argv(0) == "map" || argv(0) == "changelevel")
358 else if(argv(0) == "chmap")
360 else if(argv(0) == "gotomap")
365 if(!TryFile(strcat("maps/", argv(1), ext)))
367 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
375 if(votefinished > 0 // a vote was called
376 && time > votefinished) // time is up
387 while(argv(index) != "") {
388 vote = strcat(vote, " ", argv(index));
392 // necessary for some of the string operations
393 vote = strzone(vote);
395 // now we remove some things that could be misused
399 local float votelength;
400 votelength = strlen(vote);
401 while(!found && index < votelength)
403 local string badchar;
404 badchar = substring(vote, index, 1);
414 return substring(vote, 0, index);
417 float VoteAllowed(string votecommand) {
418 tokenize(cvar_string("sv_vote_commands"));
421 while(argv(index) != "") {
422 local string allowed;
423 allowed = argv(index);
424 if(votecommand == allowed) {
433 local string searchclass;
434 searchclass = "player";
439 player = find(player, classname, searchclass);
442 player.vote_vote = 0;
443 player = find(player, classname, searchclass);
446 if("player" == searchclass) {
447 searchclass = "observer";
448 } else if("observer" == searchclass) {
449 searchclass = "spectator";
456 votecalledmaster = FALSE;
461 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
464 votecaller.vote_master = 1;
466 localcmd(strcat(votecalledvote, "\n"));
468 votecaller.vote_next = 0; // people like your votes, no wait for next vote
473 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
478 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
482 void VoteStop(entity stopper) {
483 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
484 if(stopper == votecaller) {
485 // no wait for next vote so you can correct your vote
486 votecaller.vote_next = 0;
492 local float playercount;
494 local float yescount;
498 local string searchclass;
499 searchclass = "player";
504 player = find(player, classname, searchclass);
508 if(clienttype(player) != CLIENTTYPE_BOT) {
509 if(player.vote_vote < 0) {
511 } else if(player.vote_vote > 0) {
516 player = find(player, classname, searchclass);
519 if("player" == searchclass) {
520 searchclass = "observer";
521 } else if("observer" == searchclass) {
522 searchclass = "specator";
528 if((playercount == 1) && votecalledmaster) {
529 // if only one player is on the server becoming vote
530 // master is not allowed. This could be used for
531 // trolling or worse. 'self' is the user who has
532 // called the vote because this function is called
533 // by SV_ParseClientCommand. Maybe all voting should
534 // be disabled for a single player?
535 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
536 votecaller.vote_next = 0;
538 } else if((playercount / 2) < yescount) { // vote accepted
540 } else if((playercount / 2) < nocount) { // vote rejected
542 } else if(time > votefinished) { // vote timedout
544 } // else still running
553 e = find(world, classname, "player");
557 if(clienttype(e) == CLIENTTYPE_REAL)
562 e = find(e, classname, "player");
567 bprint("^1Server is restarting...\n");
568 localcmd("restart\n");