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