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