From 49c7a8c7cab5abeddfd966f99601f761b71ec310 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 19 Apr 2005 07:41:07 +0000 Subject: [PATCH] Fixed retry command Fixed ids starting at 3 (changed Pl_MinId) Doxyfile is no longer subdir based --HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%4030 --- sourcemm/CPlugin.cpp | 43 ++++++++++++++++++++++++++++++++++++++ sourcemm/CPlugin.h | 10 +++++++++ sourcemm/IPluginManager.h | 8 +++---- sourcemm/ISmmPlugin.h | 2 +- sourcemm/SourceMM.Doxyfile | 2 +- sourcemm/concommands.cpp | 27 ++++-------------------- sourcemm/sourcemm.vcproj | 2 +- 7 files changed, 64 insertions(+), 30 deletions(-) diff --git a/sourcemm/CPlugin.cpp b/sourcemm/CPlugin.cpp index 928d7eb..eeade11 100644 --- a/sourcemm/CPlugin.cpp +++ b/sourcemm/CPlugin.cpp @@ -142,6 +142,49 @@ bool CPluginManager::Unload(PluginId id, bool force, char *error, size_t maxlen) return _Unload(pl, force, error, maxlen); } +bool CPluginManager::Retry(PluginId id, char *error, size_t len) +{ + PluginIter i; + char buffer[64]; + for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++) + { + if ( (*i) && (*i)->m_Id == id ) + { + if ( (*i)->m_Status >= Pl_Paused) + { + snprintf(error, len, "Plugin %d is already running.", id); + return false; + } + CPlugin *pl = _Load((*i)->m_File.c_str(), Pl_Console, error, len); + if (!pl) + return false; + if (pl->m_Status >= Pl_Paused) + { + //Now it gets crazy... unload the original copy. + _Unload( (*i), true, buffer, sizeof(buffer)-1 ); + + //Set the new copy's id + pl->m_Id = id; + + //We just wasted an id... reclaim it + m_LastId--; + + return true; + } else { + //don't really care about the buffer here + _Unload(pl, true, buffer, sizeof(buffer)-1); + + //We just wasted an id... reclaim it + m_LastId--; + return false; + } + } + } + + snprintf(error, len, "Plugin %d not found,", id); + return false; +} + CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source, char *error, size_t maxlen) { FILE *fp; diff --git a/sourcemm/CPlugin.h b/sourcemm/CPlugin.h index 24e6f17..811d882 100644 --- a/sourcemm/CPlugin.h +++ b/sourcemm/CPlugin.h @@ -65,6 +65,16 @@ namespace SourceMM */ CPlugin *FindById(PluginId id); + /** + * @brief Attempts to reload a failed plugin + * + * @param id Id of plugin + * @param error Error message buffer + * @param len Maximum length of buffer + * @return True on success, false otherwise + */ + bool Retry(PluginId id, char *error, size_t len); + //Internal iterators std::list::iterator _begin(); std::list::iterator _end(); diff --git a/sourcemm/IPluginManager.h b/sourcemm/IPluginManager.h index 313b2d2..584c573 100644 --- a/sourcemm/IPluginManager.h +++ b/sourcemm/IPluginManager.h @@ -36,12 +36,12 @@ enum Pl_Status enum { Pl_BadLoad=0, - Pl_Console, - Pl_File, - Pl_MinId, + Pl_Console=-1, + Pl_File=-2, + Pl_MinId=1, }; -typedef unsigned int PluginId; +typedef int PluginId; struct factories; class ISmmPluginManager diff --git a/sourcemm/ISmmPlugin.h b/sourcemm/ISmmPlugin.h index 23428b7..4774591 100644 --- a/sourcemm/ISmmPlugin.h +++ b/sourcemm/ISmmPlugin.h @@ -32,7 +32,7 @@ struct factories }; class ISmmAPI; -typedef unsigned int PluginId; +typedef int PluginId; class ISmmPlugin { diff --git a/sourcemm/SourceMM.Doxyfile b/sourcemm/SourceMM.Doxyfile index ba1c75c..b7f2df7 100644 --- a/sourcemm/SourceMM.Doxyfile +++ b/sourcemm/SourceMM.Doxyfile @@ -6,7 +6,7 @@ PROJECT_NAME = SourceMM PROJECT_NUMBER = 1.00 OUTPUT_DIRECTORY = c:\temp\smm-dox -CREATE_SUBDIRS = YES +CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English USE_WINDOWS_ENCODING = YES BRIEF_MEMBER_DESC = YES diff --git a/sourcemm/concommands.cpp b/sourcemm/concommands.cpp index ceabe22..b68794a 100644 --- a/sourcemm/concommands.cpp +++ b/sourcemm/concommands.cpp @@ -301,34 +301,15 @@ CON_COMMAND(meta, "Metamod:Source Menu") if (args >= 3) { int id = atoi(e->Cmd_Argv(2)); - SourceMM::CPluginManager::CPlugin *pl; - - pl = g_PluginMngr.FindById(id); - - if (!pl) - { - Msg("Plugin %d not found.\n", id); - return; - } - - if (pl->m_Status >= Pl_Paused) - { - Msg("Plugin %d is already loaded.\n"); - return; - } - - PluginId plid; char error[255]; - bool already; - plid = g_PluginMngr.Load(pl->m_File.c_str(), Pl_Console, already, error, sizeof(error)-1); - if (plid < Pl_MinId) + if (!g_PluginMngr.Retry(id, error, sizeof(error)-1)) { - Msg("Failed to reload plugin %d: (%s).\n", id, error); + Msg("Error reloading plugin: %s\n", error); return; } - Msg("Plugin %d successfully reloaded as plugin %d.\n", id, plid); + Msg("Plugin %d successfully reloaded.\n", id); return; } else { @@ -350,7 +331,7 @@ CON_COMMAND(meta, "Metamod:Source Menu") Msg(" load - Load a plugin\n"); Msg(" pause - Pause a running plugin\n"); Msg(" refresh - Reparse plugins file\n"); - Msg(" retry - Attempt to reload a plugin\n"); + Msg(" retry - Attempt to reload a plugin\n"); Msg(" unload - Unload a loaded plugin\n"); Msg(" unpause - Unpause a paused plugin\n"); Msg(" version - Version information\n"); diff --git a/sourcemm/sourcemm.vcproj b/sourcemm/sourcemm.vcproj index 5d544c5..0bb6731 100644 --- a/sourcemm/sourcemm.vcproj +++ b/sourcemm/sourcemm.vcproj @@ -87,7 +87,7 @@ AdditionalDependencies="tier0.lib vstdlib.lib" OutputFile="$(OutDir)/server.dll" LinkIncremental="1" - GenerateDebugInformation="FALSE" + GenerateDebugInformation="TRUE" SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2"