Move banning natives from core to logic (bug 4406 part 3, r=fyren).
--HG-- rename : core/smn_banning.cpp => core/logic/smn_banning.cpp
This commit is contained in:
parent
78f5b513c0
commit
b5b002aa4b
@ -49,7 +49,6 @@ for i in SM.sdkInfo:
|
|||||||
'ConVarManager.cpp',
|
'ConVarManager.cpp',
|
||||||
'LibrarySys.cpp',
|
'LibrarySys.cpp',
|
||||||
'PlayerManager.cpp',
|
'PlayerManager.cpp',
|
||||||
'smn_banning.cpp',
|
|
||||||
'smn_gameconfigs.cpp',
|
'smn_gameconfigs.cpp',
|
||||||
'smn_string.cpp',
|
'smn_string.cpp',
|
||||||
'TimerSys.cpp',
|
'TimerSys.cpp',
|
||||||
|
@ -25,7 +25,7 @@ OBJECTS = AdminCache.cpp CDataPack.cpp ConCmdManager.cpp ConVarManager.cpp CoreC
|
|||||||
OBJECTS += smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \
|
OBJECTS += smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \
|
||||||
smn_datapacks.cpp smn_entities.cpp smn_events.cpp smn_fakenatives.cpp \
|
smn_datapacks.cpp smn_entities.cpp smn_events.cpp smn_fakenatives.cpp \
|
||||||
smn_filesystem.cpp smn_gameconfigs.cpp smn_halflife.cpp \
|
smn_filesystem.cpp smn_gameconfigs.cpp smn_halflife.cpp \
|
||||||
smn_handles.cpp smn_keyvalues.cpp smn_banning.cpp \
|
smn_handles.cpp smn_keyvalues.cpp \
|
||||||
smn_lang.cpp smn_player.cpp smn_string.cpp \
|
smn_lang.cpp smn_player.cpp smn_string.cpp \
|
||||||
smn_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp \
|
smn_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp \
|
||||||
smn_hudtext.cpp smn_nextmap.cpp
|
smn_hudtext.cpp smn_nextmap.cpp
|
||||||
|
@ -34,6 +34,7 @@ files = [
|
|||||||
'smn_players.cpp',
|
'smn_players.cpp',
|
||||||
'MemoryUtils.cpp',
|
'MemoryUtils.cpp',
|
||||||
'smn_admin.cpp',
|
'smn_admin.cpp',
|
||||||
|
'smn_banning.cpp',
|
||||||
'sm_crc32.cpp'
|
'sm_crc32.cpp'
|
||||||
]
|
]
|
||||||
if AMBuild.target['platform'] == 'windows':
|
if AMBuild.target['platform'] == 'windows':
|
||||||
|
@ -30,6 +30,7 @@ OBJECTS = \
|
|||||||
smn_timers.cpp \
|
smn_timers.cpp \
|
||||||
MemoryUtils.cpp \
|
MemoryUtils.cpp \
|
||||||
smn_admin.cpp \
|
smn_admin.cpp \
|
||||||
|
smn_banning.cpp \
|
||||||
smn_players.cpp
|
smn_players.cpp
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
|
@ -55,6 +55,7 @@ ITimerSystem *timersys;
|
|||||||
ServerGlobals serverGlobals;
|
ServerGlobals serverGlobals;
|
||||||
IPlayerManager *playerhelpers;
|
IPlayerManager *playerhelpers;
|
||||||
IAdminSystem *adminsys;
|
IAdminSystem *adminsys;
|
||||||
|
IGameHelpers *gamehelpers;
|
||||||
|
|
||||||
static sm_logic_t logic =
|
static sm_logic_t logic =
|
||||||
{
|
{
|
||||||
|
@ -51,6 +51,7 @@ extern ITimerSystem *timersys;
|
|||||||
extern ServerGlobals serverGlobals;
|
extern ServerGlobals serverGlobals;
|
||||||
extern IPlayerManager *playerhelpers;
|
extern IPlayerManager *playerhelpers;
|
||||||
extern IAdminSystem *adminsys;
|
extern IAdminSystem *adminsys;
|
||||||
|
extern IGameHelpers *gamehelpers;
|
||||||
|
|
||||||
#endif /* _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_ */
|
#endif /* _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_ */
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ using namespace SourceMod;
|
|||||||
* Add 1 to the RHS of this expression to bump the intercom file
|
* Add 1 to the RHS of this expression to bump the intercom file
|
||||||
* This is to prevent mismatching core/logic binaries
|
* This is to prevent mismatching core/logic binaries
|
||||||
*/
|
*/
|
||||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 7)
|
#define SM_LOGIC_MAGIC (0x0F47C0DE - 8)
|
||||||
|
|
||||||
#if defined SM_LOGIC
|
#if defined SM_LOGIC
|
||||||
class IVEngineServer
|
class IVEngineServer
|
||||||
@ -52,6 +52,7 @@ class IVEngineServer_Logic
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool IsMapValid(const char *map) = 0;
|
virtual bool IsMapValid(const char *map) = 0;
|
||||||
|
virtual void ServerCommand(const char *cmd) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace SourceMod
|
namespace SourceMod
|
||||||
@ -67,6 +68,7 @@ namespace SourceMod
|
|||||||
class IPlayerManager;
|
class IPlayerManager;
|
||||||
class IMemoryUtils;
|
class IMemoryUtils;
|
||||||
class IAdminSystem;
|
class IAdminSystem;
|
||||||
|
class IGameHelpers;
|
||||||
}
|
}
|
||||||
|
|
||||||
class IVEngineServer;
|
class IVEngineServer;
|
||||||
@ -94,6 +96,7 @@ struct sm_core_t
|
|||||||
ITimerSystem *timersys;
|
ITimerSystem *timersys;
|
||||||
IPlayerManager *playerhelpers;
|
IPlayerManager *playerhelpers;
|
||||||
IAdminSystem *adminsys;
|
IAdminSystem *adminsys;
|
||||||
|
IGameHelpers *gamehelers;
|
||||||
/* Functions */
|
/* Functions */
|
||||||
void (*AddNatives)(sp_nativeinfo_t* nlist);
|
void (*AddNatives)(sp_nativeinfo_t* nlist);
|
||||||
ConVar * (*FindConVar)(const char*);
|
ConVar * (*FindConVar)(const char*);
|
||||||
|
@ -29,11 +29,11 @@
|
|||||||
* Version: $Id$
|
* Version: $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sm_globals.h"
|
#include "common_logic.h"
|
||||||
#include "sm_stringutil.h"
|
#include <string.h>
|
||||||
#include "HalfLife2.h"
|
#include <IGameHelpers.h>
|
||||||
#include "PlayerManager.h"
|
#include <IPlayerHelpers.h>
|
||||||
#include "ForwardSys.h"
|
#include <IForwardSys.h>
|
||||||
|
|
||||||
#define BANFLAG_AUTO (1<<0) /**< Auto-detects whether to ban by steamid or IP */
|
#define BANFLAG_AUTO (1<<0) /**< Auto-detects whether to ban by steamid or IP */
|
||||||
#define BANFLAG_IP (1<<1) /**< Always ban by IP address */
|
#define BANFLAG_IP (1<<1) /**< Always ban by IP address */
|
||||||
@ -50,7 +50,7 @@ class BanNativeHelpers : public SMGlobalClass
|
|||||||
public:
|
public:
|
||||||
void OnSourceModAllInitialized()
|
void OnSourceModAllInitialized()
|
||||||
{
|
{
|
||||||
g_pOnBanClient = g_Forwards.CreateForward(
|
g_pOnBanClient = forwardsys->CreateForward(
|
||||||
"OnBanClient",
|
"OnBanClient",
|
||||||
ET_Event,
|
ET_Event,
|
||||||
7,
|
7,
|
||||||
@ -62,7 +62,7 @@ public:
|
|||||||
Param_String,
|
Param_String,
|
||||||
Param_String,
|
Param_String,
|
||||||
Param_Cell);
|
Param_Cell);
|
||||||
g_pOnBanIdentity = g_Forwards.CreateForward(
|
g_pOnBanIdentity = forwardsys->CreateForward(
|
||||||
"OnBanIdentity",
|
"OnBanIdentity",
|
||||||
ET_Event,
|
ET_Event,
|
||||||
6,
|
6,
|
||||||
@ -73,7 +73,7 @@ public:
|
|||||||
Param_String,
|
Param_String,
|
||||||
Param_String,
|
Param_String,
|
||||||
Param_Cell);
|
Param_Cell);
|
||||||
g_pOnRemoveBan = g_Forwards.CreateForward(
|
g_pOnRemoveBan = forwardsys->CreateForward(
|
||||||
"OnRemoveBan",
|
"OnRemoveBan",
|
||||||
ET_Event,
|
ET_Event,
|
||||||
4,
|
4,
|
||||||
@ -85,9 +85,9 @@ public:
|
|||||||
}
|
}
|
||||||
void OnSourceModShutdown()
|
void OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
g_Forwards.ReleaseForward(g_pOnBanClient);
|
forwardsys->ReleaseForward(g_pOnBanClient);
|
||||||
g_Forwards.ReleaseForward(g_pOnBanIdentity);
|
forwardsys->ReleaseForward(g_pOnBanIdentity);
|
||||||
g_Forwards.ReleaseForward(g_pOnRemoveBan);
|
forwardsys->ReleaseForward(g_pOnRemoveBan);
|
||||||
|
|
||||||
g_pOnBanClient = NULL;
|
g_pOnBanClient = NULL;
|
||||||
g_pOnBanIdentity = NULL;
|
g_pOnBanIdentity = NULL;
|
||||||
@ -117,8 +117,8 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
|
|||||||
|
|
||||||
/* Sanitize the input */
|
/* Sanitize the input */
|
||||||
char identity[64];
|
char identity[64];
|
||||||
strncopy(identity, r_identity, sizeof(identity));
|
smcore.strncopy(identity, r_identity, sizeof(identity));
|
||||||
UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
|
smcore.ReplaceAll(identity, sizeof(identity), ";", "", true);
|
||||||
|
|
||||||
cell_t handled = 0;
|
cell_t handled = 0;
|
||||||
if (ban_cmd[0] != '\0' && g_pOnBanIdentity->GetFunctionCount() > 0)
|
if (ban_cmd[0] != '\0' && g_pOnBanIdentity->GetFunctionCount() > 0)
|
||||||
@ -139,7 +139,7 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
|
|||||||
char command[256];
|
char command[256];
|
||||||
if (ban_by_ip)
|
if (ban_by_ip)
|
||||||
{
|
{
|
||||||
UTIL_Format(
|
smcore.Format(
|
||||||
command,
|
command,
|
||||||
sizeof(command),
|
sizeof(command),
|
||||||
"addip %d %s\n",
|
"addip %d %s\n",
|
||||||
@ -152,9 +152,9 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
|
|||||||
engine->ServerCommand("writeip\n");
|
engine->ServerCommand("writeip\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!g_HL2.IsLANServer())
|
else if (!gamehelpers->IsLANServer())
|
||||||
{
|
{
|
||||||
UTIL_Format(
|
smcore.Format(
|
||||||
command,
|
command,
|
||||||
sizeof(command),
|
sizeof(command),
|
||||||
"banid %d %s\n",
|
"banid %d %s\n",
|
||||||
@ -194,8 +194,8 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char identity[64];
|
char identity[64];
|
||||||
strncopy(identity, r_identity, sizeof(identity));
|
smcore.strncopy(identity, r_identity, sizeof(identity));
|
||||||
UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
|
smcore.ReplaceAll(identity, sizeof(identity), ";", "", true);
|
||||||
|
|
||||||
cell_t handled = 0;
|
cell_t handled = 0;
|
||||||
if (ban_cmd[0] != '\0' && g_pOnRemoveBan->GetFunctionCount() > 0)
|
if (ban_cmd[0] != '\0' && g_pOnRemoveBan->GetFunctionCount() > 0)
|
||||||
@ -212,7 +212,7 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
|
|||||||
{
|
{
|
||||||
if (!handled)
|
if (!handled)
|
||||||
{
|
{
|
||||||
UTIL_Format(
|
smcore.Format(
|
||||||
command,
|
command,
|
||||||
sizeof(command),
|
sizeof(command),
|
||||||
"removeip %s\n",
|
"removeip %s\n",
|
||||||
@ -221,11 +221,11 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
|
|||||||
engine->ServerCommand("writeip\n");
|
engine->ServerCommand("writeip\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!g_HL2.IsLANServer())
|
else if (!gamehelpers->IsLANServer())
|
||||||
{
|
{
|
||||||
if (!handled)
|
if (!handled)
|
||||||
{
|
{
|
||||||
UTIL_Format(
|
smcore.Format(
|
||||||
command,
|
command,
|
||||||
sizeof(command),
|
sizeof(command),
|
||||||
"removeid %s\n",
|
"removeid %s\n",
|
||||||
@ -248,9 +248,9 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
|
|||||||
char *ban_reason, *ban_cmd;
|
char *ban_reason, *ban_cmd;
|
||||||
int client, ban_flags, ban_source, ban_time;
|
int client, ban_flags, ban_source, ban_time;
|
||||||
|
|
||||||
client = g_HL2.ReferenceToIndex(params[1]);
|
client = gamehelpers->ReferenceToIndex(params[1]);
|
||||||
|
|
||||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
|
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||||
if (!pPlayer || !pPlayer->IsConnected())
|
if (!pPlayer || !pPlayer->IsConnected())
|
||||||
{
|
{
|
||||||
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
||||||
@ -272,7 +272,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
|
|||||||
/* Check how we should ban the player */
|
/* Check how we should ban the player */
|
||||||
if ((ban_flags & BANFLAG_AUTO) == BANFLAG_AUTO)
|
if ((ban_flags & BANFLAG_AUTO) == BANFLAG_AUTO)
|
||||||
{
|
{
|
||||||
if (g_HL2.IsLANServer() || !pPlayer->IsAuthorized())
|
if (gamehelpers->IsLANServer() || !pPlayer->IsAuthorized())
|
||||||
{
|
{
|
||||||
ban_flags |= BANFLAG_IP;
|
ban_flags |= BANFLAG_IP;
|
||||||
ban_flags &= ~BANFLAG_AUTHID;
|
ban_flags &= ~BANFLAG_AUTHID;
|
||||||
@ -335,7 +335,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
|
|||||||
{
|
{
|
||||||
/* Get the IP address and strip the port */
|
/* Get the IP address and strip the port */
|
||||||
char ip[24], *ptr;
|
char ip[24], *ptr;
|
||||||
strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip));
|
smcore.strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip));
|
||||||
if ((ptr = strchr(ip, ':')) != NULL)
|
if ((ptr = strchr(ip, ':')) != NULL)
|
||||||
{
|
{
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
@ -343,7 +343,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
|
|||||||
|
|
||||||
/* Tell the server to ban the ip */
|
/* Tell the server to ban the ip */
|
||||||
char command[256];
|
char command[256];
|
||||||
UTIL_Format(
|
smcore.Format(
|
||||||
command,
|
command,
|
||||||
sizeof(command),
|
sizeof(command),
|
||||||
"addip %d %s\n",
|
"addip %d %s\n",
|
||||||
@ -367,7 +367,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
|
|||||||
{
|
{
|
||||||
/* Tell the server to ban the auth string */
|
/* Tell the server to ban the auth string */
|
||||||
char command[256];
|
char command[256];
|
||||||
UTIL_Format(
|
smcore.Format(
|
||||||
command,
|
command,
|
||||||
sizeof(command),
|
sizeof(command),
|
||||||
"banid %d %s\n",
|
"banid %d %s\n",
|
||||||
@ -377,7 +377,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
|
|||||||
/* Kick, then ban */
|
/* Kick, then ban */
|
||||||
if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
|
if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
|
||||||
{
|
{
|
||||||
g_HL2.AddDelayedKick(client, pPlayer->GetUserId(), kick_message);
|
gamehelpers->AddDelayedKick(client, pPlayer->GetUserId(), kick_message);
|
||||||
}
|
}
|
||||||
engine->ServerCommand(command);
|
engine->ServerCommand(command);
|
||||||
|
|
||||||
@ -390,7 +390,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
|
|||||||
}
|
}
|
||||||
else if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
|
else if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
|
||||||
{
|
{
|
||||||
g_HL2.AddDelayedKick(client, pPlayer->GetUserId(), kick_message);
|
gamehelpers->AddDelayedKick(client, pPlayer->GetUserId(), kick_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,6 +48,7 @@
|
|||||||
#include "DebugReporter.h"
|
#include "DebugReporter.h"
|
||||||
#include "PlayerManager.h"
|
#include "PlayerManager.h"
|
||||||
#include "AdminCache.h"
|
#include "AdminCache.h"
|
||||||
|
#include "HalfLife2.h"
|
||||||
|
|
||||||
static ILibrary *g_pLogic = NULL;
|
static ILibrary *g_pLogic = NULL;
|
||||||
static LogicInitFunction logic_init_fn;
|
static LogicInitFunction logic_init_fn;
|
||||||
@ -64,6 +65,11 @@ public:
|
|||||||
{
|
{
|
||||||
return engine->IsMapValid(map);
|
return engine->IsMapValid(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void ServerCommand(const char *cmd)
|
||||||
|
{
|
||||||
|
engine->ServerCommand(cmd);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static VEngineServer_Logic logic_engine;
|
static VEngineServer_Logic logic_engine;
|
||||||
@ -118,6 +124,7 @@ static sm_core_t core_bridge =
|
|||||||
&g_Timers,
|
&g_Timers,
|
||||||
&g_Players,
|
&g_Players,
|
||||||
&g_Admins,
|
&g_Admins,
|
||||||
|
&g_HL2,
|
||||||
/* Functions */
|
/* Functions */
|
||||||
add_natives,
|
add_natives,
|
||||||
find_convar,
|
find_convar,
|
||||||
|
Loading…
Reference in New Issue
Block a user