re-added vsp listener support sourcemm-1.6.0
authorDavid Anderson <dvander@alliedmods.net>
Sat Sep 29 15:35:59 2007 +0000 (2007-09-29)
branchsourcemm-1.6.0
changeset 366cbfac4e86a2a
parent 365 afdf36dee1a6
child 367 fc76472b980f
re-added vsp listener support
sourcemm/ISmmAPI.h
sourcemm/Makefile.ep1
sourcemm/episode1/provider_ep1.cpp
sourcemm/episode1/vsp_listener.cpp
sourcemm/episode1/vsp_listener.h
sourcemm/metamod.cpp
sourcemm/metamod.h
sourcemm/metamod_plugins.h
     1.1 --- a/sourcemm/ISmmAPI.h	Sat Sep 29 15:01:32 2007 +0000
     1.2 +++ b/sourcemm/ISmmAPI.h	Sat Sep 29 15:35:59 2007 +0000
     1.3 @@ -343,6 +343,19 @@
     1.4  	 * @return				A SOURCE_ENGINE_* constant value.
     1.5  	 */
     1.6  	virtual int GetSourceEngineBuild() =0;
     1.7 +
     1.8 +	/**
     1.9 +	 * @brief Returns the VSP listener loaded.  
    1.10 +	 *
    1.11 +	 * This is useful for late-loading plugins which need to decide whether 
    1.12 +	 * to add a listener or not (or need to get the pointer at all).
    1.13 +	 *
    1.14 +	 * @param				Optional pointer to store the VSP version.
    1.15 +	 * @return				IServerPluginCallbacks pointer, or NULL if an
    1.16 +	 * 						IMetamodListener event has yet to occur for 
    1.17 +	 * 						EnableVSPListener().
    1.18 +	 */
    1.19 +	virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion) =0;
    1.20  };
    1.21  
    1.22  
     2.1 --- a/sourcemm/Makefile.ep1	Sat Sep 29 15:01:32 2007 +0000
     2.2 +++ b/sourcemm/Makefile.ep1	Sat Sep 29 15:35:59 2007 +0000
     2.3 @@ -17,7 +17,7 @@
     2.4  HL2LIB = $(HL2SDK)/linux_sdk
     2.5  
     2.6  OBJECTS = metamod.cpp metamod_util.cpp metamod_console.cpp metamod_oslink.cpp metamod_plugins.cpp \
     2.7 -	sourcehook.cpp episode1/console.cpp episode1/provider_ep1.cpp
     2.8 +	sourcehook.cpp episode1/console.cpp episode1/provider_ep1.cpp episode1/vsp_listener.cpp
     2.9  
    2.10  LINK = $(HL2LIB)/tier1_i486.a vstdlib_i486.so tier0_i486.so -static-libgcc
    2.11  
     3.1 --- a/sourcemm/episode1/provider_ep1.cpp	Sat Sep 29 15:01:32 2007 +0000
     3.2 +++ b/sourcemm/episode1/provider_ep1.cpp	Sat Sep 29 15:35:59 2007 +0000
     3.3 @@ -9,6 +9,7 @@
     3.4  #include "provider_ep1.h"
     3.5  #include "console.h"
     3.6  #include "metamod_console.h"
     3.7 +#include "vsp_listener.h"
     3.8  
     3.9  /* Types */
    3.10  typedef void (*CONPRINTF_FUNC)(const char *, ...);
    3.11 @@ -33,6 +34,7 @@
    3.12  ISmmAPI *metamod_api = NULL;
    3.13  IVEngineServer *engine = NULL;
    3.14  IServerGameClients *gameclients = NULL;
    3.15 +VSPListener g_VspListener;
    3.16  BaseProvider g_Ep1Provider;
    3.17  IMetamodSourceProvider *provider = &g_Ep1Provider;
    3.18  
    3.19 @@ -303,7 +305,8 @@
    3.20  
    3.21  IServerPluginCallbacks *BaseProvider::GetVSPCallbacks(const char *iface)
    3.22  {
    3.23 -	return NULL;
    3.24 +	g_VspListener.SetLoadable(true);
    3.25 +	return &g_VspListener;
    3.26  }
    3.27  
    3.28  class GlobCommand : public IMetamodSourceCommandInfo
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/sourcemm/episode1/vsp_listener.cpp	Sat Sep 29 15:35:59 2007 +0000
     4.3 @@ -0,0 +1,111 @@
     4.4 +#include "vsp_listener.h"
     4.5 +#include "svn_version.h"
     4.6 +#include "metamod.h"
     4.7 +
     4.8 +using namespace SourceMM;
     4.9 +
    4.10 +VSPListener::VSPListener()
    4.11 +{
    4.12 +	m_bLoaded = false;
    4.13 +	m_bLoadable = false;
    4.14 +}
    4.15 +
    4.16 +void VSPListener::ClientActive(edict_t *pEntity)
    4.17 +{
    4.18 +}
    4.19 +
    4.20 +PLUGIN_RESULT VSPListener::ClientCommand(edict_t *pEntity)
    4.21 +{
    4.22 +	return PLUGIN_CONTINUE;
    4.23 +}
    4.24 +
    4.25 +PLUGIN_RESULT VSPListener::ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
    4.26 +{
    4.27 +	return PLUGIN_CONTINUE;
    4.28 +}
    4.29 +
    4.30 +void VSPListener::ClientDisconnect(edict_t *pEntity)
    4.31 +{
    4.32 +}
    4.33 +
    4.34 +void VSPListener::ClientPutInServer(edict_t *pEntity, char const *playername)
    4.35 +{
    4.36 +}
    4.37 +
    4.38 +void VSPListener::ClientSettingsChanged(edict_t *pEdict)
    4.39 +{
    4.40 +}
    4.41 +
    4.42 +void VSPListener::SetCommandClient(int index)
    4.43 +{
    4.44 +}
    4.45 +
    4.46 +void VSPListener::GameFrame(bool simulating)
    4.47 +{
    4.48 +}
    4.49 +
    4.50 +const char *VSPListener::GetPluginDescription()
    4.51 +{
    4.52 +	return "Metamod:Source Interface v" SVN_FILE_VERSION_STRING;
    4.53 +}
    4.54 +
    4.55 +bool VSPListener::IsLoaded()
    4.56 +{
    4.57 +	return m_bLoaded;
    4.58 +}
    4.59 +
    4.60 +void VSPListener::LevelInit(char const *pMapName)
    4.61 +{
    4.62 +}
    4.63 +
    4.64 +void VSPListener::LevelShutdown()
    4.65 +{
    4.66 +}
    4.67 +
    4.68 +PLUGIN_RESULT VSPListener::NetworkIDValidated(const char *pszUserName, const char *pszNetworkID)
    4.69 +{
    4.70 +	return PLUGIN_CONTINUE;
    4.71 +}
    4.72 +
    4.73 +void VSPListener::Pause()
    4.74 +{
    4.75 +}
    4.76 +
    4.77 +void VSPListener::UnPause()
    4.78 +{
    4.79 +}
    4.80 +
    4.81 +void VSPListener::ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
    4.82 +{
    4.83 +}
    4.84 +
    4.85 +void VSPListener::Unload()
    4.86 +{
    4.87 +}
    4.88 +
    4.89 +void VSPListener::SetLoadable(bool set)
    4.90 +{
    4.91 +	m_bLoadable = set;
    4.92 +}
    4.93 +
    4.94 +bool VSPListener::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory)
    4.95 +{
    4.96 +	if (!m_bLoadable)
    4.97 +	{
    4.98 +		Warning("Do not manually load Metamod:Source as a Valve Server Plugin\n");
    4.99 +		return false;
   4.100 +	}
   4.101 +
   4.102 +	if (m_bLoaded)
   4.103 +	{
   4.104 +		return false;
   4.105 +	}
   4.106 +
   4.107 +	m_bLoaded = true;
   4.108 +	SetLoadable(false);
   4.109 +
   4.110 +	g_Metamod.NotifyVSPListening(this);
   4.111 +
   4.112 +	return true;
   4.113 +}
   4.114 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/sourcemm/episode1/vsp_listener.h	Sat Sep 29 15:35:59 2007 +0000
     5.3 @@ -0,0 +1,37 @@
     5.4 +#ifndef _INCLUDE_METAMOD_SOURCE_VSP_LISTENER_H_
     5.5 +#define _INCLUDE_METAMOD_SOURCE_VSP_LISTENER_H_
     5.6 +
     5.7 +#include "iserverplugin.h"
     5.8 +
     5.9 +class VSPListener : public IServerPluginCallbacks
    5.10 +{
    5.11 +public:
    5.12 +	VSPListener();
    5.13 +public:
    5.14 +	virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory);
    5.15 +	virtual void Unload();
    5.16 +	virtual void Pause();
    5.17 +	virtual void UnPause();
    5.18 +	virtual const char *GetPluginDescription();
    5.19 +	virtual void LevelInit(char const *pMapName);
    5.20 +	virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
    5.21 +	virtual void GameFrame(bool simulating);
    5.22 +	virtual void LevelShutdown(void);
    5.23 +	virtual void ClientActive(edict_t *pEntity);
    5.24 +	virtual void ClientDisconnect(edict_t *pEntity);
    5.25 +	virtual void ClientPutInServer(edict_t *pEntity, char const *playername);
    5.26 +	virtual void SetCommandClient(int index);
    5.27 +	virtual void ClientSettingsChanged(edict_t *pEdict);
    5.28 +	virtual PLUGIN_RESULT ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
    5.29 +	virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity);
    5.30 +	virtual PLUGIN_RESULT NetworkIDValidated(const char *pszUserName, const char *pszNetworkID);
    5.31 +public:
    5.32 +	bool IsLoaded();
    5.33 +	void SetLoadable(bool loadable);
    5.34 +private:
    5.35 +	bool m_bLoaded;
    5.36 +	bool m_bLoadable;
    5.37 +};
    5.38 +
    5.39 +#endif //_INCLUDE_METAMOD_SOURCE_VSP_LISTENER_H_
    5.40 +
     6.1 --- a/sourcemm/metamod.cpp	Sat Sep 29 15:01:32 2007 +0000
     6.2 +++ b/sourcemm/metamod.cpp	Sat Sep 29 15:35:59 2007 +0000
     6.3 @@ -80,6 +80,7 @@
     6.4  SourceHook::ISourceHook *g_SHPtr = &g_SourceHook;
     6.5  PluginId g_PLID = Pl_Console;
     6.6  META_RES last_meta_res;
     6.7 +IServerPluginCallbacks *vsp_callbacks = NULL;
     6.8  
     6.9  MetamodSource g_Metamod;
    6.10  
    6.11 @@ -187,19 +188,19 @@
    6.12  
    6.13  	if (strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0)
    6.14  	{
    6.15 -		IServerPluginCallbacks *pCallbacks = provider->GetVSPCallbacks(iface);
    6.16 +		vsp_callbacks = provider->GetVSPCallbacks(iface);
    6.17  
    6.18 -		if (pCallbacks && vsp_version == 0)
    6.19 +		if (vsp_callbacks != NULL && vsp_version == 0)
    6.20  		{
    6.21  			vsp_version = atoi(&iface[22]);
    6.22  		}
    6.23  
    6.24 -		if (pCallbacks && ret)
    6.25 +		if (ret)
    6.26  		{
    6.27 -			*ret = pCallbacks ? IFACE_OK : IFACE_FAILED;
    6.28 +			*ret = (vsp_callbacks != NULL) ? IFACE_OK : IFACE_FAILED;
    6.29  		}
    6.30  
    6.31 -		return pCallbacks;
    6.32 +		return vsp_callbacks;
    6.33  	}
    6.34  
    6.35  	if (!parsed_game_info)
    6.36 @@ -221,6 +222,15 @@
    6.37  		/* Get value of -game from command line, defaulting to hl2 as engine seems to do */
    6.38  		game_dir = provider->GetCommandLineValue("-game", "hl2");
    6.39  
    6.40 +		if (strcasecmp(game_dir, "ship") == 0)
    6.41 +		{
    6.42 +			engine_build = SOURCE_ENGINE_ORIGINAL;
    6.43 +		}
    6.44 +		else
    6.45 +		{
    6.46 +			engine_build = SOURCE_ENGINE_EPISODEONE;
    6.47 +		}
    6.48 +
    6.49  		/* Get absolute path */
    6.50  		abspath(game_path, game_dir);
    6.51  		mod_path.assign(game_path);
    6.52 @@ -1203,3 +1213,19 @@
    6.53  {
    6.54  	return engine_build;
    6.55  }
    6.56 +
    6.57 +void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks)
    6.58 +{
    6.59 +	ITER_EVENT(OnVSPListening, (callbacks));
    6.60 +}
    6.61 +
    6.62 +IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
    6.63 +{
    6.64 +	if (pVersion)
    6.65 +	{
    6.66 +		*pVersion = vsp_version;
    6.67 +	}
    6.68 +
    6.69 +	return vsp_callbacks;
    6.70 +}
    6.71 +
     7.1 --- a/sourcemm/metamod.h	Sat Sep 29 15:01:32 2007 +0000
     7.2 +++ b/sourcemm/metamod.h	Sat Sep 29 15:35:59 2007 +0000
     7.3 @@ -71,10 +71,12 @@
     7.4  	const char *GetUserMessage(int index, int *size=NULL);
     7.5  	int GetVSPVersion();
     7.6  	int GetSourceEngineBuild();
     7.7 +	IServerPluginCallbacks *GetVSPInfo(int *pVersion);
     7.8  public:
     7.9  	const char *GetGameBinaryPath();
    7.10  	const char *GetPluginsFile();
    7.11  	void UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand);
    7.12 +	void NotifyVSPListening(IServerPluginCallbacks *callbacks);
    7.13  };
    7.14  
    7.15  void LogMessage(const char *msg, ...);
     8.1 --- a/sourcemm/metamod_plugins.h	Sat Sep 29 15:01:32 2007 +0000
     8.2 +++ b/sourcemm/metamod_plugins.h	Sat Sep 29 15:35:59 2007 +0000
     8.3 @@ -147,3 +147,4 @@
     8.4  extern SourceMM::CPluginManager g_PluginMngr;
     8.5  
     8.6  #endif //_INCLUDE_CPLUGIN_H
     8.7 +