From 196a665d51e838135bc745a90d343f8872962873 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 23 May 2007 17:54:45 +0000 Subject: [PATCH] implemented request amb302 (onservercfg and onmapstart are now called if a plugin is late loaded) --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40854 --- core/ConCmdManager.cpp | 2 +- core/ConCmdManager.h | 6 +++++- core/PlayerManager.cpp | 3 +++ core/PlayerManager.h | 1 + core/sourcemod.cpp | 2 ++ core/systems/PluginSys.cpp | 17 +++++++++++++++++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp index 6bf92178..d352863d 100644 --- a/core/ConCmdManager.cpp +++ b/core/ConCmdManager.cpp @@ -92,7 +92,7 @@ void ConCmdManager::OnSourceModShutdown() g_RootMenu.RemoveRootConsoleCommand("cmds", this); } -void ConCmdManager::OnSourceModPluginsLoaded() +void ConCmdManager::OnSourceModLevelChange(const char *mapName) { m_bServerCfgDone = false; } diff --git a/core/ConCmdManager.h b/core/ConCmdManager.h index dbfcd0d5..ef581150 100644 --- a/core/ConCmdManager.h +++ b/core/ConCmdManager.h @@ -84,7 +84,7 @@ public: public: //SMGlobalClass void OnSourceModAllInitialized(); void OnSourceModShutdown(); - void OnSourceModPluginsLoaded(); + void OnSourceModLevelChange(const char *mapName); public: //IPluginsListener void OnPluginDestroyed(IPlugin *plugin); public: //IRootConsoleCommand @@ -116,6 +116,10 @@ public: { return m_CmdClient; } + inline bool IsServerCfgDone() + { + return m_bServerCfgDone; + } private: Trie *m_pCmds; /* command lookup */ Trie *m_pCmdGrps; /* command group lookup */ diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 15708383..813783c7 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -21,6 +21,7 @@ #include "MenuStyle_Radio.h" PlayerManager g_Players; +bool g_OnMapStarted = false; SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char *, const char *, char *, int); SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, const char *); @@ -110,6 +111,8 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl } m_onActivate->Execute(NULL); m_onActivate2->Execute(NULL); + + g_OnMapStarted = true; } void PlayerManager::RunAuthChecks() diff --git a/core/PlayerManager.h b/core/PlayerManager.h index 30986ac9..18240adf 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -127,5 +127,6 @@ private: }; extern PlayerManager g_Players; +extern bool g_OnMapStarted; #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_ diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 53bb6772..21a194e6 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -411,6 +411,8 @@ void SourceModBase::LevelShutdown() m_ExecOnMapEnd = false; } + g_OnMapStarted = false; + if (m_ExecPluginReload) { g_PluginSys.ReloadOrUnloadPlugins(); diff --git a/core/systems/PluginSys.cpp b/core/systems/PluginSys.cpp index 2940eca3..1fb61921 100644 --- a/core/systems/PluginSys.cpp +++ b/core/systems/PluginSys.cpp @@ -25,6 +25,8 @@ #include "ExtensionSys.h" #include "sm_srvcmds.h" #include "sm_stringutil.h" +#include "ConCmdManager.h" +#include "PlayerManager.h" CPluginManager g_PluginSys; HandleType_t g_PluginType = 0; @@ -299,6 +301,21 @@ void CPlugin::Call_OnPluginStart() if ((err=pFunction->Execute(&result)) != SP_ERROR_NONE) { SetErrorState(Plugin_Error, "Error detected in plugin startup (see error logs)"); + } else { + if (g_OnMapStarted) + { + if ((pFunction = m_ctx.base->GetFunctionByName("OnMapStart")) != NULL) + { + pFunction->Execute(NULL); + } + } + if (g_ConCmds.IsServerCfgDone()) + { + if ((pFunction = m_ctx.base->GetFunctionByName("OnServerCfg")) != NULL) + { + pFunction->Execute(NULL); + } + } } }