Avoid use of infokeys to communicate whether or not a client is spectating.

This commit is contained in:
Marco Cawthorne 2022-04-25 15:25:35 -07:00
parent 4c51ac7e79
commit 2d403202b9
Signed by: eukara
GPG Key ID: C196CD8BA993248A
12 changed files with 139 additions and 71 deletions

View File

@ -26,5 +26,5 @@ shake.qc
cmd.qc
event.qc
entry.qc
util.cpp
util.qc
#endlist

View File

@ -1,33 +0,0 @@
float
Client_IsSpectator(base_client cl)
{
return (getplayerkeyfloat(cl.entnum - 1, "*spec") > 0) ? TRUE : FALSE;
}
float
Client_IsRealSpectator(base_client cl)
{
return (cl.classname == "spectator") ? TRUE : FALSE;
}
float
Client_IsFakeSpectator(base_client cl)
{
return (getplayerkeyvalue(cl.entnum - 1, "*spec") == "2") ? TRUE : FALSE;
}
float
Client_IsDead(base_client cl)
{
if (Client_IsSpectator(cl) == TRUE)
return FALSE;
else
return (getplayerkeyvalue(cl.entnum - 1, "*dead") == "1") ? TRUE : FALSE;
}
float
Client_IsPlayer(base_client cl)
{
return (cl.classname == "player") ? TRUE : FALSE;
}

33
src/client/util.qc Normal file
View File

@ -0,0 +1,33 @@
float
Client_IsSpectator(base_client cl)
{
if (cl.IsRealSpectator() || cl.IsFakeSpectator())
return true;
return false;
}
float
Client_IsRealSpectator(base_client cl)
{
return cl.IsRealSpectator();
}
float
Client_IsFakeSpectator(base_client cl)
{
return cl.IsFakeSpectator();
}
float
Client_IsDead(base_client cl)
{
return cl.IsDead();
}
float
Client_IsPlayer(base_client cl)
{
return cl.IsPlayer();
}

View File

@ -93,7 +93,7 @@ CMap_Shoot(void)
setproperty(VF_ANGLES, [0,0,0]);
strReflectcube = sprintf(
"env/%s_%d_%d_%d.ktx",
"env/%s_%d_%d_%d",
mapname,
g_vecCubePos[0],
g_vecCubePos[1],

View File

@ -424,7 +424,7 @@ func_door::Respawn(void)
m_vecPos1 = GetSpawnOrigin();
m_vecPos2 = (m_vecPos1 + m_vecMoveDir * (fabs(m_vecMoveDir * size) - m_flLip));
if (spawnflags & SF_MOV_TOGGLE || spawnflags & SF_MOV_USE)
if (spawnflags & SF_MOV_USE)
m_iCanTouch = false;
else
m_iCanTouch = true;

View File

@ -17,8 +17,11 @@
entity g_multiDamage_Target;
int g_multiDamage_Value;
int g_multiDamage_HitBod;
#ifdef BULLETPENETRATION
float g_pen_flMaxThickness;
var float g_pen_flRangeMod = 1.0f;
#endif
static void
TraceAttack_Apply(entity eAttacker, int iWeapon)

View File

@ -1,4 +1,3 @@
/* both base_player and base_spectator are based off this class */
class
base_client:NSSurfacePropEntity
@ -15,7 +14,9 @@ base_client:NSSurfacePropEntity
virtual void(void) PostFrame;
virtual int(void) IsFakeSpectator;
virtual int(void) IsRealSpectator;
virtual int(void) IsDead;
virtual int(void) IsPlayer;
#ifdef CLIENT
/* gives the chance to override input variables before networking */
@ -27,4 +28,4 @@ base_client:NSSurfacePropEntity
/* run every frame before renderscene() */
virtual float(void) predraw;
#endif
};
};

View File

@ -19,6 +19,24 @@ base_client::IsFakeSpectator(void)
return (FALSE);
}
int
base_client::IsRealSpectator(void)
{
return (FALSE);
}
int
base_client::IsDead(void)
{
return (FALSE);
}
int
base_client::IsPlayer(void)
{
return (FALSE);
}
#ifdef CLIENT
void
base_client::ClientInputFrame(void)

View File

@ -76,6 +76,9 @@ base_player:spectator
virtual void(void) Physics_Run;
virtual int(void) IsFakeSpectator;
virtual int(void) IsRealSpectator;
virtual int(void) IsDead;
virtual int(void) IsPlayer;
#ifdef CLIENT
int sequence;
@ -93,7 +96,6 @@ base_player:spectator
virtual void(void) PredictPostFrame;
virtual void(void) ClientInputFrame;
#else
int voted;
int step;
float step_time;

View File

@ -14,14 +14,31 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int
base_player::IsRealSpectator(void)
{
return (FALSE);
}
int
base_player::IsDead(void)
{
if (health > 0)
return (FALSE);
else
return (TRUE);
}
int
base_player::IsPlayer(void)
{
return (FALSE);
}
int
base_player::IsFakeSpectator(void)
{
#ifdef SERVER
if (infokey(this, "*spec") == "2")
#else
if (getplayerkeyfloat(entnum - 1, "*spec") == 2)
#endif
if (movetype == MOVETYPE_NOCLIP)
return (TRUE);
return (FALSE);
@ -503,19 +520,17 @@ base_player::MakeTempSpectator(void)
{
classname = "player";
flags = FL_CLIENT;
modelindex = 0;
SetModelindex(0);
SetSolid(SOLID_NOT);
SetMovetype(MOVETYPE_NOCLIP);
SetTakedamage(DAMAGE_NO);
maxspeed = 250;
max_health = health = 0;
armor = 0;
g_items = 0;
activeweapon = 0;
effects = 0;
alpha = 0.0f;
solid = SOLID_NOT;
movetype = MOVETYPE_NOCLIP;
maxspeed = 250;
takedamage = DAMAGE_NO;
forceinfokey(this, "*spec", "2");
forceinfokey(this, "*dead", "0");
}
/*
@ -538,9 +553,7 @@ base_player::Death(void)
SetModelindex(0);
SetMovetype(MOVETYPE_NONE);
SetSolid(SOLID_NOT);
takedamage = DAMAGE_NO;
forceinfokey(this, "*spec", "0");
forceinfokey(this, "*dead", "1");
SetTakedamage(DAMAGE_NO);
viewzoom = 1.0;
view_ofs = [0,0,0];
vehicle = __NULL__;
@ -574,8 +587,6 @@ base_player::MakePlayer(void)
solid = SOLID_SLIDEBOX;
movetype = MOVETYPE_WALK;
takedamage = DAMAGE_YES;
forceinfokey(this, "*spec", "0");
forceinfokey(this, "*dead", "0");
viewzoom = 1.0;
vehicle = __NULL__;
velocity = [0,0,0];
@ -829,7 +840,8 @@ _base_player_unuseworkaround(entity eTarget)
=================
base_player:: InputUse_Down
Called when we hold down the +use button for the first time
Called when we hold down the +use button for the first time,
looks for an entity that has the .PlayerUse field set to a function and calls it.
=================
*/
void
@ -843,22 +855,28 @@ base_player::InputUse_Down(void)
vector vecSource;
entity eRad;
bool found_use = false;
makevectors(v_angle);
vecSource = origin + view_ofs;
traceline(vecSource, vecSource + (v_forward * 64), MOVE_EVERYTHING, this);
/* find anything in a 8 unit radius, including certain non-solids (func_door, func_rot_button etc. */
eRad = findradius(trace_endpos, 8);
bool found_use = false;
/* first see if we traced something head-on, else we'll findradius something */
if (trace_ent.PlayerUse) {
found_use = true;
eRad = trace_ent;
} else {
/* find anything in a 8 unit radius, including certain non-solids (func_door, func_rot_button etc. */
eRad = findradius(trace_endpos, 8);
/* loop through our chain and just pick the first valid one */
while (eRad) {
if (eRad.PlayerUse) {
found_use = true;
break;
/* loop through our chain and just pick the first valid one */
while (eRad) {
if (eRad.PlayerUse) {
found_use = true;
break;
}
eRad = eRad.chain;
}
eRad = eRad.chain;
}
/* TODO: maybe eRad will return something in the future that'll suppress a successfull use? */

View File

@ -44,6 +44,11 @@ class spectator:base_client
virtual void(void) PostFrame;
virtual void(void) SpectatorTrackPlayer;
virtual int(void) IsFakeSpectator;
virtual int(void) IsRealSpectator;
virtual int(void) IsDead;
virtual int(void) IsPlayer;
#ifdef SERVER
virtual void(void) EvaluateEntity;
virtual float(entity, float) SendEntity;

View File

@ -14,6 +14,31 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int
spectator::IsRealSpectator(void)
{
return (TRUE);
}
int
spectator::IsDead(void)
{
return (FALSE);
}
int
spectator::IsPlayer(void)
{
return (FALSE);
}
int
spectator::IsFakeSpectator(void)
{
return (FALSE);
}
void
spectator::ClientInput(void)
{
@ -434,10 +459,6 @@ spectator::spectator(void)
maxspeed = 250;
spec_ent = 0;
spec_mode = 0;
#ifdef SERVER
forceinfokey(this, "*spec", "1");
#endif
}
#ifdef CLIENT