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