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(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("^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 centermsg_setfor(head, CENTERMSG_TEAMSAY, 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, 0, strlen(msgstr) - 1), 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 VoteCount(); // needed if you are the only one
193 sprint(self, "^1This vote is not ok. See help for more info.\n");
197 sprint(self, "^1Vote calling is NOT allowed.\n");
199 } else if(argv(1) == "stop") {
201 sprint(self, "^1No vote called.\n");
202 } else if(self == votecaller
203 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
206 sprint(self, "^1You are not allowed to stop that Vote.\n");
208 } else if(argv(1) == "master") {
209 if(cvar("sv_vote_master")) {
211 sprint(self, "^1There is already a vote called.\n");
214 votecalledmaster = TRUE;
215 votecalledvote = strzone("^3master");
216 votecaller = self; // remember who called the vote
217 votefinished = time + cvar("sv_vote_timeout");
218 votecaller.vote_vote = 1; // of course you vote yes
219 votecaller.vote_next = time + cvar("sv_vote_wait");
220 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
221 VoteCount(); // needed if you are the only one
224 sprint(self, "^1Vote to become master is NOT allowed.\n");
226 } else if(argv(1) == "do") {
227 if(self.vote_master) {
229 dovote = VoteParse();
231 sprint(self, "^1Your command was empty. See help for more info.\n");
232 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
233 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
234 localcmd(strcat(dovote, "\n"));
236 sprint(self, "^1This command is not ok. See help for more info.\n");
239 sprint(self, "^1You are NOT a master.\n");
241 } else if(argv(1) == "yes") {
243 sprint(self, "^1No vote called.\n");
244 } else if(self.vote_vote == 0
245 || cvar("sv_vote_change")) {
246 sprint(self, "^1You accepted the vote.\n");
248 if(!cvar("sv_vote_singlecount")) {
252 sprint(self, "^1You have already voted.\n");
254 } else if(argv(1) == "no") {
256 sprint(self, "^1No vote called.\n");
257 } else if(self.vote_vote == 0
258 || cvar("sv_vote_change")) {
259 sprint(self, "^1You rejected the vote.\n");
261 if(!cvar("sv_vote_singlecount")) {
265 sprint(self, "^1You have already voted.\n");
269 sprint(self, "^1Unknown vote command.\n");
271 } else if(argv(0) == "autoswitch") {
272 // be backwards compatible with older clients (enabled)
273 self.autoswitch = ("0" != argv(1));
274 local string autoswitchmsg;
275 if (self.autoswitch) {
276 autoswitchmsg = "on";
278 autoswitchmsg = "off";
280 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
281 } else if(argv(0) == "clientversion") {
282 if (argv(1) == "$gameversion") {
283 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
284 // either that or someone wants to be funny
287 self.version = stof(argv(1));
289 if(self.version != cvar("gameversion"))
291 self.classname = "observer";
294 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
295 //JoinBestTeam(self, 0);
296 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
297 self.classname = "observer";
298 stuffcmd(self,"menu_showteamselect\n");
300 } else if(argv(0) == "reportcvar") {
302 } else if(argv(0) == "spectate") {
303 if(cvar("g_lms") || cvar("g_arena"))
304 return; // don't allow spectating in lms, unless player runs out of lives
305 if(self.classname == "player" && cvar("sv_spectate") == 1) {
307 DropFlag(self.flagcarried);
308 DistributeFragsAmongTeam(self, self.team, 1.0);
309 self.classname = "observer";
312 } else if(argv(0) == "join") {
314 if (self.classname != "player")
316 self.classname = "player";
318 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
321 } else if( argv(0) == "selectteam" ) {
322 if( !cvar("teamplay") ) {
323 sprint( self, "selecteam can only be used in teamgames\n");
324 } else if(cvar("g_campaign")) {
325 //JoinBestTeam(self, 0);
326 } else if( argv(1) == "none" ) {
328 } else if( argv(1) == "red" ) {
329 SV_ChangeTeam( COLOR_TEAM1 - 1 );
330 } else if( argv(1) == "blue" ) {
331 SV_ChangeTeam( COLOR_TEAM2 - 1 );
332 } else if( argv(1) == "pink" ) {
333 SV_ChangeTeam( COLOR_TEAM3 - 1 );
334 } else if( argv(1) == "yellow" ) {
335 SV_ChangeTeam( COLOR_TEAM4 - 1 );
336 } else if( argv(1) == "auto" ) {
338 JoinBestTeam( self, 0 );
340 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
342 } else if(argv(0) == "ready") {
343 if(cvar("sv_ready_restart"))
346 bprint(self.netname, "^2 is ready\n");
349 } else if(argv(0) == "say") {
350 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
351 //clientcommand(self, formatmessage(s));
352 } else if(argv(0) == "say_team") {
353 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
354 //clientcommand(self, formatmessage(s));
356 clientcommand(self,s);
360 float ValidateMap(string vote)
365 if(argv(0) == "map" || argv(0) == "changelevel")
367 else if(argv(0) == "chmap")
369 else if(argv(0) == "gotomap")
374 if(!TryFile(strcat("maps/", argv(1), ext)))
376 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
384 if(votefinished > 0 // a vote was called
385 && time > votefinished) // time is up
396 while(argv(index) != "") {
397 vote = strcat(vote, " ", argv(index));
401 // necessary for some of the string operations
402 vote = strzone(vote);
404 // now we remove some things that could be misused
408 local float votelength;
409 votelength = strlen(vote);
410 while(!found && index < votelength)
412 local string badchar;
413 badchar = substring(vote, index, 1);
423 return substring(vote, 0, index);
426 float VoteAllowed(string votecommand) {
427 tokenize(cvar_string("sv_vote_commands"));
430 while(argv(index) != "") {
431 local string allowed;
432 allowed = argv(index);
433 if(votecommand == allowed) {
442 local string searchclass;
443 searchclass = "player";
448 player = find(player, classname, searchclass);
451 player.vote_vote = 0;
452 player = find(player, classname, searchclass);
455 if("player" == searchclass) {
456 searchclass = "observer";
457 } else if("observer" == searchclass) {
458 searchclass = "spectator";
465 votecalledmaster = FALSE;
470 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
473 votecaller.vote_master = 1;
475 localcmd(strcat(votecalledvote, "\n"));
477 votecaller.vote_next = 0; // people like your votes, no wait for next vote
482 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
487 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
491 void VoteStop(entity stopper) {
492 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
493 if(stopper == votecaller) {
494 // no wait for next vote so you can correct your vote
495 votecaller.vote_next = 0;
501 local float playercount;
503 local float yescount;
507 local string searchclass;
508 searchclass = "player";
513 player = find(player, classname, searchclass);
517 if(clienttype(player) != CLIENTTYPE_BOT) {
518 if(player.vote_vote < 0) {
520 } else if(player.vote_vote > 0) {
525 player = find(player, classname, searchclass);
528 if("player" == searchclass) {
529 searchclass = "observer";
530 } else if("observer" == searchclass) {
531 searchclass = "specator";
537 if((playercount == 1) && votecalledmaster) {
538 // if only one player is on the server becoming vote
539 // master is not allowed. This could be used for
540 // trolling or worse. 'self' is the user who has
541 // called the vote because this function is called
542 // by SV_ParseClientCommand. Maybe all voting should
543 // be disabled for a single player?
544 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
545 votecaller.vote_next = 0;
547 } else if((playercount / 2) < yescount) { // vote accepted
549 } else if((playercount / 2) < nocount) { // vote rejected
551 } else if(time > votefinished) { // vote timedout
553 } // else still running
562 e = find(world, classname, "player");
566 if(clienttype(e) == CLIENTTYPE_REAL)
571 e = find(e, classname, "player");
576 bprint("^1Server is restarting...\n");
577 localcmd("restart\n");