]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/Main.qc
Merge remote branch 'origin/master' into samual/menu_updates
[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_MODEL: CSQCModel_Read(bIsNewEntity); break; 
1053                 default:
1054                         //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
1055                         error(sprintf(_("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n"), self.enttype, num_for_edict(self), self.classname));
1056                         break;
1057         }
1058
1059         time = savetime;
1060 }
1061 // Destructor, but does NOT deallocate the entity by calling remove(). Also
1062 // used when an entity changes its type. For an entity that someone interacts
1063 // with others, make sure it can no longer do so.
1064 void Ent_Remove()
1065 {
1066         if(self.entremove)
1067                 self.entremove();
1068
1069         self.enttype = 0;
1070         self.classname = "";
1071         self.draw = menu_sub_null;
1072         self.entremove = menu_sub_null;
1073         // TODO possibly set more stuff to defaults
1074 }
1075 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.
1076 void CSQC_Ent_Remove()
1077 {
1078         if(self.enttype)
1079                 Ent_Remove();
1080         remove(self);
1081 }
1082
1083 void Gamemode_Init()
1084 {
1085         if not(isdemo())
1086         {
1087                 localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
1088                 calledhooks |= HOOK_START;
1089         }
1090 }
1091 // 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.
1092 void CSQC_Parse_StuffCmd(string strMessage)
1093 {
1094         localcmd(strMessage);
1095 }
1096 // 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.
1097 void CSQC_Parse_Print(string strMessage)
1098 {
1099         print(ColorTranslateRGB(strMessage));
1100 }
1101
1102 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
1103 void CSQC_Parse_CenterPrint(string strMessage)
1104 {
1105         centerprint_hud(strMessage);
1106 }
1107
1108 string notranslate_fogcmd1 = "\nfog ";
1109 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
1110 void Fog_Force()
1111 {
1112         // TODO somehow thwart prvm_globalset client ...
1113
1114         if(forcefog != "")
1115                 localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2));
1116 }
1117
1118 void Gamemode_Init();
1119 void Ent_ScoresInfo()
1120 {
1121         float i;
1122         self.classname = "ent_client_scores_info";
1123         gametype = ReadInt24_t();
1124         for(i = 0; i < MAX_SCORE; ++i)
1125         {
1126                 scores_label[i] = strzone(ReadString());
1127                 scores_flags[i] = ReadByte();
1128         }
1129         for(i = 0; i < MAX_TEAMSCORE; ++i)
1130         {
1131                 teamscores_label[i] = strzone(ReadString());
1132                 teamscores_flags[i] = ReadByte();
1133         }
1134         HUD_InitScores();
1135         Gamemode_Init();
1136 }
1137
1138 void Ent_Init()
1139 {
1140         self.classname = "ent_client_init";
1141
1142         nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
1143
1144         hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1145         hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1146         hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1147         hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1148         electro_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1149         electro_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1150         electro_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1151         electro_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1152         gauntlet_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
1153         gauntlet_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
1154         gauntlet_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
1155         gauntlet_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
1156
1157         if(forcefog)
1158                 strunzone(forcefog);
1159         forcefog = strzone(ReadString());
1160
1161         armorblockpercent = ReadByte() / 255.0;
1162
1163         g_weaponswitchdelay = ReadByte() / 255.0;
1164
1165         g_balance_grenadelauncher_bouncefactor = ReadCoord();
1166         g_balance_grenadelauncher_bouncestop = ReadCoord();
1167         g_balance_electro_secondary_bouncefactor = ReadCoord();
1168         g_balance_electro_secondary_bouncestop = ReadCoord();
1169
1170         nex_scope = !ReadByte();
1171         rifle_scope = !ReadByte();
1172
1173         serverflags = ReadByte();
1174
1175         minelayer_maxmines = ReadByte();
1176
1177         hagar_maxrockets = ReadByte();
1178
1179         g_trueaim_minrange = ReadCoord();
1180
1181         if(!postinit)
1182                 PostInit();
1183 }
1184
1185 void Net_ReadRace()
1186 {
1187         float b;
1188
1189         b = ReadByte();
1190
1191         switch(b)
1192         {
1193                 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
1194                         race_checkpoint = ReadByte();
1195                         race_time = ReadInt24_t();
1196                         race_previousbesttime = ReadInt24_t();
1197                         if(race_previousbestname)
1198                                 strunzone(race_previousbestname);
1199                         race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
1200
1201                         race_checkpointtime = time;
1202
1203                         if(race_checkpoint == 0 || race_checkpoint == 254)
1204                         {
1205                                 race_penaltyaccumulator = 0;
1206                                 race_laptime = time; // valid
1207                         }
1208
1209                         break;
1210
1211                 case RACE_NET_CHECKPOINT_CLEAR:
1212                         race_laptime = 0;
1213                         race_checkpointtime = 0;
1214                         break;
1215
1216                 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1217                         race_laptime = ReadCoord();
1218                         race_checkpointtime = -99999;
1219                         // fall through
1220                 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1221                         race_nextcheckpoint = ReadByte();
1222
1223                         race_nextbesttime = ReadInt24_t();
1224                         if(race_nextbestname)
1225                                 strunzone(race_nextbestname);
1226                         race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1227                         break;
1228
1229                 case RACE_NET_CHECKPOINT_HIT_RACE:
1230                         race_mycheckpoint = ReadByte();
1231                         race_mycheckpointtime = time;
1232                         race_mycheckpointdelta = ReadInt24_t();
1233                         race_mycheckpointlapsdelta = ReadByte();
1234                         if(race_mycheckpointlapsdelta >= 128)
1235                                 race_mycheckpointlapsdelta -= 256;
1236                         if(race_mycheckpointenemy)
1237                                 strunzone(race_mycheckpointenemy);
1238                         race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1239                         break;
1240
1241                 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1242                         race_othercheckpoint = ReadByte();
1243                         race_othercheckpointtime = time;
1244                         race_othercheckpointdelta = ReadInt24_t();
1245                         race_othercheckpointlapsdelta = ReadByte();
1246                         if(race_othercheckpointlapsdelta >= 128)
1247                                 race_othercheckpointlapsdelta -= 256;
1248                         if(race_othercheckpointenemy)
1249                                 strunzone(race_othercheckpointenemy);
1250                         race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1251                         break;
1252
1253                 case RACE_NET_PENALTY_RACE:
1254                         race_penaltyeventtime = time;
1255                         race_penaltytime = ReadShort();
1256                         //race_penaltyaccumulator += race_penaltytime;
1257                         if(race_penaltyreason)
1258                                 strunzone(race_penaltyreason);
1259                         race_penaltyreason = strzone(ReadString());
1260                         break;
1261
1262                 case RACE_NET_PENALTY_QUALIFYING:
1263                         race_penaltyeventtime = time;
1264                         race_penaltytime = ReadShort();
1265                         race_penaltyaccumulator += race_penaltytime;
1266                         if(race_penaltyreason)
1267                                 strunzone(race_penaltyreason);
1268                         race_penaltyreason = strzone(ReadString());
1269                         break;
1270
1271                 case RACE_NET_SERVER_RECORD:
1272                         race_server_record = ReadInt24_t();
1273                         break;
1274                 case RACE_NET_SPEED_AWARD:
1275                         race_speedaward = ReadInt24_t();
1276                         if(race_speedaward_holder)
1277                                 strunzone(race_speedaward_holder);
1278                         race_speedaward_holder = strzone(ReadString());
1279                         break;
1280                 case RACE_NET_SPEED_AWARD_BEST:
1281                         race_speedaward_alltimebest = ReadInt24_t();
1282                         if(race_speedaward_alltimebest_holder)
1283                                 strunzone(race_speedaward_alltimebest_holder);
1284                         race_speedaward_alltimebest_holder = strzone(ReadString());
1285                         break;
1286                 case RACE_NET_SERVER_RANKINGS:
1287                         float pos, prevpos, del;
1288                         pos = ReadShort();
1289                         prevpos = ReadShort();
1290                         del = ReadShort();
1291
1292                         // move other rankings out of the way
1293                         float i;
1294                         if (prevpos) {
1295                                 for (i=prevpos-1;i>pos-1;--i) {
1296                                         grecordtime[i] = grecordtime[i-1];
1297                                         if(grecordholder[i])
1298                                                 strunzone(grecordholder[i]);
1299                                         grecordholder[i] = strzone(grecordholder[i-1]);
1300                                 }
1301                         } else if (del) { // a record has been deleted by the admin
1302                                 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1303                                         if (i == RANKINGS_CNT-1) { // clear out last record
1304                                                 grecordtime[i] = 0;
1305                                                 if (grecordholder[i])
1306                                                         strunzone(grecordholder[i]);
1307                                                 grecordholder[i] = string_null;
1308                                         }
1309                                         else {
1310                                                 grecordtime[i] = grecordtime[i+1];
1311                                                 if (grecordholder[i])
1312                                                         strunzone(grecordholder[i]);
1313                                                 grecordholder[i] = strzone(grecordholder[i+1]);
1314                                         }
1315                                 }
1316                         } else { // player has no ranked record yet
1317                                 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1318                                         grecordtime[i] = grecordtime[i-1];
1319                                         if(grecordholder[i])
1320                                                 strunzone(grecordholder[i]);
1321                                         grecordholder[i] = strzone(grecordholder[i-1]);
1322                                 }
1323                         }
1324
1325                         // store new ranking
1326                         if(grecordholder[pos-1] != "")
1327                                 strunzone(grecordholder[pos-1]);
1328                         grecordholder[pos-1] = strzone(ReadString());
1329                         grecordtime[pos-1] = ReadInt24_t();
1330                         if(grecordholder[pos-1] == GetPlayerName(player_localnum))
1331                                 race_myrank = pos;
1332                         break;
1333                 case RACE_NET_SERVER_STATUS:
1334                         race_status = ReadShort();
1335                         if(race_status_name)
1336                                 strunzone(race_status_name);
1337                         race_status_name = strzone(ReadString());
1338         }
1339 }
1340
1341 void Net_ReadSpawn()
1342 {
1343         zoomin_effect = 1;
1344         current_viewzoom = 0.6;
1345 }
1346
1347 void Net_TeamNagger()
1348 {
1349         teamnagger = 1;
1350 }
1351
1352 void Net_ReadPingPLReport()
1353 {
1354         float e, pi, pl, ml;
1355         e = ReadByte();
1356         pi = ReadShort();
1357         pl = ReadByte();
1358         ml = ReadByte();
1359         if not(playerslots[e])
1360                 return;
1361         playerslots[e].ping = pi;
1362         playerslots[e].ping_packetloss = pl / 255.0;
1363         playerslots[e].ping_movementloss = ml / 255.0;
1364 }
1365
1366 void Net_WeaponComplain() {
1367         complain_weapon = ReadByte();
1368
1369         if(complain_weapon_name)
1370                 strunzone(complain_weapon_name);
1371         complain_weapon_name = strzone(ReadString());
1372
1373         complain_weapon_type = ReadByte();
1374
1375         complain_weapon_time = time;
1376         weapontime = time; // ping the weapon panel
1377 }
1378
1379 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1380 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1381 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1382 float CSQC_Parse_TempEntity()
1383 {
1384         float bHandled;
1385                 bHandled  = true;
1386         // Acquire TE ID
1387         float nTEID;
1388                 nTEID = ReadByte();
1389
1390                 // NOTE: Could just do return instead of break...
1391         switch(nTEID)
1392         {
1393                 case TE_CSQC_TARGET_MUSIC:
1394                         Net_TargetMusic();
1395                         bHandled = true;
1396                         break;
1397                 case TE_CSQC_PICTURE:
1398                         Net_MapVote_Picture();
1399                         bHandled = true;
1400                         break;
1401                 case TE_CSQC_RACE:
1402                         Net_ReadRace();
1403                         bHandled = true;
1404                         break;
1405                 case TE_CSQC_SPAWN:
1406                         Net_ReadSpawn();
1407                         bHandled = true;
1408                         break;
1409                 case TE_CSQC_ZCURVEPARTICLES:
1410                         Net_ReadZCurveParticles();
1411                         bHandled = true;
1412                         break;
1413                 case TE_CSQC_NEXGUNBEAMPARTICLE:
1414                         Net_ReadNexgunBeamParticle();
1415                         bHandled = true;
1416                         break;
1417                 case TE_CSQC_TEAMNAGGER:
1418                         Net_TeamNagger();
1419                         bHandled = true;
1420                         break;
1421                 case TE_CSQC_LIGHTNINGARC:
1422                         Net_ReadLightningarc();
1423                         bHandled = true;
1424                         break;
1425                 case TE_CSQC_PINGPLREPORT:
1426                         Net_ReadPingPLReport();
1427                         bHandled = true;
1428                         break;
1429                 case TE_CSQC_ANNOUNCE:
1430                         Announcer_Play(ReadString());
1431                         bHandled = true;
1432                         break;
1433                 case TE_CSQC_KILLNOTIFY:
1434                         HUD_KillNotify(ReadString(), ReadString(), ReadString(), ReadShort(), ReadByte());
1435                         bHandled = true;
1436                         break;
1437                 case TE_CSQC_KILLCENTERPRINT:
1438                         HUD_KillCenterprint(ReadString(), ReadString(), ReadShort(), ReadByte());
1439                         bHandled = true;
1440                         break;
1441                 case TE_CSQC_CENTERPRINT_GENERIC:
1442                         float id;
1443                         string s;
1444                         id = ReadByte();
1445                         s = ReadString();
1446                         if (id != 0 && s != "")
1447                                 centerprint_generic(id, s, ReadByte(), ReadByte());
1448                         else
1449                                 centerprint_generic(id, s, 0, 0);
1450                         bHandled = true;
1451                         break;
1452                 case TE_CSQC_WEAPONCOMPLAIN:
1453                         Net_WeaponComplain();
1454                         bHandled = true;
1455                         break;
1456                 case TE_CSQC_VEHICLESETUP:
1457                         Net_VehicleSetup();
1458                         bHandled = true;
1459                         break;
1460                 default:
1461                         // No special logic for this temporary entity; return 0 so the engine can handle it
1462                         bHandled = false;
1463                         break;
1464         }
1465
1466         return bHandled;
1467 }
1468
1469 string getcommandkey(string text, string command)
1470 {
1471         string keys;
1472         float n, j, k, l;
1473
1474         if (!autocvar_hud_showbinds)
1475                 return text;
1476
1477         keys = db_get(binddb, command);
1478         if (!keys)
1479         {
1480                 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1481                 for(j = 0; j < n; ++j)
1482                 {
1483                         k = stof(argv(j));
1484                         if(k != -1)
1485                         {
1486                                 if ("" == keys)
1487                                         keys = keynumtostring(k);
1488                                 else
1489                                         keys = strcat(keys, ", ", keynumtostring(k));
1490
1491                                 ++l;
1492                                 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit >= l) break;
1493                         }
1494
1495                 }
1496                 db_put(binddb, command, keys);
1497         }
1498
1499         if ("" == keys) {
1500                 if (autocvar_hud_showbinds > 1)
1501                         return sprintf(_("%s (not bound)"), text);
1502                 else
1503                         return text;
1504         }
1505         else if (autocvar_hud_showbinds > 1)
1506                 return sprintf(_("%s (%s)"), text, keys);
1507         else
1508                 return keys;
1509 }