From b5b002aa4b0aae12c322bb618edb486c94683f18 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 14 May 2010 18:22:03 -0700 Subject: [PATCH] Move banning natives from core to logic (bug 4406 part 3, r=fyren). --HG-- rename : core/smn_banning.cpp => core/logic/smn_banning.cpp --- core/AMBuilder | 1 - core/Makefile | 2 +- core/logic/AMBuilder | 1 + core/logic/Makefile | 1 + core/logic/common_logic.cpp | 1 + core/logic/common_logic.h | 1 + core/logic/intercom.h | 5 ++- core/{ => logic}/smn_banning.cpp | 58 ++++++++++++++++---------------- core/logic_bridge.cpp | 7 ++++ 9 files changed, 45 insertions(+), 32 deletions(-) rename core/{ => logic}/smn_banning.cpp (84%) diff --git a/core/AMBuilder b/core/AMBuilder index aa1eeb80..0f2ed3f4 100644 --- a/core/AMBuilder +++ b/core/AMBuilder @@ -49,7 +49,6 @@ for i in SM.sdkInfo: 'ConVarManager.cpp', 'LibrarySys.cpp', 'PlayerManager.cpp', - 'smn_banning.cpp', 'smn_gameconfigs.cpp', 'smn_string.cpp', 'TimerSys.cpp', diff --git a/core/Makefile b/core/Makefile index b4ba5ae7..155d4c31 100644 --- a/core/Makefile +++ b/core/Makefile @@ -25,7 +25,7 @@ OBJECTS = AdminCache.cpp CDataPack.cpp ConCmdManager.cpp ConVarManager.cpp CoreC OBJECTS += smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \ smn_datapacks.cpp smn_entities.cpp smn_events.cpp smn_fakenatives.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_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp \ smn_hudtext.cpp smn_nextmap.cpp diff --git a/core/logic/AMBuilder b/core/logic/AMBuilder index 64f03d9c..c3081a43 100644 --- a/core/logic/AMBuilder +++ b/core/logic/AMBuilder @@ -34,6 +34,7 @@ files = [ 'smn_players.cpp', 'MemoryUtils.cpp', 'smn_admin.cpp', + 'smn_banning.cpp', 'sm_crc32.cpp' ] if AMBuild.target['platform'] == 'windows': diff --git a/core/logic/Makefile b/core/logic/Makefile index 8f0c57bc..045c677b 100644 --- a/core/logic/Makefile +++ b/core/logic/Makefile @@ -30,6 +30,7 @@ OBJECTS = \ smn_timers.cpp \ MemoryUtils.cpp \ smn_admin.cpp \ + smn_banning.cpp \ smn_players.cpp ############################################## diff --git a/core/logic/common_logic.cpp b/core/logic/common_logic.cpp index dcdfd616..c8c26d0b 100644 --- a/core/logic/common_logic.cpp +++ b/core/logic/common_logic.cpp @@ -55,6 +55,7 @@ ITimerSystem *timersys; ServerGlobals serverGlobals; IPlayerManager *playerhelpers; IAdminSystem *adminsys; +IGameHelpers *gamehelpers; static sm_logic_t logic = { diff --git a/core/logic/common_logic.h b/core/logic/common_logic.h index 11fffd06..207e9603 100644 --- a/core/logic/common_logic.h +++ b/core/logic/common_logic.h @@ -51,6 +51,7 @@ extern ITimerSystem *timersys; extern ServerGlobals serverGlobals; extern IPlayerManager *playerhelpers; extern IAdminSystem *adminsys; +extern IGameHelpers *gamehelpers; #endif /* _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_ */ diff --git a/core/logic/intercom.h b/core/logic/intercom.h index a35546e4..efeafc81 100644 --- a/core/logic/intercom.h +++ b/core/logic/intercom.h @@ -42,7 +42,7 @@ using namespace SourceMod; * Add 1 to the RHS of this expression to bump the intercom file * This is to prevent mismatching core/logic binaries */ -#define SM_LOGIC_MAGIC (0x0F47C0DE - 7) +#define SM_LOGIC_MAGIC (0x0F47C0DE - 8) #if defined SM_LOGIC class IVEngineServer @@ -52,6 +52,7 @@ class IVEngineServer_Logic { public: virtual bool IsMapValid(const char *map) = 0; + virtual void ServerCommand(const char *cmd) = 0; }; namespace SourceMod @@ -67,6 +68,7 @@ namespace SourceMod class IPlayerManager; class IMemoryUtils; class IAdminSystem; + class IGameHelpers; } class IVEngineServer; @@ -94,6 +96,7 @@ struct sm_core_t ITimerSystem *timersys; IPlayerManager *playerhelpers; IAdminSystem *adminsys; + IGameHelpers *gamehelers; /* Functions */ void (*AddNatives)(sp_nativeinfo_t* nlist); ConVar * (*FindConVar)(const char*); diff --git a/core/smn_banning.cpp b/core/logic/smn_banning.cpp similarity index 84% rename from core/smn_banning.cpp rename to core/logic/smn_banning.cpp index 25af4c38..6b857398 100644 --- a/core/smn_banning.cpp +++ b/core/logic/smn_banning.cpp @@ -29,11 +29,11 @@ * Version: $Id$ */ -#include "sm_globals.h" -#include "sm_stringutil.h" -#include "HalfLife2.h" -#include "PlayerManager.h" -#include "ForwardSys.h" +#include "common_logic.h" +#include +#include +#include +#include #define BANFLAG_AUTO (1<<0) /**< Auto-detects whether to ban by steamid or IP */ #define BANFLAG_IP (1<<1) /**< Always ban by IP address */ @@ -50,7 +50,7 @@ class BanNativeHelpers : public SMGlobalClass public: void OnSourceModAllInitialized() { - g_pOnBanClient = g_Forwards.CreateForward( + g_pOnBanClient = forwardsys->CreateForward( "OnBanClient", ET_Event, 7, @@ -62,7 +62,7 @@ public: Param_String, Param_String, Param_Cell); - g_pOnBanIdentity = g_Forwards.CreateForward( + g_pOnBanIdentity = forwardsys->CreateForward( "OnBanIdentity", ET_Event, 6, @@ -73,7 +73,7 @@ public: Param_String, Param_String, Param_Cell); - g_pOnRemoveBan = g_Forwards.CreateForward( + g_pOnRemoveBan = forwardsys->CreateForward( "OnRemoveBan", ET_Event, 4, @@ -85,9 +85,9 @@ public: } void OnSourceModShutdown() { - g_Forwards.ReleaseForward(g_pOnBanClient); - g_Forwards.ReleaseForward(g_pOnBanIdentity); - g_Forwards.ReleaseForward(g_pOnRemoveBan); + forwardsys->ReleaseForward(g_pOnBanClient); + forwardsys->ReleaseForward(g_pOnBanIdentity); + forwardsys->ReleaseForward(g_pOnRemoveBan); g_pOnBanClient = NULL; g_pOnBanIdentity = NULL; @@ -117,8 +117,8 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params) /* Sanitize the input */ char identity[64]; - strncopy(identity, r_identity, sizeof(identity)); - UTIL_ReplaceAll(identity, sizeof(identity), ";", ""); + smcore.strncopy(identity, r_identity, sizeof(identity)); + smcore.ReplaceAll(identity, sizeof(identity), ";", "", true); cell_t handled = 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]; if (ban_by_ip) { - UTIL_Format( + smcore.Format( command, sizeof(command), "addip %d %s\n", @@ -152,9 +152,9 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params) engine->ServerCommand("writeip\n"); } } - else if (!g_HL2.IsLANServer()) + else if (!gamehelpers->IsLANServer()) { - UTIL_Format( + smcore.Format( command, sizeof(command), "banid %d %s\n", @@ -194,8 +194,8 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params) } char identity[64]; - strncopy(identity, r_identity, sizeof(identity)); - UTIL_ReplaceAll(identity, sizeof(identity), ";", ""); + smcore.strncopy(identity, r_identity, sizeof(identity)); + smcore.ReplaceAll(identity, sizeof(identity), ";", "", true); cell_t handled = 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) { - UTIL_Format( + smcore.Format( command, sizeof(command), "removeip %s\n", @@ -221,11 +221,11 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params) engine->ServerCommand("writeip\n"); } } - else if (!g_HL2.IsLANServer()) + else if (!gamehelpers->IsLANServer()) { if (!handled) { - UTIL_Format( + smcore.Format( command, sizeof(command), "removeid %s\n", @@ -248,9 +248,9 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params) char *ban_reason, *ban_cmd; 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()) { 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 */ 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_AUTHID; @@ -335,7 +335,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params) { /* Get the IP address and strip the port */ char ip[24], *ptr; - strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip)); + smcore.strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip)); if ((ptr = strchr(ip, ':')) != NULL) { *ptr = '\0'; @@ -343,7 +343,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params) /* Tell the server to ban the ip */ char command[256]; - UTIL_Format( + smcore.Format( command, sizeof(command), "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 */ char command[256]; - UTIL_Format( + smcore.Format( command, sizeof(command), "banid %d %s\n", @@ -377,7 +377,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params) /* Kick, then ban */ 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); @@ -390,7 +390,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params) } else if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK) { - g_HL2.AddDelayedKick(client, pPlayer->GetUserId(), kick_message); + gamehelpers->AddDelayedKick(client, pPlayer->GetUserId(), kick_message); } diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index 98ad4157..4b454ff7 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -48,6 +48,7 @@ #include "DebugReporter.h" #include "PlayerManager.h" #include "AdminCache.h" +#include "HalfLife2.h" static ILibrary *g_pLogic = NULL; static LogicInitFunction logic_init_fn; @@ -64,6 +65,11 @@ public: { return engine->IsMapValid(map); } + + virtual void ServerCommand(const char *cmd) + { + engine->ServerCommand(cmd); + } }; static VEngineServer_Logic logic_engine; @@ -118,6 +124,7 @@ static sm_core_t core_bridge = &g_Timers, &g_Players, &g_Admins, + &g_HL2, /* Functions */ add_natives, find_convar,