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 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, 1, strlen(msgstr) - 2), TRUE);
81 void SV_ParseClientCommand(string s) {
87 if(argv(0) == "clogin") {
88 if(cvar("sv_clientcommands")) {
89 if(self.adminstatus < -5) {
90 sprint(self, "Too many unsuccessful tries.\n");
91 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
93 sprint(self, "You now have remote admin status.\n");
94 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " received admin status"), TRUE);
96 sprint(self, "Wrong password.\n");
97 // use of -- produces compiler warning in the if() line???
98 self.adminstatus = self.adminstatus - 1;
99 if(self.adminstatus == 0)
101 sprint(self, "You lost remote admin status.\n");
102 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " lost admin status"), TRUE);
106 sprint(self, "Clientside commands NOT allowed.\n");
108 } else if(argv(0) == "ccmd") {
109 if(cvar("sv_clientcommands")) {
110 if(self.adminstatus > 0) {
111 local string command;
114 while(argv(index) != "") {
115 command = strcat(command, " ", argv(index));
118 command = strzone(command);
119 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " issued command '", command, "'"), TRUE);
120 localcmd(strcat(command, "\n"));
123 sprint(self, "You don't have remote admin status.\n");
125 sprint(self, "Clientside commands NOT allowed.\n");
127 } else if(argv(0) == "vote") {
128 if(argv(1) == "help") {
129 local string vmasterdis;
130 if(!cvar("sv_vote_master")) {
131 vmasterdis = " ^1(disabled)";
133 local string vcalldis;
134 if(!cvar("sv_vote_call")) {
135 vcalldis = " ^1(disabled)";
137 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");
138 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");
139 sprint(self, "^7\"^2help^7\" shows this info.\n");
140 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
141 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
142 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
143 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
144 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");
145 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
146 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
147 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
148 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
149 sprint(self, "^7You can call a vote for or execute these commands:\n");
150 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
151 } else if(argv(1) == "status") {
153 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
155 sprint(self, "^1No vote called.\n");
157 } else if(argv(1) == "call") {
158 if(cvar("sv_vote_call")) {
160 sprint(self, "^1There is already a vote called.\n");
165 sprint(self, "^1Your vote is empty. See help for more info.\n");
166 } else if(time < self.vote_next) {
167 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
168 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
169 if(!ValidateMap(vote))
172 votecalledmaster = FALSE;
173 // remap chmap to gomap (forces intermission)
174 if(strlen(vote) >= 6)
175 if(substring(vote, 0, 6) == "chmap ")
176 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
177 votecalledvote = strzone(vote);
178 votecaller = self; // remember who called the vote
179 votefinished = time + cvar("sv_vote_timeout");
180 votecaller.vote_vote = 1; // of course you vote yes
181 votecaller.vote_next = time + cvar("sv_vote_wait");
182 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2 calls a vote for ^1", votecalledvote, "\n"));
183 VoteCount(); // needed if you are the only one
185 sprint(self, "^1This vote is not ok. See help for more info.\n");
189 sprint(self, "^1Vote calling is NOT allowed.\n");
191 } else if(argv(1) == "stop") {
193 sprint(self, "^1No vote called.\n");
194 } else if(self == votecaller
195 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
198 sprint(self, "^1You are not allowed to stop that Vote.\n");
200 } else if(argv(1) == "master") {
201 if(cvar("sv_vote_master")) {
203 sprint(self, "^1There is already a vote called.\n");
206 votecalledmaster = TRUE;
207 votecalledvote = strzone("^3master");
208 votecaller = self; // remember who called the vote
209 votefinished = time + cvar("sv_vote_timeout");
210 votecaller.vote_vote = 1; // of course you vote yes
211 votecaller.vote_next = time + cvar("sv_vote_wait");
212 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
213 VoteCount(); // needed if you are the only one
216 sprint(self, "^1Vote to become master is NOT allowed.\n");
218 } else if(argv(1) == "do") {
219 if(self.vote_master) {
221 dovote = VoteParse();
223 sprint(self, "^1Your command was empty. See help for more info.\n");
224 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
225 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
226 localcmd(strcat(dovote, "\n"));
228 sprint(self, "^1This command is not ok. See help for more info.\n");
231 sprint(self, "^1You are NOT a master.\n");
233 } else if(argv(1) == "yes") {
235 sprint(self, "^1No vote called.\n");
236 } else if(self.vote_vote == 0
237 || cvar("sv_vote_change")) {
238 sprint(self, "^1You accepted the vote.\n");
240 if(!cvar("sv_vote_singlecount")) {
244 sprint(self, "^1You have already voted.\n");
246 } else if(argv(1) == "no") {
248 sprint(self, "^1No vote called.\n");
249 } else if(self.vote_vote == 0
250 || cvar("sv_vote_change")) {
251 sprint(self, "^1You rejected the vote.\n");
253 if(!cvar("sv_vote_singlecount")) {
257 sprint(self, "^1You have already voted.\n");
261 sprint(self, "^1Unknown vote command.\n");
263 } else if(argv(0) == "autoswitch") {
264 // be backwards compatible with older clients (enabled)
265 self.autoswitch = ("0" != argv(1));
266 local string autoswitchmsg;
267 if (self.autoswitch) {
268 autoswitchmsg = "on";
270 autoswitchmsg = "off";
272 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
273 } else if(argv(0) == "clientversion") {
274 if (argv(1) == "$gameversion") {
275 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
276 // either that or someone wants to be funny
279 self.version = stof(argv(1));
281 if(self.version != cvar("gameversion"))
283 self.classname = "observer";
286 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
287 //JoinBestTeam(self, 0);
288 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
289 self.classname = "observer";
290 stuffcmd(self,"menu_showteamselect\n");
292 } else if(argv(0) == "reportcvar") {
294 } else if(argv(0) == "spectate") {
295 if(cvar("g_lms") || cvar("g_arena"))
296 return; // don't allow spectating in lms, unless player runs out of lives
297 if(self.classname == "player" && cvar("sv_spectate") == 1) {
299 DropFlag(self.flagcarried);
300 DistributeFragsAmongTeam(self, self.team, 1.0);
301 self.classname = "observer";
304 } else if(argv(0) == "join") {
306 if (self.classname != "player")
308 self.classname = "player";
310 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
313 } else if( argv(0) == "selectteam" ) {
314 if( !cvar("teamplay") ) {
315 sprint( self, "selecteam can only be used in teamgames\n");
316 } else if(cvar("g_campaign")) {
317 //JoinBestTeam(self, 0);
318 } else if( argv(1) == "none" ) {
320 } else if( argv(1) == "red" ) {
321 SV_ChangeTeam( COLOR_TEAM1 - 1 );
322 } else if( argv(1) == "blue" ) {
323 SV_ChangeTeam( COLOR_TEAM2 - 1 );
324 } else if( argv(1) == "pink" ) {
325 SV_ChangeTeam( COLOR_TEAM3 - 1 );
326 } else if( argv(1) == "yellow" ) {
327 SV_ChangeTeam( COLOR_TEAM4 - 1 );
328 } else if( argv(1) == "auto" ) {
330 JoinBestTeam( self, 0 );
332 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
334 } else if(argv(0) == "ready") {
335 if(cvar("sv_ready_restart"))
338 bprint(self.netname, "^2 is ready\n");
341 } else if(argv(0) == "maplist") {
344 n = tokenize(cvar_string("g_maplist"));
345 sprint(self, "^7Maps in list: ");
346 for(i = 0; i < n; ++i)
352 sprint(self, strcat(col, argv(i), " "));
355 } else if(argv(0) == "say") {
356 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
357 //clientcommand(self, formatmessage(s));
358 } else if(argv(0) == "say_team") {
359 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
360 //clientcommand(self, formatmessage(s));
361 } else if(argv(0) == "info") {
362 cmd = cvar_string(strcat("sv_info_", argv(1)));
364 sprint(self, "ERROR: unsupported info command\n");
366 wordwrap_sprint(cmd, 1111);
371 //if(cmd != "say") // handled above
372 //if(cmd != "say_team") // handled above
383 if(cmd != "playermodel")
384 if(cmd != "playerskin")
385 if(cmd != "god") if(cmd != "notarget") if(cmd != "fly") if(cmd != "give") if(cmd != "noclip")
387 ServerConsoleEcho(strcat("WARNING: Invalid clientcommand by ", self.netname, ": ", s), TRUE);
390 clientcommand(self,s);
394 float ValidateMap(string vote)
399 if(argv(0) == "map" || argv(0) == "changelevel")
401 else if(argv(0) == "chmap")
403 else if(argv(0) == "gotomap")
408 if(!TryFile(strcat("maps/", argv(1), ext)))
410 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
418 if(votefinished > 0 // a vote was called
419 && time > votefinished) // time is up
430 while(argv(index) != "") {
431 vote = strcat(vote, " ", argv(index));
435 // necessary for some of the string operations
436 vote = strzone(vote);
438 // now we remove some things that could be misused
442 local float votelength;
443 votelength = strlen(vote);
444 while(!found && index < votelength)
446 local string badchar;
447 badchar = substring(vote, index, 1);
457 return substring(vote, 0, index);
460 float VoteAllowed(string votecommand) {
461 tokenize(cvar_string("sv_vote_commands"));
464 while(argv(index) != "") {
465 local string allowed;
466 allowed = argv(index);
467 if(votecommand == allowed) {
476 local string searchclass;
477 searchclass = "player";
482 player = find(player, classname, searchclass);
485 player.vote_vote = 0;
486 player = find(player, classname, searchclass);
489 if("player" == searchclass) {
490 searchclass = "observer";
491 } else if("observer" == searchclass) {
492 searchclass = "spectator";
499 votecalledmaster = FALSE;
504 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was accepted\n"));
507 votecaller.vote_master = 1;
509 localcmd(strcat(votecalledvote, "\n"));
511 votecaller.vote_next = 0; // people like your votes, no wait for next vote
516 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 was rejected\n"));
521 bprint(strcat("\{1}^2* ^3", votecaller.netname, "^2's vote for ^1", votecalledvote, "^2 timed out\n"));
525 void VoteStop(entity stopper) {
526 bprint(strcat("\{1}^2* ^3", stopper.netname, "^2 stopped ^3", votecaller.netname, "^2's vote\n"));
527 if(stopper == votecaller) {
528 // no wait for next vote so you can correct your vote
529 votecaller.vote_next = 0;
535 local float playercount;
537 local float yescount;
541 local string searchclass;
542 searchclass = "player";
547 player = find(player, classname, searchclass);
551 if(clienttype(player) != CLIENTTYPE_BOT) {
552 if(player.vote_vote < 0) {
554 } else if(player.vote_vote > 0) {
559 player = find(player, classname, searchclass);
562 if("player" == searchclass) {
563 searchclass = "observer";
564 } else if("observer" == searchclass) {
565 searchclass = "specator";
571 if((playercount == 1) && votecalledmaster) {
572 // if only one player is on the server becoming vote
573 // master is not allowed. This could be used for
574 // trolling or worse. 'self' is the user who has
575 // called the vote because this function is called
576 // by SV_ParseClientCommand. Maybe all voting should
577 // be disabled for a single player?
578 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
579 votecaller.vote_next = 0;
581 } else if((playercount / 2) < yescount) { // vote accepted
583 } else if((playercount / 2) < nocount) { // vote rejected
585 } else if(time > votefinished) { // vote timedout
587 } // else still running
596 e = find(world, classname, "player");
600 if(clienttype(e) == CLIENTTYPE_REAL)
605 e = find(e, classname, "player");
610 bprint("^1Server is restarting...\n");
611 localcmd("restart\n");