From 2d8bfa42df59c19f1717121b82aeeb59f0f7e829 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Tue, 9 Aug 2022 09:31:37 -0700 Subject: [PATCH] player class: Use parent method OptimiseChangedFlags() to cull some fields from being networked to players other than yourself --- src/shared/player.qc | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/src/shared/player.qc b/src/shared/player.qc index 10eae2b..4e7404d 100644 --- a/src/shared/player.qc +++ b/src/shared/player.qc @@ -510,61 +510,39 @@ player::SendEntity ================= */ float -player::SendEntity(entity ePEnt, float fChanged) +player::SendEntity(entity ePEnt, float flChanged) { - bool is_spec = false; - bool spectarget = false; - /* don't broadcast invisible players */ if (IsFakeSpectator() && ePEnt != this) return (0); if (!GetModelindex() && ePEnt != this) return (0); - /* figure out if we should optimise this player */ - if (ePEnt.flags & FL_CLIENT && ePEnt != this) { - NSClientSpectator sp = (NSClientSpectator)ePEnt; - is_spec = (sp.IsFakeSpectator() || sp.IsRealSpectator()); - spectarget = (is_spec == true && edict_num(sp.spec_ent) == this); - } - - /* if we're a spectator of any type and spectate this player */ - if (ePEnt != this && spectarget == false) { - fChanged &= ~PLAYER_ITEMS; - fChanged &= ~PLAYER_HEALTH; - fChanged &= ~PLAYER_TIMINGS; - fChanged &= ~PLAYER_AMMO1; - fChanged &= ~PLAYER_AMMO2; - fChanged &= ~PLAYER_AMMO3; - fChanged &= ~PLAYER_FLAGS; - fChanged &= ~PLAYER_PUNCHANGLE; - fChanged &= ~PLAYER_VIEWZOOM; - fChanged &= ~PLAYER_SPECTATE; - } + flChanged = OptimiseChangedFlags(ePEnt, flChanged); WriteByte(MSG_ENTITY, ENT_PLAYER); - WriteFloat(MSG_ENTITY, fChanged); + WriteFloat(MSG_ENTITY, flChanged); /* the generic client attributes */ - NSClientPlayer::SendEntity(ePEnt, fChanged); + NSClientPlayer::SendEntity(ePEnt, flChanged); - if (fChanged & PLAYER_TOPFRAME) { + if (flChanged & PLAYER_TOPFRAME) { WriteByte(MSG_ENTITY, anim_top); WriteFloat(MSG_ENTITY, anim_top_time); WriteFloat(MSG_ENTITY, anim_top_delay); } - if (fChanged & PLAYER_BOTTOMFRAME) { + if (flChanged & PLAYER_BOTTOMFRAME) { WriteByte(MSG_ENTITY, anim_bottom); WriteFloat(MSG_ENTITY, anim_bottom_time); } - if (fChanged & PLAYER_AMMO1) { + if (flChanged & PLAYER_AMMO1) { WriteByte(MSG_ENTITY, mag_sbs); WriteByte(MSG_ENTITY, mag_dbs); WriteByte(MSG_ENTITY, mag_rpg); } - if (fChanged & PLAYER_AMMO2) { + if (flChanged & PLAYER_AMMO2) { WriteByte(MSG_ENTITY, m_iAmmoRockets); WriteByte(MSG_ENTITY, m_iAmmoNails); WriteByte(MSG_ENTITY, m_iAmmoCells); @@ -573,7 +551,7 @@ player::SendEntity(entity ePEnt, float fChanged) WriteByte(MSG_ENTITY, m_iAmmoMedikit); } - if (fChanged & PLAYER_AMMO3) { + if (flChanged & PLAYER_AMMO3) { WriteByte(MSG_ENTITY, mode_tempstate); WriteByte(MSG_ENTITY, classtype); }