Raised This Month: $32 Target: $400
 8% 

Edict Overflow Prevention v2.9 (18/12/15)


Post New Thread Reply   
 
Thread Tools Display Modes
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 09-08-2014 , 01:58   Re: [ANY] Edict Overflow Fix
Reply With Quote #11

Here's a version with a new ConVar to enable/disable the plugin and enable the plugin with server prints & I also added functionality to include both of the plugin versions you can enable/disable using 'eof_entlimit_action' with a value of 3 instead.

I mainly did this because I log everything printed to my console and I'd rather not have some of the prints in this plugin pop up BUT I didn't want to remove them.
Attached Files
File Type: sp Get Plugin or Get Source (edictoverflowfix_advanced_edit.sp - 524 views - 6.4 KB)
Drixevel is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-08-2014 , 08:42   Re: [ANY] Edict Overflow Fix
Reply With Quote #12

Version 0.6 Uploaded, Reworked the Logic once again, This version should end all of the previous problems.

Cheers
SM9 is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-08-2014 , 09:08   Re: [ANY] Edict Overflow Fix
Reply With Quote #13

Geez, seems this OnGameFrame loop is quite expensive on certain maps and causes lag. On other maps it seems ok though. Anybody got any ideas on how I can optimize this?
SM9 is offline
floube
SourceMod Donor
Join Date: Jan 2013
Location: Austria
Old 09-08-2014 , 10:46   Re: [ANY] Edict Overflow Fix
Reply With Quote #14

Quote:
Originally Posted by xCoderx View Post
Geez, seems this OnGameFrame loop is quite expensive on certain maps and causes lag. On other maps it seems ok though. Anybody got any ideas on how I can optimize this?
This should be at least a bit optimized, since you're running quite a few useless resource intensive things (FindEntityByClassname). Did not test, though.

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#define PLUGIN_VERSION "0.6"

public Plugin:myinfo 
{
    
name "Edict Overflow Fix",
    
author "xCoderx",
    
version PLUGIN_VERSION,
    
url "www.bravegaming.net"
};

new 
Handle:g_hEntLimit INVALID_HANDLE;
new 
g_entityLimit;
new 
g_maxEntities;
new 
String:g_className[64];

public 
OnPluginStart()
{
    
CreateConVar("eof_version"PLUGIN_VERSION"Edict Overflow Fix"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_DONTRECORD|FCVAR_NOTIFY);
    
g_hEntLimit CreateConVar("eof_entlimit""1024""Max Edicts of an Entity at any time.");
    
HookConVarChange(g_hEntLimitCvarChange_EntLimit);
    
g_entityLimit GetConVarInt(g_hEntLimit);
    
g_maxEntities GetMaxEntities();
}

/* ----- CONVAR HOOKS ----- */

public CvarChange_EntLimit(Handle:Cvar, const String:strOldValue[], const String:strNewValue[])
{
    
g_entityLimit StringToInt(strNewValue);
}

/* ----- LOGIC ----- */

public OnGameFrame() {
    for (new 
entity MaxClients 1entity g_maxEntitiesentity++) {
        if (!
IsValidEntity(entity)) {
            continue;
        }

        
GetEntityClassname(entityg_classNamesizeof(g_className));

        if (
Entity_GetCount(g_className) > g_entityLimit) {
            if (
IsValidEntity(entity) && IsValidEdict(entity)) {
                
PrintToServer("[EOF] [%s] has went over limit [%d], Killing It."g_classNameg_entityLimit);
                
RemoveEdict(entity);
            }
        }
    }
}

public 
OnEntityCreated(entity)
{
    if (
entity >= 2044
    {
        
SDKHook(entitySDKHook_SpawnStopEnt);
    }
}

public 
Action:StopEnt(entity)
{
    
PrintToServer("[EOF] Server has reached a critical level [%d], Preventing entity spawns."entity);
    return 
Plugin_Stop;
}

stock Entity_GetCount(const String:className[])
{
    new 
count 0entity = -1;

    while ((
entity FindEntityByClassname(entityclassName)) != INVALID_ENT_REFERENCE) {
        
count++;
    }
    
    return 
count;

__________________
floube is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-08-2014 , 10:59   Re: [ANY] Edict Overflow Fix
Reply With Quote #15

Quote:
Originally Posted by Oshizu View Post
Hi,

This issue is caused by server having too many entities on map
There is limit of 2048 entities with edicts associated.
Entities like players, weapons, hats, npcs, projectiles etc.
If it reaches 2048th entity and server will try to spawn 2049th then srcds shall crash
For whatever reason, Valve only allocates 11 bits for edict indexes (ran across this in stddefs.h while looking for something else).

It's a constant, so Valve probably *could* fix it easily enough and just recompile the games. Unless there's some specific reason it's limited to 11 bits...
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 09-08-2014 at 10:59.
Powerlord is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-08-2014 , 12:36   Re: [ANY] Edict Overflow Fix
Reply With Quote #16

Quote:
Originally Posted by floube View Post
This should be at least a bit optimized, since you're running quite a few useless resource intensive things (FindEntityByClassname). Did not test, though.

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#define PLUGIN_VERSION "0.6"

public Plugin:myinfo 
{
    
name "Edict Overflow Fix",
    
author "xCoderx",
    
version PLUGIN_VERSION,
    
url "www.bravegaming.net"
};

new 
Handle:g_hEntLimit INVALID_HANDLE;
new 
g_entityLimit;
new 
g_maxEntities;
new 
String:g_className[64];

public 
OnPluginStart()
{
    
CreateConVar("eof_version"PLUGIN_VERSION"Edict Overflow Fix"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_DONTRECORD|FCVAR_NOTIFY);
    
g_hEntLimit CreateConVar("eof_entlimit""1024""Max Edicts of an Entity at any time.");
    
HookConVarChange(g_hEntLimitCvarChange_EntLimit);
    
g_entityLimit GetConVarInt(g_hEntLimit);
    
g_maxEntities GetMaxEntities();
}

/* ----- CONVAR HOOKS ----- */

public CvarChange_EntLimit(Handle:Cvar, const String:strOldValue[], const String:strNewValue[])
{
    
g_entityLimit StringToInt(strNewValue);
}

/* ----- LOGIC ----- */

public OnGameFrame() {
    for (new 
entity MaxClients 1entity g_maxEntitiesentity++) {
        if (!
IsValidEntity(entity)) {
            continue;
        }

        
GetEntityClassname(entityg_classNamesizeof(g_className));

        if (
Entity_GetCount(g_className) > g_entityLimit) {
            if (
IsValidEntity(entity) && IsValidEdict(entity)) {
                
PrintToServer("[EOF] [%s] has went over limit [%d], Killing It."g_classNameg_entityLimit);
                
RemoveEdict(entity);
            }
        }
    }
}

public 
OnEntityCreated(entity)
{
    if (
entity >= 2044
    {
        
SDKHook(entitySDKHook_SpawnStopEnt);
    }
}

public 
Action:StopEnt(entity)
{
    
PrintToServer("[EOF] Server has reached a critical level [%d], Preventing entity spawns."entity);
    return 
Plugin_Stop;
}

stock Entity_GetCount(const String:className[])
{
    new 
count 0entity = -1;

    while ((
entity FindEntityByClassname(entityclassName)) != INVALID_ENT_REFERENCE) {
        
count++;
    }
    
    return 
count;

Thanks

Version 0.7 Released -
Lots of code optimization with thanks to floube.
Improved code logic even more.
SM9 is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 09-08-2014 , 13:24   Re: [ANY] Edict Overflow Fix
Reply With Quote #17

Version 0.5 allowed server crash twice. Version 0.6 caused sustained 100% CPU usage, even after mapchange and unloading/refreshing plugins. I'll give version 0.7 a try.

Thanks for working on this!
PC Gamer is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-08-2014 , 14:06   Re: [ANY] Edict Overflow Fix
Reply With Quote #18

Quote:
Originally Posted by PC Gamer View Post
Version 0.5 allowed server crash twice. Version 0.6 caused sustained 100% CPU usage, even after mapchange and unloading/refreshing plugins. I'll give version 0.7 a try.

Thanks for working on this!
I can seewhy this plugin takes up so much of the CPU since it iterates though every entity every frame.
Mitchell is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 09-08-2014 , 14:29   Re: [ANY] Edict Overflow Fix
Reply With Quote #19

I put version 0.7 through stress testing. Here are the errors that appeared in the error log before the server became unresponsive:

L 09/08/2014 - 13:24:02: [SM] Plugin encountered error 30: Script execution timed out
L 09/08/2014 - 13:24:02: [SM] Displaying call stack trace for plugin "edictoverflowfix.smx":
L 09/08/2014 - 13:24:02: [SM] [0] Line 97, /home/forums/content/files/2/3/7/2/6/0/137704.attach::Entity_GetCount()
L 09/08/2014 - 13:24:02: [SM] [1] Line 82, /home/forums/content/files/2/3/7/2/6/0/137704.attach::HandleEdict()
L 09/08/2014 - 13:24:02: [SM] [2] Line 63, /home/forums/content/files/2/3/7/2/6/0/137704.attach::EntHook()
PC Gamer is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-08-2014 , 15:15   Re: [ANY] Edict Overflow Fix
Reply With Quote #20

Quote:
Originally Posted by PC Gamer View Post
I put version 0.7 through stress testing. Here are the errors that appeared in the error log before the server became unresponsive:

L 09/08/2014 - 13:24:02: [SM] Plugin encountered error 30: Script execution timed out
L 09/08/2014 - 13:24:02: [SM] Displaying call stack trace for plugin "edictoverflowfix.smx":
L 09/08/2014 - 13:24:02: [SM] [0] Line 97, /home/forums/content/files/2/3/7/2/6/0/137704.attach::Entity_GetCount()
L 09/08/2014 - 13:24:02: [SM] [1] Line 82, /home/forums/content/files/2/3/7/2/6/0/137704.attach::HandleEdict()
L 09/08/2014 - 13:24:02: [SM] [2] Line 63, /home/forums/content/files/2/3/7/2/6/0/137704.attach::EntHook()
Version 0.8 Released -
Optimized plugin even more & Fixed loop timeout issue.

That should finally do the trick!

Last edited by SM9; 09-08-2014 at 15:16.
SM9 is offline
Reply


Thread Tools
Display Modes

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 17:48.


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