Raised This Month: $ Target: $400
 0% 

GetEntityClassname() and connecting players


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 06-26-2022 , 12:05   GetEntityClassname() and connecting players
Reply With Quote #1

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: [SMException reportedEntity 21 (21is invalid
L 06
/24/2022 20:28:17: [SMBlamingGameplay\Buildings\engipads.smx
L 06
/24/2022 20:28:17: [SMCall stack trace:
L 06/24/2022 20:28:17: [SM]   [0GetEntPropString
L 06
/24/2022 20:28:17: [SM]   [1Line 758C:\Users\User\Dropbox\compilator\include\entity.inc::GetEntityClassname
L 06
/24/2022 20:28:17: [SM]   [2Line 404engipads.sp::HookSound 
Ok, I checked this offending plugin and I can see that:
PHP Code:
public Action HookSound(int clients[MAXPLAYERS], int &numClientschar sample[PLATFORM_MAX_PATH],
        
int &entityint &channelfloat &volumeint &levelint &pitchint &flags,
        
char soundEntry[PLATFORM_MAX_PATH], int &seed)
{
    if (
IsValidEntity(entity))
    {
        
char className[64];
        
GetEntityClassname(entityclassNamesizeof(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 && 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.
__________________
My plugins:
*None for now*


Steam:
naydef

Last edited by Naydef; 06-26-2022 at 12:06.
Naydef is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode