]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/Main.qc
a4f118371cfb586f4237fa0360ed662a8e9a4649
[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 void menu_show_error()
7 {
8         drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
9 }
10
11 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
12 // Useful for precaching things
13
14 void menu_sub_null()
15 {
16 }
17
18 #ifdef USE_FTE
19 float __engine_check;
20 #endif
21
22 string forcefog;
23 void WaypointSprite_Load();
24 void CSQC_Init(void)
25 {
26         prvm_language = cvar_string("prvm_language");
27
28 #ifdef USE_FTE
29 #pragma target ID
30         __engine_check = checkextension("DP_SV_WRITEPICTURE");
31         if(!__engine_check)
32         {
33                 print(_("^3Your engine build is outdated\n^3This Server uses a newer QC VM. Please update!\n"));
34                 localcmd("\ndisconnect\n");
35                 return;
36         }
37 #pragma target FTE
38 #endif
39
40         check_unacceptable_compiler_bugs();
41
42 #ifdef WATERMARK
43         print(sprintf(_("^4CSQC Build information: ^1%s\n"), WATERMARK()));
44 #endif
45
46         float i;
47
48         binddb = db_create();
49         tempdb = db_create();
50         ClientProgsDB = db_load("client.db");
51         compressShortVector_init();
52
53         drawfont = FONT_USER+1;
54         menu_visible = FALSE;
55         menu_show = menu_show_error;
56         menu_action = menu_sub_null;
57
58         for(i = 0; i < 255; ++i)
59                 if(getplayerkey(i, "viewentity") == "")
60                         break;
61         maxclients = i;
62
63         //registercmd("hud_configure");
64         //registercmd("hud_save");
65         //registercmd("menu_action");
66
67         registercvar("hud_usecsqc", "1");
68         registercvar("scoreboard_columns", "default", CVAR_SAVE);
69
70         gametype = 0;
71
72         // hud_fields uses strunzone on the titles!
73         for(i = 0; i < MAX_HUD_FIELDS; ++i)
74                 hud_title[i] = strzone("(null)");
75
76         postinit = false;
77
78         calledhooks = 0;
79
80         teams = Sort_Spawn();
81         players = Sort_Spawn();
82
83         GetTeam(COLOR_SPECTATOR, true); // add specs first
84
85         RegisterWeapons();
86
87         WaypointSprite_Load();
88
89         // precaches
90         precache_sound("misc/hit.wav");
91         precache_sound("misc/typehit.wav");
92         Projectile_Precache();
93         Hook_Precache();
94         GibSplash_Precache();
95         Casings_Precache();
96         DamageInfo_Precache();
97         Vehicles_Precache();
98         turrets_precache();
99   Announcer_Precache();
100         Tuba_Precache();
101         
102         if(autocvar_cl_reticle)
103         {
104                 if(autocvar_cl_reticle_item_normal) { precache_pic("gfx/reticle_normal"); }
105                 if(autocvar_cl_reticle_item_nex) { precache_pic("gfx/reticle_nex"); }
106         }
107         
108         get_mi_min_max_texcoords(1); // try the CLEVER way first
109         minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
110         shortmapname = mi_shortname;
111
112         if(precache_pic(minimapname) == "")
113         {
114                 // but maybe we have a non-clever minimap
115                 minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
116                 if(precache_pic(minimapname) == "")
117                         minimapname = ""; // FAIL
118                 else
119                         get_mi_min_max_texcoords(0); // load new texcoords
120         }
121
122         mi_center = (mi_min + mi_max) * 0.5;
123         mi_scale = mi_max - mi_min;
124         minimapname = strzone(minimapname);
125
126         WarpZone_Init();
127
128         hud_configure_prev = -1;
129         tab_panel = -1;
130 }
131
132 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
133 void cvar_clientsettemp_restore();
134 void CSQC_Shutdown(void)
135 {
136 #ifdef USE_FTE
137 #pragma TARGET id
138         if(!__engine_check)
139                 return 0;
140 #pragma TARGET fte
141 #endif
142
143         WarpZone_Shutdown();
144
145         remove(teams);
146         remove(players);
147         db_close(binddb);
148         db_close(tempdb);
149         if(autocvar_cl_db_saveasdump)
150                 db_dump(ClientProgsDB, "client.db");
151         else
152                 db_save(ClientProgsDB, "client.db");
153         db_close(ClientProgsDB);
154
155         cvar_clientsettemp_restore();
156
157         if(camera_active)
158                 cvar_set("chase_active",ftos(chase_active_backup));
159
160         // unset the event chasecam's chase_active
161         if(autocvar_chase_active < 0)
162                 cvar_set("chase_active", "0");
163
164         if not(isdemo())
165         {
166                 if not(calledhooks & HOOK_START)
167                         localcmd("\n_cl_hook_gamestart nop\n");
168                 if not(calledhooks & HOOK_END)
169                         localcmd("\ncl_hook_gameend\n");
170         }
171 }
172
173 .float has_team;
174 float SetTeam(entity o, float Team)
175 {
176         entity tm;
177         if(teamplay)
178         {
179                 switch(Team)
180                 {
181                         case -1:
182                         case COLOR_TEAM1:
183                         case COLOR_TEAM2:
184                         case COLOR_TEAM3:
185                         case COLOR_TEAM4:
186                                 break;
187                         default:
188                                 if(GetTeam(Team, false) == NULL)
189                                 {
190                                         print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
191                                         Team = COLOR_SPECTATOR;
192                                 }
193                                 break;
194                 }
195         }
196         else
197         {
198                 switch(Team)
199                 {
200                         case -1:
201                         case 0:
202                                 break;
203                         default:
204                                 if(GetTeam(Team, false) == NULL)
205                                 {
206                                         print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
207                                         Team = COLOR_SPECTATOR;
208                                 }
209                                 break;
210                 }
211         }
212         if(Team == -1) // leave
213         {
214                 if(o.has_team)
215                 {
216                         tm = GetTeam(o.team, false);
217                         tm.team_size -= 1;
218                         o.has_team = 0;
219                         return TRUE;
220                 }
221         }
222         else
223         {
224                 if not(o.has_team)
225                 {
226                         o.team = Team;
227                         tm = GetTeam(Team, true);
228                         tm.team_size += 1;
229                         o.has_team = 1;
230                         return TRUE;
231                 }
232                 else if(Team != o.team)
233                 {
234                         tm = GetTeam(o.team, false);
235                         tm.team_size -= 1;
236                         o.team = Team;
237                         tm = GetTeam(Team, true);
238                         tm.team_size += 1;
239                         return TRUE;
240                 }
241         }
242         return FALSE;
243 }
244
245 void Playerchecker_Think()
246 {
247         float i;
248         entity e;
249         for(i = 0; i < maxclients; ++i)
250         {
251                 e = playerslots[i];
252                 if(GetPlayerName(i) == "")
253                 {
254                         if(e.sort_prev)
255                         {
256                                 // player disconnected
257                                 SetTeam(e, -1);
258                                 RemovePlayer(e);
259                                 e.sort_prev = world;
260                                 //e.gotscores = 0;
261                         }
262                 }
263                 else
264                 {
265                         if not(e.sort_prev)
266                         {
267                                 // player connected
268                                 if not(e)
269                                         playerslots[i] = e = spawn();
270                                 e.sv_entnum = i;
271                                 e.ping = 0;
272                                 e.ping_packetloss = 0;
273                                 e.ping_movementloss = 0;
274                                 //e.gotscores = 0; // we might already have the scores...
275                                 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
276                                 RegisterPlayer(e);
277                                 HUD_UpdatePlayerPos(e);
278                         }
279                 }
280         }
281         self.nextthink = time + 0.2;
282 }
283
284 void Porto_Init();
285 void TrueAim_Init();
286 void PostInit(void)
287 {
288         localcmd(strcat("\nscoreboard_columns_set ", autocvar_scoreboard_columns, ";\n"));
289
290         entity playerchecker;
291         playerchecker = spawn();
292         playerchecker.think = Playerchecker_Think;
293         playerchecker.nextthink = time + 0.2;
294
295         Porto_Init();
296         TrueAim_Init();
297
298         postinit = true;
299 }
300
301 float button_zoom;
302
303 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
304 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
305 // All keys are in ascii.
306 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
307 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
308 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
309 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
310 {
311         float bSkipKey;
312         bSkipKey = false;
313
314         if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
315                 return true;
316
317         if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
318                 return true;
319
320         if(menu_visible)
321                 if(menu_action(bInputType, nPrimary, nSecondary))
322                         return TRUE;
323
324         return bSkipKey;
325 }
326
327 // END REQUIRED CSQC FUNCTIONS
328 // --------------------------------------------------------------------------
329
330 // --------------------------------------------------------------------------
331 // BEGIN OPTIONAL CSQC FUNCTIONS
332 void Ent_RemoveEntCS()
333 {
334         entcs_receiver[self.sv_entnum] = world;
335 }
336 void Ent_ReadEntCS()
337 {
338         float sf;
339         InterpolateOrigin_Undo();
340
341         self.classname = "entcs_receiver";
342         sf = ReadByte();
343
344         if(sf & 1)
345                 self.sv_entnum = ReadByte();
346         if(sf & 2)
347         {
348                 self.origin_x = ReadShort();
349                 self.origin_y = ReadShort();
350                 self.origin_z = ReadShort();
351         }
352         if(sf & 4)
353         {
354                 self.angles_y = ReadByte() * 360.0 / 256;
355                 self.angles_x = self.angles_z = 0;
356         }
357         if(sf & 8)
358                 self.healthvalue = ReadByte() * 10;
359         if(sf & 16)
360                 self.armorvalue = ReadByte() * 10;
361
362         entcs_receiver[self.sv_entnum] = self;
363         self.entremove = Ent_RemoveEntCS;
364
365         InterpolateOrigin_Note();
366 }
367
368 void Ent_Remove();
369
370 void Ent_RemovePlayerScore()
371 {
372         float i;
373
374         if(self.owner)
375         {
376                 SetTeam(self.owner, -1);
377                 self.owner.gotscores = 0;
378                 for(i = 0; i < MAX_SCORE; ++i)
379                         self.owner.(scores[i]) = 0; // clear all scores
380         }
381 }
382
383 void Ent_ReadPlayerScore()
384 {
385         float i, n;
386         float isNew;
387         entity o;
388
389         // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
390         // (no I've never heard of M-x replace-string, sed, or anything like that)
391         isNew = !self.owner; // workaround for DP bug
392         n = ReadByte()-1;
393
394 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
395         if(!isNew && n != self.sv_entnum)
396         {
397                 //print(_("A CSQC entity changed its owner!\n"));
398                 print(sprintf(_("A CSQC entity changed its owner! (edict: %d, classname: %s)\n"), num_for_edict(self), self.classname));
399                 isNew = true;
400                 Ent_Remove();
401                 self.enttype = ENT_CLIENT_SCORES;
402         }
403 #endif
404
405         self.sv_entnum = n;
406
407         if not(playerslots[self.sv_entnum])
408                 playerslots[self.sv_entnum] = spawn();
409         o = self.owner = playerslots[self.sv_entnum];
410         o.sv_entnum = self.sv_entnum;
411         o.gotscores = 1;
412
413         //if not(o.sort_prev)
414         //      RegisterPlayer(o);
415         //playerchecker will do this for us later, if it has not already done so
416
417         float sf, lf;
418 #if MAX_SCORE <= 8
419         sf = ReadByte();
420         lf = ReadByte();
421 #else
422         sf = ReadShort();
423         lf = ReadShort();
424 #endif
425         float p;
426         for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
427                 if(sf & p)
428                 {
429                         if(lf & p)
430                                 o.(scores[i]) = ReadInt24_t();
431                         else
432                                 o.(scores[i]) = ReadChar();
433                 }
434
435         if(o.sort_prev)
436                 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
437
438         self.entremove = Ent_RemovePlayerScore;
439 }
440
441 void Ent_ReadTeamScore()
442 {
443         float i;
444         entity o;
445
446         self.team = ReadByte();
447         o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
448
449         float sf, lf;
450 #if MAX_TEAMSCORE <= 8
451         sf = ReadByte();
452         lf = ReadByte();
453 #else
454         sf = ReadShort();
455         lf = ReadShort();
456 #endif
457         float p;
458         for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
459                 if(sf & p)
460                 {
461                         if(lf & p)
462                                 o.(teamscores[i]) = ReadInt24_t();
463                         else
464                                 o.(teamscores[i]) = ReadChar();
465                 }
466
467         HUD_UpdateTeamPos(o);
468 }
469
470 void Ent_ClientData()
471 {
472         float f;
473         float newspectatee_status;
474
475         f = ReadByte();
476
477         scoreboard_showscores_force = (f & 1);
478
479         if(f & 2)
480         {
481                 newspectatee_status = ReadByte();
482                 if(newspectatee_status == player_localentnum)
483                         newspectatee_status = -1; // observing
484         }
485         else
486                 newspectatee_status = 0;
487
488         spectatorbutton_zoom = (f & 4);
489
490         if(f & 8)
491         {
492                 angles_held_status = 1;
493                 angles_held_x = ReadAngle();
494                 angles_held_y = ReadAngle();
495                 angles_held_z = 0;
496         }
497         else
498                 angles_held_status = 0;
499
500         if(newspectatee_status != spectatee_status)
501         {
502                 // clear race stuff
503                 race_laptime = 0;
504                 race_checkpointtime = 0;
505         }
506         if (autocvar_hud_panel_healtharmor_progressbar_gfx)
507         {
508                 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
509                   || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
510                 )
511                         prev_p_health = -1;
512                 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
513                         prev_health = -1;
514         }
515         spectatee_status = newspectatee_status;
516 }
517
518 void Ent_Nagger()
519 {
520         float nags, i, j, b, f;
521
522         nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
523
524         if(!(nags & 4))
525         {
526                 if(vote_called_vote)
527                         strunzone(vote_called_vote);
528                 vote_called_vote = string_null;
529                 vote_active = 0;
530         }
531         else
532         {
533                 vote_active = 1;
534         }
535
536         if(nags & 64)
537         {
538                 vote_yescount = ReadByte();
539                 vote_nocount = ReadByte();
540                 vote_needed = ReadByte();
541                 vote_highlighted = ReadChar();
542         }
543
544         if(nags & 128)
545         {
546                 if(vote_called_vote)
547                         strunzone(vote_called_vote);
548                 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
549         }
550
551         if(nags & 1)
552         {
553                 for(j = 0; j < maxclients; ++j)
554                         if(playerslots[j])
555                                 playerslots[j].ready = 1;
556                 for(i = 1; i <= maxclients; i += 8)
557                 {
558                         f = ReadByte();
559                         for(j = i-1, b = 1; b < 256; b *= 2, ++j)
560                                 if not(f & b)
561                                         if(playerslots[j])
562                                                 playerslots[j].ready = 0;
563                 }
564         }
565
566         ready_waiting = (nags & 1);
567         ready_waiting_for_me = (nags & 2);
568         vote_waiting = (nags & 4);
569         vote_waiting_for_me = (nags & 8);
570         warmup_stage = (nags & 16);
571 }
572
573 void Ent_RandomSeed()
574 {
575         float s;
576         prandom_debug();
577         s = ReadShort();
578         psrandom(s);
579 }
580
581 void Ent_ReadAccuracy(void)
582 {
583         float sf, f, w, b;
584         sf = ReadInt24_t();
585         if(sf == 0)
586         {
587                 for(w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
588                         weapon_accuracy[w] = -1;
589                 return;
590         }
591
592         for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w, f *= 2)
593         {
594                 if(sf & f)
595                 {
596                         b = ReadByte();
597                         if(b == 0)
598                                 weapon_accuracy[w] = -1;
599                         else if(b == 255)
600                                 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
601                         else
602                                 weapon_accuracy[w] = (b - 1.0) / 100.0;
603                 }
604         }
605 }
606
607 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
608 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
609 void Ent_RadarLink();
610 void Ent_Init();
611 void Ent_ScoresInfo();
612 void CSQC_Ent_Update(float bIsNewEntity)
613 {
614         float t;
615         float savetime;
616         t = ReadByte();
617
618         // set up the "time" global for received entities to be correct for interpolation purposes
619         savetime = time;
620         if(servertime)
621         {
622                 time = servertime;
623         }
624         else
625         {
626                 serverprevtime = time;
627                 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
628                 time = serverprevtime + serverdeltatime;
629         }
630
631 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
632         if(self.enttype)
633         {
634                 if(t != self.enttype || bIsNewEntity)
635                 {
636                         //print(_("A CSQC entity changed its type!\n"));
637                         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));
638                         Ent_Remove();
639                         bIsNewEntity = 1;
640                 }
641         }
642         else
643         {
644                 if(!bIsNewEntity)
645                 {
646                         print(sprintf(_("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n"), num_for_edict(self), self.entnum, t));
647                         bIsNewEntity = 1;
648                 }
649         }
650 #endif
651         self.enttype = t;
652         switch(t)
653         {
654                 case ENT_CLIENT_ENTCS: Ent_ReadEntCS(); break;
655                 case ENT_CLIENT_SCORES: Ent_ReadPlayerScore(); break;
656                 case ENT_CLIENT_TEAMSCORES: Ent_ReadTeamScore(); break;
657                 case ENT_CLIENT_POINTPARTICLES: Ent_PointParticles(); break;
658                 case ENT_CLIENT_RAINSNOW: Ent_RainOrSnow(); break;
659                 case ENT_CLIENT_LASER: Ent_Laser(); break;
660                 case ENT_CLIENT_NAGGER: Ent_Nagger(); break;
661                 case ENT_CLIENT_WAYPOINT: Ent_WaypointSprite(); break;
662                 case ENT_CLIENT_RADARLINK: Ent_RadarLink(); break;
663                 case ENT_CLIENT_PROJECTILE: Ent_Projectile(); break;
664                 case ENT_CLIENT_GIBSPLASH: Ent_GibSplash(bIsNewEntity); break;
665                 case ENT_CLIENT_DAMAGEINFO: Ent_DamageInfo(bIsNewEntity); break;
666                 case ENT_CLIENT_CASING: Ent_Casing(bIsNewEntity); break;
667                 case ENT_CLIENT_INIT: Ent_Init(); break;
668                 case ENT_CLIENT_SCORES_INFO: Ent_ScoresInfo(); break;
669                 case ENT_CLIENT_MAPVOTE: Ent_MapVote(); break;
670                 case ENT_CLIENT_CLIENTDATA: Ent_ClientData(); break;
671                 case ENT_CLIENT_RANDOMSEED: Ent_RandomSeed(); break;
672                 case ENT_CLIENT_WALL: Ent_Wall(); break;
673                 case ENT_CLIENT_MODELEFFECT: Ent_ModelEffect(bIsNewEntity); break;
674                 case ENT_CLIENT_TUBANOTE: Ent_TubaNote(bIsNewEntity); break;
675                 case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;
676                 case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;
677                 case ENT_CLIENT_WARPZONE_TELEPORTED: WarpZone_Teleported_Read(bIsNewEntity); break;
678                 case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;
679                 case ENT_CLIENT_HOOK: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_HOOK); break;
680                 case ENT_CLIENT_LGBEAM: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_LGBEAM); break;
681                 case ENT_CLIENT_GAUNTLET: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_GAUNTLET); break;
682                 case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
683                 case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
684                 case ENT_CLIENT_TURRET: ent_turret(); break; 
685                 default:
686                         //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
687                         error(sprintf(_("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n"), self.enttype, num_for_edict(self), self.classname));
688                         break;
689         }
690
691         time = savetime;
692 }
693 // Destructor, but does NOT deallocate the entity by calling remove(). Also
694 // used when an entity changes its type. For an entity that someone interacts
695 // with others, make sure it can no longer do so.
696 void Ent_Remove()
697 {
698         if(self.entremove)
699                 self.entremove();
700
701         self.enttype = 0;
702         self.classname = "";
703         self.draw = menu_sub_null;
704         self.entremove = menu_sub_null;
705         // TODO possibly set more stuff to defaults
706 }
707 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.
708 void CSQC_Ent_Remove()
709 {
710         if(self.enttype)
711                 Ent_Remove();
712         remove(self);
713 }
714
715 void Gamemode_Init()
716 {
717         if not(isdemo())
718         {
719                 localcmd("\n_cl_hook_gamestart ", GametypeNameFromType(gametype), "\n");
720                 calledhooks |= HOOK_START;
721         }
722 }
723 // 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.
724 void CSQC_Parse_StuffCmd(string strMessage)
725 {
726         localcmd(strMessage);
727 }
728 // 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.
729 void CSQC_Parse_Print(string strMessage)
730 {
731         print(ColorTranslateRGB(strMessage));
732 }
733
734 // CSQC_Parse_CenterPrint : Provides the centerprint string in the first parameter that the server provided.
735 void CSQC_Parse_CenterPrint(string strMessage)
736 {
737         centerprint(strMessage);
738 }
739
740 string notranslate_fogcmd1 = "\nfog ";
741 string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
742 void Fog_Force()
743 {
744         // TODO somehow thwart prvm_globalset client ...
745
746         if(forcefog != "")
747                 localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2));
748 }
749
750 void Gamemode_Init();
751 void Ent_ScoresInfo()
752 {
753         float i;
754         self.classname = "ent_client_scores_info";
755         gametype = ReadByte();
756         for(i = 0; i < MAX_SCORE; ++i)
757         {
758                 scores_label[i] = strzone(ReadString());
759                 scores_flags[i] = ReadByte();
760         }
761         for(i = 0; i < MAX_TEAMSCORE; ++i)
762         {
763                 teamscores_label[i] = strzone(ReadString());
764                 teamscores_flags[i] = ReadByte();
765         }
766         HUD_InitScores();
767         Gamemode_Init();
768 }
769
770 void Ent_Init()
771 {
772         self.classname = "ent_client_init";
773
774         nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
775
776         hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
777         hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
778         hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
779         hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
780         electro_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
781         electro_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
782         electro_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
783         electro_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
784         gauntlet_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
785         gauntlet_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
786         gauntlet_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
787         gauntlet_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
788
789         if(forcefog)
790                 strunzone(forcefog);
791         forcefog = strzone(ReadString());
792
793         armorblockpercent = ReadByte() / 255.0;
794
795         g_weaponswitchdelay = ReadByte() / 255.0;
796
797         g_balance_grenadelauncher_bouncefactor = ReadCoord();
798         g_balance_grenadelauncher_bouncestop = ReadCoord();
799         g_balance_electro_secondary_bouncefactor = ReadCoord();
800         g_balance_electro_secondary_bouncestop = ReadCoord();
801
802         nex_scope = !ReadByte();
803         rifle_scope = !ReadByte();
804
805         serverflags = ReadByte();
806
807         minelayer_maxmines = ReadByte();
808
809         hagar_maxrockets = ReadByte();
810
811         g_trueaim_minrange = ReadCoord();
812
813         if(!postinit)
814                 PostInit();
815 }
816
817 void Net_ReadRace()
818 {
819         float b;
820
821         b = ReadByte();
822
823         switch(b)
824         {
825                 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
826                         race_checkpoint = ReadByte();
827                         race_time = ReadInt24_t();
828                         race_previousbesttime = ReadInt24_t();
829                         if(race_previousbestname)
830                                 strunzone(race_previousbestname);
831                         race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
832
833                         race_checkpointtime = time;
834
835                         if(race_checkpoint == 0 || race_checkpoint == 254)
836                         {
837                                 race_penaltyaccumulator = 0;
838                                 race_laptime = time; // valid
839                         }
840
841                         break;
842
843                 case RACE_NET_CHECKPOINT_CLEAR:
844                         race_laptime = 0;
845                         race_checkpointtime = 0;
846                         break;
847
848                 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
849                         race_laptime = ReadCoord();
850                         race_checkpointtime = -99999;
851                         // fall through
852                 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
853                         race_nextcheckpoint = ReadByte();
854
855                         race_nextbesttime = ReadInt24_t();
856                         if(race_nextbestname)
857                                 strunzone(race_nextbestname);
858                         race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
859                         break;
860
861                 case RACE_NET_CHECKPOINT_HIT_RACE:
862                         race_mycheckpoint = ReadByte();
863                         race_mycheckpointtime = time;
864                         race_mycheckpointdelta = ReadInt24_t();
865                         race_mycheckpointlapsdelta = ReadByte();
866                         if(race_mycheckpointlapsdelta >= 128)
867                                 race_mycheckpointlapsdelta -= 256;
868                         if(race_mycheckpointenemy)
869                                 strunzone(race_mycheckpointenemy);
870                         race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
871                         break;
872
873                 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
874                         race_othercheckpoint = ReadByte();
875                         race_othercheckpointtime = time;
876                         race_othercheckpointdelta = ReadInt24_t();
877                         race_othercheckpointlapsdelta = ReadByte();
878                         if(race_othercheckpointlapsdelta >= 128)
879                                 race_othercheckpointlapsdelta -= 256;
880                         if(race_othercheckpointenemy)
881                                 strunzone(race_othercheckpointenemy);
882                         race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
883                         break;
884
885                 case RACE_NET_PENALTY_RACE:
886                         race_penaltyeventtime = time;
887                         race_penaltytime = ReadShort();
888                         //race_penaltyaccumulator += race_penaltytime;
889                         if(race_penaltyreason)
890                                 strunzone(race_penaltyreason);
891                         race_penaltyreason = strzone(ReadString());
892                         break;
893
894                 case RACE_NET_PENALTY_QUALIFYING:
895                         race_penaltyeventtime = time;
896                         race_penaltytime = ReadShort();
897                         race_penaltyaccumulator += race_penaltytime;
898                         if(race_penaltyreason)
899                                 strunzone(race_penaltyreason);
900                         race_penaltyreason = strzone(ReadString());
901                         break;
902
903                 case RACE_NET_SERVER_RECORD:
904                         race_server_record = ReadInt24_t();
905                         break;
906                 case RACE_NET_SPEED_AWARD:
907                         race_speedaward = ReadInt24_t();
908                         if(race_speedaward_holder)
909                                 strunzone(race_speedaward_holder);
910                         race_speedaward_holder = strzone(ReadString());
911                         break;
912                 case RACE_NET_SPEED_AWARD_BEST:
913                         race_speedaward_alltimebest = ReadInt24_t();
914                         if(race_speedaward_alltimebest_holder)
915                                 strunzone(race_speedaward_alltimebest_holder);
916                         race_speedaward_alltimebest_holder = strzone(ReadString());
917                         break;
918                 case RACE_NET_SERVER_RANKINGS:
919                         float pos, prevpos, del;
920                         pos = ReadShort();
921                         prevpos = ReadShort();
922                         del = ReadShort();
923
924                         // move other rankings out of the way
925                         float i;
926                         if (prevpos) {
927                                 for (i=prevpos-1;i>pos-1;--i) {
928                                         grecordtime[i] = grecordtime[i-1];
929                                         if(grecordholder[i])
930                                                 strunzone(grecordholder[i]);
931                                         grecordholder[i] = strzone(grecordholder[i-1]);
932                                 }
933                         } else if (del) { // a record has been deleted by the admin
934                                 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
935                                         if (i == RANKINGS_CNT-1) { // clear out last record
936                                                 grecordtime[i] = 0;
937                                                 if (grecordholder[i])
938                                                         strunzone(grecordholder[i]);
939                                                 grecordholder[i] = string_null;
940                                         }
941                                         else {
942                                                 grecordtime[i] = grecordtime[i+1];
943                                                 if (grecordholder[i])
944                                                         strunzone(grecordholder[i]);
945                                                 grecordholder[i] = strzone(grecordholder[i+1]);
946                                         }
947                                 }
948                         } else { // player has no ranked record yet
949                                 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
950                                         grecordtime[i] = grecordtime[i-1];
951                                         if(grecordholder[i])
952                                                 strunzone(grecordholder[i]);
953                                         grecordholder[i] = strzone(grecordholder[i-1]);
954                                 }
955                         }
956
957                         // store new ranking
958                         if(grecordholder[pos-1] != "")
959                                 strunzone(grecordholder[pos-1]);
960                         grecordholder[pos-1] = strzone(ReadString());
961                         grecordtime[pos-1] = ReadInt24_t();
962                         if(grecordholder[pos-1] == GetPlayerName(player_localentnum -1))
963                                 race_myrank = pos;
964                         break;
965                 case RACE_NET_SERVER_STATUS:
966                         race_status = ReadShort();
967                         if(race_status_name)
968                                 strunzone(race_status_name);
969                         race_status_name = strzone(ReadString());
970         }
971 }
972
973 void Net_ReadSpawn()
974 {
975         zoomin_effect = 1;
976         current_viewzoom = 0.6;
977 }
978
979 void Net_TeamNagger()
980 {
981         teamnagger = 1;
982 }
983
984 void Net_ReadPingPLReport()
985 {
986         float e, pi, pl, ml;
987         e = ReadByte();
988         pi = ReadShort();
989         pl = ReadByte();
990         ml = ReadByte();
991         if not(playerslots[e])
992                 return;
993         playerslots[e].ping = pi;
994         playerslots[e].ping_packetloss = pl / 255.0;
995         playerslots[e].ping_movementloss = ml / 255.0;
996 }
997
998 void Net_WeaponComplain() {
999         complain_weapon = ReadByte();
1000
1001         if(complain_weapon_name)
1002                 strunzone(complain_weapon_name);
1003         complain_weapon_name = strzone(ReadString());
1004
1005         complain_weapon_type = ReadByte();
1006
1007         complain_weapon_time = time;
1008         weapontime = time; // ping the weapon panel
1009 }
1010
1011 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
1012 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
1013 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
1014 float CSQC_Parse_TempEntity()
1015 {
1016         float bHandled;
1017                 bHandled  = true;
1018         // Acquire TE ID
1019         float nTEID;
1020                 nTEID = ReadByte();
1021
1022                 // NOTE: Could just do return instead of break...
1023         switch(nTEID)
1024         {
1025                 case TE_CSQC_TARGET_MUSIC:
1026                         Net_TargetMusic();
1027                         bHandled = true;
1028                         break;
1029                 case TE_CSQC_PICTURE:
1030                         Net_MapVote_Picture();
1031                         bHandled = true;
1032                         break;
1033                 case TE_CSQC_RACE:
1034                         Net_ReadRace();
1035                         bHandled = true;
1036                         break;
1037                 case TE_CSQC_SPAWN:
1038                         Net_ReadSpawn();
1039                         bHandled = true;
1040                         break;
1041                 case TE_CSQC_ZCURVEPARTICLES:
1042                         Net_ReadZCurveParticles();
1043                         bHandled = true;
1044                         break;
1045                 case TE_CSQC_NEXGUNBEAMPARTICLE:
1046                         Net_ReadNexgunBeamParticle();
1047                         bHandled = true;
1048                         break;
1049                 case TE_CSQC_TEAMNAGGER:
1050                         Net_TeamNagger();
1051                         bHandled = true;
1052                         break;
1053                 case TE_CSQC_LIGHTNINGARC:
1054                         Net_ReadLightningarc();
1055                         bHandled = true;
1056                         break;
1057                 case TE_CSQC_PINGPLREPORT:
1058                         Net_ReadPingPLReport();
1059                         bHandled = true;
1060                         break;
1061                 case TE_CSQC_ANNOUNCE:
1062                         Announcer_Play(ReadString());
1063                         bHandled = true;
1064                         break;
1065                 case TE_CSQC_KILLNOTIFY:
1066                         HUD_KillNotify(ReadString(), ReadString(), ReadString(), ReadShort(), ReadByte());
1067                         bHandled = true;
1068                         break;
1069                 case TE_CSQC_KILLCENTERPRINT:
1070                         HUD_KillCenterprint(ReadString(), ReadString(), ReadShort(), ReadByte());
1071                         bHandled = true;
1072                         break;
1073                 case TE_CSQC_CENTERPRINT_GENERIC:
1074                         float id;
1075                         string s;
1076                         id = ReadByte();
1077                         s = ReadString();
1078                         if (id != 0 && s != "")
1079                                 centerprint_generic(id, s, ReadByte(), ReadByte());
1080                         else
1081                                 centerprint_generic(id, s, 0, 0);
1082                         bHandled = true;
1083                         break;
1084                 case TE_CSQC_WEAPONCOMPLAIN:
1085                         Net_WeaponComplain();
1086                         bHandled = true;
1087                         break;
1088                 case TE_CSQC_VEHICLESETUP:
1089                         Net_VehicleSetup();
1090                         bHandled = true;
1091                         break;
1092                 default:
1093                         // No special logic for this temporary entity; return 0 so the engine can handle it
1094                         bHandled = false;
1095                         break;
1096         }
1097
1098         return bHandled;
1099 }
1100
1101 string getcommandkey(string text, string command)
1102 {
1103         string keys;
1104         float n, j, k, l;
1105
1106         if (!autocvar_hud_showbinds)
1107                 return text;
1108
1109         keys = db_get(binddb, command);
1110         if (!keys)
1111         {
1112                 n = tokenize(findkeysforcommand(command)); // uses '...' strings
1113                 for(j = 0; j < n; ++j)
1114                 {
1115                         k = stof(argv(j));
1116                         if(k != -1)
1117                         {
1118                                 if ("" == keys)
1119                                         keys = keynumtostring(k);
1120                                 else
1121                                         keys = strcat(keys, ", ", keynumtostring(k));
1122
1123                                 ++l;
1124                                 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit >= l) break;
1125                         }
1126
1127                 }
1128                 db_put(binddb, command, keys);
1129         }
1130
1131         if ("" == keys) {
1132                 if (autocvar_hud_showbinds > 1)
1133                         return sprintf(_("%s (not bound)"), text);
1134                 else
1135                         return text;
1136         }
1137         else if (autocvar_hud_showbinds > 1)
1138                 return sprintf(_("%s (%s)"), text, keys);
1139         else
1140                 return keys;
1141 }