From 8028dc4d42a0de5c0ca7c9d8b40cd159f4a61bc6 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 29 Sep 2007 15:35:59 +0000 Subject: [PATCH] re-added vsp listener support --HG-- branch : sourcemm-1.6.0 extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/branches/sourcemm-1.6.0%40441 --- sourcemm/ISmmAPI.h | 13 ++++ sourcemm/Makefile.ep1 | 2 +- sourcemm/episode1/provider_ep1.cpp | 5 +- sourcemm/episode1/vsp_listener.cpp | 111 +++++++++++++++++++++++++++++ sourcemm/episode1/vsp_listener.h | 37 ++++++++++ sourcemm/metamod.cpp | 36 ++++++++-- sourcemm/metamod.h | 2 + sourcemm/metamod_plugins.h | 1 + 8 files changed, 200 insertions(+), 7 deletions(-) create mode 100644 sourcemm/episode1/vsp_listener.cpp create mode 100644 sourcemm/episode1/vsp_listener.h diff --git a/sourcemm/ISmmAPI.h b/sourcemm/ISmmAPI.h index e872262..466e129 100644 --- a/sourcemm/ISmmAPI.h +++ b/sourcemm/ISmmAPI.h @@ -343,6 +343,19 @@ public: // Added in 1.6.0 (1:7) * @return A SOURCE_ENGINE_* constant value. */ virtual int GetSourceEngineBuild() =0; + + /** + * @brief Returns the VSP listener loaded. + * + * This is useful for late-loading plugins which need to decide whether + * to add a listener or not (or need to get the pointer at all). + * + * @param Optional pointer to store the VSP version. + * @return IServerPluginCallbacks pointer, or NULL if an + * IMetamodListener event has yet to occur for + * EnableVSPListener(). + */ + virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion) =0; }; diff --git a/sourcemm/Makefile.ep1 b/sourcemm/Makefile.ep1 index e051cb5..9f8e12b 100644 --- a/sourcemm/Makefile.ep1 +++ b/sourcemm/Makefile.ep1 @@ -17,7 +17,7 @@ HL2PUB = $(HL2SDK)/public HL2LIB = $(HL2SDK)/linux_sdk OBJECTS = metamod.cpp metamod_util.cpp metamod_console.cpp metamod_oslink.cpp metamod_plugins.cpp \ - sourcehook.cpp episode1/console.cpp episode1/provider_ep1.cpp + sourcehook.cpp episode1/console.cpp episode1/provider_ep1.cpp episode1/vsp_listener.cpp LINK = $(HL2LIB)/tier1_i486.a vstdlib_i486.so tier0_i486.so -static-libgcc diff --git a/sourcemm/episode1/provider_ep1.cpp b/sourcemm/episode1/provider_ep1.cpp index 27c2d52..77667fb 100644 --- a/sourcemm/episode1/provider_ep1.cpp +++ b/sourcemm/episode1/provider_ep1.cpp @@ -9,6 +9,7 @@ #include "provider_ep1.h" #include "console.h" #include "metamod_console.h" +#include "vsp_listener.h" /* Types */ typedef void (*CONPRINTF_FUNC)(const char *, ...); @@ -33,6 +34,7 @@ ICvar *icvar = NULL; ISmmAPI *metamod_api = NULL; IVEngineServer *engine = NULL; IServerGameClients *gameclients = NULL; +VSPListener g_VspListener; BaseProvider g_Ep1Provider; IMetamodSourceProvider *provider = &g_Ep1Provider; @@ -303,7 +305,8 @@ ConVar *BaseProvider::CreateConVar(const char *name, IServerPluginCallbacks *BaseProvider::GetVSPCallbacks(const char *iface) { - return NULL; + g_VspListener.SetLoadable(true); + return &g_VspListener; } class GlobCommand : public IMetamodSourceCommandInfo diff --git a/sourcemm/episode1/vsp_listener.cpp b/sourcemm/episode1/vsp_listener.cpp new file mode 100644 index 0000000..4a89902 --- /dev/null +++ b/sourcemm/episode1/vsp_listener.cpp @@ -0,0 +1,111 @@ +#include "vsp_listener.h" +#include "svn_version.h" +#include "metamod.h" + +using namespace SourceMM; + +VSPListener::VSPListener() +{ + m_bLoaded = false; + m_bLoadable = false; +} + +void VSPListener::ClientActive(edict_t *pEntity) +{ +} + +PLUGIN_RESULT VSPListener::ClientCommand(edict_t *pEntity) +{ + return PLUGIN_CONTINUE; +} + +PLUGIN_RESULT VSPListener::ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) +{ + return PLUGIN_CONTINUE; +} + +void VSPListener::ClientDisconnect(edict_t *pEntity) +{ +} + +void VSPListener::ClientPutInServer(edict_t *pEntity, char const *playername) +{ +} + +void VSPListener::ClientSettingsChanged(edict_t *pEdict) +{ +} + +void VSPListener::SetCommandClient(int index) +{ +} + +void VSPListener::GameFrame(bool simulating) +{ +} + +const char *VSPListener::GetPluginDescription() +{ + return "Metamod:Source Interface v" SVN_FILE_VERSION_STRING; +} + +bool VSPListener::IsLoaded() +{ + return m_bLoaded; +} + +void VSPListener::LevelInit(char const *pMapName) +{ +} + +void VSPListener::LevelShutdown() +{ +} + +PLUGIN_RESULT VSPListener::NetworkIDValidated(const char *pszUserName, const char *pszNetworkID) +{ + return PLUGIN_CONTINUE; +} + +void VSPListener::Pause() +{ +} + +void VSPListener::UnPause() +{ +} + +void VSPListener::ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) +{ +} + +void VSPListener::Unload() +{ +} + +void VSPListener::SetLoadable(bool set) +{ + m_bLoadable = set; +} + +bool VSPListener::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory) +{ + if (!m_bLoadable) + { + Warning("Do not manually load Metamod:Source as a Valve Server Plugin\n"); + return false; + } + + if (m_bLoaded) + { + return false; + } + + m_bLoaded = true; + SetLoadable(false); + + g_Metamod.NotifyVSPListening(this); + + return true; +} + diff --git a/sourcemm/episode1/vsp_listener.h b/sourcemm/episode1/vsp_listener.h new file mode 100644 index 0000000..228e902 --- /dev/null +++ b/sourcemm/episode1/vsp_listener.h @@ -0,0 +1,37 @@ +#ifndef _INCLUDE_METAMOD_SOURCE_VSP_LISTENER_H_ +#define _INCLUDE_METAMOD_SOURCE_VSP_LISTENER_H_ + +#include "iserverplugin.h" + +class VSPListener : public IServerPluginCallbacks +{ +public: + VSPListener(); +public: + virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory); + virtual void Unload(); + virtual void Pause(); + virtual void UnPause(); + virtual const char *GetPluginDescription(); + virtual void LevelInit(char const *pMapName); + virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax); + virtual void GameFrame(bool simulating); + virtual void LevelShutdown(void); + virtual void ClientActive(edict_t *pEntity); + virtual void ClientDisconnect(edict_t *pEntity); + virtual void ClientPutInServer(edict_t *pEntity, char const *playername); + virtual void SetCommandClient(int index); + virtual void ClientSettingsChanged(edict_t *pEdict); + virtual PLUGIN_RESULT ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen); + virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity); + virtual PLUGIN_RESULT NetworkIDValidated(const char *pszUserName, const char *pszNetworkID); +public: + bool IsLoaded(); + void SetLoadable(bool loadable); +private: + bool m_bLoaded; + bool m_bLoadable; +}; + +#endif //_INCLUDE_METAMOD_SOURCE_VSP_LISTENER_H_ + diff --git a/sourcemm/metamod.cpp b/sourcemm/metamod.cpp index 6818e22..daf5780 100644 --- a/sourcemm/metamod.cpp +++ b/sourcemm/metamod.cpp @@ -80,6 +80,7 @@ SourceHook::CSourceHookImpl g_SourceHook; SourceHook::ISourceHook *g_SHPtr = &g_SourceHook; PluginId g_PLID = Pl_Console; META_RES last_meta_res; +IServerPluginCallbacks *vsp_callbacks = NULL; MetamodSource g_Metamod; @@ -187,19 +188,19 @@ SMM_API void *CreateInterface(const char *iface, int *ret) if (strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0) { - IServerPluginCallbacks *pCallbacks = provider->GetVSPCallbacks(iface); + vsp_callbacks = provider->GetVSPCallbacks(iface); - if (pCallbacks && vsp_version == 0) + if (vsp_callbacks != NULL && vsp_version == 0) { vsp_version = atoi(&iface[22]); } - if (pCallbacks && ret) + if (ret) { - *ret = pCallbacks ? IFACE_OK : IFACE_FAILED; + *ret = (vsp_callbacks != NULL) ? IFACE_OK : IFACE_FAILED; } - return pCallbacks; + return vsp_callbacks; } if (!parsed_game_info) @@ -221,6 +222,15 @@ SMM_API void *CreateInterface(const char *iface, int *ret) /* Get value of -game from command line, defaulting to hl2 as engine seems to do */ game_dir = provider->GetCommandLineValue("-game", "hl2"); + if (strcasecmp(game_dir, "ship") == 0) + { + engine_build = SOURCE_ENGINE_ORIGINAL; + } + else + { + engine_build = SOURCE_ENGINE_EPISODEONE; + } + /* Get absolute path */ abspath(game_path, game_dir); mod_path.assign(game_path); @@ -1203,3 +1213,19 @@ int MetamodSource::GetSourceEngineBuild() { return engine_build; } + +void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks) +{ + ITER_EVENT(OnVSPListening, (callbacks)); +} + +IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion) +{ + if (pVersion) + { + *pVersion = vsp_version; + } + + return vsp_callbacks; +} + diff --git a/sourcemm/metamod.h b/sourcemm/metamod.h index eaff4ed..cb03391 100644 --- a/sourcemm/metamod.h +++ b/sourcemm/metamod.h @@ -71,10 +71,12 @@ public: const char *GetUserMessage(int index, int *size=NULL); int GetVSPVersion(); int GetSourceEngineBuild(); + IServerPluginCallbacks *GetVSPInfo(int *pVersion); public: const char *GetGameBinaryPath(); const char *GetPluginsFile(); void UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand); + void NotifyVSPListening(IServerPluginCallbacks *callbacks); }; void LogMessage(const char *msg, ...); diff --git a/sourcemm/metamod_plugins.h b/sourcemm/metamod_plugins.h index dbc038d..d4ba6af 100644 --- a/sourcemm/metamod_plugins.h +++ b/sourcemm/metamod_plugins.h @@ -147,3 +147,4 @@ typedef SourceHook::List::iterator PluginIt extern SourceMM::CPluginManager g_PluginMngr; #endif //_INCLUDE_CPLUGIN_H +