I asked about this in the IRC server, but no response.
So I can notice sometimes in the server error logs that some plugins, in this case
Engineer pads, are throwing invalid entity errors.
PHP Code:
L 06/24/2022 - 20:28:17: [SM] Exception reported: Entity 21 (21) is invalid
L 06/24/2022 - 20:28:17: [SM] Blaming: Gameplay\Buildings\engipads.smx
L 06/24/2022 - 20:28:17: [SM] Call stack trace:
L 06/24/2022 - 20:28:17: [SM] [0] GetEntPropString
L 06/24/2022 - 20:28:17: [SM] [1] Line 758, C:\Users\User\Dropbox\compilator\include\entity.inc::GetEntityClassname
L 06/24/2022 - 20:28:17: [SM] [2] Line 404, engipads.sp::HookSound
Ok, I checked this offending plugin and I can see that:
PHP Code:
public Action HookSound(int clients[MAXPLAYERS], int &numClients, char sample[PLATFORM_MAX_PATH],
int &entity, int &channel, float &volume, int &level, int &pitch, int &flags,
char soundEntry[PLATFORM_MAX_PATH], int &seed)
{
if (IsValidEntity(entity))
{
char className[64];
GetEntityClassname(entity, className, sizeof(className)); // Line 404
if (StrEqual(className, "obj_attachment_sapper") && TF2_GetObjectType(entity) == TFObject_Sapper && channel == SNDCHAN_STATIC)
{
//...
}
}
return Plugin_Continue;
}
So there's entity validity check before calling
GetEntityClassname(). So I dig deeper.
GetEntityClassname() calls
GetEntPropString(). All these
Get/SetEntProp[Int/String/Float] functions call
IndexToAThings() function. If it returns false this error will be printed. Inside this function i see some special casing for player entities:
PHP Code:
int index = g_HL2.ReferenceToIndex(num);
if (index > 0 && index <= g_Players.GetMaxClients())
{
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
if (!pPlayer || !pPlayer->IsConnected())
{
return false;
}
}
There's a
IsConnected() check inside. So we can't get entity classname(or use any of the prop getting/setting functions) if it's a player that's unconnected. Why? Is this an oversight(SM bug) or something plugins should check before using these functions? What should be done? I need opinion on this.
__________________