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