]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/Main.qc
Merge branch 'master' into terencehill/quickmenu
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / Main.qc
1 // --------------------------------------------------------------------------
2 // BEGIN REQUIRED CSQC FUNCTIONS
3 //include "main.qh"
4
5 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
6
7 void cvar_clientsettemp(string cv, string val)
8 {
9         entity e;
10         for(e = world; (e = find(e, classname, "saved_cvar_value")); )
11                 if(e.netname == cv)
12                         goto saved;
13         e = spawn();
14         e.classname = "saved_cvar_value";
15         e.netname = strzone(cv);
16         e.message = strzone(cvar_string(cv));
17 :saved
18         cvar_set(cv, val);
19 }
20
21 void cvar_clientsettemp_restore()
22 {
23         entity e;
24         for(e = world; (e = find(e, classname, "saved_cvar_value")); )
25                         cvar_set(e.netname, e.message);
26 }
27
28 void menu_show_error()
29 {
30         drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
31 }
32
33 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
34 // Useful for precaching things
35
36 void menu_sub_null()
37 {
38 }
39
40 #ifdef USE_FTE
41 float __engine_check;
42 #endif
43
44 string forcefog;
45 void WaypointSprite_Load();
46 void CSQC_Init(void)
47 {
48         prvm_language = cvar_string("prvm_language");
49
50 #ifdef USE_FTE
51 #pragma target ID
52         __engine_check = checkextension("DP_SV_WRITEPICTURE");
53         if(!__engine_check)
54         {
55                 print(_("^3Your engine build is outdated\n^3This Server uses a newer QC VM. Please update!\n"));
56                 localcmd("\ndisconnect\n");
57                 return;
58         }
59 #pragma target FTE
60 #endif
61
62         check_unacceptable_compiler_bugs();
63
64 #ifdef WATERMARK
65         print(sprintf(_("^4CSQC Build information: ^1%s\n"), WATERMARK()));
66 #endif
67
68         float i;
69
70 #ifdef COMPAT_XON050_ENGINE
71         // old engine lacks implementation of player_localnum
72         player_localnum = player_localentnum - 1;
73 #endif
74
75         binddb = db_create();
76         tempdb = db_create();
77         ClientProgsDB = db_load("client.db");
78         compressShortVector_init();
79
80         drawfont = FONT_USER+1;
81         menu_visible = FALSE;
82         menu_show = menu_show_error;
83         menu_action = menu_sub_null;
84
85         for(i = 0; i < 255; ++i)
86                 if(getplayerkeyvalue(i, "viewentity") == "")
87                         break;
88         maxclients = i;
89
90         registercommand("hud_configure");
91         registercommand("hud_save");
92         //registercommand("menu_action");
93
94         registercommand("+showscores");registercommand("-showscores");
95         registercommand("+showaccuracy");registercommand("-showaccuracy");
96
97 #ifndef CAMERATEST
98         if(isdemo())
99         {
100 #endif
101                 registercommand("+forward");registercommand("-forward");
102                 registercommand("+back");registercommand("-back");
103                 registercommand("+moveup");registercommand("-moveup");
104                 registercommand("+movedown");registercommand("-movedown");
105                 registercommand("+moveright");registercommand("-moveright");
106                 registercommand("+moveleft");registercommand("-moveleft");
107                 registercommand("+roll_right");registercommand("-roll_right");
108                 registercommand("+roll_left");registercommand("-roll_left");
109 #ifndef CAMERATEST
110         }
111 #endif
112         registercvar("hud_usecsqc", "1");
113         registercvar("scoreboard_columns", "default");
114
115         gametype = 0;
116
117         // hud_fields uses strunzone on the titles!
118         for(i = 0; i < MAX_HUD_FIELDS; ++i)
119                 hud_title[i] = strzone("(null)");
120
121         postinit = false;
122
123         calledhooks = 0;
124
125         teams = Sort_Spawn();
126         players = Sort_Spawn();
127
128         GetTeam(COLOR_SPECTATOR, true); // add specs first
129
130         RegisterWeapons();
131
132         WaypointSprite_Load();
133
134         // precaches
135         precache_model("null");
136         precache_sound("misc/hit.wav");
137         precache_sound("misc/typehit.wav");
138         Projectile_Precache();
139         Hook_Precache();
140         GibSplash_Precache();
141         Casings_Precache();
142         DamageInfo_Precache();
143         Vehicles_Precache();
144         turrets_precache();
145   Announcer_Precache();
146         Tuba_Precache();
147         
148         if(autocvar_cl_reticle)
149         {
150                 if(autocvar_cl_reticle_item_normal) { precache_pic("gfx/reticle_normal"); }
151                 if(autocvar_cl_reticle_item_nex) { precache_pic("gfx/reticle_nex"); }
152         }
153         
154         get_mi_min_max_texcoords(1); // try the CLEVER way first
155         minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
156         shortmapname = mi_shortname;
157
158         if(precache_pic(minimapname) == "")
159         {
160                 // but maybe we have a non-clever minimap
161                 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
162                 if(precache_pic(minimapname) == "")
163                         minimapname = ""; // FAIL
164                 else
165                         get_mi_min_max_texcoords(0); // load new texcoords
166         }
167
168         mi_center = (mi_min + mi_max) * 0.5;
169         mi_scale = mi_max - mi_min;
170         minimapname = strzone(minimapname);
171
172         WarpZone_Init();
173
174         hud_configure_prev = -1;
175         tab_panel = -1;
176 }
177
178 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
179 void CSQC_Shutdown(void)
180 {
181 #ifdef USE_FTE
182 #pragma TARGET id
183         if(!__engine_check)
184                 return 0;
185 #pragma TARGET fte
186 #endif
187
188         WarpZone_Shutdown();
189
190         remove(teams);
191         remove(players);
192         db_close(binddb);
193         db_close(tempdb);
194         if(autocvar_cl_db_saveasdump)
195                 db_dump(ClientProgsDB, "client.db");
196         else
197                 db_save(ClientProgsDB, "client.db");
198         db_close(ClientProgsDB);
199
200         cvar_clientsettemp_restore();
201
202         if(camera_active)
203                 cvar_set("chase_active",ftos(chase_active_backup));
204
205         // unset the event chasecam's chase_active
206         if(autocvar_chase_active < 0)
207                 cvar_set("chase_active", "0");
208
209         if not(isdemo())
210         {
211                 if not(calledhooks & HOOK_START)
212                         localcmd("\n_cl_hook_gamestart nop\n");
213                 if not(calledhooks & HOOK_END)
214                         localcmd("\ncl_hook_gameend\n");
215         }
216 }
217
218 .float has_team;
219 float SetTeam(entity o, float Team)
220 {
221         entity tm;
222         if(teamplay)
223         {
224                 switch(Team)
225                 {
226                         case -1:
227                         case COLOR_TEAM1:
228                         case COLOR_TEAM2:
229                         case COLOR_TEAM3:
230                         case COLOR_TEAM4:
231                                 break;
232                         default:
233                                 if(GetTeam(Team, false) == world)
234                                 {
235                                         print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
236                                         Team = COLOR_SPECTATOR;
237                                 }
238                                 break;
239                 }
240         }
241         else
242         {
243                 switch(Team)
244                 {
245                         case -1:
246                         case 0:
247                                 break;
248                         default:
249                                 if(GetTeam(Team, false) == world)
250                                 {
251                                         print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
252                                         Team = COLOR_SPECTATOR;
253                                 }
254                                 break;
255                 }
256         }
257         if(Team == -1) // leave
258         {
259                 if(o.has_team)
260                 {
261                         tm = GetTeam(o.team, false);
262                         tm.team_size -= 1;
263                         o.has_team = 0;
264                         return TRUE;
265                 }
266         }
267         else
268         {
269                 if not(o.has_team)
270                 {
271                         o.team = Team;
272                         tm = GetTeam(Team, true);
273                         tm.team_size += 1;
274                         o.has_team = 1;
275                         return TRUE;
276                 }
277                 else if(Team != o.team)
278                 {
279                         tm = GetTeam(o.team, false);
280                         tm.team_size -= 1;
281                         o.team = Team;
282                         tm = GetTeam(Team, true);
283                         tm.team_size += 1;
284                         return TRUE;
285                 }
286         }
287         return FALSE;
288 }
289
290 void Playerchecker_Think()
291 {
292         float i;
293         entity e;
294         for(i = 0; i < maxclients; ++i)
295         {
296                 e = playerslots[i];
297                 if(GetPlayerName(i) == "")
298                 {
299                         if(e.sort_prev)
300                         {
301                                 // player disconnected
302                                 SetTeam(e, -1);
303                                 RemovePlayer(e);
304                                 e.sort_prev = world;
305                                 //e.gotscores = 0;
306                         }
307                 }
308                 else
309                 {
310                         if not(e.sort_prev)
311                         {
312                                 // player connected
313                                 if not(e)
314                                         playerslots[i] = e = spawn();
315                                 e.sv_entnum = i;
316                                 e.ping = 0;
317                                 e.ping_packetloss = 0;
318                                 e.ping_movementloss = 0;
319                                 //e.gotscores = 0; // we might already have the scores...
320                                 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
321                                 RegisterPlayer(e);
322                                 HUD_UpdatePlayerPos(e);
323                         }
324                 }
325         }
326         self.nextthink = time + 0.2;
327 }
328
329 void Porto_Init();
330 void TrueAim_Init();
331 void PostInit(void)
332 {
333         localcmd(strcat("\nscoreboard_columns_set ", autocvar_scoreboard_columns, ";\n"));
334
335         entity playerchecker;
336         playerchecker = spawn();
337         playerchecker.think = Playerchecker_Think;
338         playerchecker.nextthink = time + 0.2;
339
340         Porto_Init();
341         TrueAim_Init();
342
343         postinit = true;
344 }
345
346 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercommand" function
347 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
348 float button_zoom;
349 void Cmd_HUD_SetFields(float);
350 void Cmd_HUD_Help(float);
351 float CSQC_ConsoleCommand(string strMessage)
352 {
353         float argc;
354         // Tokenize String
355         argc = tokenize_console(strMessage);
356
357         // Acquire Command
358         string strCmd;
359         strCmd = argv(0);
360
361         if(strCmd == "hud_configure") { // config hud
362                 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
363                 return true;
364         } else if(strCmd == "hud_save") { // save hud config
365                 if(argv(1) == "" || argv(2)) {
366                         print(_("Usage:\n"));
367                         print(_("hud_save configname   (saves to hud_skinname_configname.cfg)\n"));
368                 }
369                 else
370                         HUD_Panel_ExportCfg(argv(1));
371                 return true;
372         } else if(strCmd == "+showscores") {
373                 scoreboard_showscores = true;
374                 return true;
375         } else if(strCmd == "-showscores") {
376                 scoreboard_showscores = false;
377                 return true;
378         } else if(strCmd == "+showaccuracy") {
379                 scoreboard_showaccuracy = true;
380                 return true;
381         } else if(strCmd == "-showaccuracy") {
382                 scoreboard_showaccuracy = false;
383                 return true;
384         }
385
386         if(camera_active)
387         if(strCmd == "+forward" || strCmd == "-back") {
388                 ++camera_direction_x;
389                 return true;
390         } else if(strCmd == "-forward" || strCmd == "+back") {
391                 --camera_direction_x;
392                 return true;
393         } else if(strCmd == "+moveright" || strCmd == "-moveleft") {
394                 --camera_direction_y;
395                 return true;
396         } else if(strCmd == "-moveright" || strCmd == "+moveleft") {
397                 ++camera_direction_y;
398                 return true;
399         } else if(strCmd == "+moveup" || strCmd == "-movedown") {
400                 ++camera_direction_z;
401                 return true;
402         } else if(strCmd == "-moveup" || strCmd == "+movedown") {
403                 --camera_direction_z;
404                 return true;
405         } else if(strCmd == "+roll_right" || strCmd == "-roll_left") {
406                 ++camera_roll;
407                 return true;
408         } else if(strCmd == "+roll_left" || strCmd == "-roll_right") {
409                 --camera_roll;
410                 return true;
411         }
412
413         return false;
414 }
415
416 .vector view_ofs;
417 entity debug_shotorg;
418 void ShotOrg_Draw()
419 {
420         self.origin = view_origin + view_forward * self.view_ofs_x + view_right * self.view_ofs_y + view_up * self.view_ofs_z;
421         self.angles = view_angles;
422         self.angles_x = -self.angles_x;
423         if not(self.cnt)
424                 self.drawmask = MASK_NORMAL;
425         else
426                 self.drawmask = 0;
427 }
428 void ShotOrg_Draw2D()
429 {
430         vector coord2d_topleft, coord2d_topright, coord2d;
431         string s;
432         vector fs;
433
434         s = vtos(self.view_ofs);
435         s = substring(s, 1, strlen(s) - 2);
436         if(tokenize_console(s) == 3)
437                 s = strcat(argv(0), " ", argv(1), " ", argv(2));
438
439         coord2d_topleft = project_3d_to_2d(self.origin + view_up * 4 - view_right * 4);
440         coord2d_topright = project_3d_to_2d(self.origin + view_up * 4 + view_right * 4);
441
442         fs = '1 1 0' * ((coord2d_topright_x - coord2d_topleft_x) / stringwidth(s, FALSE, '8 8 0'));
443
444         coord2d = coord2d_topleft;
445         if(fs_x < 8)
446         {
447                 coord2d_x += (coord2d_topright_x - coord2d_topleft_x) * (1 - 8 / fs_x) * 0.5;
448                 fs = '8 8 0';
449         }
450         coord2d_y -= fs_y;
451         coord2d_z = 0;
452         drawstring(coord2d, s, fs, '1 1 1', 1, 0);
453 }
454
455 void ShotOrg_Spawn()
456 {
457         debug_shotorg = spawn();
458         debug_shotorg.draw = ShotOrg_Draw;
459         debug_shotorg.draw2d = ShotOrg_Draw2D;
460         debug_shotorg.renderflags = RF_VIEWMODEL;
461         debug_shotorg.effects = EF_FULLBRIGHT;
462         precache_model("models/shotorg_adjuster.md3");
463         setmodel(debug_shotorg, "models/shotorg_adjuster.md3");
464         debug_shotorg.scale = 2;
465         debug_shotorg.view_ofs = '25 8 -8';
466 }
467
468 void DrawDebugModel()
469 {
470         if(time - floor(time) > 0.5)
471         {
472                 PolyDrawModel(self);
473                 self.drawmask = 0;
474         }
475         else
476         {
477                 self.renderflags = 0;
478                 self.drawmask = MASK_NORMAL;
479         }
480 }
481
482 void GameCommand(string msg)
483 {
484         string s;
485         float argc;
486         entity e;
487         argc = tokenize_console(msg);
488
489         if(argv(0) == "help" || argc == 0)
490         {
491                 print(_("Usage: cl_cmd COMMAND..., where possible commands are:\n"));
492                 print(_("  settemp cvar value\n"));
493                 print(_("  scoreboard_columns_set ...\n"));
494                 print(_("  scoreboard_columns_help\n"));
495                 GameCommand_Generic("help");
496                 return;
497         }
498
499         if(GameCommand_Generic(msg))
500                 return;
501
502         string cmd;
503         cmd = argv(0);
504         if(cmd == "mv_download") {
505                 Cmd_MapVote_MapDownload(argc);
506         }
507         else if(cmd == "hud_panel_radar_maximized")
508         {
509                 if(argc == 1)
510                         hud_panel_radar_maximized = !hud_panel_radar_maximized;
511                 else
512                         hud_panel_radar_maximized = (stof(argv(1)) != 0);
513         }
514         else if(cmd == "hud_panel_quickmenu")
515         {
516                 if(argc == 1 && HUD_QuickMenu_IsOpened())
517                         HUD_QuickMenu_Close();
518                 else
519                         if (HUD_QuickMenu_Buffer_Init())
520                                 HUD_QuickMenu_Open("", 0);
521         }
522         else if(cmd == "settemp") {
523                 cvar_clientsettemp(argv(1), argv(2));
524         }
525         else if(cmd == "scoreboard_columns_set") {
526                 Cmd_HUD_SetFields(argc);
527         }
528         else if(cmd == "scoreboard_columns_help") {
529                 Cmd_HUD_Help(argc);
530         }
531 #ifdef BLURTEST
532         else if(cmd == "blurtest") {
533                 blurtest_time0 = time;
534                 blurtest_time1 = time + stof(argv(1));
535                 blurtest_radius = stof(argv(2));
536                 blurtest_power = stof(argv(3));
537         }
538 #endif
539         else if(cmd == "shotorg_move") {
540                 if(!debug_shotorg)
541                         ShotOrg_Spawn();
542                 else
543                         debug_shotorg.view_ofs = debug_shotorg.view_ofs + stov(argv(1));
544                 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
545         }
546         else if(cmd == "shotorg_movez") {
547                 if(!debug_shotorg)
548                         ShotOrg_Spawn();
549                 else
550                         debug_shotorg.view_ofs = debug_shotorg.view_ofs + stof(argv(1)) * (debug_shotorg.view_ofs * (1 / debug_shotorg.view_ofs_x)); // closer/farther, same xy pos
551                 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
552         }
553         else if(cmd == "shotorg_set") {
554                 if(!debug_shotorg)
555                         ShotOrg_Spawn();
556                 else
557                         debug_shotorg.view_ofs = stov(argv(1));
558                 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
559         }
560         else if(cmd == "shotorg_setz") {
561                 if(!debug_shotorg)
562                         ShotOrg_Spawn();
563                 else
564                         debug_shotorg.view_ofs = debug_shotorg.view_ofs * (stof(argv(1)) / debug_shotorg.view_ofs_x); // closer/farther, same xy pos
565                 localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
566         }
567         else if(cmd == "shotorg_toggle_hide") {
568                 if(debug_shotorg)
569                 {
570                         debug_shotorg.cnt = !debug_shotorg.cnt;
571                 }
572         }
573         else if(cmd == "shotorg_end") {
574                 if(debug_shotorg)
575                 {
576                         print(vtos(debug_shotorg.view_ofs), "\n");
577                         remove(debug_shotorg);
578                         debug_shotorg = world;
579                 }
580                 localcmd("sv_cmd debug_shotorg\n");
581         }
582         else if(cmd == "sendcvar") {
583                 // W_FixWeaponOrder will trash argv, so save what we need.
584                 string thiscvar;
585                 thiscvar = strzone(argv(1));
586                 s = cvar_string(thiscvar);
587                 if(thiscvar == "cl_weaponpriority")
588                         s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
589                 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
590                         s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
591                 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
592                 strunzone(thiscvar);
593         }
594         else if(cmd == "spawn") {
595                 s = argv(1);
596                 e = spawn();
597                 precache_model(s);
598                 setmodel(e, s);
599                 setorigin(e, view_origin);
600                 e.angles = view_angles;
601                 e.draw = DrawDebugModel;
602                 e.classname = "debugmodel";
603         }
604     else if(cmd == "vyes")
605     {
606         if(uid2name_dialog)
607         {
608             vote_active = 0; // force the panel to disappear right as we have selected the value (to prevent it from fading out in the normal vote panel pos)
609             vote_prev = 0;
610             localcmd("setreport cl_allow_uid2name 1\n");
611             vote_change = -9999;
612                         uid2name_dialog = 0;
613         }
614         else
615         {
616             localcmd("cmd vote yes\n");
617         }
618     }
619     else if(cmd == "vno")
620     {
621         if(uid2name_dialog)
622         {
623             vote_active = 0;
624             vote_prev = 0;
625             localcmd("setreport cl_allow_uid2name 0\n");
626             vote_change = -9999;
627                         uid2name_dialog = 0;
628         }
629         else
630         {
631             localcmd("cmd vote no\n");
632         }
633     }
634
635         else
636         {
637                 print("Invalid command. For a list of supported commands, try cl_cmd help.\n");
638         }
639
640         return;
641 }
642
643 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
644 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
645 // All keys are in ascii.
646 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
647 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
648 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
649 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
650 {
651         float bSkipKey;
652         bSkipKey = false;
653
654         if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
655                 return true;
656
657         if (HUD_QuickMenu_InputEvent(bInputType, nPrimary, nSecondary))
658                 return true;
659
660         if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
661                 return true;
662
663         if(menu_visible)
664                 if(menu_action(bInputType, nPrimary, nSecondary))
665                         return TRUE;
666
667         return bSkipKey;
668 }
669
670 // END REQUIRED CSQC FUNCTIONS
671 // --------------------------------------------------------------------------
672
673 // --------------------------------------------------------------------------
674 // BEGIN OPTIONAL CSQC FUNCTIONS
675 void Ent_RemoveEntCS()
676 {
677         entcs_receiver[self.sv_entnum] = world;
678 }
679 void Ent_ReadEntCS()
680 {
681         float sf;
682         InterpolateOrigin_Undo();
683
684         self.classname = "entcs_receiver";
685         sf = ReadByte();
686
687         if(sf & 1)
688                 self.sv_entnum = ReadByte();
689         if(sf & 2)
690         {
691                 self.origin_x = ReadShort();
692                 self.origin_y = ReadShort();
693                 self.origin_z = ReadShort();
694         }
695         if(sf & 4)
696         {
697                 self.angles_y = ReadByte() * 360.0 / 256;
698                 self.angles_x = self.angles_z = 0;
699         }
700         if(sf & 8)
701                 self.healthvalue = ReadByte() * 10;
702         if(sf & 16)
703                 self.armorvalue = ReadByte() * 10;
704
705         entcs_receiver[self.sv_entnum] = self;
706         self.entremove = Ent_RemoveEntCS;
707
708         InterpolateOrigin_Note();
709 }
710
711 void Ent_Remove();
712
713 void Ent_RemovePlayerScore()
714 {
715         float i;
716
717         if(self.owner)
718         {
719                 SetTeam(self.owner, -1);
720                 self.owner.gotscores = 0;
721                 for(i = 0; i < MAX_SCORE; ++i)
722                         self.owner.(scores[i]) = 0; // clear all scores
723         }
724 }
725
726 void Ent_ReadPlayerScore()
727 {
728         float i, n;
729         float isNew;
730         entity o;
731
732         // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
733         // (no I've never heard of M-x replace-string, sed, or anything like that)
734         isNew = !self.owner; // workaround for DP bug
735         n = ReadByte()-1;
736
737 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
738         if(!isNew && n != self.sv_entnum)
739         {
740                 //print(_("A CSQC entity changed its owner!\n"));
741                 print(sprintf(_("A CSQC entity changed its owner! (edict: %d, classname: %s)\n"), num_for_edict(self), self.classname));
742                 isNew = true;
743                 Ent_Remove();
744                 self.enttype = ENT_CLIENT_SCORES;
745         }
746 #endif
747
748         self.sv_entnum = n;
749
750         if not(playerslots[self.sv_entnum])
751                 playerslots[self.sv_entnum] = spawn();
752         o = self.owner = playerslots[self.sv_entnum];
753         o.sv_entnum = self.sv_entnum;
754         o.gotscores = 1;
755
756         //if not(o.sort_prev)
757         //      RegisterPlayer(o);
758         //playerchecker will do this for us later, if it has not already done so
759
760         float sf, lf;
761 #if MAX_SCORE <= 8
762         sf = ReadByte();
763         lf = ReadByte();
764 #else
765         sf = ReadShort();
766         lf = ReadShort();
767 #endif
768         float p;
769         for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
770                 if(sf & p)
771                 {
772                         if(lf & p)
773                                 o.(scores[i]) = ReadInt24_t();
774                         else
775                                 o.(scores[i]) = ReadChar();
776                 }
777
778         if(o.sort_prev)
779                 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
780
781         self.entremove = Ent_RemovePlayerScore;
782 }
783
784 void Ent_ReadTeamScore()
785 {
786         float i;
787         entity o;
788
789         self.team = ReadByte();
790         o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
791
792         float sf, lf;
793 #if MAX_TEAMSCORE <= 8
794         sf = ReadByte();
795         lf = ReadByte();
796 #else
797         sf = ReadShort();
798         lf = ReadShort();
799 #endif
800         float p;
801         for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
802                 if(sf & p)
803                 {
804                         if(lf & p)
805                                 o.(teamscores[i]) = ReadInt24_t();
806                         else
807                                 o.(teamscores[i]) = ReadChar();
808                 }
809
810         HUD_UpdateTeamPos(o);
811 }
812
813 void Ent_ClientData()
814 {
815         float f;
816         float newspectatee_status;
817
818         f = ReadByte();
819
820         scoreboard_showscores_force = (f & 1);
821
822         if(f & 2)
823         {
824                 newspectatee_status = ReadByte();
825                 if(newspectatee_status == player_localnum + 1)
826                         newspectatee_status = -1; // observing
827         }
828         else
829                 newspectatee_status = 0;
830
831         spectatorbutton_zoom = (f & 4);
832
833         if(f & 8)
834         {
835                 angles_held_status = 1;
836                 angles_held_x = ReadAngle();
837                 angles_held_y = ReadAngle();
838                 angles_held_z = 0;
839         }
840         else
841                 angles_held_status = 0;
842
843         if(newspectatee_status != spectatee_status)
844         {
845                 // clear race stuff
846                 race_laptime = 0;
847                 race_checkpointtime = 0;
848         }
849         if (autocvar_hud_panel_healtharmor_progressbar_gfx)
850         {
851                 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
852                   || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
853                 )
854                         prev_p_health = -1;
855                 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
856                         prev_health = -1;
857         }
858         spectatee_status = newspectatee_status;
859
860         // non-COMPAT_XON050_ENGINE: we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
861 }
862
863 void Ent_Nagger()
864 {
865         float nags, i, j, b, f;
866
867         nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
868
869         if(!(nags & 4))
870         {
871                 if(vote_called_vote)
872                         strunzone(vote_called_vote);
873                 vote_called_vote = string_null;
874                 vote_active = 0;
875         }
876         else
877         {
878                 vote_active = 1;
879         }
880
881         if(nags & 64)
882         {
883                 vote_yescount = ReadByte();
884                 vote_nocount = ReadByte();
885                 vote_needed = ReadByte();
886                 vote_highlighted = ReadChar();
887         }
888
889         if(nags & 128)
890         {
891                 if(vote_called_vote)
892                         strunzone(vote_called_vote);
893                 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
894         }
895
896         if(nags & 1)
897         {
898                 for(j = 0; j < maxclients; ++j)
899                         if(playerslots[j])
900                                 playerslots[j].ready = 1;
901                 for(i = 1; i <= maxclients; i += 8)
902                 {
903                         f = ReadByte();
904                         for(j = i-1, b = 1; b < 256; b *= 2, ++j)
905                                 if not(f & b)
906                                         if(playerslots[j])
907                                                 playerslots[j].ready = 0;
908                 }
909         }
910
911         ready_waiting = (nags & 1);
912         ready_waiting_for_me = (nags & 2);
913         vote_waiting = (nags & 4);
914         vote_waiting_for_me = (nags & 8);
915         warmup_stage = (nags & 16);
916 }
917
918 void Ent_RandomSeed()
919 {
920         float s;
921         prandom_debug();
922         s = ReadShort();
923         psrandom(s);
924 }
925
926 void Ent_ReadAccuracy(void)
927 {
928         float sf, f, w, b;
929         sf = ReadInt24_t();
930         if(sf == 0)
931         {
932                 for(w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
933                         weapon_accuracy[w] = -1;
934                 return;
935         }
936
937         for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w, f *= 2)
938         {
939                 if(sf & f)
940                 {
941                         b = ReadByte();
942                         if(b == 0)
943                                 weapon_accuracy[w] = -1;
944                         else if(b == 255)
945                                 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
946                         else
947                                 weapon_accuracy[w] = (b - 1.0) / 100.0;
948                 }
949         }
950 }
951
952 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
953 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
954 void Ent_RadarLink();
955 void Ent_Init();
956 void Ent_ScoresInfo();
957 void CSQC_Ent_Update(float bIsNewEntity)
958 {
959         float t;
960         float savetime;
961         t = ReadByte();
962
963         // set up the "time" global for received entities to be correct for interpolation purposes
964         savetime = time;
965         if(servertime)
966         {
967                 time = servertime;
968         }
969         else
970         {
971                 serverprevtime = time;
972                 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
973                 time = serverprevtime + serverdeltatime;
974         }
975
976 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
977         if(self.enttype)
978         {
979                 if(t != self.enttype || bIsNewEntity)
980                 {
981                         //print(_("A CSQC entity changed its type!\n"));
982                         print(sprintf(_("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n"), num_for_edict(self), self.entnum, self.enttype, t));
983                         Ent_Remove();
984                         bIsNewEntity = 1;
985                 }
986         }
987         else
988         {
989                 if(!bIsNewEntity)
990                 {
991                         print(sprintf(_("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n"), num_for_edict(self), self.entnum, t));
992                         bIsNewEntity = 1;
993                 }
994         }
995 #endif
996         self.enttype = t;
997         switch(t)
998         {
999                 case ENT_CLIENT_ENTCS: Ent_ReadEntCS(); break;
1000                 case ENT_CLIENT_SCORES: Ent_ReadPlayerScore(); break;
1001                 case ENT_CLIENT_TEAMSCORES: Ent_ReadTeamScore(); break;
1002                 case ENT_CLIENT_POINTPARTICLES: Ent_PointParticles(); break;
1003                 case ENT_CLIENT_RAINSNOW: Ent_RainOrSnow(); break;
1004                 case ENT_CLIENT_LASER: Ent_Laser(); break;
1005                 case ENT_CLIENT_NAGGER: Ent_Nagger(); break;
1006                 case ENT_CLIENT_WAYPOINT: Ent_WaypointSprite(); break;
1007                 case ENT_CLIENT_RADARLINK: Ent_RadarLink(); break;
1008                 case ENT_CLIENT_PROJECTILE: Ent_Projectile(); break;
1009                 case ENT_CLIENT_GIBSPLASH: Ent_GibSplash(bIsNewEntity); break;
1010                 case ENT_CLIENT_DAMAGEINFO: Ent_DamageInfo(bIsNewEntity); break;
1011                 case ENT_CLIENT_CASING: Ent_Casing(bIsNewEntity); break;
1012                 case ENT_CLIENT_INIT: Ent_Init(); break;
1013                 case ENT_CLIENT_SCORES_INFO: Ent_ScoresInfo(); break;
1014                 case ENT_CLIENT_MAPVOTE: Ent_MapVote(); break;
1015                 case ENT_CLIENT_CLIENTDATA: Ent_ClientData(); break;
1016                 case ENT_CLIENT_RANDOMSEED: Ent_RandomSeed(); break;
1017                 case ENT_CLIENT_WALL: Ent_Wall(); break;
1018                 case ENT_CLIENT_MODELEFFECT: Ent_ModelEffect(bIsNewEntity); break;
1019                 case ENT_CLIENT_TUBANOTE: Ent_TubaNote(bIsNewEntity); break;
1020                 case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;
1021                 case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;
1022                 case ENT_CLIENT_WARPZONE_TELEPORTED: WarpZone_Teleported_Read(bIsNewEntity); break;
1023                 case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;
1024                 case ENT_CLIENT_HOOK: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_HOOK); break;
1025                 case ENT_CLIENT_LGBEAM: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_LGBEAM); break;
1026                 case ENT_CLIENT_GAUNTLET: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_GAUNTLET); break;
1027                 case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
1028                 case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
1029                 case ENT_CLIENT_TURRET: ent_turret(); break; 
1030                 default:
1031                         //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
1032                         error(sprintf(_("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n"), self.enttype, num_for_edict(self), self.classname));
1033                         break;
1034         }
1035
1036         time = savetime;
1037 }
1038 // Destructor, but does NOT deallocate the entity by calling remove(). Also
1039 // used when an entity changes its type. For an entity that someone interacts
1040 // with others, make sure it can no longer do so.
1041 void Ent_Remove()
1042 {
1043         if(self.entremove)
1044                 self.entremove();
1045
1046         self.enttype = 0;
1047         self.classname = "";
1048         self.draw = menu_sub_null;
1049         self.entremove = menu_sub_null;
1050         // TODO possibly set more stuff to defaults
1051 }
1052 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.
1053 void CSQC_Ent_Remove()
1054 {
1055         if(self.enttype)
1056                 Ent_Remove();
1057         remove(self);
1058 }
1059
1060 void Gamemode_Init()
1061 {
1062         if not(isdemo())
1063         {
1064                 localcmd("\n_cl_hook_gamestart ", GametypeNameFromType(gametype), "\n");
1065                 calledhooks |= HOOK_START;
1066         }
1067 }
1068 // 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.
1069 void CSQC_Parse_StuffCmd(string strMessage)
1070 {
1071         localcmd(strMessage);
1072 }
1073 // 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.
1074 void CSQC_Parse_Print(string strMessage)
1075 {
1076         print(ColorTranslateRGB(strMessage));
1077 }
1078
1079 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
1080 void CSQC_Parse_CenterPrint(string strMessage)
1081 {
1082         centerprint_hud(strMessage);
1083 }
1084
1085 string notranslate_fogcmd1 = "\nfog ";
1086 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
1087 void Fog_Force()
1088 {
1089         // TODO somehow thwart prvm_globalset client ...
1090
1091         if(forcefog != "")
1092                 localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2));
1093 }
1094
1095 void Gamemode_Init();
1096 void Ent_ScoresInfo()
1097 {
1098         float i;
1099         self.classname = "ent_client_scores_info";
1100         gametype = ReadByte();
1101         for(i = 0; i < MAX_SCORE; ++i)
1102         {
1103                 scores_label[i] = strzone(ReadString());
1104                 scores_flags[i] = ReadByte();
1105         }
1106         for(i = 0; i < MAX_TEAMSCORE; ++i)
1107         {
1108                 teamscores_label[i] = strzone(ReadString());
1109                 teamscores_flags[i] = ReadByte();
1110         }
1111         HUD_InitScores();
1112         Gamemode_Init();
1113 }
1114
1115 void Ent_Init()
1116 {
1117         self.classname = "ent_client_init";
1118
1119         nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
1120
1121         hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1122         hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1123         hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1124         hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1125         electro_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1126         electro_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1127         electro_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1128         electro_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1129         gauntlet_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1130         gauntlet_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1131         gauntlet_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1132         gauntlet_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1133
1134         if(forcefog)
1135                 strunzone(forcefog);
1136         forcefog = strzone(ReadString());
1137
1138         armorblockpercent = ReadByte() / 255.0;
1139
1140         g_weaponswitchdelay = ReadByte() / 255.0;
1141
1142         g_balance_grenadelauncher_bouncefactor = ReadCoord();
1143         g_balance_grenadelauncher_bouncestop = ReadCoord();
1144         g_balance_electro_secondary_bouncefactor = ReadCoord();
1145         g_balance_electro_secondary_bouncestop = ReadCoord();
1146
1147         nex_scope = !ReadByte();
1148         rifle_scope = !ReadByte();
1149
1150         serverflags = ReadByte();
1151
1152         minelayer_maxmines = ReadByte();
1153
1154         hagar_maxrockets = ReadByte();
1155
1156         g_trueaim_minrange = ReadCoord();
1157
1158         if(!postinit)
1159                 PostInit();
1160 }
1161
1162 void Net_ReadRace()
1163 {
1164         float b;
1165
1166         b = ReadByte();
1167
1168         switch(b)
1169         {
1170                 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1171                         race_checkpoint = ReadByte();
1172                         race_time = ReadInt24_t();
1173                         race_previousbesttime = ReadInt24_t();
1174                         if(race_previousbestname)
1175                                 strunzone(race_previousbestname);
1176                         race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
1177
1178                         race_checkpointtime = time;
1179
1180                         if(race_checkpoint == 0 || race_checkpoint == 254)
1181                         {
1182                                 race_penaltyaccumulator = 0;
1183                                 race_laptime = time; // valid
1184                         }
1185
1186                         break;
1187
1188                 case RACE_NET_CHECKPOINT_CLEAR:
1189                         race_laptime = 0;
1190                         race_checkpointtime = 0;
1191                         break;
1192
1193                 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1194                         race_laptime = ReadCoord();
1195                         race_checkpointtime = -99999;
1196                         // fall through
1197                 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1198                         race_nextcheckpoint = ReadByte();
1199
1200                         race_nextbesttime = ReadInt24_t();
1201                         if(race_nextbestname)
1202                                 strunzone(race_nextbestname);
1203                         race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1204                         break;
1205
1206                 case RACE_NET_CHECKPOINT_HIT_RACE:
1207                         race_mycheckpoint = ReadByte();
1208                         race_mycheckpointtime = time;
1209                         race_mycheckpointdelta = ReadInt24_t();
1210                         race_mycheckpointlapsdelta = ReadByte();
1211                         if(race_mycheckpointlapsdelta >= 128)
1212                                 race_mycheckpointlapsdelta -= 256;
1213                         if(race_mycheckpointenemy)
1214                                 strunzone(race_mycheckpointenemy);
1215                         race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1216                         break;
1217
1218                 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1219                         race_othercheckpoint = ReadByte();
1220                         race_othercheckpointtime = time;
1221                         race_othercheckpointdelta = ReadInt24_t();
1222                         race_othercheckpointlapsdelta = ReadByte();
1223                         if(race_othercheckpointlapsdelta >= 128)
1224                                 race_othercheckpointlapsdelta -= 256;
1225                         if(race_othercheckpointenemy)
1226                                 strunzone(race_othercheckpointenemy);
1227                         race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1228                         break;
1229
1230                 case RACE_NET_PENALTY_RACE:
1231                         race_penaltyeventtime = time;
1232                         race_penaltytime = ReadShort();
1233                         //race_penaltyaccumulator += race_penaltytime;
1234                         if(race_penaltyreason)
1235                                 strunzone(race_penaltyreason);
1236                         race_penaltyreason = strzone(ReadString());
1237                         break;
1238
1239                 case RACE_NET_PENALTY_QUALIFYING:
1240                         race_penaltyeventtime = time;
1241                         race_penaltytime = ReadShort();
1242                         race_penaltyaccumulator += race_penaltytime;
1243                         if(race_penaltyreason)
1244                                 strunzone(race_penaltyreason);
1245                         race_penaltyreason = strzone(ReadString());
1246                         break;
1247
1248                 case RACE_NET_SERVER_RECORD:
1249                         race_server_record = ReadInt24_t();
1250                         break;
1251                 case RACE_NET_SPEED_AWARD:
1252                         race_speedaward = ReadInt24_t();
1253                         if(race_speedaward_holder)
1254                                 strunzone(race_speedaward_holder);
1255                         race_speedaward_holder = strzone(ReadString());
1256                         break;
1257                 case RACE_NET_SPEED_AWARD_BEST:
1258                         race_speedaward_alltimebest = ReadInt24_t();
1259                         if(race_speedaward_alltimebest_holder)
1260                                 strunzone(race_speedaward_alltimebest_holder);
1261                         race_speedaward_alltimebest_holder = strzone(ReadString());
1262                         break;
1263                 case RACE_NET_SERVER_RANKINGS:
1264                         float pos, prevpos, del;
1265                         pos = ReadShort();
1266                         prevpos = ReadShort();
1267                         del = ReadShort();
1268
1269                         // move other rankings out of the way
1270                         float i;
1271                         if (prevpos) {
1272                                 for (i=prevpos-1;i>pos-1;--i) {
1273                                         grecordtime[i] = grecordtime[i-1];
1274                                         if(grecordholder[i])
1275                                                 strunzone(grecordholder[i]);
1276                                         grecordholder[i] = strzone(grecordholder[i-1]);
1277                                 }
1278                         } else if (del) { // a record has been deleted by the admin
1279                                 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1280                                         if (i == RANKINGS_CNT-1) { // clear out last record
1281                                                 grecordtime[i] = 0;
1282                                                 if (grecordholder[i])
1283                                                         strunzone(grecordholder[i]);
1284                                                 grecordholder[i] = string_null;
1285                                         }
1286                                         else {
1287                                                 grecordtime[i] = grecordtime[i+1];
1288                                                 if (grecordholder[i])
1289                                                         strunzone(grecordholder[i]);
1290                                                 grecordholder[i] = strzone(grecordholder[i+1]);
1291                                         }
1292                                 }
1293                         } else { // player has no ranked record yet
1294                                 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1295                                         grecordtime[i] = grecordtime[i-1];
1296                                         if(grecordholder[i])
1297                                                 strunzone(grecordholder[i]);
1298                                         grecordholder[i] = strzone(grecordholder[i-1]);
1299                                 }
1300                         }
1301
1302                         // store new ranking
1303                         if(grecordholder[pos-1] != "")
1304                                 strunzone(grecordholder[pos-1]);
1305                         grecordholder[pos-1] = strzone(ReadString());
1306                         grecordtime[pos-1] = ReadInt24_t();
1307                         if(grecordholder[pos-1] == GetPlayerName(player_localnum))
1308                                 race_myrank = pos;
1309                         break;
1310                 case RACE_NET_SERVER_STATUS:
1311                         race_status = ReadShort();
1312                         if(race_status_name)
1313                                 strunzone(race_status_name);
1314                         race_status_name = strzone(ReadString());
1315         }
1316 }
1317
1318 void Net_ReadSpawn()
1319 {
1320         zoomin_effect = 1;
1321         current_viewzoom = 0.6;
1322 }
1323
1324 void Net_TeamNagger()
1325 {
1326         teamnagger = 1;
1327 }
1328
1329 void Net_ReadPingPLReport()
1330 {
1331         float e, pi, pl, ml;
1332         e = ReadByte();
1333         pi = ReadShort();
1334         pl = ReadByte();
1335         ml = ReadByte();
1336         if not(playerslots[e])
1337                 return;
1338         playerslots[e].ping = pi;
1339         playerslots[e].ping_packetloss = pl / 255.0;
1340         playerslots[e].ping_movementloss = ml / 255.0;
1341 }
1342
1343 void Net_WeaponComplain() {
1344         complain_weapon = ReadByte();
1345
1346         if(complain_weapon_name)
1347                 strunzone(complain_weapon_name);
1348         complain_weapon_name = strzone(ReadString());
1349
1350         complain_weapon_type = ReadByte();
1351
1352         complain_weapon_time = time;
1353         weapontime = time; // ping the weapon panel
1354 }
1355
1356 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1357 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1358 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1359 float CSQC_Parse_TempEntity()
1360 {
1361         float bHandled;
1362                 bHandled  = true;
1363         // Acquire TE ID
1364         float nTEID;
1365                 nTEID = ReadByte();
1366
1367                 // NOTE: Could just do return instead of break...
1368         switch(nTEID)
1369         {
1370                 case TE_CSQC_TARGET_MUSIC:
1371                         Net_TargetMusic();
1372                         bHandled = true;
1373                         break;
1374                 case TE_CSQC_PICTURE:
1375                         Net_MapVote_Picture();
1376                         bHandled = true;
1377                         break;
1378                 case TE_CSQC_RACE:
1379                         Net_ReadRace();
1380                         bHandled = true;
1381                         break;
1382                 case TE_CSQC_SPAWN:
1383                         Net_ReadSpawn();
1384                         bHandled = true;
1385                         break;
1386                 case TE_CSQC_ZCURVEPARTICLES:
1387                         Net_ReadZCurveParticles();
1388                         bHandled = true;
1389                         break;
1390                 case TE_CSQC_NEXGUNBEAMPARTICLE:
1391                         Net_ReadNexgunBeamParticle();
1392                         bHandled = true;
1393                         break;
1394                 case TE_CSQC_TEAMNAGGER:
1395                         Net_TeamNagger();
1396                         bHandled = true;
1397                         break;
1398                 case TE_CSQC_LIGHTNINGARC:
1399                         Net_ReadLightningarc();
1400                         bHandled = true;
1401                         break;
1402                 case TE_CSQC_PINGPLREPORT:
1403                         Net_ReadPingPLReport();
1404                         bHandled = true;
1405                         break;
1406                 case TE_CSQC_ANNOUNCE:
1407                         Announcer_Play(ReadString());
1408                         bHandled = true;
1409                         break;
1410                 case TE_CSQC_KILLNOTIFY:
1411                         HUD_KillNotify(ReadString(), ReadString(), ReadString(), ReadShort(), ReadByte());
1412                         bHandled = true;
1413                         break;
1414                 case TE_CSQC_KILLCENTERPRINT:
1415                         HUD_KillCenterprint(ReadString(), ReadString(), ReadShort(), ReadByte());
1416                         bHandled = true;
1417                         break;
1418                 case TE_CSQC_CENTERPRINT_GENERIC:
1419                         float id;
1420                         string s;
1421                         id = ReadByte();
1422                         s = ReadString();
1423                         if (id != 0 && s != "")
1424                                 centerprint_generic(id, s, ReadByte(), ReadByte());
1425                         else
1426                                 centerprint_generic(id, s, 0, 0);
1427                         bHandled = true;
1428                         break;
1429                 case TE_CSQC_WEAPONCOMPLAIN:
1430                         Net_WeaponComplain();
1431                         bHandled = true;
1432                         break;
1433                 case TE_CSQC_VEHICLESETUP:
1434                         Net_VehicleSetup();
1435                         bHandled = true;
1436                         break;
1437                 default:
1438                         // No special logic for this temporary entity; return 0 so the engine can handle it
1439                         bHandled = false;
1440                         break;
1441         }
1442
1443         return bHandled;
1444 }
1445
1446 string getcommandkey(string text, string command)
1447 {
1448         string keys;
1449         float n, j, k, l;
1450
1451         if (!autocvar_hud_showbinds)
1452                 return text;
1453
1454         keys = db_get(binddb, command);
1455         if (!keys)
1456         {
1457                 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1458                 for(j = 0; j < n; ++j)
1459                 {
1460                         k = stof(argv(j));
1461                         if(k != -1)
1462                         {
1463                                 if ("" == keys)
1464                                         keys = keynumtostring(k);
1465                                 else
1466                                         keys = strcat(keys, ", ", keynumtostring(k));
1467
1468                                 ++l;
1469                                 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit >= l) break;
1470                         }
1471
1472                 }
1473                 db_put(binddb, command, keys);
1474         }
1475
1476         if ("" == keys) {
1477                 if (autocvar_hud_showbinds > 1)
1478                         return sprintf(_("%s (not bound)"), text);
1479                 else
1480                         return text;
1481         }
1482         else if (autocvar_hud_showbinds > 1)
1483                 return sprintf(_("%s (%s)"), text, keys);
1484         else
1485                 return keys;
1486 }