]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/clientcommands.qc
precache the gauntlet sound
[divverent/nexuiz.git] / data / qcsrc / server / clientcommands.qc
1 entity nagger;
2 float readycount;
3 float Nagger_SendEntity(entity to, float sendflags)
4 {
5         float nags, i, f, b;
6         entity e;
7         WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER);
8
9         nags = 0;
10         if(readycount)
11         {
12                 nags |= 1;
13                 if(to.ready == 0)
14                         nags |= 2;
15         }
16         if(votecalled)
17         {
18                 nags |= 4;
19                 if(to.vote_vote == 0)
20                         nags |= 8;
21         }
22         if(inWarmupStage)
23                 nags |= 16;
24
25         if(sendflags & 128)
26                 nags |= 128;
27
28         WriteByte(MSG_ENTITY, nags);
29
30         if(nags & 128)
31         {
32                 if(votecalled)
33                         WriteString(MSG_ENTITY, votecalledvote_display);
34                 else
35                         WriteString(MSG_ENTITY, "");
36         }
37
38         if(nags & 1)
39         {
40                 for(i = 1; i <= maxclients; i += 8)
41                 {
42                         for(f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e))
43                                 if(clienttype(e) != CLIENTTYPE_REAL || e.ready)
44                                         f |= b;
45                         WriteByte(MSG_ENTITY, f);
46                 }
47         }
48
49         return TRUE;
50 }
51 void Nagger_Init()
52 {
53         Net_LinkEntity(nagger = spawn(), FALSE, 0, Nagger_SendEntity);
54 }
55 void Nagger_VoteChanged()
56 {
57         if(nagger)
58                 nagger.SendFlags |= 128;
59 }
60 void Nagger_VoteCountChanged()
61 {
62         if(nagger)
63                 nagger.SendFlags |= 1;
64 }
65 void Nagger_ReadyCounted()
66 {
67         if(nagger)
68                 nagger.SendFlags |= 1;
69 }
70
71 void ReadyCount();
72 string MapVote_Suggest(string m);
73
74 entity GetPlayer(string name)
75 {
76         float num;
77         entity e;
78         string ns;
79
80         if(substring(name, 0, 1) == "#") {
81                 num = stof(substring(name, 1, 999));
82                 if(num >= 1 && num <= maxclients) {
83                         for((e = world); num > 0; --num, (e = nextent(e)))
84                                 ;
85                         //if(clienttype(e) == CLIENTTYPE_REAL)
86                         if(e.classname == "player")
87                                 return e;
88                 }
89         } else {
90                 ns = strdecolorize(name);
91                 FOR_EACH_REALPLAYER(e) {
92                         if(!strcasecmp(strdecolorize(e.netname), ns)) {
93                                 return e;
94                         }
95                 }
96         }
97         return world;
98 }
99
100 float drag_lastcnt;
101 void DragBox_Think()
102 {
103         if(self.aiment && self.enemy)
104         {
105                 self.origin_x = (self.aiment.origin_x + self.enemy.origin_x) * 0.5;
106                 self.origin_y = (self.aiment.origin_y + self.enemy.origin_y) * 0.5;
107                 self.origin_z = (self.aiment.origin_z + self.enemy.origin_z) * 0.5;
108                 self.maxs_x = fabs(self.aiment.origin_x - self.enemy.origin_x) * 0.5;
109                 self.maxs_y = fabs(self.aiment.origin_y - self.enemy.origin_y) * 0.5;
110                 self.maxs_z = fabs(self.aiment.origin_z - self.enemy.origin_z) * 0.5;
111                 self.mins = -1 * self.maxs;
112                 setorigin(self, self.origin); setsize(self, self.mins, self.maxs); // link edict
113         }
114
115         if(self.cnt == -1) // actually race_place -1
116         {
117                 // show "10 10" for qualifying spawns
118                 setmodel(self.killindicator, "models/sprites/10.spr32");
119                 setmodel(self.killindicator.killindicator, "models/sprites/10.spr32");
120         }
121         else if(self.cnt == -2) // actually race_place 0
122         {
123                 // show "10 0" for loser spawns
124                 setmodel(self.killindicator, "models/sprites/10.spr32");
125                 setmodel(self.killindicator.killindicator, "models/sprites/0.spr32");
126         }
127         else
128         {
129                 setmodel(self.killindicator, strcat("models/sprites/", ftos(mod(self.cnt, 10)), ".spr32"));
130                 setmodel(self.killindicator.killindicator, strcat("models/sprites/", ftos(floor(self.cnt / 10)), ".spr32"));
131         }
132
133         self.nextthink = time;
134 }
135
136 //float ctf_clientcommand();
137 float readyrestart_happened;
138 .float lms_spectate_warning;
139 void spawnfunc_func_breakable();
140
141 .float cmd_floodtime;
142 .float cmd_floodcount;
143 float cmd_floodcheck()
144 {
145         if (timeoutStatus != 2)
146         {
147                 if(time == self.cmd_floodtime)
148                 {
149                         self.cmd_floodcount += 1;
150                         if(self.cmd_floodcount > 8)
151                                 return TRUE;
152                 }
153                 else
154                 {
155                         self.cmd_floodtime = time;
156                         self.cmd_floodcount = 1;
157                 }
158         }
159         return FALSE;
160 }
161
162 void SV_ParseClientCommand(string s) {
163         string cmd;
164         float tokens, f, effectnum;
165         vector start, end;
166         entity e, oldself;
167
168         tokens = tokenize_console(s);
169
170         cmd = argv(0);
171         if(cmd != "reportcvar")
172         if(cmd != "sentcvar")
173         if(cmd != "pause")
174         if(cmd != "prespawn")
175         if(cmd != "spawn")
176         if(cmd != "begin")
177         {
178                 if(cmd_floodcheck())
179                         return;
180         }
181
182         if(GameCommand_Vote(s, self)) {
183                 return;
184         } else if(GameCommand_MapVote(argv(0))) {
185                 return;
186         } else if(cmd == "autoswitch") {
187                 // be backwards compatible with older clients (enabled)
188                 self.autoswitch = ("0" != argv(1));
189                 local string autoswitchmsg;
190                 if (self.autoswitch) {
191                         autoswitchmsg = "on";
192                 } else {
193                         autoswitchmsg = "off";
194                 }
195                 sprint(self, strcat("^1autoswitch turned ", autoswitchmsg, "\n"));
196         } else if(cmd == "clientversion") {
197                 if not(self.flags & FL_CLIENT)
198                         return;
199                 if (argv(1) == "$gameversion") {
200                         //versionmsg = "^1client is too old to get versioninfo.\nUPDATE!!! (http://www.nexuiz.com)^8";
201                         // either that or someone wants to be funny
202                         self.version = 1;
203                 } else {
204                         self.version = stof(argv(1));
205                 }
206                 if(self.version != cvar("gameversion"))
207                 {
208                         self.classname = "observer";
209                         self.version_mismatch = 1;
210                         PutClientInServer();
211                 } else if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force")) {
212                         //JoinBestTeam(self, FALSE, TRUE);
213                 } else if(teams_matter && !cvar("sv_spectate")) {
214                         self.classname = "observer";
215                         stuffcmd(self,"menu_showteamselect\n");
216                 }
217         } else if(cmd == "reportcvar") { // old system
218                 if(substring(argv(2), 0, 1) == "$") // undefined cvar: use the default value on the server then
219                 {
220                         s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
221                         tokens = tokenize_console(s);
222                 }
223                 GetCvars(1);
224         } else if(cmd == "sentcvar") { // new system
225                 if(tokens == 2) // undefined cvar: use the default value on the server then
226                 {
227                         s = strcat(substring(s, argv_start_index(0), argv_end_index(1) - argv_start_index(0)), " \"", cvar_defstring(argv(1)), "\"");
228                         tokens = tokenize_console(s);
229                 }
230                 GetCvars(1);
231         } else if(cmd == "spectate") {
232                 if(cmd_floodcheck())
233                         return;
234                 if not(self.flags & FL_CLIENT)
235                         return;
236                 if(g_arena)
237                         return;
238                 if(g_lms)
239                 {
240                         if(self.lms_spectate_warning)
241                         {
242                                 // mark player as spectator
243                                 PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0));
244                         }
245                         else
246                         {
247                                 self.lms_spectate_warning = 1;
248                                 sprint(self, "WARNING: you won't be able to enter the game again after spectating in LMS. Use the same command again to spectate anyway.\n");
249                                 return;
250                         }
251                 }
252                 if(self.classname == "player" && cvar("sv_spectate") == 1) {
253                         if(self.flagcarried)
254                                 DropFlag(self.flagcarried, world, world);
255                         if(self.ballcarried)
256                                 DropBall(self.ballcarried, self.origin, self.velocity);
257                         kh_Key_DropAll(self, TRUE);
258                         WaypointSprite_PlayerDead();
259                         self.classname = "observer";
260                         if(g_ca)
261                                 self.caplayer = 0;
262                         if(blockSpectators)
263                                 sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
264                         PutClientInServer();
265                 }
266         } else if(cmd == "join") {
267                 if not(self.flags & FL_CLIENT)
268                         return;
269                 if(!g_arena)
270                 if (self.classname != "player" && !lockteams)
271                 {
272                         if(isJoinAllowed()) {
273                                 self.classname = "player";
274                                 if(g_ca)
275                                         self.caplayer = 1;
276                                 PlayerScore_Clear(self);
277                                 bprint ("^4", self.netname, "^4 is playing now\n");
278                                 self.stat_count = WEP_LAST;
279                                 PutClientInServer();
280                                 if(cvar("g_campaign"))
281                                         campaign_bots_may_start = 1;
282                         }
283                         else {
284                                 //player may not join because of g_maxplayers is set
285                                 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
286                         }
287                 }
288         } else if( cmd == "selectteam" ) {
289                 if not(self.flags & FL_CLIENT)
290                         return;
291                 if( !teams_matter ) {
292                         sprint( self, "selecteam can only be used in teamgames\n");
293                 } else if(cvar("g_campaign")) {
294                         //JoinBestTeam(self, 0);
295                 } else if(lockteams) {
296                         sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
297                 } else if( argv(1) == "red" ) {
298                         DoTeamChange(COLOR_TEAM1);
299                 } else if( argv(1) == "blue" ) {
300                         DoTeamChange(COLOR_TEAM2);
301                 } else if( argv(1) == "yellow" ) {
302                         DoTeamChange(COLOR_TEAM3);
303                 } else if( argv(1) == "pink" ) {
304                         DoTeamChange(COLOR_TEAM4);
305                 } else if( argv(1) == "auto" ) {
306                         DoTeamChange(-1);
307                 } else {
308                         sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
309                 }
310         } else if(cmd == "ready") {
311                 if not(self.flags & FL_CLIENT)
312                         return;
313
314                 if((inWarmupStage && 0 >= g_warmup_limit) // with unlimited warmup players have to be able to restart
315                    || cvar("sv_ready_restart") || g_race_qualifying == 2)
316                 {
317                         if(!readyrestart_happened || cvar("sv_ready_restart_repeatable"))
318                         {
319                                 if (self.ready) // toggle
320                                 {
321                                         self.ready = FALSE;
322                                         bprint(self.netname, "^2 is ^1NOT^2 ready\n");
323                                 }
324                                 else
325                                 {
326                                         self.ready = TRUE;
327                                         bprint(self.netname, "^2 is ready\n");
328                                 }
329
330                                 // cannot reset the game while a timeout is active!
331                                 if(!timeoutStatus)
332                                         ReadyCount();
333                         } else {
334                                 sprint(self, "^1Game has already been restarted\n");
335                         }
336                 }
337         } else if(cmd == "maplist") {
338                 sprint(self, maplist_reply);
339         } else if(cmd == "lsmaps") {
340                 sprint(self, lsmaps_reply);
341         } else if(cmd == "records") {
342                 sprint(self, records_reply);
343         } else if(cmd == "voice") {
344                 if(tokens >= 3)
345                         VoiceMessage(argv(1), substring(s, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
346                 else
347                         VoiceMessage(argv(1), "");
348         } else if(cmd == "say") {
349                 if(tokens >= 2)
350                         Say(self, FALSE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
351                 //clientcommand(self, formatmessage(s));
352         } else if(cmd == "say_team") {
353                 if(tokens >= 2)
354                         Say(self, TRUE, world, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), 1);
355                 //clientcommand(self, formatmessage(s));
356         } else if(cmd == "tell") {
357                 e = GetCommandPlayerSlotTargetFromTokenizedCommand(tokens, 1);
358                 if(e && tokens > ParseCommandPlayerSlotTarget_firsttoken)
359                 {
360                         Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
361                 }
362                 else
363                 {
364                         if(tokens > ParseCommandPlayerSlotTarget_firsttoken)
365                                 trigger_magicear_processmessage_forallears(self, -1, world, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
366                         sprint(self, "ERROR: usage: tell # playerid text...\n");
367                 }
368                 //clientcommand(self, formatmessage(s));
369         } else if(cmd == "info") {
370                 cmd = cvar_string(strcat("sv_info_", argv(1)));
371                 if(cmd == "")
372                         sprint(self, "ERROR: unsupported info command\n");
373                 else
374                         wordwrap_sprint(cmd, 1111);
375         } else if(cmd == "suggestmap") {
376                 sprint(self, strcat(MapVote_Suggest(argv(1)), "\n"));
377         } else if(cmd == "timeout") {
378                 if not(self.flags & FL_CLIENT)
379                         return;
380                 if(cvar("sv_timeout")) {
381                         if(self.classname == "player") {
382                                 if(votecalled)
383                                         sprint(self, "^7Error: you can not call a timeout while a vote is active!\n");
384                                 else
385                                         evaluateTimeout();
386                         }
387                         else
388                                 sprint(self, "^7Error: only players can call a timeout!\n");
389                 }
390         } else if(cmd == "timein") {
391                 if not(self.flags & FL_CLIENT)
392                         return;
393                 if(cvar("sv_timeout")) {
394                         evaluateTimein();
395                 }
396         } else if(cmd == "teamstatus") {
397                 Score_NicePrint(self);
398         } else if(cmd == "cvar_changes") {
399                 sprint(self, cvar_changes);
400         } else if(cmd == "pointparticles") {
401                 if((sv_cheats || self.maycheat) && tokens == 5)
402                 {
403                         // arguments:
404                         //   effectname
405                         //   origin (0..1, on crosshair line)
406                         //   velocity
407                         //   howmany
408                         effectnum = particleeffectnum(argv(1));
409                         f = stof(argv(2));
410                         start = (1-f) * self.origin + f * self.cursor_trace_endpos;
411                         end = stov(argv(3));
412                         f = stof(argv(4));
413                         pointparticles(effectnum, start, end, f);
414                 }
415                 else
416                         sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
417         } else if(cmd == "trailparticles") {
418                 if((sv_cheats || self.maycheat) && tokens == 2)
419                 {
420                         // arguments:
421                         //   effectname
422                         effectnum = particleeffectnum(argv(1));
423                         W_SetupShot(self, FALSE, FALSE, "",0);
424                         traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
425                         trailparticles(self, effectnum, w_shotorg, trace_endpos);
426                 }
427                 else
428                         sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
429         } else if(cmd == "make") {
430                 if((sv_cheats || self.maycheat) && tokens == 3)
431                 {
432                         // arguments:
433                         //   modelname mode
434                         f = stof(argv(2));
435                         W_SetupShot(self, FALSE, FALSE, "", 0);
436                         traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, self);
437                         if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
438                         {
439                                 sprint(self, "cannot make stuff there (bad surface)\n");
440                         }
441                         else
442                         {
443                                 oldself = self;
444                                 self = spawn();
445                                 self.model = strzone(argv(1));
446                                 self.mdl = "rocket_explode";
447                                 self.health = 1000;
448                                 setorigin(self, trace_endpos);
449                                 self.effects = EF_NOMODELFLAGS;
450                                 if(f == 1)
451                                 {
452                                         self.angles = fixedvectoangles2(trace_plane_normal, v_forward);
453                                         self.angles = AnglesTransform_Multiply(self.angles, '-90 0 0'); // so unrotated models work
454                                 }
455                                 spawnfunc_func_breakable();
456                                 // now, is it valid?
457                                 if(f == 0)
458                                 {
459                                         tracebox(self.origin, self.mins, self.maxs, self.origin, MOVE_NORMAL, self);
460                                         if(trace_startsolid)
461                                         {
462                                                 sprint(oldself, "cannot make stuff there (no space)\n");
463                                                 remove(self);
464                                         }
465                                 }
466                                 self = oldself;
467                         }
468                 }
469                 else
470                         sprint(self, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
471         } else if(cmd == "penalty") {
472                 if((sv_cheats || self.maycheat) && tokens == 3)
473                         race_ImposePenaltyTime(self, stof(argv(1)), argv(2));
474                 else
475                         sprint(self, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
476         } else if(cmd == "dragbox_spawn") {
477                 if(sv_cheats || self.maycheat)
478                 {
479                         e = spawn();
480                         e.classname = "dragbox_box";
481                         e.think = DragBox_Think;
482                         e.nextthink = time;
483                         e.solid = -1; // black
484                         setmodel(e, "null"); // network it
485                         if(tokens == 4)
486                                 e.cnt = stof(argv(1));
487                         else
488                                 e.cnt = max(0, drag_lastcnt);
489
490                         e.aiment = spawn();
491                         e.aiment.classname = "dragbox_corner_1";
492                         e.aiment.owner = e;
493                         setmodel(e.aiment, "models/marker.md3");
494                         e.aiment.skin = 0;
495                         setsize(e.aiment, '0 0 0', '0 0 0');
496                         if(tokens == 4)
497                                 setorigin(e.aiment, stov(argv(2)));
498                         else
499                                 setorigin(e.aiment, self.cursor_trace_endpos);
500
501                         e.enemy = spawn();
502                         e.enemy.classname = "dragbox_corner_2";
503                         e.enemy.owner = e;
504                         setmodel(e.enemy, "models/marker.md3");
505                         e.enemy.skin = 1;
506                         setsize(e.enemy, '0 0 0', '0 0 0');
507                         end = normalize(self.cursor_trace_start - e.aiment.origin);
508                         end_x = (end_x > 0) * 2 - 1;
509                         end_y = (end_y > 0) * 2 - 1;
510                         end_z = (end_z > 0) * 2 - 1;
511                         if(tokens == 4)
512                                 setorigin(e.enemy, stov(argv(3)));
513                         else
514                                 setorigin(e.enemy, e.aiment.origin + 32 * end);
515
516                         e.killindicator = spawn();
517                         e.killindicator.classname = "drag_digit";
518                         e.killindicator.owner = e;
519                         setattachment(e.killindicator, e, "");
520                         setorigin(e.killindicator, '0 0 -8');
521                         e.killindicator.killindicator = spawn();
522                         e.killindicator.killindicator.classname = "drag_digit";
523                         e.killindicator.killindicator.owner = e;
524                         setattachment(e.killindicator.killindicator, e, "");
525                         setorigin(e.killindicator.killindicator, '0 0 8');
526                 }
527                 else
528                         sprint(self, "Usage: sv_cheats 1; r_showbboxes 1.5; restart; cmd dragbox_spawn\n");
529         } else if(cmd == "dragpoint_spawn") {
530                 if(sv_cheats || self.maycheat)
531                 {
532                         e = spawn();
533                         e.classname = "dragpoint";
534                         e.think = DragBox_Think;
535                         e.nextthink = time;
536                         e.solid = 0; // nothing special
537                         setmodel(e, "models/marker.md3");
538                         setsize(e, PL_MIN, PL_MAX);
539                         e.skin = 2;
540                         if(tokens == 3)
541                                 e.cnt = stof(argv(1));
542                         else
543                                 e.cnt = drag_lastcnt;
544                         if(tokens == 3)
545                                 setorigin(e, stov(argv(2)));
546                         else
547                         {
548                                 setorigin(e, self.cursor_trace_endpos + normalize(self.cursor_trace_start - self.cursor_trace_endpos));
549                                 move_out_of_solid(e);
550                         }
551
552                         e.killindicator = spawn();
553                         e.killindicator.classname = "drag_digit";
554                         e.killindicator.owner = e;
555                         setattachment(e.killindicator, e, "");
556                         setorigin(e.killindicator, '0 0 40');
557                         e.killindicator.killindicator = spawn();
558                         e.killindicator.killindicator.classname = "drag_digit";
559                         e.killindicator.killindicator.owner = e;
560                         setattachment(e.killindicator.killindicator, e, "");
561                         setorigin(e.killindicator.killindicator, '0 0 56');
562                 }
563                 else
564                         sprint(self, "Usage: sv_cheats 1; r_showbboxes 1.5; restart; cmd dragbox_spawn\n");
565         } else if(cmd == "drag_remove") {
566                 if(sv_cheats || self.maycheat)
567                 {
568                         RandomSelection_Init();
569                         for(e = world; (e = find(e, classname, "dragbox_box")); )
570                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
571                         for(e = world; (e = find(e, classname, "dragpoint")); )
572                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
573                         if(RandomSelection_chosen_ent)
574                         {
575                                 remove(RandomSelection_chosen_ent.killindicator.killindicator);
576                                 remove(RandomSelection_chosen_ent.killindicator);
577                                 if(RandomSelection_chosen_ent.aiment)
578                                         remove(RandomSelection_chosen_ent.aiment);
579                                 if(RandomSelection_chosen_ent.enemy)
580                                         remove(RandomSelection_chosen_ent.enemy);
581                                 remove(RandomSelection_chosen_ent);
582                         }
583                 }
584                 else
585                         sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_remove\n");
586         } else if(cmd == "drag_setcnt") {
587                 if((sv_cheats || self.maycheat) && tokens >= 2)
588                 {
589                         RandomSelection_Init();
590                         for(e = world; (e = find(e, classname, "dragbox_box")); )
591                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
592                         for(e = world; (e = find(e, classname, "dragpoint")); )
593                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
594                         if(RandomSelection_chosen_ent)
595                         {
596                                 if(substring(argv(1), 0, 1) == "*")
597                                         RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
598                                 else
599                                         RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
600                         }
601                 }
602                 else
603                         sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
604         } else if(cmd == "drag_save") {
605                 if((sv_cheats || self.maycheat) && tokens >= 2)
606                 {
607                         f = fopen(argv(1), FILE_WRITE);
608                         fputs(f, "cmd drag_clear\n");
609                         for(e = world; (e = find(e, classname, "dragbox_box")); )
610                         {
611                                 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
612                         }
613                         for(e = world; (e = find(e, classname, "dragpoint")); )
614                         {
615                                 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
616                         }
617                         fclose(f);
618                 }
619                 else
620                         sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
621         } else if(cmd == "drag_saveraceent") {
622                 if((sv_cheats || self.maycheat) && tokens >= 2)
623                 {
624                         f = fopen(argv(1), FILE_WRITE);
625                         for(e = world; (e = find(e, classname, "dragbox_box")); )
626                         {
627                                 fputs(f, "{\n");
628                                 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
629                                 fputs(f, strcat("\"origin\" \"", ftos(e.absmin_x), " ", ftos(e.absmin_y), " ", ftos(e.absmin_z), "\"\n"));
630                                 fputs(f, strcat("\"maxs\" \"", ftos(e.absmax_x - e.absmin_x), " ", ftos(e.absmax_y - e.absmin_y), " ", ftos(e.absmax_z - e.absmin_z), "\"\n"));
631                                 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
632                                 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
633                                 fputs(f, "}\n");
634                         }
635                         for(e = world; (e = find(e, classname, "dragpoint")); )
636                         {
637                                 start = '0 0 0';
638                                 effectnum = 0;
639                                 for(oldself = world; (oldself = find(oldself, classname, "dragbox_box")); )
640                                 {
641                                         if(e.cnt <= 0 && oldself.cnt == 0 || e.cnt == oldself.cnt)
642                                         {
643                                                 start = start + oldself.origin;
644                                                 ++effectnum;
645                                         }
646                                 }
647                                 start *= 1 / effectnum;
648                                 fputs(f, "{\n");
649                                 fputs(f, "\"classname\" \"info_player_race\"\n");
650                                 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
651                                 fputs(f, strcat("\"origin\" \"", ftos(e.origin_x), " ", ftos(e.origin_y), " ", ftos(e.origin_z), "\"\n"));
652                                 if(e.cnt == -2)
653                                 {
654                                         fputs(f, "\"target\" \"checkpoint0\"\n");
655                                         fputs(f, "\"race_place\" \"0\"\n");
656                                 }
657                                 else if(e.cnt == -1)
658                                 {
659                                         fputs(f, "\"target\" \"checkpoint0\"\n");
660                                         fputs(f, "\"race_place\" \"-1\"\n");
661                                 }
662                                 else
663                                 {
664                                         fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
665                                         if(e.cnt == 0)
666                                         {
667                                                 // these need race_place
668                                                 // counting...
669                                                 effectnum = 1;
670                                                 for(oldself = world; (oldself = find(oldself, classname, "dragpoint")); )
671                                                 if(oldself.cnt == 0)
672                                                 {
673                                                         if(vlen(oldself.origin - start) < vlen(e.origin - start))
674                                                                 ++effectnum;
675                                                         else if(vlen(oldself.origin - start) == vlen(e.origin - start) && num_for_edict(oldself) < num_for_edict(e))
676                                                                 ++effectnum;
677                                                 }
678                                                 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
679                                         }
680                                 }
681                                 fputs(f, "}\n");
682                         }
683                         fclose(f);
684                 }
685                 else
686                         sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
687         } else if(cmd == "drag_clear") {
688                 if(sv_cheats || self.maycheat)
689                 {
690                         for(e = world; (e = find(e, classname, "dragbox_box")); )
691                                 remove(e);
692                         for(e = world; (e = find(e, classname, "dragbox_corner_1")); )
693                                 remove(e);
694                         for(e = world; (e = find(e, classname, "dragbox_corner_2")); )
695                                 remove(e);
696                         for(e = world; (e = find(e, classname, "dragpoint")); )
697                                 remove(e);
698                         for(e = world; (e = find(e, classname, "drag_digit")); )
699                                 remove(e);
700                 }
701                 else
702                         sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_clear\n");
703         } else {
704                 //if(ctf_clientcommand())
705                 //      return;
706                 // grep for Cmd_AddCommand_WithClientCommand to find them all
707                 if(cmd != "status")
708                 if(cmd != "max")
709                 if(cmd != "monster")
710                 if(cmd != "scrag")
711                 if(cmd != "wraith")
712                 if(cmd != "gimme")
713                 if(cmd != "god")
714                 if(cmd != "notarget")
715                 if(cmd != "fly")
716                 if(cmd != "noclip")
717                 if(cmd != "give")
718                 //if(cmd != "say") // handled above
719                 //if(cmd != "say_team") // handled above
720                 if(cmd != "kill")
721                 if(cmd != "pause")
722                 if(cmd != "ping")
723                 if(cmd != "name")
724                 if(cmd != "color")
725                 if(cmd != "rate")
726                 if(cmd != "pmodel")
727                 if(cmd != "playermodel")
728                 if(cmd != "playerskin")
729                 if(cmd != "prespawn")
730                 if(cmd != "spawn")
731                 if(cmd != "begin")
732                 if(cmd != "pings")
733                 if(cmd != "sv_startdownload")
734                 if(cmd != "download")
735                 {
736                         print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
737                         return;
738                 }
739
740                 if(self.jointime > 0 && time > self.jointime + 10 && time > self.nickspamtime) // allow any changes in the first 10 seconds since joining
741                 if(cmd == "name" || cmd == "playermodel") // TODO also playerskin and color?
742                 {
743                         if(self.nickspamtime == 0 || time > self.nickspamtime + cvar("g_nick_flood_timeout"))
744                                 // good, no serious flood
745                                 self.nickspamcount = 1;
746                         else
747                                 self.nickspamcount += 1;
748                         self.nickspamtime = time + cvar("g_nick_flood_penalty");
749
750                         if (timeoutStatus == 2) //when game is paused, no flood protection
751                                 self.nickspamcount = self.nickspamtime = 0;
752                 }
753
754                 clientcommand(self,s);
755         }
756 }
757
758 void ReadyRestartForce()
759 {
760         local entity e;
761
762         bprint("^1Server is restarting...\n");
763
764         VoteReset();
765
766         // clear overtime
767         if (checkrules_overtimesadded > 0 && g_race_qualifying != 2) {
768                 //we have to decrease timelimit to its original value again!!
769                 float newTL;
770                 newTL = cvar("timelimit");
771                 newTL -= checkrules_overtimesadded * cvar("timelimit_overtime");
772                 cvar_set("timelimit", ftos(newTL));
773         }
774
775         checkrules_suddendeathend = checkrules_overtimesadded = checkrules_suddendeathwarning = 0;
776
777
778         readyrestart_happened = 1;
779         game_starttime = time + RESTART_COUNTDOWN;
780         restart_mapalreadyrestarted = 0; //reset this var, needed when cvar sv_ready_restart_repeatable is in use
781
782         inWarmupStage = 0; //once the game is restarted the game is in match stage
783
784         //reset the .ready status of all players (also spectators)
785         FOR_EACH_CLIENTSLOT(e)
786                 e.ready = 0;
787         readycount = 0;
788         Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
789
790         if(cvar("teamplay_lockonrestart") && teams_matter) {
791                 lockteams = 1;
792                 bprint("^1The teams are now locked.\n");
793         }
794
795         //initiate the restart-countdown-announcer entity
796         if(cvar("sv_ready_restart_after_countdown"))
797         {
798                 restartTimer = spawn();
799                 restartTimer.think = restartTimer_Think;
800                 restartTimer.nextthink = game_starttime;
801         }
802
803         //after a restart every players number of allowed timeouts gets reset, too
804         if(cvar("sv_timeout"))
805         {
806                 FOR_EACH_REALPLAYER(e)
807                         e.allowedTimeouts = cvar("sv_timeout_number");
808         }
809
810         //reset map immediately if this cvar is not set
811         if (!cvar("sv_ready_restart_after_countdown"))
812                 reset_map(TRUE);
813
814         if(cvar("sv_eventlog"))
815                 GameLogEcho(":restart");
816 }
817
818 void ReadyRestart()
819 {
820         // no arena, assault support yet...
821         // TODO: CA support
822         if(g_arena | g_ca | g_assault | gameover | intermission_running | race_completing)
823                 localcmd("restart\n");
824         else
825                 localcmd("\nsv_hook_gamerestart;");
826
827         ReadyRestartForce();
828
829         // reset ALL scores, but only do that at the beginning
830         //of the countdown if sv_ready_restart_after_countdown is off!
831         //Otherwise scores could be manipulated during the countdown!
832         if (!cvar("sv_ready_restart_after_countdown"))
833                 Score_ClearAll();
834 }
835
836 /**
837  * Counts how many players are ready. If not enough players are ready, the function
838  * does nothing. If all players are ready, the timelimit will be extended and the
839  * restart_countdown variable is set to allow other functions like PlayerPostThink
840  * to detect that the countdown is now active. If the cvar sv_ready_restart_after_countdown
841  * is not set the map will be resetted.
842  *
843  * Function is called after the server receives a 'ready' sign from a player.
844  */
845 void ReadyCount()
846 {
847         local entity e;
848         local float r, p;
849
850         r = p = 0;
851
852         FOR_EACH_REALPLAYER(e)
853         {
854                 p += 1;
855                 if(e.ready)
856                         r += 1;
857         }
858
859         readycount = r;
860
861         Nagger_ReadyCounted();
862
863         if(r) // at least one is ready
864         if(r == p) // and, everyone is ready
865                 ReadyRestart();
866 }
867
868 /**
869  * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown
870  * is set)
871  */
872 void restartTimer_Think() {
873         restart_mapalreadyrestarted = 1;
874         reset_map(TRUE);
875         Score_ClearAll();
876         remove(self);
877         return;
878 }
879
880 /**
881  * Checks whether the player who calls the timeout is allowed to do so.
882  * If so, it initializes the timeout countdown. It also checks whether another
883  * timeout was already running at this time and reacts correspondingly.
884  *
885  * affected globals/fields: .allowedTimeouts, remainingTimeoutTime, remainingLeadTime,
886  *                          timeoutInitiator, timeoutStatus, timeoutHandler
887  *
888  * This function is called when a player issues the calltimeout command.
889  */
890 void evaluateTimeout() {
891         if (inWarmupStage && !g_warmup_allow_timeout)
892                 return sprint(self, "^7Error: You can not call a timeout in warmup-stage!\n");
893         if (time < game_starttime )
894                 return sprint(self, "^7Error: You can not call a timeout while the map is being restarted!\n");
895         if (timeoutStatus != 2) {
896                 //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
897                 if (cvar("timelimit")) {
898                         //a timelimit was used
899                         local float myTl;
900                         myTl = cvar("timelimit");
901
902                         local float lastPossibleTimeout;
903                         lastPossibleTimeout = (myTl*60) - cvar("sv_timeout_leadtime") - 1;
904
905                         if (lastPossibleTimeout < time - game_starttime)
906                                 return sprint(self, "^7Error: It is too late to call a timeout now!\n");
907                 }
908         }
909         //player may not call a timeout if he has no calls left
910         if (self.allowedTimeouts < 1)
911                 return sprint(self, "^7Error: You already used all your timeout calls for this map!\n");
912         //now all required checks are passed
913         self.allowedTimeouts -= 1;
914         bprint(self.netname, " ^7called a timeout (", ftos(self.allowedTimeouts), " timeouts left)!\n"); //write a bprint who started the timeout (and how many he has left)
915         remainingTimeoutTime = cvar("sv_timeout_length");
916         remainingLeadTime = cvar("sv_timeout_leadtime");
917         timeoutInitiator = self;
918         if (timeoutStatus == 0) { //if another timeout was already active, don't change its status (which was 1 or 2) to 1, only change it to 1 if no timeout was active yet
919                 timeoutStatus = 1;
920                 //create the timeout indicator which centerprints the information to all players and takes care of pausing/unpausing
921                 timeoutHandler = spawn();
922                 timeoutHandler.think = timeoutHandler_Think;
923         }
924         timeoutHandler.nextthink = time; //always let the entity think asap
925
926         //inform all connected clients about the timeout call
927         play2all("announcer/robotic/timeoutcalled.wav");
928 }
929
930 /**
931  * Checks whether a player is allowed to resume the game. If he is allowed to do it,
932  * and the lead time for the timeout is still active, this countdown just will be aborted (the
933  * game will never be paused). Otherwise the remainingTimeoutTime will be set to the corresponding
934  * value of the cvar sv_timeout_resumetime.
935  *
936  * This function is called when a player issues the resumegame command.
937  */
938 void evaluateTimein() {
939         if (!timeoutStatus)
940                 return sprint(self, "^7Error: There is no active timeout which could be aborted!\n");
941         if (self != timeoutInitiator)
942                 return sprint(self, "^7Error: You may not abort the active timeout. Only the player who called it can do that!\n");
943         if (timeoutStatus == 1) {
944                 remainingTimeoutTime = timeoutStatus = 0;
945                 timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
946                 bprint(strcat("^7The timeout was aborted by ", self.netname, " !\n"));
947         }
948         else if (timeoutStatus == 2) {
949                 //only shorten the remainingTimeoutTime if it makes sense
950                 if( remainingTimeoutTime > (cvar("sv_timeout_resumetime") + 1) ) {
951                         bprint(strcat("^1Attention: ^7", self.netname, " resumed the game! Prepare for battle!\n"));
952                         remainingTimeoutTime = cvar("sv_timeout_resumetime");
953                         timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
954                 }
955                 else
956                         sprint(self, "^7Error: Your resumegame call was discarded!\n");
957
958         }
959 }