Implement mp_checkentities to prevent creating too many monsters

This commit is contained in:
mittorn 2017-02-13 21:14:07 +00:00
parent 22d9421b0b
commit 9944698ae5
5 changed files with 109 additions and 0 deletions

View File

@ -129,10 +129,16 @@ int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion )
}
#endif
int UTIL_CoopCheckSpawn( edict_t *pent );
int DispatchSpawn( edict_t *pent )
{
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
int ret = UTIL_CoopCheckSpawn( pent );
if( ret )
return ret;
if( pEntity )
{
// Initialize these or entities who don't link to the world won't have anything in here

View File

@ -814,3 +814,99 @@ bool UTIL_CoopConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int co
}
return true;
}
#ifdef _WIN32
// Shitty windows does not even have this!!!!!!!
#include <string.h>
/* @NOPEDANTRY: ignore use of reserved identifier */
char *strrstr(const char *x, const char *y) {
char *prev = NULL;
char *next;
if (*y == '\0')
return strchr(x, '\0');
while ((next = strstr(x, y)) != NULL) {
prev = next;
x = next + 1;
}
return prev;
}
#endif
int UTIL_CheckForEntTools( edict_t *pent )
{
if( pent->v.targetname )
{
char *s = (char*)STRING( pent->v.targetname );
char str[256];
strcpy( str, s );
s = strrstr( str, "_e" );
if( s )
{
*s = 0;
s = s + 2;
if( atoi(s) == ENTINDEX( pent ) )
{
s = strrstr( str, "_");
if( s )
{
int userid = atoi( s + 1 );
for( int i = 1; i < gpGlobals->maxClients; i++ )
if( userid == g_engfuncs.pfnGetPlayerUserId( INDEXENT( i ) ) )
return i;
}
}
}
}
return 0;
}
int UTIL_CoopCheckSpawn( edict_t *pent )
{
if( mp_checkentities.value )
{
const char *szClassName = NULL;
if( !pent->v.classname )
return 0;
szClassName = STRING( pent->v.classname );
if( !szClassName || !szClassName[0] )
return 0;
if( strstr( szClassName, "monster_") )
{
CBasePlayer *pPlayer = (CBasePlayer*)UTIL_PlayerByIndex( UTIL_CheckForEntTools( pent ) );
if( pPlayer )
{
if( UTIL_CoopIsBadPlayer( pPlayer ) )
{
pent->v.flags = FL_KILLME;
return -1;
}
if( gpGlobals->time - pPlayer->m_fEnttoolsMonsterTime < 5 )
{
UTIL_CoopKickPlayer( pPlayer );
pent->v.flags = FL_KILLME;
return -1;
}
if( gpGlobals->time - pPlayer->m_fEnttoolsMonsterTime > 120 )
pPlayer->m_iEnttoolsMonsters = 0;
if( pPlayer->m_iEnttoolsMonsters > 5 )
{
UTIL_CoopKickPlayer( pPlayer );
pent->v.flags = FL_KILLME;
return -1;
}
pPlayer->m_iEnttoolsMonsters++;
pPlayer->m_fEnttoolsMonsterTime = gpGlobals->time;
}
}
}
return 0;
}

View File

@ -28,6 +28,8 @@ extern cvar_t mp_coop_reconnect_hack;
extern cvar_t mp_coop_noangry;
extern cvar_t mp_spectator;
extern cvar_t mp_fixhornetbug;
extern cvar_t mp_checkentities;
extern cvar_t sentences_txt;
extern cvar_t materials_txt;

View File

@ -64,6 +64,7 @@ cvar_t mp_unduck = { "mp_unduck", "0", FCVAR_SERVER };
cvar_t mp_semclip = { "mp_semclip", "0", FCVAR_SERVER };
cvar_t mp_spectator = { "mp_spectator", "0", FCVAR_SERVER };
cvar_t mp_fixhornetbug = { "mp_fixhornetbug", "0", FCVAR_SERVER };
cvar_t mp_checkentities = { "mp_checkentities", "0", FCVAR_SERVER };
cvar_t materials_txt = { "materials_txt", "sound/materials.txt", FCVAR_SERVER };
cvar_t sentences_txt = { "sentences_txt", "sound/sentences.txt", FCVAR_SERVER };
@ -522,6 +523,8 @@ void GameDLLInit( void )
CVAR_REGISTER( &mp_skipdefaults );
CVAR_REGISTER( &mp_coop_strongcheckpoints );
CVAR_REGISTER( &mp_fixhornetbug );
CVAR_REGISTER( &mp_checkentities );
CVAR_REGISTER( &sentences_txt );

View File

@ -338,6 +338,8 @@ public:
int m_iMenuState;
int m_iLocalConfirm;
int m_iConfirmKey;
int m_iEnttoolsMonsters;
float m_fEnttoolsMonsterTime;
virtual void Touch( CBaseEntity *pOther );
};