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