Browse Source

Implement mp_checkentities to prevent creating too many monsters

gravgun
mittorn 8 years ago
parent
commit
9944698ae5
  1. 6
      dlls/cbase.cpp
  2. 96
      dlls/coop.cpp
  3. 2
      dlls/coop_util.h
  4. 3
      dlls/game.cpp
  5. 2
      dlls/player.h

6
dlls/cbase.cpp

@ -129,10 +129,16 @@ int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion ) @@ -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

96
dlls/coop.cpp

@ -814,3 +814,99 @@ bool UTIL_CoopConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int co @@ -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;
}

2
dlls/coop_util.h

@ -28,6 +28,8 @@ extern cvar_t mp_coop_reconnect_hack; @@ -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;

3
dlls/game.cpp

@ -64,6 +64,7 @@ cvar_t mp_unduck = { "mp_unduck", "0", FCVAR_SERVER }; @@ -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 ) @@ -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 );

2
dlls/player.h

@ -338,6 +338,8 @@ public: @@ -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 );
};

Loading…
Cancel
Save