implemented request amb302 (onservercfg and onmapstart are now called if a plugin is late loaded)
authorDavid Anderson <dvander@alliedmods.net>
Wed May 23 17:54:45 2007 +0000 (2007-05-23)
changeset 84832c29dd9c7ec
parent 847 133dc1075efd
child 849 fe1e531a19ce
implemented request amb302 (onservercfg and onmapstart are now called if a plugin is late loaded)
core/ConCmdManager.cpp
core/ConCmdManager.h
core/PlayerManager.cpp
core/PlayerManager.h
core/sourcemod.cpp
core/systems/PluginSys.cpp
     1.1 --- a/core/ConCmdManager.cpp	Wed May 23 16:58:53 2007 +0000
     1.2 +++ b/core/ConCmdManager.cpp	Wed May 23 17:54:45 2007 +0000
     1.3 @@ -92,7 +92,7 @@
     1.4  	g_RootMenu.RemoveRootConsoleCommand("cmds", this);
     1.5  }
     1.6  
     1.7 -void ConCmdManager::OnSourceModPluginsLoaded()
     1.8 +void ConCmdManager::OnSourceModLevelChange(const char *mapName)
     1.9  {
    1.10  	m_bServerCfgDone = false;
    1.11  }
     2.1 --- a/core/ConCmdManager.h	Wed May 23 16:58:53 2007 +0000
     2.2 +++ b/core/ConCmdManager.h	Wed May 23 17:54:45 2007 +0000
     2.3 @@ -84,7 +84,7 @@
     2.4  public: //SMGlobalClass
     2.5  	void OnSourceModAllInitialized();
     2.6  	void OnSourceModShutdown();
     2.7 -	void OnSourceModPluginsLoaded();
     2.8 +	void OnSourceModLevelChange(const char *mapName);
     2.9  public: //IPluginsListener
    2.10  	void OnPluginDestroyed(IPlugin *plugin);
    2.11  public: //IRootConsoleCommand
    2.12 @@ -116,6 +116,10 @@
    2.13  	{
    2.14  		return m_CmdClient;
    2.15  	}
    2.16 +	inline bool IsServerCfgDone()
    2.17 +	{
    2.18 +		return m_bServerCfgDone;
    2.19 +	}
    2.20  private:
    2.21  	Trie *m_pCmds;					/* command lookup */
    2.22  	Trie *m_pCmdGrps;				/* command group lookup */
     3.1 --- a/core/PlayerManager.cpp	Wed May 23 16:58:53 2007 +0000
     3.2 +++ b/core/PlayerManager.cpp	Wed May 23 17:54:45 2007 +0000
     3.3 @@ -21,6 +21,7 @@
     3.4  #include "MenuStyle_Radio.h"
     3.5  
     3.6  PlayerManager g_Players;
     3.7 +bool g_OnMapStarted = false;
     3.8  
     3.9  SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char *, const char *, char *, int);
    3.10  SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, const char *);
    3.11 @@ -110,6 +111,8 @@
    3.12  	}
    3.13  	m_onActivate->Execute(NULL);
    3.14  	m_onActivate2->Execute(NULL);
    3.15 +
    3.16 +	g_OnMapStarted = true;
    3.17  }
    3.18  
    3.19  void PlayerManager::RunAuthChecks()
     4.1 --- a/core/PlayerManager.h	Wed May 23 16:58:53 2007 +0000
     4.2 +++ b/core/PlayerManager.h	Wed May 23 17:54:45 2007 +0000
     4.3 @@ -127,5 +127,6 @@
     4.4  };
     4.5  
     4.6  extern PlayerManager g_Players;
     4.7 +extern bool g_OnMapStarted;
     4.8  
     4.9  #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
     5.1 --- a/core/sourcemod.cpp	Wed May 23 16:58:53 2007 +0000
     5.2 +++ b/core/sourcemod.cpp	Wed May 23 17:54:45 2007 +0000
     5.3 @@ -411,6 +411,8 @@
     5.4  		m_ExecOnMapEnd = false;
     5.5  	}
     5.6  
     5.7 +	g_OnMapStarted = false;
     5.8 +
     5.9  	if (m_ExecPluginReload)
    5.10  	{
    5.11  		g_PluginSys.ReloadOrUnloadPlugins();
     6.1 --- a/core/systems/PluginSys.cpp	Wed May 23 16:58:53 2007 +0000
     6.2 +++ b/core/systems/PluginSys.cpp	Wed May 23 17:54:45 2007 +0000
     6.3 @@ -25,6 +25,8 @@
     6.4  #include "ExtensionSys.h"
     6.5  #include "sm_srvcmds.h"
     6.6  #include "sm_stringutil.h"
     6.7 +#include "ConCmdManager.h"
     6.8 +#include "PlayerManager.h"
     6.9  
    6.10  CPluginManager g_PluginSys;
    6.11  HandleType_t g_PluginType = 0;
    6.12 @@ -299,6 +301,21 @@
    6.13  	if ((err=pFunction->Execute(&result)) != SP_ERROR_NONE)
    6.14  	{
    6.15  		SetErrorState(Plugin_Error, "Error detected in plugin startup (see error logs)");
    6.16 +	} else {
    6.17 +		if (g_OnMapStarted)
    6.18 +		{
    6.19 +			if ((pFunction = m_ctx.base->GetFunctionByName("OnMapStart")) != NULL)
    6.20 +			{
    6.21 +				pFunction->Execute(NULL);
    6.22 +			}
    6.23 +		}
    6.24 +		if (g_ConCmds.IsServerCfgDone())
    6.25 +		{
    6.26 +			if ((pFunction = m_ctx.base->GetFunctionByName("OnServerCfg")) != NULL)
    6.27 +			{
    6.28 +				pFunction->Execute(NULL);
    6.29 +			}
    6.30 +		}
    6.31  	}
    6.32  }
    6.33