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("\{1}", 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("\{1}^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 centerprint(head, 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, 1, strlen(msgstr) - 2), TRUE);
81 void SV_ParseClientCommand(string s) {
86 if(argv(0) == "vote") {
87 if(argv(1) == "help") {
88 local string vmasterdis;
89 if(!cvar("sv_vote_master")) {
90 vmasterdis = " ^1(disabled)";
92 local string vcalldis;
93 if(!cvar("sv_vote_call")) {
94 vcalldis = " ^1(disabled)";
96 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");
97 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");
98 sprint(self, "^7\"^2help^7\" shows this info.\n");
99 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
100 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
101 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
102 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
103 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");
104 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
105 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
106 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
107 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
108 sprint(self, "^7You can call a vote for or execute these commands:\n");
109 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
110 } else if(argv(1) == "status") {
112 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
114 sprint(self, "^1No vote called.\n");
116 } else if(argv(1) == "call") {
117 if(cvar("sv_vote_call")) {
119 sprint(self, "^1There is already a vote called.\n");
124 sprint(self, "^1Your vote is empty. See help for more info.\n");
125 } else if(time < self.vote_next) {
126 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
127 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
128 if(!ValidateMap(vote))
131 votecalledmaster = FALSE;
132 // remap chmap to gotomap (forces intermission)
133 if(strlen(vote) >= 6)
134 if(substring(vote, 0, 6) == "chmap ")
135 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
136 votecalledvote = strzone(vote);
137 votecaller = self; // remember who called the vote
138 votefinished = time + cvar("sv_vote_timeout");
139 votecaller.vote_vote = 1; // of course you vote yes
140 votecaller.vote_next = time + cvar("sv_vote_wait");
141 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ^1", votecalledvote, "\n"));
142 VoteCount(); // needed if you are the only one
144 sprint(self, "^1This vote is not ok. See help for more info.\n");
148 sprint(self, "^1Vote calling is NOT allowed.\n");
150 } else if(argv(1) == "stop") {
152 sprint(self, "^1No vote called.\n");
153 } else if(self == votecaller) { // the votecaller can stop a vote
156 sprint(self, "^1You are not allowed to stop that Vote.\n");
158 } else if(argv(1) == "master") {
159 if(cvar("sv_vote_master")) {
161 sprint(self, "^1There is already a vote called.\n");
164 votecalledmaster = TRUE;
165 votecalledvote = strzone("^3master");
166 votecaller = self; // remember who called the vote
167 votefinished = time + cvar("sv_vote_timeout");
168 votecaller.vote_vote = 1; // of course you vote yes
169 votecaller.vote_next = time + cvar("sv_vote_wait");
170 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2 calls a vote to become ^3master^2.\n"));
171 VoteCount(); // needed if you are the only one
174 sprint(self, "^1Vote to become master is NOT allowed.\n");
176 } else if(argv(1) == "do") {
177 if(argv(2) == "login") {
178 local string masterpwd;
179 masterpwd = cvar_string("sv_vote_master_password");
180 if(masterpwd != "") {
181 self.vote_master = (masterpwd == argv(3));
182 if(self.vote_master) {
183 ServerConsoleEcho(strcat("Accepted master login from ", self.netname), TRUE);
184 bprint(strcat("\{1}^2* ^3", self.netname, "^2 logged in as ^3master^2\n"));
187 ServerConsoleEcho(strcat("REJECTED master login from ", self.netname), TRUE);
190 sprint(self, "^1You are NOT a master.\n");
191 } else if(self.vote_master) {
193 dovote = VoteParse();
195 sprint(self, "^1Your command was empty. See help for more info.\n");
196 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
197 if(!ValidateMap(dovote))
199 // remap chmap to gotomap (forces intermission)
200 if(strlen(dovote) >= 6)
201 if(substring(dovote, 0, 6) == "chmap ")
202 vote = strcat("gotomap ", substring(dovote, 6, strlen(dovote) - 6));
203 bprint("\{1}^2* ^3", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
204 localcmd(strcat(dovote, "\n"));
206 sprint(self, "^1This command is not ok. See help for more info.\n");
209 sprint(self, "^1You are NOT a master.\n");
211 } else if(argv(1) == "yes") {
213 sprint(self, "^1No vote called.\n");
214 } else if(self.vote_vote == 0
215 || cvar("sv_vote_change")) {
216 sprint(self, "^1You accepted the vote.\n");
218 if(!cvar("sv_vote_singlecount")) {
222 sprint(self, "^1You have already voted.\n");
224 } else if(argv(1) == "no") {
226 sprint(self, "^1No vote called.\n");
227 } else if(self.vote_vote == 0
228 || cvar("sv_vote_change")) {
229 sprint(self, "^1You rejected the vote.\n");
231 if(!cvar("sv_vote_singlecount")) {
235 sprint(self, "^1You have already voted.\n");
239 sprint(self, "^1Unknown vote command.\n");
241 } else if(argv(0) == "autoswitch") {
242 // be backwards compatible with older clients (enabled)
243 self.autoswitch = ("0" != argv(1));
244 local string autoswitchmsg;
245 if (self.autoswitch) {
246 autoswitchmsg = "on";
248 autoswitchmsg = "off";
250 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
251 } else if(argv(0) == "clientversion") {
252 if (argv(1) == "$gameversion") {
253 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
254 // either that or someone wants to be funny
257 self.version = stof(argv(1));
259 if(self.version != cvar("gameversion"))
261 self.classname = "observer";
264 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
265 //JoinBestTeam(self, 0);
266 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
267 self.classname = "observer";
268 stuffcmd(self,"menu_showteamselect\n");
270 } else if(argv(0) == "reportcvar") {
272 } else if(argv(0) == "spectate") {
273 if(cvar("g_lms") || cvar("g_arena"))
274 return; // don't allow spectating in lms, unless player runs out of lives
275 if(self.classname == "player" && cvar("sv_spectate") == 1) {
277 DropFlag(self.flagcarried);
278 DistributeFragsAmongTeam(self, self.team, 1.0);
279 self.classname = "observer";
282 } else if(argv(0) == "join") {
284 if (self.classname != "player")
286 self.classname = "player";
288 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
291 } else if( argv(0) == "selectteam" ) {
292 if( !cvar("teamplay") ) {
293 sprint( self, "selecteam can only be used in teamgames\n");
294 } else if(cvar("g_campaign")) {
295 //JoinBestTeam(self, 0);
296 } else if( argv(1) == "none" ) {
298 } else if( argv(1) == "red" ) {
299 SV_ChangeTeam( COLOR_TEAM1 - 1 );
300 } else if( argv(1) == "blue" ) {
301 SV_ChangeTeam( COLOR_TEAM2 - 1 );
302 } else if( argv(1) == "pink" ) {
303 SV_ChangeTeam( COLOR_TEAM3 - 1 );
304 } else if( argv(1) == "yellow" ) {
305 SV_ChangeTeam( COLOR_TEAM4 - 1 );
306 } else if( argv(1) == "auto" ) {
308 JoinBestTeam( self, 0 );
310 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
312 } else if(argv(0) == "ready") {
313 if(cvar("sv_ready_restart"))
316 bprint(self.netname, "^2 is ready\n");
319 } else if(argv(0) == "maplist") {
322 n = tokenize(cvar_string("g_maplist"));
323 sprint(self, "^7Maps in list: ");
324 for(i = 0; i < n; ++i)
330 sprint(self, strcat(col, argv(i), " "));
333 } else if(argv(0) == "say") {
334 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
335 //clientcommand(self, formatmessage(s));
336 } else if(argv(0) == "say_team") {
337 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
338 //clientcommand(self, formatmessage(s));
339 } else if(argv(0) == "info") {
340 cmd = cvar_string(strcat("sv_info_", argv(1)));
342 sprint(self, "ERROR: unsupported info command\n");
344 wordwrap_sprint(cmd, 1111);
347 /* checks not needed any more since DP has separated clientcommands and regular commands
350 //if(cmd != "say") // handled above
351 //if(cmd != "say_team") // handled above
362 if(cmd != "playermodel")
363 if(cmd != "playerskin")
364 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
366 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
370 clientcommand(self,s);
374 float ValidateMap(string vote)
379 if(argv(0) == "map" || argv(0) == "changelevel")
381 else if(argv(0) == "chmap")
383 else if(argv(0) == "gotomap")
388 if(!TryFile(strcat("maps/", argv(1), ext)))
390 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
398 if(votefinished > 0 // a vote was called
399 && time > votefinished) // time is up
410 while(argv(index) != "") {
411 vote = strcat(vote, " ", argv(index));
415 // necessary for some of the string operations
416 vote = strzone(vote);
418 // now we remove some things that could be misused
422 local float votelength;
423 votelength = strlen(vote);
424 while(!found && index < votelength)
426 local string badchar;
427 badchar = substring(vote, index, 1);
437 return substring(vote, 0, index);
440 float VoteAllowed(string votecommand) {
441 tokenize(cvar_string("sv_vote_commands"));
444 while(argv(index) != "") {
445 local string allowed;
446 allowed = argv(index);
447 if(votecommand == allowed) {
456 local string searchclass;
457 searchclass = "player";
462 player = find(player, classname, searchclass);
465 player.vote_vote = 0;
466 player = find(player, classname, searchclass);
469 if("player" == searchclass) {
470 searchclass = "observer";
471 } else if("observer" == searchclass) {
472 searchclass = "spectator";
479 votecalledmaster = FALSE;
484 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was accepted\n"));
487 votecaller.vote_master = 1;
489 localcmd(strcat(votecalledvote, "\n"));
491 votecaller.vote_next = 0; // people like your votes, no wait for next vote
496 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was rejected\n"));
501 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 timed out\n"));
505 void VoteStop(entity stopper) {
506 bprint(strcat("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n"));
507 if(stopper == votecaller) {
508 // no wait for next vote so you can correct your vote
509 votecaller.vote_next = 0;
515 local float playercount;
517 local float yescount;
521 local string searchclass;
522 searchclass = "player";
527 player = find(player, classname, searchclass);
531 if(clienttype(player) != CLIENTTYPE_BOT) {
532 if(player.vote_vote < 0) {
534 } else if(player.vote_vote > 0) {
539 player = find(player, classname, searchclass);
542 if("player" == searchclass) {
543 searchclass = "observer";
544 } else if("observer" == searchclass) {
545 searchclass = "specator";
551 if((playercount == 1) && votecalledmaster) {
552 // if only one player is on the server becoming vote
553 // master is not allowed. This could be used for
554 // trolling or worse. 'self' is the user who has
555 // called the vote because this function is called
556 // by SV_ParseClientCommand. Maybe all voting should
557 // be disabled for a single player?
558 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
559 votecaller.vote_next = 0;
561 } else if((playercount / 2) < yescount) { // vote accepted
563 } else if((playercount / 2) < nocount) { // vote rejected
565 } else if(time > votefinished) { // vote timedout
567 } // else still running
576 e = find(world, classname, "player");
580 if(clienttype(e) == CLIENTTYPE_REAL)
585 e = find(e, classname, "player");
590 bprint("^1Server is restarting...\n");
591 localcmd("restart\n");