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