3 #include "../common/effects/qc/all.qh"
6 #include "mapvoting.qh"
7 #include "modeleffects.qh"
8 #include "mutators/events.qh"
9 #include "quickmenu.qh"
10 #include "scoreboard.qh"
11 #include "shownames.qh"
15 #include "weapons/projectile.qh"
16 #include "../common/deathtypes/all.qh"
17 #include "../common/items/all.qh"
18 #include "../common/mapinfo.qh"
19 #include "../common/minigames/cl_minigames.qh"
20 #include "../common/minigames/cl_minigames_hud.qh"
21 #include "../common/net_notice.qh"
22 #include "../common/triggers/include.qh"
23 #include "../common/vehicles/all.qh"
24 #include "../lib/csqcmodel/cl_model.qh"
25 #include "../lib/csqcmodel/interpolate.qh"
26 #include "../lib/warpzone/client.qh"
28 // --------------------------------------------------------------------------
29 // BEGIN REQUIRED CSQC FUNCTIONS
32 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
34 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
35 // Useful for precaching things
37 void ConsoleCommand_macro_init();
40 prvm_language = strzone(cvar_string("prvm_language"));
43 LOG_TRACEF("^4CSQC Build information: ^1%s\n", WATERMARK);
48 ClientProgsDB = db_load("client.db");
49 compressShortVector_init();
56 if (getplayerkeyvalue(i, "viewentity") == "")
61 //registercommand("hud_configure");
62 //registercommand("hud_save");
63 //registercommand("menu_action");
65 ConsoleCommand_macro_init();
67 registercvar("hud_usecsqc", "1");
68 registercvar("scoreboard_columns", "default");
70 registercvar("cl_nade_type", "3");
71 registercvar("cl_pokenade_type", "zombie");
73 registercvar("cl_jumpspeedcap_min", "");
74 registercvar("cl_jumpspeedcap_max", "");
76 registercvar("cl_multijump", "0");
78 registercvar("cl_spawn_near_teammate", "1");
82 // hud_fields uses strunzone on the titles!
83 for(int i = 0; i < MAX_HUD_FIELDS; ++i)
84 hud_title[i] = strzone("(null)");
93 players = Sort_Spawn();
95 GetTeam(NUM_SPECTATOR, true); // add specs first
97 // needs to be done so early because of the constants they create
100 static_init_precache();
104 if(autocvar_cl_reticle)
106 precache_pic("gfx/reticle_normal");
107 // weapon reticles are precached in weapon files
111 get_mi_min_max_texcoords(1); // try the CLEVER way first
112 minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
113 shortmapname = mi_shortname;
115 if (precache_pic(minimapname) == "")
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
122 get_mi_min_max_texcoords(0); // load new texcoords
125 mi_center = (mi_min + mi_max) * 0.5;
126 mi_scale = mi_max - mi_min;
127 minimapname = strzone(minimapname);
130 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
131 draw_currentSkin = strzone(strcat("gfx/menu/", cvar_string("menu_skin")));
134 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
143 if(autocvar_cl_db_saveasdump)
144 db_dump(ClientProgsDB, "client.db");
146 db_save(ClientProgsDB, "client.db");
147 db_close(ClientProgsDB);
150 cvar_set("chase_active",ftos(chase_active_backup));
152 // unset the event chasecam's chase_active
153 if(autocvar_chase_active < 0)
154 cvar_set("chase_active", "0");
158 if (!(calledhooks & HOOK_START))
159 localcmd("\n_cl_hook_gamestart nop\n");
160 if (!(calledhooks & HOOK_END))
161 localcmd("\ncl_hook_gameend\n");
164 deactivate_minigame();
165 HUD_MinigameMenu_Close();
169 float SetTeam(entity o, int Team)
183 if(GetTeam(Team, false) == world)
185 LOG_TRACEF("trying to switch to unsupported team %d\n", Team);
186 Team = NUM_SPECTATOR;
199 if(GetTeam(Team, false) == world)
201 LOG_TRACEF("trying to switch to unsupported team %d\n", Team);
202 Team = NUM_SPECTATOR;
207 if(Team == -1) // leave
211 tm = GetTeam(o.team, false);
222 tm = GetTeam(Team, true);
227 else if(Team != o.team)
229 tm = GetTeam(o.team, false);
232 tm = GetTeam(Team, true);
240 void Playerchecker_Think()
245 for(i = 0; i < maxclients; ++i)
248 if(GetPlayerName(i) == "")
252 // player disconnected
266 playerslots[i] = e = new(playerslot);
271 e.ping_packetloss = 0;
272 e.ping_movementloss = 0;
273 //e.gotscores = 0; // we might already have the scores...
274 SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
276 HUD_UpdatePlayerPos(e);
280 this.nextthink = time + 0.2;
287 entity playerchecker = new(playerchecker);
288 make_pure(playerchecker);
289 playerchecker.think = Playerchecker_Think;
290 playerchecker.nextthink = time + 0.2;
298 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
299 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
300 // All keys are in ascii.
301 // bInputType = 0 is key pressed, 1 is key released, 2 and 3 are mouse input.
302 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
303 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
304 // In the case of mouse input after a setcursormode(1) call, nPrimary is xpos, nSecondary is ypos.
305 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
307 if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
310 if (QuickMenu_InputEvent(bInputType, nPrimary, nSecondary))
313 if (HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary))
316 if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
319 if (HUD_Minigame_InputEvent(bInputType, nPrimary, nSecondary))
325 // END REQUIRED CSQC FUNCTIONS
326 // --------------------------------------------------------------------------
328 // --------------------------------------------------------------------------
329 // BEGIN OPTIONAL CSQC FUNCTIONS
331 void Ent_RemoveEntCS()
334 entcs_receiver[this.sv_entnum] = NULL;
337 NET_HANDLE(ENT_CLIENT_ENTCS, bool isnew)
340 this.classname = "entcs_receiver";
341 InterpolateOrigin_Undo();
345 this.sv_entnum = ReadByte();
348 this.origin_x = ReadShort();
349 this.origin_y = ReadShort();
350 this.origin_z = ReadShort();
351 setorigin(this, this.origin);
355 this.angles_y = ReadByte() * 360.0 / 256;
356 this.angles_x = this.angles_z = 0;
359 this.healthvalue = ReadByte() * 10;
361 this.armorvalue = ReadByte() * 10;
365 entcs_receiver[this.sv_entnum] = this;
366 this.entremove = Ent_RemoveEntCS;
367 this.iflags |= IFLAG_ORIGIN;
369 InterpolateOrigin_Note();
374 void Ent_RemovePlayerScore()
378 SetTeam(this.owner, -1);
379 this.owner.gotscores = 0;
380 for(int i = 0; i < MAX_SCORE; ++i) {
381 this.owner.(scores[i]) = 0; // clear all scores
386 NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
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 = !this.owner; // workaround for DP bug
398 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
399 if(!isNew && n != this.sv_entnum)
401 //print("A CSQC entity changed its owner!\n");
402 LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", num_for_edict(this), this.classname);
410 o = playerslots[this.sv_entnum];
413 o = playerslots[this.sv_entnum] = new(playerslot);
417 o.sv_entnum = this.sv_entnum;
421 // RegisterPlayer(o);
422 //playerchecker will do this for us later, if it has not already done so
433 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
437 o.(scores[i]) = ReadInt24_t();
439 o.(scores[i]) = ReadChar();
445 HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
447 this.entremove = Ent_RemovePlayerScore;
450 NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew)
456 this.team = ReadByte();
457 o = this.owner = GetTeam(this.team, true); // these team numbers can always be trusted
460 #if MAX_TEAMSCORE <= 8
468 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
472 o.(teamscores[i]) = ReadInt24_t();
474 o.(teamscores[i]) = ReadChar();
479 HUD_UpdateTeamPos(o);
482 NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
485 float newspectatee_status;
489 scoreboard_showscores_force = (f & 1);
493 newspectatee_status = ReadByte();
494 if(newspectatee_status == player_localnum + 1)
495 newspectatee_status = -1; // observing
498 newspectatee_status = 0;
500 spectatorbutton_zoom = (f & 4);
504 angles_held_status = 1;
505 angles_held.x = ReadAngle();
506 angles_held.y = ReadAngle();
510 angles_held_status = 0;
514 if(newspectatee_status != spectatee_status)
518 race_checkpointtime = 0;
520 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
522 if ( (spectatee_status == -1 && newspectatee_status > 0) //before observing, now spectating
523 || (spectatee_status > 0 && newspectatee_status > 0 && spectatee_status != newspectatee_status) //changed spectated player
526 else if(spectatee_status && !newspectatee_status) //before observing/spectating, now playing
529 spectatee_status = newspectatee_status;
531 // we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
534 NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew)
539 int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
544 strunzone(vote_called_vote);
545 vote_called_vote = string_null;
555 vote_yescount = ReadByte();
556 vote_nocount = ReadByte();
557 vote_needed = ReadByte();
558 vote_highlighted = ReadChar();
564 strunzone(vote_called_vote);
565 vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
570 for(j = 0; j < maxclients; ++j)
572 playerslots[j].ready = 1;
573 for(i = 1; i <= maxclients; i += 8)
576 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
579 playerslots[j].ready = 0;
585 ready_waiting = (nags & BIT(0));
586 ready_waiting_for_me = (nags & BIT(1));
587 vote_waiting = (nags & BIT(2));
588 vote_waiting_for_me = (nags & BIT(3));
589 warmup_stage = (nags & BIT(4));
592 NET_HANDLE(ENT_CLIENT_ELIMINATEDPLAYERS, bool isnew)
600 for(j = 0; j < maxclients; ++j)
602 playerslots[j].eliminated = 1;
603 for(i = 1; i <= maxclients; i += 8)
606 for(j = i-1, b = 1; b < 256; b *= 2, ++j)
609 playerslots[j].eliminated = 0;
615 NET_HANDLE(ENT_CLIENT_RANDOMSEED, bool isnew)
619 float s = ReadShort();
624 NET_HANDLE(ENT_CLIENT_ACCURACY, bool isnew)
627 int sf = ReadInt24_t();
629 for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
630 weapon_accuracy[w] = -1;
635 for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w) {
639 weapon_accuracy[w] = -1;
641 weapon_accuracy[w] = 1.0; // no better error handling yet, sorry
643 weapon_accuracy[w] = (b - 1.0) / 100.0;
645 f = (f == 0x800000) ? 1 : f * 2;
650 void Spawn_Draw(entity this)
652 __pointparticles(this.cnt, this.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1));
655 NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new)
657 float teamnum = (ReadByte() - 1);
659 spn_origin.x = ReadShort();
660 spn_origin.y = ReadShort();
661 spn_origin.z = ReadShort();
665 this.origin = spn_origin;
666 setsize(this, PL_MIN_CONST, PL_MAX_CONST);
669 /*if(autocvar_cl_spawn_point_model) // needs a model first
671 this.mdl = "models/spawnpoint.md3";
672 this.colormod = Team_ColorRGB(teamnum);
673 precache_model(this.mdl);
674 setmodel(this, this.mdl);
675 this.drawmask = MASK_NORMAL;
676 //this.movetype = MOVETYPE_NOCLIP;
677 //this.draw = Spawn_Draw;
679 if(autocvar_cl_spawn_point_particles)
681 if((serverflags & SERVERFLAG_TEAMPLAY))
685 case NUM_TEAM_1: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_RED); break;
686 case NUM_TEAM_2: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_BLUE); break;
687 case NUM_TEAM_3: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_YELLOW); break;
688 case NUM_TEAM_4: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_PINK); break;
689 default: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); break;
692 else { this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); }
694 this.draw = Spawn_Draw;
698 //printf("Ent_ReadSpawnPoint(is_new = %d); origin = %s, team = %d, effect = %d\n", is_new, vtos(this.origin), teamnum, this.cnt);
702 NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool is_new)
704 // If entnum is 0, ONLY do the local spawn actions
705 // this way the server can disable the sending of
706 // spawn origin or such to clients if wanted.
707 float entnum = ReadByte();
711 this.origin_x = ReadShort();
712 this.origin_y = ReadShort();
713 this.origin_z = ReadShort();
717 float teamnum = GetPlayerColor(entnum - 1);
719 if(autocvar_cl_spawn_event_particles)
723 case NUM_TEAM_1: pointparticles(EFFECT_SPAWN_RED, this.origin, '0 0 0', 1); break;
724 case NUM_TEAM_2: pointparticles(EFFECT_SPAWN_BLUE, this.origin, '0 0 0', 1); break;
725 case NUM_TEAM_3: pointparticles(EFFECT_SPAWN_YELLOW, this.origin, '0 0 0', 1); break;
726 case NUM_TEAM_4: pointparticles(EFFECT_SPAWN_PINK, this.origin, '0 0 0', 1); break;
727 default: pointparticles(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1); break;
730 if(autocvar_cl_spawn_event_sound)
732 sound(this, CH_TRIGGER, SND_SPAWN, VOL_BASE, ATTEN_NORM);
738 // local spawn actions
739 if(is_new && (!entnum || (entnum == player_localentnum)))
742 current_viewzoom = (1 / bound(1, autocvar_cl_spawnzoom_factor, 16));
744 if(autocvar_cl_unpress_zoom_on_spawn)
750 HUD_Radar_Hide_Maximized();
751 //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(this.origin), entnum, player_localentnum);
754 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
755 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
756 void CSQC_Ent_Update(float bIsNewEntity)
759 this.sourceLocLine = __LINE__;
760 this.sourceLocFile = __FILE__;
763 // set up the "time" global for received entities to be correct for interpolation purposes
764 float savetime = time;
771 serverprevtime = time;
772 serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
773 time = serverprevtime + serverdeltatime;
776 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
779 if(t != this.enttype || bIsNewEntity)
781 LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", num_for_edict(this), this.entnum, this.enttype, t);
791 LOG_INFOF("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", num_for_edict(this), this.entnum, t);
798 FOREACH(LinkedEntities, it.m_id == t, LAMBDA(
799 this.classname = it.netname;
800 if (autocvar_developer_csqcentities)
801 LOG_INFOF("CSQC_Ent_Update(%d) with this=%i {.entnum=%d, .enttype=%d} t=%s (%d)\n", bIsNewEntity, this, this.entnum, this.enttype, it.netname, t);
802 done = it.m_read(this, bIsNewEntity);
808 //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), this.enttype));
809 error(sprintf("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n", this.enttype, num_for_edict(this), this.classname));
813 // Destructor, but does NOT deallocate the entity by calling remove(). Also
814 // used when an entity changes its type. For an entity that someone interacts
815 // with others, make sure it can no longer do so.
819 if(this.entremove) this.entremove();
821 if(this.skeletonindex)
823 skel_delete(this.skeletonindex);
824 this.skeletonindex = 0;
827 if(this.snd_looping > 0)
829 sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_g_jetpack_attenuation);
830 this.snd_looping = 0;
835 this.draw = func_null;
836 this.entremove = func_null;
837 // TODO possibly set more stuff to defaults
839 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(this) as well.
840 void CSQC_Ent_Remove()
843 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Ent_Remove() with this=%i {.entnum=%d, .enttype=%d}\n", this, this.entnum, this.enttype);
846 LOG_WARNING("CSQC_Ent_Remove called for already removed entity. Packet loss?\n");
849 if (this.enttype) Ent_Remove();
857 if(!(calledhooks & HOOK_START))
858 localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
859 calledhooks |= HOOK_START;
862 // 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.
863 void CSQC_Parse_StuffCmd(string strMessage)
865 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_StuffCmd(\"%s\")\n", strMessage);
866 localcmd(strMessage);
868 // 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.
869 void CSQC_Parse_Print(string strMessage)
871 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_Print(\"%s\")\n", strMessage);
872 print(ColorTranslateRGB(strMessage));
875 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
876 void CSQC_Parse_CenterPrint(string strMessage)
878 if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_CenterPrint(\"%s\")\n", strMessage);
879 centerprint_hud(strMessage);
882 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
883 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
884 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
885 bool CSQC_Parse_TempEntity()
888 int nTEID = ReadByte();
890 FOREACH(TempEntities, it.m_id == nTEID, LAMBDA(
891 if (autocvar_developer_csqcentities)
892 LOG_INFOF("CSQC_Parse_TempEntity() nTEID=%s (%d)\n", it.netname, nTEID);
893 return it.m_read(NULL, true);
896 if (autocvar_developer_csqcentities)
897 LOG_INFOF("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID);
899 // No special logic for this temporary entity; return 0 so the engine can handle it
903 /** TODO somehow thwart prvm_globalset client ... */
907 if (autocvar_cl_orthoview && autocvar_cl_orthoview_nofog)
908 localcmd("\nr_drawfog 0\n");
909 else if (forcefog != "")
910 localcmd(sprintf("\nfog %s\nr_fog_exp2 0\nr_drawfog 1\n", forcefog));
913 void Gamemode_Init();
914 NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew)
917 gametype = ReadInt24_t();
918 HUD_ModIcons_SetFunc();
919 for (int i = 0; i < MAX_SCORE; ++i)
921 if (scores_label[i]) strunzone(scores_label[i]);
922 scores_label[i] = strzone(ReadString());
923 scores_flags[i] = ReadByte();
925 for (int i = 0; i < MAX_TEAMSCORE; ++i)
927 if (teamscores_label[i]) strunzone(teamscores_label[i]);
928 teamscores_label[i] = strzone(ReadString());
929 teamscores_flags[i] = ReadByte();
936 NET_HANDLE(ENT_CLIENT_INIT, bool isnew)
940 nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
942 hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
943 hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
944 hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
945 hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
946 arc_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
947 arc_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
948 arc_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
949 arc_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
951 if (forcefog) strunzone(forcefog);
952 forcefog = strzone(ReadString());
954 armorblockpercent = ReadByte() / 255.0;
956 g_balance_mortar_bouncefactor = ReadCoord();
957 g_balance_mortar_bouncestop = ReadCoord();
958 g_balance_electro_secondary_bouncefactor = ReadCoord();
959 g_balance_electro_secondary_bouncestop = ReadCoord();
961 vortex_scope = !ReadByte();
962 rifle_scope = !ReadByte();
964 serverflags = ReadByte();
966 minelayer_maxmines = ReadByte();
968 hagar_maxrockets = ReadByte();
970 g_trueaim_minrange = ReadCoord();
971 g_balance_porto_secondary = ReadByte();
974 MUTATOR_CALLHOOK(Ent_Init);
976 if (!postinit) PostInit();
979 NET_HANDLE(TE_CSQC_RACE, bool isNew)
985 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
986 race_checkpoint = ReadByte();
987 race_time = ReadInt24_t();
988 race_previousbesttime = ReadInt24_t();
989 if(race_previousbestname)
990 strunzone(race_previousbestname);
991 race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
993 race_checkpointtime = time;
995 if(race_checkpoint == 0 || race_checkpoint == 254)
997 race_penaltyaccumulator = 0;
998 race_laptime = time; // valid
1003 case RACE_NET_CHECKPOINT_CLEAR:
1005 race_checkpointtime = 0;
1008 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
1009 race_laptime = ReadCoord();
1010 race_checkpointtime = -99999;
1012 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
1013 race_nextcheckpoint = ReadByte();
1015 race_nextbesttime = ReadInt24_t();
1016 if(race_nextbestname)
1017 strunzone(race_nextbestname);
1018 race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
1021 case RACE_NET_CHECKPOINT_HIT_RACE:
1022 race_mycheckpoint = ReadByte();
1023 race_mycheckpointtime = time;
1024 race_mycheckpointdelta = ReadInt24_t();
1025 race_mycheckpointlapsdelta = ReadByte();
1026 if(race_mycheckpointlapsdelta >= 128)
1027 race_mycheckpointlapsdelta -= 256;
1028 if(race_mycheckpointenemy)
1029 strunzone(race_mycheckpointenemy);
1030 race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1033 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
1034 race_othercheckpoint = ReadByte();
1035 race_othercheckpointtime = time;
1036 race_othercheckpointdelta = ReadInt24_t();
1037 race_othercheckpointlapsdelta = ReadByte();
1038 if(race_othercheckpointlapsdelta >= 128)
1039 race_othercheckpointlapsdelta -= 256;
1040 if(race_othercheckpointenemy)
1041 strunzone(race_othercheckpointenemy);
1042 race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
1045 case RACE_NET_PENALTY_RACE:
1046 race_penaltyeventtime = time;
1047 race_penaltytime = ReadShort();
1048 //race_penaltyaccumulator += race_penaltytime;
1049 if(race_penaltyreason)
1050 strunzone(race_penaltyreason);
1051 race_penaltyreason = strzone(ReadString());
1054 case RACE_NET_PENALTY_QUALIFYING:
1055 race_penaltyeventtime = time;
1056 race_penaltytime = ReadShort();
1057 race_penaltyaccumulator += race_penaltytime;
1058 if(race_penaltyreason)
1059 strunzone(race_penaltyreason);
1060 race_penaltyreason = strzone(ReadString());
1063 case RACE_NET_SERVER_RECORD:
1064 race_server_record = ReadInt24_t();
1066 case RACE_NET_SPEED_AWARD:
1067 race_speedaward = ReadInt24_t();
1068 if(race_speedaward_holder)
1069 strunzone(race_speedaward_holder);
1070 race_speedaward_holder = strzone(ReadString());
1072 case RACE_NET_SPEED_AWARD_BEST:
1073 race_speedaward_alltimebest = ReadInt24_t();
1074 if(race_speedaward_alltimebest_holder)
1075 strunzone(race_speedaward_alltimebest_holder);
1076 race_speedaward_alltimebest_holder = strzone(ReadString());
1078 case RACE_NET_SERVER_RANKINGS:
1080 int pos = ReadShort();
1081 prevpos = ReadShort();
1084 // move other rankings out of the way
1087 for (i=prevpos-1;i>pos-1;--i) {
1088 grecordtime[i] = grecordtime[i-1];
1089 if(grecordholder[i])
1090 strunzone(grecordholder[i]);
1091 grecordholder[i] = strzone(grecordholder[i-1]);
1093 } else if (del) { // a record has been deleted by the admin
1094 for (i=pos-1; i<= RANKINGS_CNT-1; ++i) {
1095 if (i == RANKINGS_CNT-1) { // clear out last record
1097 if (grecordholder[i])
1098 strunzone(grecordholder[i]);
1099 grecordholder[i] = string_null;
1102 grecordtime[i] = grecordtime[i+1];
1103 if (grecordholder[i])
1104 strunzone(grecordholder[i]);
1105 grecordholder[i] = strzone(grecordholder[i+1]);
1108 } else { // player has no ranked record yet
1109 for (i=RANKINGS_CNT-1;i>pos-1;--i) {
1110 grecordtime[i] = grecordtime[i-1];
1111 if(grecordholder[i])
1112 strunzone(grecordholder[i]);
1113 grecordholder[i] = strzone(grecordholder[i-1]);
1117 // store new ranking
1118 if(grecordholder[pos-1] != "")
1119 strunzone(grecordholder[pos-1]);
1120 grecordholder[pos-1] = strzone(ReadString());
1121 grecordtime[pos-1] = ReadInt24_t();
1122 if(grecordholder[pos-1] == GetPlayerName(player_localnum))
1125 case RACE_NET_SERVER_STATUS:
1126 race_status = ReadShort();
1127 if(race_status_name)
1128 strunzone(race_status_name);
1129 race_status_name = strzone(ReadString());
1134 NET_HANDLE(TE_CSQC_TEAMNAGGER, bool isNew)
1140 NET_HANDLE(TE_CSQC_PINGPLREPORT, bool isNew)
1143 int pi = ReadShort();
1144 int pl = ReadByte();
1145 int ml = ReadByte();
1147 entity e = playerslots[i];
1150 e.ping_packetloss = pl / 255.0;
1151 e.ping_movementloss = ml / 255.0;
1154 NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew)
1156 complain_weapon = ReadByte();
1157 if (complain_weapon_name) strunzone(complain_weapon_name);
1158 complain_weapon_name = strzone(WEP_NAME(complain_weapon));
1159 complain_weapon_type = ReadByte();
1162 complain_weapon_time = time;
1163 weapontime = time; // ping the weapon panel
1165 switch(complain_weapon_type)
1167 case 0: Local_Notification(MSG_MULTI, ITEM_WEAPON_NOAMMO, complain_weapon); break;
1168 case 1: Local_Notification(MSG_MULTI, ITEM_WEAPON_DONTHAVE, complain_weapon); break;
1169 default: Local_Notification(MSG_MULTI, ITEM_WEAPON_UNAVAILABLE, complain_weapon); break;
1173 string getcommandkey(string text, string command)
1176 float n, j, k, l = 0;
1178 if (!autocvar_hud_showbinds)
1181 keys = db_get(binddb, command);
1184 n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
1185 for(j = 0; j < n; ++j)
1191 keys = keynumtostring(k);
1193 keys = strcat(keys, ", ", keynumtostring(k));
1196 if (autocvar_hud_showbinds_limit > 0 && autocvar_hud_showbinds_limit <= l)
1203 db_put(binddb, command, keys);
1206 if (keys == "NO_KEY") {
1207 if (autocvar_hud_showbinds > 1)
1208 return sprintf(_("%s (not bound)"), text);
1212 else if (autocvar_hud_showbinds > 1)
1213 return sprintf("%s (%s)", text, keys);