2 float ValidateMap(string vote);
4 void Say(entity source, float teamsay, string msgin)
6 string msgstr, colorstr, cmsgstr;
9 msgin = formatmessage(msgin);
14 if(source.team == COLOR_TEAM1)
16 else if(source.team == COLOR_TEAM2)
18 else if(source.team == COLOR_TEAM3)
20 else if(source.team == COLOR_TEAM4)
28 if(source.classname != "player") // observers can't
31 // how can we prevent the message from appearing in a listen server?
32 // for now, just give "say" back and only handle say_team
35 clientcommand(self, strcat("say ", msgin));
41 msgstr = strzone(strcat(colorstr, "(^3", source.netname, colorstr, ") ^7", msgin, "\n"));
42 cmsgstr = strcat(colorstr, "(^3", source.netname, colorstr, ")\n^7", wordwrap(msgin, 50));
45 msgstr = strzone(strcat("^3", source.netname, "^7: ", msgin, "\n"));
47 head = find(world, classname, "player");
50 if(clienttype(head) == CLIENTTYPE_REAL)
51 if(!teamsay || (head.team == source.team))
55 centermsg_setfor(head, CENTERMSG_TEAMSAY, cmsgstr);
56 stuffcmd(head, "play2 misc/talk.wav\n");
58 head = find(head, classname, "player");
63 head = find(world, classname, "observer");
66 if(clienttype(head) == CLIENTTYPE_REAL)
69 stuffcmd(head, "play2 misc/talk.wav\n");
71 head = find(head, classname, "observer");
73 head = find(world, classname, "spectator");
76 if(clienttype(head) == CLIENTTYPE_REAL)
79 stuffcmd(head, "play2 misc/talk.wav\n");
81 head = find(head, classname, "spectator");
83 ServerConsoleEcho(substring(msgstr, 0, strlen(msgstr) - 1), TRUE);
89 void SV_ParseClientCommand(string s) {
94 if(argv(0) == "clogin") {
95 if(cvar("sv_clientcommands")) {
96 if(self.adminstatus < -5) {
97 sprint(self, "Too many unsuccessful tries.\n");
98 } else if(argv(1) == cvar_string("sv_clientcommands_password")) {
100 sprint(self, "You now have remote admin status.\n");
101 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " received admin status"), TRUE);
103 sprint(self, "Wrong password.\n");
104 // use of -- produces compiler warning in the if() line???
105 self.adminstatus = self.adminstatus - 1;
106 if(self.adminstatus == 0)
108 sprint(self, "You lost remote admin status.\n");
109 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " lost admin status"), TRUE);
113 sprint(self, "Clientside commands NOT allowed.\n");
115 } else if(argv(0) == "ccmd") {
116 if(cvar("sv_clientcommands")) {
117 if(self.adminstatus > 0) {
118 local string command;
121 while(argv(index) != "") {
122 command = strcat(command, " ", argv(index));
125 command = strzone(command);
126 ServerConsoleEcho(strcat("ClientCommands: ", self.netname, " issued command '", command, "'"), TRUE);
127 localcmd(strcat(command, "\n"));
130 sprint(self, "You don't have remote admin status.\n");
132 sprint(self, "Clientside commands NOT allowed.\n");
134 } else if(argv(0) == "vote") {
135 if(argv(1) == "help") {
136 local string vmasterdis;
137 if(!cvar("sv_vote_master")) {
138 vmasterdis = " ^1(disabled)";
140 local string vcalldis;
141 if(!cvar("sv_vote_call")) {
142 vcalldis = " ^1(disabled)";
144 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");
145 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");
146 sprint(self, "^7\"^2help^7\" shows this info.\n");
147 sprint(self, "^7\"^2status^7\" shows if there is a vote called and who called it.\n");
148 sprint(self, strcat("^7\"^2call^7\" is used to call a vote. See the list of allowed commands.", vcalldis, "^7\n"));
149 sprint(self, "^7\"^2stop^7\" can be used by the vote caller or an admin to stop a vote and maybe correct it.\n");
150 sprint(self, strcat("^7\"^2master^7\" is used to call a vote to become a master.", vmasterdis, "^7\n"));
151 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");
152 sprint(self, "^7\"^2yes^7\" and \"^2no^7\" to make your vote.\n");
153 sprint(self, "^7If more then 50% of the players vote yes the vote is accepted.\n");
154 sprint(self, "^7If more then 50% of the players vote no the vote is rejected.\n");
155 sprint(self, strcat("^7The vote will end after ", cvar_string("sv_vote_timeout"), "^7 seconds.\n"));
156 sprint(self, "^7You can call a vote for or execute these commands:\n");
157 sprint(self, strcat("^3", cvar_string("sv_vote_commands"), "^7 and maybe further ^3arguments^7\n"));
158 } else if(argv(1) == "status") {
160 sprint(self, strcat("^7Vote for \"^1", votecalledvote, "^7\" called by \"^7", votecaller.netname, "^7\".\n"));
162 sprint(self, "^1No vote called.\n");
164 } else if(argv(1) == "call") {
165 if(cvar("sv_vote_call")) {
167 sprint(self, "^1There is already a vote called.\n");
172 sprint(self, "^1Your vote is empty. See help for more info.\n");
173 } else if(time < self.vote_next) {
174 sprint(self, strcat("^1You have to wait ^2", ftos(self.vote_next - time), "^1 seconds before you can again call a vote.\n"));
175 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
176 if(!ValidateMap(vote))
179 votecalledmaster = FALSE;
180 // remap chmap to gomap (forces intermission)
181 if(strlen(vote) >= 6)
182 if(substring(vote, 0, 6) == "chmap ")
183 vote = strcat("gotomap ", substring(vote, 6, strlen(vote) - 6));
184 votecalledvote = strzone(vote);
185 votecaller = self; // remember who called the vote
186 votefinished = time + cvar("sv_vote_timeout");
187 votecaller.vote_vote = 1; // of course you vote yes
188 votecaller.vote_next = time + cvar("sv_vote_wait");
189 bprint(strcat("^3Vote for \"^1", votecalledvote, "^3\" called by \"^7", votecaller.netname, "^3\".\n"));
190 VoteCount(); // needed if you are the only one
192 sprint(self, "^1This vote is not ok. See help for more info.\n");
196 sprint(self, "^1Vote calling is NOT allowed.\n");
198 } else if(argv(1) == "stop") {
200 sprint(self, "^1No vote called.\n");
201 } else if(self == votecaller
202 || self.adminstatus > 0) { // the votecaller and admins can stop a vote
205 sprint(self, "^1You are not allowed to stop that Vote.\n");
207 } else if(argv(1) == "master") {
208 if(cvar("sv_vote_master")) {
210 sprint(self, "^1There is already a vote called.\n");
213 votecalledmaster = TRUE;
214 votecalledvote = strzone("^3master");
215 votecaller = self; // remember who called the vote
216 votefinished = time + cvar("sv_vote_timeout");
217 votecaller.vote_vote = 1; // of course you vote yes
218 votecaller.vote_next = time + cvar("sv_vote_wait");
219 bprint(strcat("\"^3", votecaller.netname, "^3\" called a vote to become ^3master^3.\n"));
220 VoteCount(); // needed if you are the only one
223 sprint(self, "^1Vote to become master is NOT allowed.\n");
225 } else if(argv(1) == "do") {
226 if(self.vote_master) {
228 dovote = VoteParse();
230 sprint(self, "^1Your command was empty. See help for more info.\n");
231 } else if(VoteAllowed(strcat(argv(2)))) { // strcat seems to be necessary
232 bprint("\"^7", strcat(self.netname, "^2 used his ^3master^2 status to do \"^2", dovote, "^2\".\n"));
233 localcmd(strcat(dovote, "\n"));
235 sprint(self, "^1This command is not ok. See help for more info.\n");
238 sprint(self, "^1You are NOT a master.\n");
240 } else if(argv(1) == "yes") {
242 sprint(self, "^1No vote called.\n");
243 } else if(self.vote_vote == 0
244 || cvar("sv_vote_change")) {
245 sprint(self, "^1You accepted the vote.\n");
247 if(!cvar("sv_vote_singlecount")) {
251 sprint(self, "^1You have already voted.\n");
253 } else if(argv(1) == "no") {
255 sprint(self, "^1No vote called.\n");
256 } else if(self.vote_vote == 0
257 || cvar("sv_vote_change")) {
258 sprint(self, "^1You rejected the vote.\n");
260 if(!cvar("sv_vote_singlecount")) {
264 sprint(self, "^1You have already voted.\n");
268 sprint(self, "^1Unknown vote command.\n");
270 } else if(argv(0) == "autoswitch") {
271 // be backwards compatible with older clients (enabled)
272 self.autoswitch = ("0" != argv(1));
273 local string autoswitchmsg;
274 if (self.autoswitch) {
275 autoswitchmsg = "on";
277 autoswitchmsg = "off";
279 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
280 } else if(argv(0) == "clientversion") {
281 if (argv(1) == "$gameversion") {
282 //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
283 // either that or someone wants to be funny
286 self.version = stof(argv(1));
288 if(self.version != cvar("gameversion"))
290 self.classname = "observer";
293 } else if(cvar("g_campaign") || cvar("g_balance_teams")) {
294 //JoinBestTeam(self, 0);
295 } else if(cvar("teamplay") && !cvar("sv_spectate")) {
296 self.classname = "observer";
297 stuffcmd(self,"menu_showteamselect\n");
299 } else if(argv(0) == "reportcvar") {
301 } else if(argv(0) == "spectate") {
302 if(cvar("g_lms") || cvar("g_arena"))
303 return; // don't allow spectating in lms, unless player runs out of lives
304 if(self.classname == "player" && cvar("sv_spectate") == 1) {
305 DistributeFragsAmongTeam(self, self.team, 1.0);
306 self.classname = "observer";
309 } else if(argv(0) == "join") {
311 if (self.classname != "player")
313 self.classname = "player";
315 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
318 } else if( argv(0) == "selectteam" ) {
319 if( !cvar("teamplay") ) {
320 sprint( self, "selecteam can only be used in teamgames\n");
321 } else if(cvar("g_campaign")) {
322 //JoinBestTeam(self, 0);
323 } else if( argv(1) == "none" ) {
325 } else if( argv(1) == "red" ) {
326 SV_ChangeTeam( COLOR_TEAM1 - 1 );
327 } else if( argv(1) == "blue" ) {
328 SV_ChangeTeam( COLOR_TEAM2 - 1 );
329 } else if( argv(1) == "pink" ) {
330 SV_ChangeTeam( COLOR_TEAM3 - 1 );
331 } else if( argv(1) == "yellow" ) {
332 SV_ChangeTeam( COLOR_TEAM4 - 1 );
333 } else if( argv(1) == "auto" ) {
335 JoinBestTeam( self, 0 );
337 sprint( self, strcat( "selectteam none/red/blue/pink/yellow/auto - \"", argv(1), "\" not recognised\n" ) );
339 } else if(argv(0) == "ready") {
340 if(cvar("sv_ready_restart"))
343 bprint(self.netname, "^2 is ready\n");
346 } else if(argv(0) == "say") {
347 Say(self, FALSE, substring(s, 4, strlen(s) - 4));
348 //clientcommand(self, formatmessage(s));
349 } else if(argv(0) == "say_team") {
350 Say(self, TRUE, substring(s, 9, strlen(s) - 9));
351 //clientcommand(self, formatmessage(s));
353 clientcommand(self,s);
357 float ValidateMap(string vote)
362 if(argv(0) == "map" || argv(0) == "changelevel")
364 else if(argv(0) == "chmap")
366 else if(argv(0) == "gotomap")
371 if(!TryFile(strcat("maps/", argv(1), ext)))
373 sprint(self, strcat("^1Invalid mapname, \"^3", argv(1), "^1\" does not exist on this server.\n"));
381 if(votefinished > 0 // a vote was called
382 && time > votefinished) // time is up
393 while(argv(index) != "") {
394 vote = strcat(vote, " ", argv(index));
398 // necessary for some of the string operations
399 vote = strzone(vote);
401 // now we remove some things that could be misused
405 local float votelength;
406 votelength = strlen(vote);
407 while(!found && index < votelength)
409 local string badchar;
410 badchar = substring(vote, index, 1);
420 return substring(vote, 0, index);
423 float VoteAllowed(string votecommand) {
424 tokenize(cvar_string("sv_vote_commands"));
427 while(argv(index) != "") {
428 local string allowed;
429 allowed = argv(index);
430 if(votecommand == allowed) {
439 local string searchclass;
440 searchclass = "player";
445 player = find(player, classname, searchclass);
448 player.vote_vote = 0;
449 player = find(player, classname, searchclass);
452 if("player" == searchclass) {
453 searchclass = "observer";
454 } else if("observer" == searchclass) {
455 searchclass = "spectator";
462 votecalledmaster = FALSE;
467 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was accepted.\n"));
470 votecaller.vote_master = 1;
472 localcmd(strcat(votecalledvote, "\n"));
474 votecaller.vote_next = 0; // people like your votes, no wait for next vote
479 bprint(strcat("^2The vote for \"^1", votecalledvote, "^2\" from \"^7", votecaller.netname, "^2\" was rejected.\n"));
484 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" did timeout.\n"));
488 void VoteStop(entity stopper) {
489 bprint(strcat("^5The vote for \"^1", votecalledvote, "^5\" from \"^7", votecaller.netname, "^5\" was stopped by \"^5", stopper.netname, "^5\".\n"));
490 if(stopper == votecaller) {
491 // no wait for next vote so you can correct your vote
492 votecaller.vote_next = 0;
498 local float playercount;
500 local float yescount;
504 local string searchclass;
505 searchclass = "player";
510 player = find(player, classname, searchclass);
514 if(clienttype(player) != CLIENTTYPE_BOT) {
515 if(player.vote_vote < 0) {
517 } else if(player.vote_vote > 0) {
522 player = find(player, classname, searchclass);
525 if("player" == searchclass) {
526 searchclass = "observer";
527 } else if("observer" == searchclass) {
528 searchclass = "specator";
534 if((playercount == 1) && votecalledmaster) {
535 // if only one player is on the server becoming vote
536 // master is not allowed. This could be used for
537 // trolling or worse. 'self' is the user who has
538 // called the vote because this function is called
539 // by SV_ParseClientCommand. Maybe all voting should
540 // be disabled for a single player?
541 sprint(self, "^1You are the only player on this server so you can not become vote master.\n");
542 votecaller.vote_next = 0;
544 } else if((playercount / 2) < yescount) { // vote accepted
546 } else if((playercount / 2) < nocount) { // vote rejected
548 } else if(time > votefinished) { // vote timedout
550 } // else still running
559 e = find(world, classname, "player");
563 if(clienttype(e) == CLIENTTYPE_REAL)
568 e = find(e, classname, "player");
573 bprint("^1Server is restarting...\n");
574 localcmd("restart\n");