Browse Source

Update gravgunmod

gravgun
mittorn 7 years ago
parent
commit
4973eb01a7
  1. 4
      dlls/cbase.cpp
  2. 4
      dlls/cbase.h
  3. 21
      dlls/client.cpp
  4. 147
      dlls/coop.cpp
  5. 152
      dlls/enttools.cpp
  6. 6
      dlls/enttools.h
  7. 6
      dlls/gamerules.cpp
  8. 192
      dlls/gravgunmod.cpp
  9. 38
      dlls/gravgunmod.h
  10. 24
      dlls/multiplay_gamerules.cpp
  11. 6
      dlls/player.cpp
  12. 31
      dlls/player.h
  13. 2
      dlls/singleplay_gamerules.cpp
  14. 10
      dlls/triggers.cpp

4
dlls/cbase.cpp

@ -129,13 +129,13 @@ int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion ) @@ -129,13 +129,13 @@ int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion )
}
#endif
int UTIL_CoopCheckSpawn( edict_t *pent );
int Ent_CheckEntitySpawn( edict_t *pent );
int DispatchSpawn( edict_t *pent )
{
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
int ret = UTIL_CoopCheckSpawn( pent );
int ret = Ent_CheckEntitySpawn( pent );
if( ret )
return ret;

4
dlls/cbase.h

@ -49,6 +49,8 @@ CBaseEntity @@ -49,6 +49,8 @@ CBaseEntity
#include "monsterevent.h"
#endif
#include "enttools.h"
// C functions for external declarations that call the appropriate C++ methods
#include "exportdef.h"
@ -350,6 +352,8 @@ public: @@ -350,6 +352,8 @@ public:
enum EGON_FIRESTATE { FIRE_OFF, FIRE_CHARGE };
int m_fireState;
EntoolsEntData enttools_data;
};
// Ugly technique to override base member functions

21
dlls/client.cpp

@ -83,7 +83,7 @@ BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddres @@ -83,7 +83,7 @@ BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddres
CBasePlayer *pl = (CBasePlayer *)CBaseEntity::Instance( pEntity ) ;
if( pl )
{
pl->m_state = STATE_UNINITIALIZED;
pl->gravgunmod_data.m_state = STATE_UNINITIALIZED;
pl->RemoveAllItems( TRUE );
UTIL_BecomeSpectator( pl );
}
@ -140,7 +140,7 @@ void ClientDisconnect( edict_t *pEntity ) @@ -140,7 +140,7 @@ void ClientDisconnect( edict_t *pEntity )
{
CBasePlayer *pPlayer = (CBasePlayer*)CBaseEntity::Instance( pEntity );
if( pPlayer )
pPlayer->m_state = STATE_UNINITIALIZED;
pPlayer->gravgunmod_data.m_state = STATE_UNINITIALIZED;
}
}
@ -219,20 +219,13 @@ void ClientPutInServer( edict_t *pEntity ) @@ -219,20 +219,13 @@ void ClientPutInServer( edict_t *pEntity )
pPlayer = GetClassPtr((CBasePlayer *)pev);
pPlayer->SetCustomDecalFrames(-1); // Assume none;
if( mp_coop.value && pPlayer->m_state == STATE_UNINITIALIZED )
g_engfuncs.pfnQueryClientCvarValue2( pEntity, "touch_enable", 111 );
pPlayer->m_state = STATE_CONNECTED;
GGM_ClientPutinServer( pEntity, pPlayer );
// Allocate a CBasePlayer for pev, and call spawn
pPlayer->Spawn();
// AGHL-like spectator
if( mp_spectator.value )
{
pPlayer->RemoveAllItems( TRUE );
UTIL_BecomeSpectator( pPlayer );
}
GGM_ClientFirstSpawn( pPlayer );
// Reset interpolation during first frame
pPlayer->pev->effects |= EF_NOINTERP;
@ -614,7 +607,7 @@ void ClientUserInfoChanged( edict_t *pEntity, char *infobuffer ) @@ -614,7 +607,7 @@ void ClientUserInfoChanged( edict_t *pEntity, char *infobuffer )
g_engfuncs.pfnSetClientKeyValue( ENTINDEX(pEntity), infobuffer, "name", sName );
// prevent phantom nickname changed messages
if( mp_coop.value && ((CBasePlayer *)pEntity->pvPrivateData)->m_state == STATE_UNINITIALIZED )
if( mp_coop.value && ((CBasePlayer *)pEntity->pvPrivateData)->gravgunmod_data.m_state == STATE_UNINITIALIZED )
return;
char text[256];
@ -711,7 +704,7 @@ void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) @@ -711,7 +704,7 @@ void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
// reset all players state
if( plr )
{
plr->m_state = STATE_UNINITIALIZED;
plr->gravgunmod_data.m_state = STATE_UNINITIALIZED;
plr->RemoveAllItems( TRUE );
UTIL_BecomeSpectator( plr );
//plr->Spawn();
@ -1917,7 +1910,7 @@ void CvarValue2( const edict_t *pEnt, int requestID, const char *cvarName, const @@ -1917,7 +1910,7 @@ void CvarValue2( const edict_t *pEnt, int requestID, const char *cvarName, const
if( mp_coop.value && pEnt && requestID == 111 && FStrEq( cvarName , "touch_enable" ) && atoi( value) )
{
CBasePlayer *player = (CBasePlayer * ) CBaseEntity::Instance( (edict_t*)pEnt );
player->m_fTouchMenu = !!atof( value );
player->gravgunmod_data.m_fTouchMenu = !!atof( value );
CLIENT_COMMAND((edict_t*)pEnt, "touch_addbutton \"_coopm\" \"*black\" \"coopmenu\" 0 0.05 0.15 0.11 0 0 0 128 335\ntouch_addbutton \"_coopmt\" \"#COOP MENU\" \"\" 0 0.05 0.16 0.11 255 255 127 255 79 2\nm1\n");
}

147
dlls/coop.cpp

@ -206,7 +206,7 @@ void UTIL_BecomeSpectator( CBasePlayer *pPlayer ) @@ -206,7 +206,7 @@ void UTIL_BecomeSpectator( CBasePlayer *pPlayer )
void UTIL_SpawnPlayer( CBasePlayer *pPlayer )
{
pPlayer->m_state = STATE_SPAWNED;
pPlayer->gravgunmod_data.m_state = STATE_SPAWNED;
pPlayer->m_iRespawnFrames = 0;
pPlayer->pev->effects &= ~EF_NODRAW;
@ -336,9 +336,9 @@ void UTIL_CoopLocalConfirmMenu(CBasePlayer *pPlayer) @@ -336,9 +336,9 @@ void UTIL_CoopLocalConfirmMenu(CBasePlayer *pPlayer)
"Единая Россия"
};
menu[pPlayer->m_iConfirmKey = RANDOM_LONG(2,4)] = "Confirm";
menu[pPlayer->gravgunmod_data.m_iConfirmKey = RANDOM_LONG(2,4)] = "Confirm";
UTIL_CoopShowMenu(pPlayer, "Confirm changing map BACK (NOT RECOMMENDED)?", ARRAYSIZE(menu), menu);
pPlayer->m_iMenuState = MENUSTATE_LOCAL_CONFIRM;
pPlayer->gravgunmod_data.m_iMenuState = MENUSTATE_LOCAL_CONFIRM;
}
@ -422,7 +422,7 @@ void GlobalMenu::ShowGlobalMenu( const char *title, int count, const char **menu @@ -422,7 +422,7 @@ void GlobalMenu::ShowGlobalMenu( const char *title, int count, const char **menu
count2++;
CBasePlayer *player = (CBasePlayer *) plr;
UTIL_CoopShowMenu( player, title, count, menu, 30 );
player->m_iMenuState = MENUSTATE_GLOBAL;
player->gravgunmod_data.m_iMenuState = MENUSTATE_GLOBAL;
}
}
@ -434,9 +434,9 @@ void GlobalMenu::ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const @@ -434,9 +434,9 @@ void GlobalMenu::ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const
{
if( g_iMenu && gpGlobals->time - m_flTime < 30 )
return; // wait 30s befor new confirm vote
if( pPlayer->m_iMenuState == MENUSTATE_LOCAL_CONFIRM )
if( pPlayer->gravgunmod_data.m_iMenuState == MENUSTATE_LOCAL_CONFIRM )
return;
if( pPlayer->m_iLocalConfirm < 3 )
if( pPlayer->gravgunmod_data.m_iLocalConfirm < 3 )
{
UTIL_CoopLocalConfirmMenu( pPlayer );
return;
@ -460,7 +460,7 @@ void GlobalMenu::ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const @@ -460,7 +460,7 @@ void GlobalMenu::ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const
void UTIL_CoopCheckpointMenu( CBasePlayer *pPlayer )
{
//if( pPlayer->m_state == STATE_SPAWNED )
//if( pPlayer->gravgunmod_data.m_state == STATE_SPAWNED )
{
if( mp_coop_checkpoints.value )
@ -469,12 +469,12 @@ void UTIL_CoopCheckpointMenu( CBasePlayer *pPlayer ) @@ -469,12 +469,12 @@ void UTIL_CoopCheckpointMenu( CBasePlayer *pPlayer )
"New checkpoint"
};
int i;
if( pPlayer->m_state == STATE_SPECTATOR || pPlayer->m_state == STATE_SPECTATOR_BEGIN )
if( pPlayer->gravgunmod_data.m_state == STATE_SPECTATOR || pPlayer->gravgunmod_data.m_state == STATE_SPECTATOR_BEGIN )
menu[0] = "Just spawn";
for( i = 1; g_checkpoints[i-1].time; i++ )
menu[i] = g_checkpoints[i-1].str;
UTIL_CoopShowMenu( pPlayer, "Select checkpoint", i, menu );
pPlayer->m_iMenuState = MENUSTATE_CHECKPOINT;
pPlayer->gravgunmod_data.m_iMenuState = MENUSTATE_CHECKPOINT;
}
}
}
@ -516,9 +516,9 @@ void UTIL_CoopVoteMenu( CBasePlayer *pPlayer ) @@ -516,9 +516,9 @@ void UTIL_CoopVoteMenu( CBasePlayer *pPlayer )
void UTIL_CoopMenu( CBasePlayer *pPlayer )
{
if( pPlayer->m_state == STATE_SPAWNED )
if( pPlayer->gravgunmod_data.m_state == STATE_SPAWNED )
{
pPlayer->m_iMenuState = MENUSTATE_COOPMENU;
pPlayer->gravgunmod_data.m_iMenuState = MENUSTATE_COOPMENU;
if( mp_coop.value )
{
const char *menu[] = {
@ -534,9 +534,9 @@ void UTIL_CoopMenu( CBasePlayer *pPlayer ) @@ -534,9 +534,9 @@ void UTIL_CoopMenu( CBasePlayer *pPlayer )
UTIL_CoopShowMenu( pPlayer, "Coop menu", count1, menu );
}
}
else if ( pPlayer->m_state == STATE_SPECTATOR )
else if ( pPlayer->gravgunmod_data.m_state == STATE_SPECTATOR )
{
pPlayer->m_iMenuState = MENUSTATE_COOPMENU_SPEC;
pPlayer->gravgunmod_data.m_iMenuState = MENUSTATE_COOPMENU_SPEC;
if( mp_coop.value )
{
const char *menu[] = {
@ -551,7 +551,7 @@ void UTIL_CoopMenu( CBasePlayer *pPlayer ) @@ -551,7 +551,7 @@ void UTIL_CoopMenu( CBasePlayer *pPlayer )
void UTIL_CoopProcessMenu( CBasePlayer *pPlayer, int imenu )
{
switch( pPlayer->m_iMenuState )
switch( pPlayer->gravgunmod_data.m_iMenuState )
{
case MENUSTATE_COOPMENU_SPEC:
if( imenu == 1 )
@ -561,17 +561,17 @@ void UTIL_CoopProcessMenu( CBasePlayer *pPlayer, int imenu ) @@ -561,17 +561,17 @@ void UTIL_CoopProcessMenu( CBasePlayer *pPlayer, int imenu )
else
{
UTIL_SpawnPlayer( pPlayer );
pPlayer->m_state = STATE_SPAWNED;
pPlayer->gravgunmod_data.m_state = STATE_SPAWNED;
}
}
if( imenu == 2 )
{
pPlayer->m_state = STATE_SPECTATOR;
pPlayer->gravgunmod_data.m_state = STATE_SPECTATOR;
CLIENT_COMMAND( pPlayer->edict(), "touch_show _coopm*\n" );
}
break;
case MENUSTATE_COOPMENU:
if( pPlayer->m_state != STATE_SPAWNED )
if( pPlayer->gravgunmod_data.m_state != STATE_SPAWNED )
break;
if( imenu == 1 )
{
@ -586,7 +586,7 @@ void UTIL_CoopProcessMenu( CBasePlayer *pPlayer, int imenu ) @@ -586,7 +586,7 @@ void UTIL_CoopProcessMenu( CBasePlayer *pPlayer, int imenu )
{
pPlayer->RemoveAllItems( TRUE );
UTIL_BecomeSpectator( pPlayer );
pPlayer->m_state = STATE_SPECTATOR;
pPlayer->gravgunmod_data.m_state = STATE_SPECTATOR;
}
if( imenu == 4 )
{
@ -604,7 +604,7 @@ void UTIL_CoopProcessMenu( CBasePlayer *pPlayer, int imenu ) @@ -604,7 +604,7 @@ void UTIL_CoopProcessMenu( CBasePlayer *pPlayer, int imenu )
case MENUSTATE_CHECKPOINT:
if( imenu == 1 )
{
if( pPlayer->m_state != STATE_SPAWNED )
if( pPlayer->gravgunmod_data.m_state != STATE_SPAWNED )
UTIL_SpawnPlayer( pPlayer );
else if( !UTIL_CoopIsBadPlayer( pPlayer ) )
UTIL_CoopNewCheckpoint( pPlayer->pev );
@ -618,16 +618,16 @@ void UTIL_CoopProcessMenu( CBasePlayer *pPlayer, int imenu ) @@ -618,16 +618,16 @@ void UTIL_CoopProcessMenu( CBasePlayer *pPlayer, int imenu )
}
break;
case MENUSTATE_LOCAL_CONFIRM:
if( imenu - 1 == pPlayer->m_iConfirmKey )
pPlayer->m_iLocalConfirm++;
if( imenu - 1 == pPlayer->gravgunmod_data.m_iConfirmKey )
pPlayer->gravgunmod_data.m_iLocalConfirm++;
else
pPlayer->m_iLocalConfirm = 0;
pPlayer->m_iMenuState = MENUSTATE_NONE;
pPlayer->gravgunmod_data.m_iLocalConfirm = 0;
pPlayer->gravgunmod_data.m_iMenuState = MENUSTATE_NONE;
break;
default:
break;
}
//pPlayer->m_iMenuState = MENUSTATE_NONE;
//pPlayer->gravgunmod_data.m_iMenuState = MENUSTATE_NONE;
}
bool UTIL_CoopRestorePlayerCoords(CBaseEntity *player, Vector *origin, Vector *angles )
@ -772,7 +772,7 @@ extern int gmsgShowMenu; @@ -772,7 +772,7 @@ extern int gmsgShowMenu;
void UTIL_CoopShowMenu( CBasePlayer *pPlayer, const char *title, int count, const char **slot, signed char time )
{
if( pPlayer->m_fTouchMenu)
if( pPlayer->gravgunmod_data.m_fTouchMenu)
{
char buf[256];
#define MENU_STR(VAR) (#VAR)
@ -833,103 +833,6 @@ bool UTIL_CoopConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int co @@ -833,103 +833,6 @@ bool UTIL_CoopConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int co
return true;
}
#include <string.h>
/* @NOPEDANTRY: ignore use of reserved identifier */
static char *strrstr(const char *x, const char *y) {
char *prev = NULL;
char *next;
if (*y == '\0')
return (char*)strchr(x, '\0');
while ((next = (char*)strstr(x, y)) != NULL) {
prev = next;
x = next + 1;
}
return prev;
}
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;
}
void COOP_RegisterCVars()
{
CVAR_REGISTER( &mp_coop );

152
dlls/enttools.cpp

@ -2,19 +2,15 @@ @@ -2,19 +2,15 @@
#include "util.h"
#include "cbase.h"
#include "game.h"
#include "player.h"
#define Ent_IsValidEdict( e ) ( e && !e->free )
bool Q_isdigit( const char *str )
{
if( str && *str )
{
while( isdigit( *str )) str++;
if( !*str ) return true;
}
return false;
}
// stop any actions with players
static cvar_t mp_enttools_players = { "mp_enttools_players", "0", FCVAR_SERVER };
// prevent ent_fire with entities not created with enttools
static cvar_t mp_enttools_lockmapentities = { "mp_enttools_lockmapentities", "0", FCVAR_SERVER };
static cvar_t mp_enttools_checkowner = { "mp_enttools_checkowner", "0", FCVAR_SERVER };
bool Q_stricmpext( const char *pattern, const char *text );
static bool Q_starcmp( const char *pattern, const char *text )
@ -64,6 +60,114 @@ bool Q_stricmpext( const char *pattern, const char *text ) @@ -64,6 +60,114 @@ bool Q_stricmpext( const char *pattern, const char *text )
return true;
}
bool Q_isdigit( const char *str )
{
if( str && *str )
{
while( isdigit( *str )) str++;
if( !*str ) return true;
}
return false;
}
typedef struct entblacklist_s
{
struct entblacklist_s *next;
char pattern[32];
int limit;
int behaviour;
} entblacklist_t;
entblacklist_t *entblacklist;
void Ent_AddToBlacklist_f( void )
{
if( CMD_ARGC() != 4 )
{
ALERT( at_console, "Usage: mp_enttools_blacklist <pattern> <per minute limit> <behaviour (0 - block, 1 - kick, 2 - ban)>\n" );
}
entblacklist_t *node = (entblacklist_t *)malloc( sizeof( entblacklist_t ) );
node->next = entblacklist;
strncpy( node->pattern, CMD_ARGV(1), 31 );
node->pattern[32] = 0;
node->limit = atoi( CMD_ARGV(2) );
node->behaviour = atoi( CMD_ARGV( 3 ) );
entblacklist = node;
}
bool Ent_CheckFire( edict_t *player, edict_t *ent, const char *command )
{
if( !mp_enttools_players.value && ENTINDEX( ent ) < gpGlobals->maxClients + 1 )
return false;
CBaseEntity *pEntity = CBaseEntity::Instance( ent );
if( pEntity )
{
if( mp_enttools_lockmapentities.value && !pEntity->enttools_data.enttools )
return false;
// only if player online
if( mp_enttools_checkowner.value == 1 )
{
if( GGM_PlayerByID( pEntity->enttools_data.ownerid ) )
return !strcmp( pEntity->enttools_data.ownerid, GGM_GetPlayerID( player ) );
}
if( mp_enttools_checkowner.value == 2 )
{
return !strcmp( pEntity->enttools_data.ownerid, GGM_GetPlayerID( player ) );
}
}
return true;
}
bool Ent_CheckCreate( edict_t *player, const char *classname )
{
CBasePlayer *p = (CBasePlayer*)CBaseEntity::Instance(player);
entblacklist_t *node;
if( !p )
return false;
if( p->gravgunmod_data.m_flEntScope > 1 )
return false;
if( gpGlobals->time - p->gravgunmod_data.m_flEntTime > 60 )
{
p->gravgunmod_data.m_flEntTime = gpGlobals->time;
p->gravgunmod_data.m_flEntScope = 0;
}
for( node = entblacklist; node; node = node->next )
{
if( Q_stricmpext(node->pattern, classname ) )
{
if( !node->limit || ( p->gravgunmod_data.m_flEntScope + 1.0f / (float)node->limit > 1 ) )
{
// remove all created entities
Ent_RunGC( false, true, GGM_GetPlayerID( player ) );
if( node->behaviour == 2 )
{
SERVER_COMMAND( UTIL_VarArgs("banid 0 #%d kick\nwriteid\n", GETPLAYERUSERID( player ) ) );
}
else if( node->behaviour == 1 )
{
SERVER_COMMAND( UTIL_VarArgs("kick #%d\nwriteid\n", GETPLAYERUSERID( player ) ) );
}
return false;
}
p->gravgunmod_data.m_flEntScope += 1.0f / (float)node->limit;
}
}
return true;
}
void Ent_ClientPrintf( edict_t *player, const char *format, ... )
{
va_list argptr;
@ -427,6 +531,9 @@ void Ent_Fire_f( edict_t *player ) @@ -427,6 +531,9 @@ void Ent_Fire_f( edict_t *player )
continue;
}
if( !Ent_CheckFire( player, ent, CMD_ARGV( 2 ) ) )
return;
Ent_ClientPrintf( player, "entity %i\n", i );
count++;
@ -649,6 +756,9 @@ void Ent_Create_f( edict_t *player ) @@ -649,6 +756,9 @@ void Ent_Create_f( edict_t *player )
return;
}
if( !Ent_CheckCreate( player, CMD_ARGV(1) ) )
return;
classname = ALLOC_STRING( CMD_ARGV( 1 ) );
ent = CREATE_NAMED_ENTITY( classname );
@ -689,18 +799,19 @@ void Ent_Create_f( edict_t *player ) @@ -689,18 +799,19 @@ void Ent_Create_f( edict_t *player )
if( !ent->v.targetname )
{
char newname[256], clientname[256];
int j;
for( i = 0; i < 32; i++ )
for( j = 0; j < 32; j++ )
{
char c = tolower( (STRING( player->v.netname ))[i] );
char c = tolower( (STRING( player->v.netname ))[j] );
if( c < 'a' || c > 'z' )
c = '_';
if( !(STRING( player->v.netname ))[i] )
if( !(STRING( player->v.netname ))[j] )
{
clientname[i] = 0;
clientname[j] = 0;
break;
}
clientname[i] = c;
clientname[j] = c;
}
// generate name based on nick name and index
@ -740,6 +851,13 @@ void Ent_Create_f( edict_t *player ) @@ -740,6 +851,13 @@ void Ent_Create_f( edict_t *player )
if( pkvd.fHandled )
Ent_ClientPrintf( player, "value \"%s\" set to \"%s\"!\n", pkvd.szKeyName, pkvd.szValue );
}
CBaseEntity *entity = CBaseEntity::Instance( ent );
if( entity )
{
entity->enttools_data.enttools = true;
strcpy( entity->enttools_data.ownerid, GGM_GetPlayerID( player ) );
}
}
typedef struct ucmd_s
{
@ -789,4 +907,8 @@ void ENT_RegisterCVars( void ) @@ -789,4 +907,8 @@ void ENT_RegisterCVars( void )
{
CVAR_REGISTER( &mp_enttools_enable );
CVAR_REGISTER( &mp_enttools_maxfire );
CVAR_REGISTER( &mp_enttools_lockmapentities );
CVAR_REGISTER( &mp_enttools_checkowner );
CVAR_REGISTER( &mp_enttools_players );
g_engfuncs.pfnAddServerCommand( "mp_enttools_addblacklist", Ent_AddToBlacklist_f );
}

6
dlls/enttools.h

@ -5,5 +5,11 @@ extern cvar_t mp_enttools_maxfire; @@ -5,5 +5,11 @@ extern cvar_t mp_enttools_maxfire;
extern cvar_t mp_enttools_enable;
bool Ent_ProcessClientCommand( edict_t *player );
void ENT_RegisterCVars( void );
struct EntoolsEntData {
bool enttools; // created by enttools
char ownerid[32];
};
#endif // ENTTOOLS_H

6
dlls/gamerules.cpp

@ -65,9 +65,9 @@ extern EHANDLE g_pLastSpawn; @@ -65,9 +65,9 @@ extern EHANDLE g_pLastSpawn;
edict_t *CGameRules::GetPlayerSpawnSpot( CBasePlayer *pPlayer )
{
edict_t *pentSpawnSpot = EntSelectSpawnPoint( pPlayer );
if( pPlayer->m_state == STATE_POINT_SELECT )
if( pPlayer->gravgunmod_data.m_state == STATE_POINT_SELECT )
{
pPlayer->m_state = STATE_SPAWNED;
pPlayer->gravgunmod_data.m_state = STATE_SPAWNED;
pPlayer->pev->effects &= ~EF_NODRAW;
pPlayer->pev->takedamage = DAMAGE_YES;
@ -104,7 +104,7 @@ edict_t *CGameRules::GetPlayerSpawnSpot( CBasePlayer *pPlayer ) @@ -104,7 +104,7 @@ edict_t *CGameRules::GetPlayerSpawnSpot( CBasePlayer *pPlayer )
UTIL_HudMessage( pPlayer, params, "Server cannot select a spawnpoint\nplease fly to it manually\nand press attack button" );
// select spawn point
pPlayer->m_state = STATE_POINT_SELECT;
pPlayer->gravgunmod_data.m_state = STATE_POINT_SELECT;
pPlayer->m_afButtonPressed = 0;
if(pPlayer->pev->origin.Length() > 8192)

192
dlls/gravgunmod.cpp

@ -2,8 +2,10 @@ @@ -2,8 +2,10 @@
#include "util.h"
#include "cbase.h"
#include "gravgunmod.h"
#include "player.h"
#include "coop_util.h"
cvar_t cvar_allow_gravgun = { "mp_allow_gravgun","1", FCVAR_SERVER };
cvar_t cvar_allow_ar2 = { "mp_allow_ar2","0", FCVAR_SERVER };
cvar_t cvar_ar2_mp5 = { "mp_ar2_mp5","0", FCVAR_SERVER };
@ -19,6 +21,8 @@ cvar_t mp_gravgun_players = { "mp_gravgun_players", "0", FCVAR_SERVER }; @@ -19,6 +21,8 @@ cvar_t mp_gravgun_players = { "mp_gravgun_players", "0", FCVAR_SERVER };
cvar_t mp_fixhornetbug = { "mp_fixhornetbug", "0", FCVAR_SERVER };
cvar_t mp_checkentities = { "mp_checkentities", "0", FCVAR_SERVER };
void Ent_RunGC_f( void );
void GGM_RegisterCVars( void )
{
CVAR_REGISTER( &cvar_allow_ar2 );
@ -34,4 +38,192 @@ void GGM_RegisterCVars( void ) @@ -34,4 +38,192 @@ void GGM_RegisterCVars( void )
CVAR_REGISTER( &mp_gravgun_players );
CVAR_REGISTER( &mp_fixhornetbug );
CVAR_REGISTER( &mp_checkentities );
g_engfuncs.pfnAddServerCommand( "ent_rungc", Ent_RunGC_f );
}
void Ent_RunGC( bool common, bool enttools, const char *userid )
{
int i, count = 0, removed = 0;
edict_t *ent = g_engfuncs.pfnPEntityOfEntIndex( gpGlobals->maxClients + 5 );
ALERT( at_warning, "Running garbage collector\n" );
for( i = gpGlobals->maxClients; i < gpGlobals->maxEntities; i++, ent++ )
{
const char *classname = STRING( ent->v.classname );
if( ent->free )
continue;
if( !classname || !ent->v.classname || !classname[0] )
continue;
count++;
if( ent->v.flags & FL_KILLME )
continue;
if( common )
{
if( !strcmp( classname, "gib" ) )
{
ent->v.flags |= FL_KILLME;
removed++;
continue;
}
if( !strncmp( classname, "monster_", 8 ) && ent->v.health <= 0 || ent->v.deadflag != DEAD_NO )
{
ent->v.flags |= FL_KILLME;
removed++;
continue;
}
}
if( !enttools )
{
if( strncmp( classname, "monster_", 8 ) || strncmp( classname, "weapon_", 7 ) || strncmp( classname, "ammo_", 5 ) )
continue;
}
if( !ent->v.owner && ent->v.spawnflags & SF_NORESPAWN )
{
ent->v.flags |= FL_KILLME;
removed++;
continue;
}
CBaseEntity *entity = CBaseEntity::Instance( ent );
if( !entity )
{
ent->v.flags |= FL_KILLME;
removed++;
continue;
}
if( enttools && entity->enttools_data.enttools )
{
if( !userid || !strcmp( userid, entity->enttools_data.ownerid ) )
{
ent->v.flags |= FL_KILLME;
removed++;
continue;
}
}
else if( common && !entity->IsInWorld() )
{
ent->v.flags |= FL_KILLME;
removed++;
continue;
}
}
ALERT( at_notice, "Total %d entities, %d cleaned\n", count, removed );
}
void Ent_RunGC_f()
{
int enttools = atoi(CMD_ARGV(1));
Ent_RunGC( !enttools, enttools, NULL );
}
int Ent_CheckEntitySpawn( edict_t *pent )
{
if( mp_checkentities.value )
{
int index = ENTINDEX( pent );
static uint counter, lastgc;
counter++;
if( gpGlobals->maxEntities - index < 10 )
{
ALERT( at_error, "REFUSING CREATING ENTITY %s\n", STRING( pent->v.classname ) );
Ent_RunGC( true, true, NULL );
return 1;
}
if( gpGlobals->maxEntities - index < 100 )
{
if( !strncmp( STRING(pent->v.classname), "env_", 4) )
return 1;
if( !strcmp( STRING(pent->v.classname), "gib" ) )
return 1;
Ent_RunGC( true, false, NULL );
return 0;
}
if( index > gpGlobals->maxEntities / 2 && counter - lastgc > 64 )
{
lastgc = counter;
Ent_RunGC( true, false, NULL );
return 0;
}
}
return 0;
}
void GGM_ClientPutinServer(edict_t *pEntity, CBasePlayer *pPlayer)
{
if( mp_coop.value && pPlayer->gravgunmod_data.m_state == STATE_UNINITIALIZED )
g_engfuncs.pfnQueryClientCvarValue2( pEntity, "touch_enable", 111 );
pPlayer->gravgunmod_data.m_state = STATE_CONNECTED;
const char *uid = GETPLAYERAUTHID( pPlayer->edict() );
if( strstr(uid, "PENDING") )
uid = g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "ip" );
strncpy( pPlayer->gravgunmod_data.uid, uid, 31 );
pPlayer->gravgunmod_data.uid[32] = 0;
pPlayer->gravgunmod_data.m_flEntTime = 0;
pPlayer->gravgunmod_data.m_flEntScope = 0;
}
void GGM_ClientFirstSpawn(CBasePlayer *pPlayer)
{
// AGHL-like spectator
if( mp_spectator.value )
{
pPlayer->RemoveAllItems( TRUE );
UTIL_BecomeSpectator( pPlayer );
}
}
edict_t *GGM_PlayerByID( const char *id )
{
for( int i = 1; i <= gpGlobals->maxClients; i++ )
{
CBaseEntity *plr = UTIL_PlayerByIndex( i );
if( plr && plr->IsPlayer() )
{
CBasePlayer *player = (CBasePlayer *) plr;
if( !strcmp( player->gravgunmod_data.uid, id ) )
return player->edict();
}
}
return NULL;
}
const char *GGM_GetPlayerID( edict_t *player )
{
CBasePlayer *plr = (CBasePlayer*)CBaseEntity::Instance( player );
if( !plr->IsPlayer() )
return NULL;
return plr->gravgunmod_data.uid;
}

38
dlls/gravgunmod.h

@ -19,6 +19,44 @@ extern cvar_t mp_fixhornetbug; @@ -19,6 +19,44 @@ extern cvar_t mp_fixhornetbug;
extern cvar_t mp_checkentities;
void GGM_RegisterCVars( void );
void Ent_RunGC( bool common, bool enttools, const char *userid );
class CBasePlayer;
void GGM_ClientPutinServer(edict_t *pEntity , CBasePlayer *pPlayer);
void GGM_ClientFirstSpawn(CBasePlayer *pPlayer );
const char *GGM_GetPlayerID( edict_t *player );
edict_t *GGM_PlayerByID( const char *id );
enum PlayerState
{
STATE_UNINITIALIZED = 0,
STATE_CONNECTED,
STATE_SPECTATOR_BEGIN,
STATE_SPAWNED,
STATE_SPECTATOR,
STATE_POINT_SELECT
};
enum PlayerMenuState
{
MENUSTATE_NONE = 0,
MENUSTATE_COOPMENU,
MENUSTATE_COOPMENU_SPEC,
MENUSTATE_CHECKPOINT,
MENUSTATE_GLOBAL,
MENUSTATE_LOCAL_CONFIRM
};
struct GGMData
{
float m_flSpawnTime;
PlayerState m_state;
bool m_fTouchMenu;
int m_iMenuState;
int m_iLocalConfirm;
int m_iConfirmKey;
float m_flEntScope;
float m_flEntTime;
char uid[32];
};
#endif // GRAVGUNMOD_H

24
dlls/multiplay_gamerules.cpp

@ -129,7 +129,7 @@ BOOL CHalfLifeMultiplay::ClientCommand( CBasePlayer *pPlayer, const char *pcmd ) @@ -129,7 +129,7 @@ BOOL CHalfLifeMultiplay::ClientCommand( CBasePlayer *pPlayer, const char *pcmd )
{
if( FStrEq( pcmd, "joincoop" ) )
{
if( pPlayer->m_state == STATE_SPECTATOR_BEGIN )
if( pPlayer->gravgunmod_data.m_state == STATE_SPECTATOR_BEGIN )
UTIL_SpawnPlayer( pPlayer );
else
ClientPrint( pPlayer->pev, HUD_PRINTCONSOLE, "You cannot use joincoop now!\n\n" );
@ -509,15 +509,15 @@ void CHalfLifeMultiplay::InitHUD( CBasePlayer *pl ) @@ -509,15 +509,15 @@ void CHalfLifeMultiplay::InitHUD( CBasePlayer *pl )
MESSAGE_END();
}
if( pl->m_state <= STATE_CONNECTED )
if( pl->gravgunmod_data.m_state <= STATE_CONNECTED )
ClientPutInServer( pl->edict() );
if( mp_coop.value )
{
if( pl->m_state == STATE_SPECTATOR_BEGIN )
if( pl->gravgunmod_data.m_state == STATE_SPECTATOR_BEGIN )
{
pl->m_iMenuState = MENUSTATE_COOPMENU_SPEC;
pl->gravgunmod_data.m_iMenuState = MENUSTATE_COOPMENU_SPEC;
if( mp_coop.value )
{
@ -601,10 +601,10 @@ BOOL CHalfLifeMultiplay::FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity @@ -601,10 +601,10 @@ BOOL CHalfLifeMultiplay::FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity
//=========================================================
void CHalfLifeMultiplay::PlayerThink( CBasePlayer *pPlayer )
{
if( !mp_coop.value && pPlayer->m_state == STATE_SPECTATOR_BEGIN )
if( !mp_coop.value && pPlayer->gravgunmod_data.m_state == STATE_SPECTATOR_BEGIN )
if( pPlayer->m_afButtonPressed & ( IN_DUCK | IN_ATTACK | IN_ATTACK2 | IN_USE | IN_JUMP ) )
UTIL_SpawnPlayer( pPlayer );
if( pPlayer->m_state == STATE_UNINITIALIZED )
if( pPlayer->gravgunmod_data.m_state == STATE_UNINITIALIZED )
if( pPlayer->m_afButtonPressed || pPlayer->pev->button )
{
ClientPutInServer( pPlayer->edict() );
@ -614,7 +614,7 @@ void CHalfLifeMultiplay::PlayerThink( CBasePlayer *pPlayer ) @@ -614,7 +614,7 @@ void CHalfLifeMultiplay::PlayerThink( CBasePlayer *pPlayer )
return;
}
if( pPlayer->m_state == STATE_POINT_SELECT )
if( pPlayer->gravgunmod_data.m_state == STATE_POINT_SELECT )
{
if( pPlayer->m_afButtonPressed & ( IN_DUCK | IN_ATTACK | IN_ATTACK2 | IN_USE | IN_JUMP ) )
pPlayer->Spawn();
@ -640,21 +640,21 @@ void CHalfLifeMultiplay::PlayerSpawn( CBasePlayer *pPlayer ) @@ -640,21 +640,21 @@ void CHalfLifeMultiplay::PlayerSpawn( CBasePlayer *pPlayer )
BOOL addDefault;
CBaseEntity *pWeaponEntity = NULL;
if( pPlayer->m_state == STATE_UNINITIALIZED )
if( pPlayer->gravgunmod_data.m_state == STATE_UNINITIALIZED )
{
ClientPutInServer( pPlayer->edict() );
return;
}
if( mp_spectator.value && pPlayer->m_state == STATE_CONNECTED )
if( mp_spectator.value && pPlayer->gravgunmod_data.m_state == STATE_CONNECTED )
{
pPlayer->m_state = STATE_SPECTATOR_BEGIN;
pPlayer->gravgunmod_data.m_state = STATE_SPECTATOR_BEGIN;
pPlayer->RemoveAllItems( TRUE );
UTIL_BecomeSpectator( pPlayer );
return;
}
if( mp_coop_changelevel.value && pPlayer->m_state == STATE_POINT_SELECT && !(pPlayer->pev->flags & FL_SPECTATOR) )
if( mp_coop_changelevel.value && pPlayer->gravgunmod_data.m_state == STATE_POINT_SELECT && !(pPlayer->pev->flags & FL_SPECTATOR) )
{
pPlayer->RemoveAllItems( TRUE );
UTIL_BecomeSpectator( pPlayer );
@ -662,7 +662,7 @@ void CHalfLifeMultiplay::PlayerSpawn( CBasePlayer *pPlayer ) @@ -662,7 +662,7 @@ void CHalfLifeMultiplay::PlayerSpawn( CBasePlayer *pPlayer )
}
if( !mp_coop_changelevel.value )
pPlayer->m_state = STATE_SPAWNED;
pPlayer->gravgunmod_data.m_state = STATE_SPAWNED;
g_fPause = false;

6
dlls/player.cpp

@ -2481,7 +2481,7 @@ void CBasePlayer::PostThink() @@ -2481,7 +2481,7 @@ void CBasePlayer::PostThink()
}
// Handle Tank controlling
if( m_pTank && m_state == STATE_SPAWNED )
if( m_pTank && gravgunmod_data.m_state == STATE_SPAWNED )
{
// if they've moved too far from the gun, or selected a weapon, unuse the gun
if( m_pTank->OnControls( pev ) && !pev->weaponmodel )
@ -2878,7 +2878,7 @@ void CBasePlayer::Spawn( void ) @@ -2878,7 +2878,7 @@ void CBasePlayer::Spawn( void )
m_lastx = m_lasty = 0;
m_flNextChatTime = gpGlobals->time;
m_flSpawnTime = gpGlobals->time;
gravgunmod_data.m_flSpawnTime = gpGlobals->time;
g_pGameRules->PlayerSpawn( this );
g_flSemclipTime = 0;
@ -3011,7 +3011,7 @@ int CBasePlayer::Restore( CRestore &restore ) @@ -3011,7 +3011,7 @@ int CBasePlayer::Restore( CRestore &restore )
// restored player has some bugs untill respawned
if( mp_coop_changelevel.value )
{
m_state = STATE_CONNECTED;
gravgunmod_data.m_state = STATE_CONNECTED;
SetThink( &CBasePlayer::Spawn );
pev->nextthink = gpGlobals->time + 0.5;
}

31
dlls/player.h

@ -83,26 +83,7 @@ enum sbar_data @@ -83,26 +83,7 @@ enum sbar_data
#define CHAT_INTERVAL 1.0f
enum PlayerState
{
STATE_UNINITIALIZED = 0,
STATE_CONNECTED,
STATE_SPECTATOR_BEGIN,
STATE_SPAWNED,
STATE_SPECTATOR,
STATE_POINT_SELECT
};
enum PlayerMenuState
{
MENUSTATE_NONE = 0,
MENUSTATE_COOPMENU,
MENUSTATE_COOPMENU_SPEC,
MENUSTATE_CHECKPOINT,
MENUSTATE_GLOBAL,
MENUSTATE_LOCAL_CONFIRM
};
#include "gravgunmod.h"
#include "whandle.h"
class CBasePlayer : public CBaseMonster
@ -332,14 +313,8 @@ public: @@ -332,14 +313,8 @@ public:
float m_flNextChatTime;
virtual float TouchGravGun( CBaseEntity *attacker, int stage );
float m_flSpawnTime;
PlayerState m_state;
bool m_fTouchMenu;
int m_iMenuState;
int m_iLocalConfirm;
int m_iConfirmKey;
int m_iEnttoolsMonsters;
float m_fEnttoolsMonsterTime;
struct GGMData gravgunmod_data;
virtual void Touch( CBaseEntity *pOther );
};

2
dlls/singleplay_gamerules.cpp

@ -121,7 +121,7 @@ float CHalfLifeRules::FlPlayerFallDamage( CBasePlayer *pPlayer ) @@ -121,7 +121,7 @@ float CHalfLifeRules::FlPlayerFallDamage( CBasePlayer *pPlayer )
//=========================================================
void CHalfLifeRules::PlayerSpawn( CBasePlayer *pPlayer )
{
pPlayer->m_state = STATE_SPAWNED;
pPlayer->gravgunmod_data.m_state = STATE_SPAWNED;
}
//=========================================================

10
dlls/triggers.cpp

@ -1653,7 +1653,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) @@ -1653,7 +1653,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator )
continue;
// count only players spawned more 30 seconds ago
if( plr && plr->IsPlayer() && (pTrain || (gpGlobals->time -((CBasePlayer*)plr)->m_flSpawnTime ) > 30 ) )
if( plr && plr->IsPlayer() && (pTrain || (gpGlobals->time -((CBasePlayer*)plr)->gravgunmod_data.m_flSpawnTime ) > 30 ) )
{
count2++;
@ -1687,7 +1687,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) @@ -1687,7 +1687,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator )
UTIL_CoopPrintMessage("%s^7 trying activate changelevel too soon\n", UTIL_CoopPlayerName( pPlayer ));
UTIL_CleanSpawnPoint( pPlayer->pev->origin, 50 );
m_flRepeatTimer = gpGlobals->time;
pPlayer->m_iLocalConfirm = -2;
pPlayer->gravgunmod_data.m_iLocalConfirm = -2;
}
UTIL_CoopHudMessage( 1, 5, 0xFF0000FF, 0xFF0000FF, 0, 0.7, "Cannot change level: Not enough players!\nWait 30 sec before you may changelevel!" );
@ -1776,7 +1776,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) @@ -1776,7 +1776,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator )
{
CBaseEntity *plr = UTIL_PlayerByIndex( i );
if( plr && plr->IsPlayer() && ( !FindTriggerTransition( m_szLandmarkName ) || (gpGlobals->time -((CBasePlayer*)plr)->m_flSpawnTime ) > 30 || m_fSkipSpawnCheck ) )
if( plr && plr->IsPlayer() && ( !FindTriggerTransition( m_szLandmarkName ) || (gpGlobals->time -((CBasePlayer*)plr)->gravgunmod_data.m_flSpawnTime ) > 30 || m_fSkipSpawnCheck ) )
{
if( InTransitionVolume( plr, m_szLandmarkName ))
{
@ -1794,7 +1794,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) @@ -1794,7 +1794,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator )
ALERT( at_console, "There are %d players in transition volume %s\n", count, m_szLandmarkName );
}
else if( ( (gpGlobals->time -((CBasePlayer*)pPlayer)->m_flSpawnTime ) < 30 ) && FindTriggerTransition( m_szLandmarkName ) || !InTransitionVolume( pPlayer, m_szLandmarkName ) )
else if( ( (gpGlobals->time -((CBasePlayer*)pPlayer)->gravgunmod_data.m_flSpawnTime ) < 30 ) && FindTriggerTransition( m_szLandmarkName ) || !InTransitionVolume( pPlayer, m_szLandmarkName ) )
{
ALERT( at_console, "Player isn't in the transition volume %s, aborting\n", m_szLandmarkName );
if( !m_fSkipSpawnCheck )
@ -1853,7 +1853,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) @@ -1853,7 +1853,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator )
// reset all players state to make it spawn again after restart
if( plr )
{
plr->m_state = STATE_UNINITIALIZED;
plr->gravgunmod_data.m_state = STATE_UNINITIALIZED;
plr->RemoveAllItems( TRUE );
UTIL_BecomeSpectator( plr );
// HACK: force perform reconnection

Loading…
Cancel
Save