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