]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/main.qc
HUD: split panels into files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / main.qc
1 #include "main.qh"
2
3 #include "controlpoint.qh"
4 #include "damage.qh"
5 #include "effects.qh"
6 #include "generator.qh"
7 #include "gibs.qh"
8 #include "hook.qh"
9 #include "hud/all.qh"
10 #include "laser.qh"
11 #include "mapvoting.qh"
12 #include "modeleffects.qh"
13 #include "mutators/events.qh"
14 #include "particles.qh"
15 #include "quickmenu.qh"
16 #include "scoreboard.qh"
17 #include "shownames.qh"
18 #include "tuba.qh"
19 #include "t_items.qh"
20 #include "wall.qh"
21 #include "weapons/projectile.qh"
22 #include "../common/deathtypes/all.qh"
23 #include "../common/items/all.qh"
24 #include "../common/mapinfo.qh"
25 #include "../common/minigames/cl_minigames.qh"
26 #include "../common/minigames/cl_minigames_hud.qh"
27 #include "../common/net_notice.qh"
28 #include "../common/triggers/include.qh"
29 #include "../common/turrets/cl_turrets.qh"
30 #include "../common/vehicles/all.qh"
31 #include "../lib/csqcmodel/cl_model.qh"
32 #include "../lib/csqcmodel/interpolate.qh"
33 #include "../lib/warpzone/client.qh"
34
35 // --------------------------------------------------------------------------
36 // BEGIN REQUIRED CSQC FUNCTIONS
37 //include "main.qh"
38
39 entity clearentity_ent;
40 void clearentity(entity e)
41 {
42         if (!clearentity_ent)
43         {
44                 clearentity_ent = new(clearentity);
45         }
46         int n = e.entnum;
47         copyentity(clearentity_ent, e);
48         e.entnum = n;
49 }
50
51 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
52 void menu_show_error()
53 {
54         drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
55 }
56
57 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
58 // Useful for precaching things
59
60 void menu_sub_null()
61 {
62 }
63
64 void draw_null(entity this) { }
65
66 string forcefog;
67 void ConsoleCommand_macro_init();
68 void CSQC_Init()
69 {
70         prvm_language = strzone(cvar_string("prvm_language"));
71
72 #ifdef WATERMARK
73         LOG_TRACEF("^4CSQC Build information: ^1%s\n", WATERMARK);
74 #endif
75
76         int i;
77
78         binddb = db_create();
79         tempdb = db_create();
80         ClientProgsDB = db_load("client.db");
81         compressShortVector_init();
82
83         draw_endBoldFont();
84         menu_visible = false;
85         menu_show = menu_show_error;
86         menu_action = func_null;
87
88         for(i = 0; i < 255; ++i)
89                 if(getplayerkeyvalue(i, "viewentity") == "")
90                         break;
91         maxclients = i;
92
93         //registercommand("hud_configure");
94         //registercommand("hud_save");
95         //registercommand("menu_action");
96
97         ConsoleCommand_macro_init();
98
99         registercvar("hud_usecsqc", "1");
100         registercvar("scoreboard_columns", "default");
101
102         registercvar("cl_nade_type", "3");
103         registercvar("cl_pokenade_type", "zombie");
104
105         registercvar("cl_jumpspeedcap_min", "");
106         registercvar("cl_jumpspeedcap_max", "");
107
108         registercvar("cl_multijump", "0");
109
110         registercvar("cl_spawn_near_teammate", "1");
111
112         gametype = 0;
113
114         // hud_fields uses strunzone on the titles!
115         for(i = 0; i < MAX_HUD_FIELDS; ++i)
116                 hud_title[i] = strzone("(null)");
117
118         Cmd_HUD_SetFields(0);
119
120         postinit = false;
121
122         calledhooks = 0;
123
124         teams = Sort_Spawn();
125         players = Sort_Spawn();
126
127         GetTeam(NUM_SPECTATOR, true); // add specs first
128
129         // needs to be done so early because of the constants they create
130         static_init();
131         static_init_late();
132         static_init_precache();
133
134         // precaches
135
136         Projectile_Precache();
137         Tuba_Precache();
138
139         if(autocvar_cl_reticle)
140         {
141                 precache_pic("gfx/reticle_normal");
142                 // weapon reticles are precached in weapon files
143         }
144
145         get_mi_min_max_texcoords(1); // try the CLEVER way first
146         minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
147         shortmapname = mi_shortname;
148
149         if(precache_pic(minimapname) == "")
150         {
151                 // but maybe we have a non-clever minimap
152                 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
153                 if(precache_pic(minimapname) == "")
154                         minimapname = ""; // FAIL
155                 else
156                         get_mi_min_max_texcoords(0); // load new texcoords
157         }
158
159         mi_center = (mi_min + mi_max) * 0.5;
160         mi_scale = mi_max - mi_min;
161         minimapname = strzone(minimapname);
162
163         WarpZone_Init();
164
165         hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
166         draw_currentSkin = strzone(strcat("gfx/menu/", cvar_string("menu_skin")));
167 }
168
169 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
170 void Shutdown()
171 {
172         WarpZone_Shutdown();
173
174         remove(teams);
175         remove(players);
176         db_close(binddb);
177         db_close(tempdb);
178         if(autocvar_cl_db_saveasdump)
179                 db_dump(ClientProgsDB, "client.db");
180         else
181                 db_save(ClientProgsDB, "client.db");
182         db_close(ClientProgsDB);
183
184         if(camera_active)
185                 cvar_set("chase_active",ftos(chase_active_backup));
186
187         // unset the event chasecam's chase_active
188         if(autocvar_chase_active < 0)
189                 cvar_set("chase_active", "0");
190
191         if (!isdemo())
192         {
193                 if (!(calledhooks & HOOK_START))
194                         localcmd("\n_cl_hook_gamestart nop\n");
195                 if (!(calledhooks & HOOK_END))
196                         localcmd("\ncl_hook_gameend\n");
197         }
198
199         deactivate_minigame();
200         HUD_MinigameMenu_Close();
201 }
202
203 .float has_team;
204 float SetTeam(entity o, int Team)
205 {
206         entity tm;
207         if(teamplay)
208         {
209                 switch(Team)
210                 {
211                         case -1:
212                         case NUM_TEAM_1:
213                         case NUM_TEAM_2:
214                         case NUM_TEAM_3:
215                         case NUM_TEAM_4:
216                                 break;
217                         default:
218                                 if(GetTeam(Team, false) == world)
219                                 {
220                                         LOG_TRACEF("trying to switch to unsupported team %d\n", Team);
221                                         Team = NUM_SPECTATOR;
222                                 }
223                                 break;
224                 }
225         }
226         else
227         {
228                 switch(Team)
229                 {
230                         case -1:
231                         case 0:
232                                 break;
233                         default:
234                                 if(GetTeam(Team, false) == world)
235                                 {
236                                         LOG_TRACEF("trying to switch to unsupported team %d\n", Team);
237                                         Team = NUM_SPECTATOR;
238                                 }
239                                 break;
240                 }
241         }
242         if(Team == -1) // leave
243         {
244                 if(o.has_team)
245                 {
246                         tm = GetTeam(o.team, false);
247                         tm.team_size -= 1;
248                         o.has_team = 0;
249                         return true;
250                 }
251         }
252         else
253         {
254                 if (!o.has_team)
255                 {
256                         o.team = Team;
257                         tm = GetTeam(Team, true);
258                         tm.team_size += 1;
259                         o.has_team = 1;
260                         return true;
261                 }
262                 else if(Team != o.team)
263                 {
264                         tm = GetTeam(o.team, false);
265                         tm.team_size -= 1;
266                         o.team = Team;
267                         tm = GetTeam(Team, true);
268                         tm.team_size += 1;
269                         return true;
270                 }
271         }
272         return false;
273 }
274
275 void Playerchecker_Think()
276 {SELFPARAM();
277     int i;
278         entity e;
279         for(i = 0; i < maxclients; ++i)
280         {
281                 e = playerslots[i];
282                 if(GetPlayerName(i) == "")
283                 {
284                         if(e.sort_prev)
285                         {
286                                 // player disconnected
287                                 SetTeam(e, -1);
288                                 RemovePlayer(e);
289                                 e.sort_prev = world;
290                                 //e.gotscores = 0;
291                         }
292                 }
293                 else
294                 {
295                         if (!e.sort_prev)
296                         {
297                                 // player connected
298                                 if (!e)
299                                 {
300                                         playerslots[i] = e = new(playerslot);
301                                         make_pure(e);
302                                 }
303                                 e.sv_entnum = i;
304                                 e.ping = 0;
305                                 e.ping_packetloss = 0;
306                                 e.ping_movementloss = 0;
307                                 //e.gotscores = 0; // we might already have the scores...
308                                 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
309                                 RegisterPlayer(e);
310                                 HUD_UpdatePlayerPos(e);
311                         }
312                 }
313         }
314         self.nextthink = time + 0.2;
315 }
316
317 void Porto_Init();
318 void TrueAim_Init();
319 void PostInit()
320 {
321         entity playerchecker = new(playerchecker);
322         make_pure(playerchecker);
323         playerchecker.think = Playerchecker_Think;
324         playerchecker.nextthink = time + 0.2;
325
326         Porto_Init();
327         TrueAim_Init();
328
329         postinit = true;
330 }
331
332 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
333 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
334 // All keys are in ascii.
335 // bInputType = 0 is key pressed, 1 is key released, 2 and 3 are mouse input.
336 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
337 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
338 // In the case of mouse input after a setcursormode(1) call, nPrimary is xpos, nSecondary is ypos.
339 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
340 {
341         float bSkipKey;
342         bSkipKey = false;
343
344         if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
345                 return true;
346
347         if (QuickMenu_InputEvent(bInputType, nPrimary, nSecondary))
348                 return true;
349
350         if ( HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary) )
351                 return true;
352
353         if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
354                 return true;
355
356         if (HUD_Minigame_InputEvent(bInputType, nPrimary, nSecondary))
357                 return true;
358
359         if(menu_visible && menu_action)
360                 if(menu_action(bInputType, nPrimary, nSecondary))
361                         return true;
362
363         return bSkipKey;
364 }
365
366 // END REQUIRED CSQC FUNCTIONS
367 // --------------------------------------------------------------------------
368
369 // --------------------------------------------------------------------------
370 // BEGIN OPTIONAL CSQC FUNCTIONS
371
372 void Ent_RemoveEntCS()
373 {SELFPARAM();
374         entcs_receiver[self.sv_entnum] = NULL;
375 }
376 void Ent_ReadEntCS()
377 {SELFPARAM();
378         make_pure(this);
379         this.classname = "entcs_receiver";
380         InterpolateOrigin_Undo();
381         int sf = ReadByte();
382
383         if(sf & BIT(0))
384                 self.sv_entnum = ReadByte();
385         if (sf & BIT(1))
386         {
387                 self.origin_x = ReadShort();
388                 self.origin_y = ReadShort();
389                 self.origin_z = ReadShort();
390                 setorigin(self, self.origin);
391         }
392         if (sf & BIT(2))
393         {
394                 self.angles_y = ReadByte() * 360.0 / 256;
395                 self.angles_x = self.angles_z = 0;
396         }
397         if (sf & BIT(3))
398                 self.healthvalue = ReadByte() * 10;
399         if (sf & BIT(4))
400                 self.armorvalue = ReadByte() * 10;
401
402         entcs_receiver[self.sv_entnum] = self;
403         self.entremove = Ent_RemoveEntCS;
404         self.iflags |= IFLAG_ORIGIN;
405
406         InterpolateOrigin_Note();
407 }
408
409 void Ent_Remove();
410
411 void Ent_RemovePlayerScore()
412 {SELFPARAM();
413         if(self.owner) {
414                 SetTeam(self.owner, -1);
415                 self.owner.gotscores = 0;
416                 for(int i = 0; i < MAX_SCORE; ++i) {
417                         self.owner.(scores[i]) = 0; // clear all scores
418                 }
419         }
420 }
421
422 void Ent_ReadPlayerScore()
423 {SELFPARAM();
424         make_pure(this);
425         int i, n;
426         bool isNew;
427         entity o;
428
429         // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
430         // (no I've never heard of M-x replace-string, sed, or anything like that)
431         isNew = !self.owner; // workaround for DP bug
432         n = ReadByte()-1;
433
434 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
435         if(!isNew && n != self.sv_entnum)
436         {
437                 //print("A CSQC entity changed its owner!\n");
438                 LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", num_for_edict(self), self.classname);
439                 isNew = true;
440                 Ent_Remove();
441         }
442 #endif
443
444         self.sv_entnum = n;
445
446         o = playerslots[self.sv_entnum];
447         if (!o)
448         {
449                 o = playerslots[self.sv_entnum] = new(playerslot);
450                 make_pure(o);
451         }
452         self.owner = o;
453         o.sv_entnum = self.sv_entnum;
454         o.gotscores = 1;
455
456         //if (!o.sort_prev)
457         //      RegisterPlayer(o);
458         //playerchecker will do this for us later, if it has not already done so
459
460     int sf, lf;
461 #if MAX_SCORE <= 8
462         sf = ReadByte();
463         lf = ReadByte();
464 #else
465         sf = ReadShort();
466         lf = ReadShort();
467 #endif
468     int p;
469         for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
470                 if(sf & p)
471                 {
472                         if(lf & p)
473                                 o.(scores[i]) = ReadInt24_t();
474                         else
475                                 o.(scores[i]) = ReadChar();
476                 }
477
478         if(o.sort_prev)
479                 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
480
481         self.entremove = Ent_RemovePlayerScore;
482 }
483
484 void Ent_ReadTeamScore()
485 {SELFPARAM();
486         make_pure(this);
487         int i;
488         entity o;
489
490         self.team = ReadByte();
491         o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
492
493     int sf, lf;
494 #if MAX_TEAMSCORE <= 8
495         sf = ReadByte();
496         lf = ReadByte();
497 #else
498         sf = ReadShort();
499         lf = ReadShort();
500 #endif
501         int p;
502         for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
503                 if(sf & p)
504                 {
505                         if(lf & p)
506                                 o.(teamscores[i]) = ReadInt24_t();
507                         else
508                                 o.(teamscores[i]) = ReadChar();
509                 }
510
511         HUD_UpdateTeamPos(o);
512 }
513
514 void Ent_ClientData()
515 {
516         make_pure(self);
517         float newspectatee_status;
518
519     int f = ReadByte();
520
521         scoreboard_showscores_force = (f & 1);
522
523         if(f & 2)
524         {
525                 newspectatee_status = ReadByte();
526                 if(newspectatee_status == player_localnum + 1)
527                         newspectatee_status = -1; // observing
528         }
529         else
530                 newspectatee_status = 0;
531
532         spectatorbutton_zoom = (f & 4);
533
534         if(f & 8)
535         {
536                 angles_held_status = 1;
537                 angles_held.x = ReadAngle();
538                 angles_held.y = ReadAngle();
539                 angles_held.z = 0;
540         }
541         else
542                 angles_held_status = 0;
543
544         if(newspectatee_status != spectatee_status)
545         {
546                 // clear race stuff
547                 race_laptime = 0;
548                 race_checkpointtime = 0;
549         }
550         if (autocvar_hud_panel_healtharmor_progressbar_gfx)
551         {
552                 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
553                   || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
554                 )
555                         prev_p_health = -1;
556                 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
557                         prev_health = -1;
558         }
559         spectatee_status = newspectatee_status;
560
561         // we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
562 }
563
564 void Ent_Nagger()
565 {
566         make_pure(self);
567     int i, j, b, f;
568
569     int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
570
571         if(!(nags & BIT(2)))
572         {
573                 if(vote_called_vote)
574                         strunzone(vote_called_vote);
575                 vote_called_vote = string_null;
576                 vote_active = 0;
577         }
578         else
579         {
580                 vote_active = 1;
581         }
582
583         if(nags & BIT(6))
584         {
585                 vote_yescount = ReadByte();
586                 vote_nocount = ReadByte();
587                 vote_needed = ReadByte();
588                 vote_highlighted = ReadChar();
589         }
590
591         if(nags & BIT(7))
592         {
593                 if(vote_called_vote)
594                         strunzone(vote_called_vote);
595                 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
596         }
597
598         if(nags & 1)
599         {
600                 for(j = 0; j < maxclients; ++j)
601                         if(playerslots[j])
602                                 playerslots[j].ready = 1;
603                 for(i = 1; i <= maxclients; i += 8)
604                 {
605                         f = ReadByte();
606                         for(j = i-1, b = 1; b < 256; b *= 2, ++j)
607                                 if (!(f & b))
608                                         if(playerslots[j])
609                                                 playerslots[j].ready = 0;
610                 }
611         }
612
613         ready_waiting = (nags & BIT(0));
614         ready_waiting_for_me = (nags & BIT(1));
615         vote_waiting = (nags & BIT(2));
616         vote_waiting_for_me = (nags & BIT(3));
617         warmup_stage = (nags & BIT(4));
618 }
619
620 void Ent_EliminatedPlayers()
621 {
622         make_pure(self);
623     int i, j, b, f;
624
625     int sf = ReadByte();
626         if(sf & 1)
627         {
628                 for(j = 0; j < maxclients; ++j)
629                         if(playerslots[j])
630                                 playerslots[j].eliminated = 1;
631                 for(i = 1; i <= maxclients; i += 8)
632                 {
633                         f = ReadByte();
634                         for(j = i-1, b = 1; b < 256; b *= 2, ++j)
635                                 if (!(f & b))
636                                         if(playerslots[j])
637                                                 playerslots[j].eliminated = 0;
638                 }
639         }
640 }
641
642 void Ent_RandomSeed()
643 {
644         make_pure(self);
645         prandom_debug();
646         float s = ReadShort();
647         psrandom(s);
648 }
649
650 void Ent_ReadAccuracy()
651 {
652         make_pure(self);
653     int sf = ReadInt24_t();
654         if (sf == 0) {
655                 for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
656                         weapon_accuracy[w] = -1;
657                 return;
658         }
659
660         int f = 1;
661         for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w) {
662                 if (sf & f) {
663             int b = ReadByte();
664                         if (b == 0)
665                                 weapon_accuracy[w] = -1;
666                         else if (b == 255)
667                                 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
668                         else
669                                 weapon_accuracy[w] = (b - 1.0) / 100.0;
670                 }
671                 f = (f == 0x800000) ? 1 : f * 2;
672         }
673 }
674
675 void Spawn_Draw(entity this)
676 {
677         __pointparticles(this.cnt, this.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1));
678 }
679
680 void Ent_ReadSpawnPoint(float is_new) // entity for spawnpoint
681 {SELFPARAM();
682         float teamnum = (ReadByte() - 1);
683         vector spn_origin;
684         spn_origin.x = ReadShort();
685         spn_origin.y = ReadShort();
686         spn_origin.z = ReadShort();
687
688         //if(is_new)
689         //{
690                 self.origin = spn_origin;
691                 setsize(self, PL_MIN_CONST, PL_MAX_CONST);
692                 //droptofloor();
693
694                 /*if(autocvar_cl_spawn_point_model) // needs a model first
695                 {
696                         self.mdl = "models/spawnpoint.md3";
697                         self.colormod = Team_ColorRGB(teamnum);
698                         precache_model(self.mdl);
699                         setmodel(self, self.mdl);
700                         self.drawmask = MASK_NORMAL;
701                         //self.movetype = MOVETYPE_NOCLIP;
702                         //self.draw = Spawn_Draw;
703                 }*/
704                 if(autocvar_cl_spawn_point_particles)
705                 {
706                         if((serverflags & SERVERFLAG_TEAMPLAY))
707                         {
708                                 switch(teamnum)
709                                 {
710                                         case NUM_TEAM_1: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_RED); break;
711                                         case NUM_TEAM_2: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_BLUE); break;
712                                         case NUM_TEAM_3: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_YELLOW); break;
713                                         case NUM_TEAM_4: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_PINK); break;
714                                         default: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); break;
715                                 }
716                         }
717                         else { self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); }
718
719                         self.draw = Spawn_Draw;
720                 }
721         //}
722
723         //printf("Ent_ReadSpawnPoint(is_new = %d); origin = %s, team = %d, effect = %d\n", is_new, vtos(self.origin), teamnum, self.cnt);
724 }
725
726 void Ent_ReadSpawnEvent(float is_new)
727 {SELFPARAM();
728         // If entnum is 0, ONLY do the local spawn actions
729         // this way the server can disable the sending of
730         // spawn origin or such to clients if wanted.
731         float entnum = ReadByte();
732
733         if(entnum)
734         {
735                 self.origin_x = ReadShort();
736                 self.origin_y = ReadShort();
737                 self.origin_z = ReadShort();
738
739                 if(is_new)
740                 {
741                         float teamnum = GetPlayerColor(entnum - 1);
742
743                         if(autocvar_cl_spawn_event_particles)
744                         {
745                                 switch(teamnum)
746                                 {
747                                         case NUM_TEAM_1: pointparticles(EFFECT_SPAWN_RED, self.origin, '0 0 0', 1); break;
748                                         case NUM_TEAM_2: pointparticles(EFFECT_SPAWN_BLUE, self.origin, '0 0 0', 1); break;
749                                         case NUM_TEAM_3: pointparticles(EFFECT_SPAWN_YELLOW, self.origin, '0 0 0', 1); break;
750                                         case NUM_TEAM_4: pointparticles(EFFECT_SPAWN_PINK, self.origin, '0 0 0', 1); break;
751                                         default: pointparticles(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1); break;
752                                 }
753                         }
754                         if(autocvar_cl_spawn_event_sound)
755                         {
756                                 sound(self, CH_TRIGGER, SND_SPAWN, VOL_BASE, ATTEN_NORM);
757                         }
758                 }
759         }
760
761         // local spawn actions
762         if(is_new && (!entnum || (entnum == player_localentnum)))
763         {
764                 zoomin_effect = 1;
765                 current_viewzoom = (1 / bound(1, autocvar_cl_spawnzoom_factor, 16));
766
767                 if(autocvar_cl_unpress_zoom_on_spawn)
768                 {
769                         localcmd("-zoom\n");
770                         button_zoom = false;
771                 }
772         }
773         HUD_Radar_Hide_Maximized();
774         //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(self.origin), entnum, player_localentnum);
775 }
776
777 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
778 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
779 void Ent_RadarLink();
780 void Ent_Init();
781 void Ent_ScoresInfo();
782 void CSQC_Ent_Update(float bIsNewEntity)
783 {
784         SELFPARAM();
785         this.sourceLocLine = __LINE__;
786         this.sourceLocFile = __FILE__;
787         int t = ReadByte();
788
789         // set up the "time" global for received entities to be correct for interpolation purposes
790         float savetime = time;
791         if(servertime)
792         {
793                 time = servertime;
794         }
795         else
796         {
797                 serverprevtime = time;
798                 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
799                 time = serverprevtime + serverdeltatime;
800         }
801
802 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
803         if(this.enttype)
804         {
805                 if(t != this.enttype || bIsNewEntity)
806                 {
807                         LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", num_for_edict(this), this.entnum, this.enttype, t);
808                         Ent_Remove();
809                         clearentity(this);
810                         bIsNewEntity = 1;
811                 }
812         }
813         else
814         {
815                 if(!bIsNewEntity)
816                 {
817                         LOG_INFOF("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", num_for_edict(this), this.entnum, t);
818                         bIsNewEntity = 1;
819                 }
820         }
821 #endif
822         this.enttype = t;
823         bool done = false;
824         FOREACH(LinkedEntities, it.m_id == t, LAMBDA(
825                 this.classname = it.netname;
826                 if (autocvar_developer_csqcentities)
827             LOG_INFOF("CSQC_Ent_Update(%d) with self=%i {.entnum=%d, .enttype=%d} t=%s (%d)\n", bIsNewEntity, this, this.entnum, this.enttype, it.netname, t);
828                 done = it.m_read(this, bIsNewEntity);
829                 break;
830         ));
831         time = savetime;
832         if (!done)
833         {
834                 //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), this.enttype));
835                 error(sprintf("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n", this.enttype, num_for_edict(this), this.classname));
836         }
837 }
838 NET_HANDLE(ENT_CLIENT_ENTCS, bool isnew)
839 {
840         Ent_ReadEntCS();
841         return true;
842 }
843 NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
844 {
845         Ent_ReadPlayerScore();
846         return true;
847 }
848 NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew)
849 {
850         Ent_ReadTeamScore();
851         return true;
852 }
853 NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew)
854 {
855         Ent_PointParticles();
856         return true;
857 }
858 NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
859 {
860         Ent_RainOrSnow();
861         return true;
862 }
863 NET_HANDLE(ENT_CLIENT_LASER, bool isnew)
864 {
865         Ent_Laser();
866         return true;
867 }
868 NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew)
869 {
870         Ent_Nagger();
871         return true;
872 }
873 NET_HANDLE(ENT_CLIENT_ELIMINATEDPLAYERS, bool isnew)
874 {
875         Ent_EliminatedPlayers();
876         return true;
877 }
878 NET_HANDLE(ENT_CLIENT_RADARLINK, bool isnew)
879 {
880         Ent_RadarLink();
881         return true;
882 }
883 NET_HANDLE(ENT_CLIENT_PROJECTILE, bool isnew)
884 {
885         Ent_Projectile();
886         return true;
887 }
888 NET_HANDLE(ENT_CLIENT_DAMAGEINFO, bool isnew)
889 {
890         Ent_DamageInfo(isnew);
891         return true;
892 }
893 NET_HANDLE(ENT_CLIENT_INIT, bool isnew)
894 {
895         Ent_Init();
896         return true;
897 }
898 NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew)
899 {
900         Ent_ScoresInfo();
901         return true;
902 }
903 NET_HANDLE(ENT_CLIENT_MAPVOTE, bool isnew)
904 {
905         Ent_MapVote();
906         return true;
907 }
908 NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
909 {
910         Ent_ClientData();
911         return true;
912 }
913 NET_HANDLE(ENT_CLIENT_RANDOMSEED, bool isnew)
914 {
915         Ent_RandomSeed();
916         return true;
917 }
918 NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
919 {
920         Ent_Wall();
921         return true;
922 }
923 NET_HANDLE(ENT_CLIENT_MODELEFFECT, bool isnew)
924 {
925         Ent_ModelEffect(isnew);
926         return true;
927 }
928 NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isnew)
929 {
930         Ent_TubaNote(isnew);
931         return true;
932 }
933 NET_HANDLE(ENT_CLIENT_WARPZONE, bool isnew)
934 {
935         WarpZone_Read(isnew);
936         return true;
937 }
938 NET_HANDLE(ENT_CLIENT_WARPZONE_CAMERA, bool isnew)
939 {
940         WarpZone_Camera_Read(isnew);
941         return true;
942 }
943 NET_HANDLE(ENT_CLIENT_WARPZONE_TELEPORTED, bool isnew)
944 {
945         WarpZone_Teleported_Read(isnew);
946         return true;
947 }
948 NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
949 {
950         Ent_ReadTriggerMusic();
951         return true;
952 }
953 NET_HANDLE(ENT_CLIENT_HOOK, bool isnew)
954 {
955         Ent_ReadHook(isnew, NET_ENT_CLIENT_HOOK);
956         return true;
957 }
958 NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
959 {
960         Inventory_Read(this);
961         return true;
962 }
963 NET_HANDLE(ENT_CLIENT_ARC_BEAM, bool isnew)
964 {
965         Ent_ReadArcBeam(isnew);
966         return true;
967 }
968 NET_HANDLE(ENT_CLIENT_ACCURACY, bool isnew)
969 {
970         Ent_ReadAccuracy();
971         return true;
972 }
973 NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew)
974 {
975         Net_AuXair2(isnew);
976         return true;
977 }
978 NET_HANDLE(ENT_CLIENT_TURRET, bool isnew)
979 {
980         ent_turret();
981         return true;
982 }
983 NET_HANDLE(ENT_CLIENT_GENERATOR, bool isnew)
984 {
985         ent_generator();
986         return true;
987 }
988 NET_HANDLE(ENT_CLIENT_CONTROLPOINT_ICON, bool isnew)
989 {
990         ent_cpicon(this);
991         return true;
992 }
993 NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
994 {
995         CSQCModel_Read(isnew);
996         return true;
997 }
998 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
999 {
1000         ItemRead(isnew);
1001         return true;
1002 }
1003 NET_HANDLE(ENT_CLIENT_BUMBLE_RAYGUN, bool isnew)
1004 {
1005         bumble_raygun_read(isnew);
1006         return true;
1007 }
1008 NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool isnew)
1009 {
1010         Ent_ReadSpawnPoint(isnew);
1011         return true;
1012 }
1013 NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool isnew)
1014 {
1015         Ent_ReadSpawnEvent(isnew);
1016         return true;
1017 }
1018 NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool isnew)
1019 {
1020         Read_Notification(isnew);
1021         return true;
1022 }
1023 NET_HANDLE(ENT_CLIENT_MINIGAME, bool isnew)
1024 {
1025         ent_read_minigame();
1026         return true;
1027 }
1028 NET_HANDLE(ENT_CLIENT_VIEWLOC, bool isnew)
1029 {
1030         ent_viewloc();
1031         return true;
1032 }
1033 NET_HANDLE(ENT_CLIENT_VIEWLOC_TRIGGER, bool isnew)
1034 {
1035         ent_viewloc_trigger();
1036         return true;
1037 }
1038 NET_HANDLE(ENT_CLIENT_LADDER, bool isnew)
1039 {
1040         ent_func_ladder();
1041         return true;
1042 }
1043 NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH, bool isnew)
1044 {
1045         ent_trigger_push();
1046         return true;
1047 }
1048 NET_HANDLE(ENT_CLIENT_TARGET_PUSH, bool isnew)
1049 {
1050         ent_target_push();
1051         return true;
1052 }
1053 NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew)
1054 {
1055         ent_conveyor();
1056         return true;
1057 }
1058 NET_HANDLE(ENT_CLIENT_DOOR, bool isnew)
1059 {
1060         ent_door();
1061         return true;
1062 }
1063 NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
1064 {
1065         ent_plat();
1066         return true;
1067 }
1068 NET_HANDLE(ENT_CLIENT_SWAMP, bool isnew)
1069 {
1070         ent_swamp();
1071         return true;
1072 }
1073 NET_HANDLE(ENT_CLIENT_CORNER, bool isnew)
1074 {
1075         ent_corner();
1076         return true;
1077 }
1078 NET_HANDLE(ENT_CLIENT_KEYLOCK, bool isnew)
1079 {
1080         ent_keylock();
1081         return true;
1082 }
1083 NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
1084 {
1085         ent_train();
1086         return true;
1087 }
1088 NET_HANDLE(ENT_CLIENT_TRIGGER_IMPULSE, bool isnew)
1089 {
1090         ent_trigger_impulse();
1091         return true;
1092 }
1093
1094 // Destructor, but does NOT deallocate the entity by calling remove(). Also
1095 // used when an entity changes its type. For an entity that someone interacts
1096 // with others, make sure it can no longer do so.
1097 void Ent_Remove()
1098 {SELFPARAM();
1099         if(self.entremove)
1100                 self.entremove();
1101
1102         if(self.skeletonindex)
1103         {
1104                 skel_delete(self.skeletonindex);
1105                 self.skeletonindex = 0;
1106         }
1107
1108         if(self.snd_looping > 0)
1109         {
1110                 sound(self, self.snd_looping, SND_Null, VOL_BASE, autocvar_g_jetpack_attenuation);
1111                 self.snd_looping = 0;
1112         }
1113
1114         self.enttype = 0;
1115         self.classname = "";
1116         self.draw = draw_null;
1117         self.entremove = menu_sub_null;
1118         // TODO possibly set more stuff to defaults
1119 }
1120 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.
1121 void CSQC_Ent_Remove()
1122 {SELFPARAM();
1123         if(autocvar_developer_csqcentities)
1124                 LOG_INFOF("CSQC_Ent_Remove() with self=%i self.entnum=%d self.enttype=%d\n", self, self.entnum, self.enttype);
1125
1126         if(wasfreed(self))
1127         {
1128                 LOG_INFO("WARNING: CSQC_Ent_Remove called for already removed entity. Packet loss?\n");
1129                 return;
1130         }
1131         if(self.enttype)
1132                 Ent_Remove();
1133         remove(self);
1134 }
1135
1136 void Gamemode_Init()
1137 {
1138         if (!isdemo())
1139         {
1140                 if(!(calledhooks & HOOK_START))
1141                         localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
1142                 calledhooks |= HOOK_START;
1143         }
1144 }
1145 // CSQC_Parse_StuffCmd : Provides the stuffcmd string in the first parameter that the server provided.  To execute standard behavior, simply execute localcmd with the string.
1146 void CSQC_Parse_StuffCmd(string strMessage)
1147 {
1148         if(autocvar_developer_csqcentities)
1149                 LOG_INFOF("CSQC_Parse_StuffCmd(\"%s\")\n", strMessage);
1150
1151         localcmd(strMessage);
1152 }
1153 // CSQC_Parse_Print : Provides the print string in the first parameter that the server provided.  To execute standard behavior, simply execute print with the string.
1154 void CSQC_Parse_Print(string strMessage)
1155 {
1156         if(autocvar_developer_csqcentities)
1157                 LOG_INFOF("CSQC_Parse_Print(\"%s\")\n", strMessage);
1158
1159         print(ColorTranslateRGB(strMessage));
1160 }
1161
1162 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
1163 void CSQC_Parse_CenterPrint(string strMessage)
1164 {
1165         if(autocvar_developer_csqcentities)
1166                 LOG_INFOF("CSQC_Parse_CenterPrint(\"%s\")\n", strMessage);
1167
1168         centerprint_hud(strMessage);
1169 }
1170
1171 string notranslate_fogcmd1 = "\nfog ";
1172 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
1173 void Fog_Force()
1174 {
1175         // TODO somehow thwart prvm_globalset client ...
1176
1177         if(autocvar_cl_orthoview && autocvar_cl_orthoview_nofog)
1178                 { localcmd("\nr_drawfog 0\n"); }
1179         else if(forcefog != "")
1180                 { localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2)); }
1181 }
1182
1183 void Gamemode_Init();
1184 void Ent_ScoresInfo()
1185 {SELFPARAM();
1186     int i;
1187         make_pure(this);
1188         gametype = ReadInt24_t();
1189         HUD_ModIcons_SetFunc();
1190         for(i = 0; i < MAX_SCORE; ++i)
1191         {
1192                 if(scores_label[i])
1193                         strunzone(scores_label[i]);
1194                 scores_label[i] = strzone(ReadString());
1195                 scores_flags[i] = ReadByte();
1196         }
1197         for(i = 0; i < MAX_TEAMSCORE; ++i)
1198         {
1199                 if(teamscores_label[i])
1200                         strunzone(teamscores_label[i]);
1201                 teamscores_label[i] = strzone(ReadString());
1202                 teamscores_flags[i] = ReadByte();
1203         }
1204         HUD_InitScores();
1205         Gamemode_Init();
1206 }
1207
1208 void Ent_Init()
1209 {SELFPARAM();
1210         make_pure(this);
1211
1212         nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
1213
1214         hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1215         hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1216         hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1217         hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1218         arc_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1219         arc_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1220         arc_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1221         arc_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1222
1223         if(forcefog)
1224                 strunzone(forcefog);
1225         forcefog = strzone(ReadString());
1226
1227         armorblockpercent = ReadByte() / 255.0;
1228
1229         g_balance_mortar_bouncefactor = ReadCoord();
1230         g_balance_mortar_bouncestop = ReadCoord();
1231         g_balance_electro_secondary_bouncefactor = ReadCoord();
1232         g_balance_electro_secondary_bouncestop = ReadCoord();
1233
1234         vortex_scope = !ReadByte();
1235         rifle_scope = !ReadByte();
1236
1237         serverflags = ReadByte();
1238
1239         minelayer_maxmines = ReadByte();
1240
1241         hagar_maxrockets = ReadByte();
1242
1243         g_trueaim_minrange = ReadCoord();
1244         g_balance_porto_secondary = ReadByte();
1245
1246         MUTATOR_CALLHOOK(Ent_Init);
1247
1248         if(!postinit)
1249                 PostInit();
1250 }
1251
1252 void Net_ReadRace()
1253 {
1254         float b;
1255
1256         b = ReadByte();
1257
1258         switch(b)
1259         {
1260                 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1261                         race_checkpoint = ReadByte();
1262                         race_time = ReadInt24_t();
1263                         race_previousbesttime = ReadInt24_t();
1264                         if(race_previousbestname)
1265                                 strunzone(race_previousbestname);
1266                         race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
1267
1268                         race_checkpointtime = time;
1269
1270                         if(race_checkpoint == 0 || race_checkpoint == 254)
1271                         {
1272                                 race_penaltyaccumulator = 0;
1273                                 race_laptime = time; // valid
1274                         }
1275
1276                         break;
1277
1278                 case RACE_NET_CHECKPOINT_CLEAR:
1279                         race_laptime = 0;
1280                         race_checkpointtime = 0;
1281                         break;
1282
1283                 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1284                         race_laptime = ReadCoord();
1285                         race_checkpointtime = -99999;
1286                         // fall through
1287                 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1288                         race_nextcheckpoint = ReadByte();
1289
1290                         race_nextbesttime = ReadInt24_t();
1291                         if(race_nextbestname)
1292                                 strunzone(race_nextbestname);
1293                         race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1294                         break;
1295
1296                 case RACE_NET_CHECKPOINT_HIT_RACE:
1297                         race_mycheckpoint = ReadByte();
1298                         race_mycheckpointtime = time;
1299                         race_mycheckpointdelta = ReadInt24_t();
1300                         race_mycheckpointlapsdelta = ReadByte();
1301                         if(race_mycheckpointlapsdelta >= 128)
1302                                 race_mycheckpointlapsdelta -= 256;
1303                         if(race_mycheckpointenemy)
1304                                 strunzone(race_mycheckpointenemy);
1305                         race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1306                         break;
1307
1308                 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1309                         race_othercheckpoint = ReadByte();
1310                         race_othercheckpointtime = time;
1311                         race_othercheckpointdelta = ReadInt24_t();
1312                         race_othercheckpointlapsdelta = ReadByte();
1313                         if(race_othercheckpointlapsdelta >= 128)
1314                                 race_othercheckpointlapsdelta -= 256;
1315                         if(race_othercheckpointenemy)
1316                                 strunzone(race_othercheckpointenemy);
1317                         race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1318                         break;
1319
1320                 case RACE_NET_PENALTY_RACE:
1321                         race_penaltyeventtime = time;
1322                         race_penaltytime = ReadShort();
1323                         //race_penaltyaccumulator += race_penaltytime;
1324                         if(race_penaltyreason)
1325                                 strunzone(race_penaltyreason);
1326                         race_penaltyreason = strzone(ReadString());
1327                         break;
1328
1329                 case RACE_NET_PENALTY_QUALIFYING:
1330                         race_penaltyeventtime = time;
1331                         race_penaltytime = ReadShort();
1332                         race_penaltyaccumulator += race_penaltytime;
1333                         if(race_penaltyreason)
1334                                 strunzone(race_penaltyreason);
1335                         race_penaltyreason = strzone(ReadString());
1336                         break;
1337
1338                 case RACE_NET_SERVER_RECORD:
1339                         race_server_record = ReadInt24_t();
1340                         break;
1341                 case RACE_NET_SPEED_AWARD:
1342                         race_speedaward = ReadInt24_t();
1343                         if(race_speedaward_holder)
1344                                 strunzone(race_speedaward_holder);
1345                         race_speedaward_holder = strzone(ReadString());
1346                         break;
1347                 case RACE_NET_SPEED_AWARD_BEST:
1348                         race_speedaward_alltimebest = ReadInt24_t();
1349                         if(race_speedaward_alltimebest_holder)
1350                                 strunzone(race_speedaward_alltimebest_holder);
1351                         race_speedaward_alltimebest_holder = strzone(ReadString());
1352                         break;
1353                 case RACE_NET_SERVER_RANKINGS:
1354                         float prevpos, del;
1355             int pos = ReadShort();
1356                         prevpos = ReadShort();
1357                         del = ReadShort();
1358
1359                         // move other rankings out of the way
1360             int i;
1361                         if (prevpos) {
1362                                 for (i=prevpos-1;i>pos-1;--i) {
1363                                         grecordtime[i] = grecordtime[i-1];
1364                                         if(grecordholder[i])
1365                                                 strunzone(grecordholder[i]);
1366                                         grecordholder[i] = strzone(grecordholder[i-1]);
1367                                 }
1368                         } else if (del) { // a record has been deleted by the admin
1369                                 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1370                                         if (i == RANKINGS_CNT-1) { // clear out last record
1371                                                 grecordtime[i] = 0;
1372                                                 if (grecordholder[i])
1373                                                         strunzone(grecordholder[i]);
1374                                                 grecordholder[i] = string_null;
1375                                         }
1376                                         else {
1377                                                 grecordtime[i] = grecordtime[i+1];
1378                                                 if (grecordholder[i])
1379                                                         strunzone(grecordholder[i]);
1380                                                 grecordholder[i] = strzone(grecordholder[i+1]);
1381                                         }
1382                                 }
1383                         } else { // player has no ranked record yet
1384                                 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1385                                         grecordtime[i] = grecordtime[i-1];
1386                                         if(grecordholder[i])
1387                                                 strunzone(grecordholder[i]);
1388                                         grecordholder[i] = strzone(grecordholder[i-1]);
1389                                 }
1390                         }
1391
1392                         // store new ranking
1393                         if(grecordholder[pos-1] != "")
1394                                 strunzone(grecordholder[pos-1]);
1395                         grecordholder[pos-1] = strzone(ReadString());
1396                         grecordtime[pos-1] = ReadInt24_t();
1397                         if(grecordholder[pos-1] == GetPlayerName(player_localnum))
1398                                 race_myrank = pos;
1399                         break;
1400                 case RACE_NET_SERVER_STATUS:
1401                         race_status = ReadShort();
1402                         if(race_status_name)
1403                                 strunzone(race_status_name);
1404                         race_status_name = strzone(ReadString());
1405         }
1406 }
1407
1408 NET_HANDLE(TE_CSQC_RACE, bool isNew)
1409 {
1410         Net_ReadRace();
1411         return true;
1412 }
1413
1414 NET_HANDLE(TE_CSQC_TEAMNAGGER, bool isNew)
1415 {
1416         teamnagger = 1;
1417         return true;
1418 }
1419
1420 void Net_ReadPingPLReport()
1421 {
1422         int e, pi, pl, ml;
1423         e = ReadByte();
1424         pi = ReadShort();
1425         pl = ReadByte();
1426         ml = ReadByte();
1427         if (!(playerslots[e]))
1428                 return;
1429         playerslots[e].ping = pi;
1430         playerslots[e].ping_packetloss = pl / 255.0;
1431         playerslots[e].ping_movementloss = ml / 255.0;
1432 }
1433 NET_HANDLE(TE_CSQC_PINGPLREPORT, bool isNew)
1434 {
1435         Net_ReadPingPLReport();
1436         return true;
1437 }
1438
1439 void Net_WeaponComplain()
1440 {
1441         complain_weapon = ReadByte();
1442
1443         if(complain_weapon_name)
1444                 strunzone(complain_weapon_name);
1445         complain_weapon_name = strzone(WEP_NAME(complain_weapon));
1446
1447         complain_weapon_type = ReadByte();
1448
1449         complain_weapon_time = time;
1450         weapontime = time; // ping the weapon panel
1451
1452         switch(complain_weapon_type)
1453         {
1454                 case 0: Local_Notification(MSG_MULTI, ITEM_WEAPON_NOAMMO, complain_weapon); break;
1455                 case 1: Local_Notification(MSG_MULTI, ITEM_WEAPON_DONTHAVE, complain_weapon); break;
1456                 default: Local_Notification(MSG_MULTI, ITEM_WEAPON_UNAVAILABLE, complain_weapon); break;
1457         }
1458 }
1459 NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew)
1460 {
1461         Net_WeaponComplain();
1462         return true;
1463 }
1464
1465 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1466 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1467 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1468 bool CSQC_Parse_TempEntity()
1469 {
1470         // Acquire TE ID
1471         int nTEID = ReadByte();
1472
1473         FOREACH(TempEntities, it.m_id == nTEID, LAMBDA(
1474                 if (autocvar_developer_csqcentities)
1475                         LOG_INFOF("CSQC_Parse_TempEntity() nTEID=%s (%d)\n", it.netname, nTEID);
1476                 return it.m_read(NULL, true);
1477         ));
1478
1479         if (autocvar_developer_csqcentities)
1480                 LOG_INFOF("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID);
1481
1482         // No special logic for this temporary entity; return 0 so the engine can handle it
1483         return false;
1484 }
1485
1486 string getcommandkey(string text, string command)
1487 {
1488         string keys;
1489         float n, j, k, l = 0;
1490
1491         if (!autocvar_hud_showbinds)
1492                 return text;
1493
1494         keys = db_get(binddb, command);
1495         if (keys == "")
1496         {
1497                 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1498                 for(j = 0; j < n; ++j)
1499                 {
1500                         k = stof(argv(j));
1501                         if(k != -1)
1502                         {
1503                                 if ("" == keys)
1504                                         keys = keynumtostring(k);
1505                                 else
1506                                         keys = strcat(keys, ", ", keynumtostring(k));
1507
1508                                 ++l;
1509                                 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit <= l)
1510                                         break;
1511                         }
1512
1513                 }
1514                 if (keys == "")
1515                         keys = "NO_KEY";
1516                 db_put(binddb, command, keys);
1517         }
1518
1519         if (keys == "NO_KEY") {
1520                 if (autocvar_hud_showbinds > 1)
1521                         return sprintf(_("%s (not bound)"), text);
1522                 else
1523                         return text;
1524         }
1525         else if (autocvar_hud_showbinds > 1)
1526                 return sprintf("%s (%s)", text, keys);
1527         else
1528                 return keys;
1529 }