From 5524d5dca13d2f6eae504d07a0f54532f2ac61b5 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 17 Aug 2006 18:25:23 +0000 Subject: [PATCH] Added the ability to mark plugins as "disabled." This blocks the plugin from loading in other files. Fixed a bug where the PCALM cache was invalidated on file read, rather than plugin finalization. --- amxmodx/CPlugin.cpp | 55 +++++++++++++++++++++++++++++++++++++++++--- amxmodx/CPlugin.h | 1 + amxmodx/meta_api.cpp | 7 +++++- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/amxmodx/CPlugin.cpp b/amxmodx/CPlugin.cpp index 18e15d63..865ab083 100755 --- a/amxmodx/CPlugin.cpp +++ b/amxmodx/CPlugin.cpp @@ -99,6 +99,8 @@ int CPluginMngr::loadPluginsFromFile(const char* filename) String line; + List::iterator block_iter; + while (!feof(fp)) { pluginName[0] = '\0'; @@ -122,13 +124,32 @@ int CPluginMngr::loadPluginsFromFile(const char* filename) sscanf(line.c_str(), "%s %s", pluginName, debug); if (!isalnum(*pluginName)) + { continue; + } - if (isalnum(*debug) && strcmp(debug, "debug") == 0) + if (isalnum(*debug) && !strcmp(debug, "debug")) { debugFlag = 1; } + bool skip = false; + for (block_iter = m_BlockList.begin(); + block_iter != m_BlockList.end(); + block_iter++) + { + if ((*block_iter)->compare(pluginName) == 0) + { + skip = true; + break; + } + } + + if (skip || !strcmp(debug, "disabled")) + { + continue; + } + CPlugin* plugin = loadPlugin(pluginsDir, pluginName, error, debugFlag); if (plugin->getStatusCode() == ps_bad_load) @@ -142,8 +163,6 @@ int CPluginMngr::loadPluginsFromFile(const char* filename) fclose(fp); - InvalidateCache(); - return pCounter; } @@ -161,6 +180,14 @@ void CPluginMngr::clear() delete [] pNatives; pNatives = NULL; } + + List::iterator iter = m_BlockList.begin(); + while (iter != m_BlockList.end()) + { + delete (*iter); + iter = m_BlockList.erase(iter); + } + m_BlockList.clear(); } CPluginMngr::CPlugin* CPluginMngr::findPlugin(AMX *amx) @@ -616,7 +643,9 @@ void CPluginMngr::CALMFromFile(const char *file) { fgets(line, sizeof(line)-1, fp); if (line[0] == ';' || line[0] == '\n' || line[0] == '\0') + { continue; + } /** quick hack */ char *ptr = line; @@ -635,8 +664,28 @@ void CPluginMngr::CALMFromFile(const char *file) pluginName[0] = '\0'; sscanf(rline.c_str(), "%s", pluginName); + /* HACK: see if there's a 'disabled' coming up + * new block for scopying flexibility + */ + if (1) + { + const char *_ptr = rline.c_str() + strlen(pluginName); + while (*_ptr != '\0' && isspace(*_ptr)) + { + _ptr++; + } + if ((*_ptr != '\0') && !strcmp(_ptr, "disabled")) + { + String *pString = new String(pluginName); + m_BlockList.push_back(pString); + continue; + } + } + if (!isalnum(*pluginName)) + { continue; + } build_pathname_r(filename, sizeof(filename)-1, "%s/%s", get_localinfo("amxx_pluginsdir", "addons/amxmodx/plugins"), pluginName); diff --git a/amxmodx/CPlugin.h b/amxmodx/CPlugin.h index bd22d80a..e24320de 100755 --- a/amxmodx/CPlugin.h +++ b/amxmodx/CPlugin.h @@ -165,6 +165,7 @@ public: void CALMFromFile(const char *file); private: List m_plcache; + List m_BlockList; }; #endif //PLUGIN_H diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 23510495..99464a57 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -268,7 +268,9 @@ const char* get_localinfo(const char* name, const char* def) const char* b = LOCALINFO((char*)name); if (b == 0 || *b == 0) + { SET_LOCALINFO((char*)name, (char*)(b = def)); + } return b; } @@ -280,7 +282,9 @@ const char* get_localinfo(const char* name, const char* def) int C_Spawn(edict_t *pent) { if (g_initialized) + { RETURN_META_VALUE(MRES_IGNORED, 0); + } g_activated = false; g_initialized = true; @@ -365,7 +369,7 @@ int C_Spawn(edict_t *pent) if (!g_opt_level) g_opt_level = 7; - // ###### Load AMX scripts + // ###### Load AMX Mod X plugins g_plugins.loadPluginsFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini")); BuildPluginFileList(files); while (!files.empty()) @@ -379,6 +383,7 @@ int C_Spawn(edict_t *pent) files.pop(); } g_plugins.Finalize(); + g_plugins.InvalidateCache(); // Register forwards FF_PluginInit = registerForward("plugin_init", ET_IGNORE, FP_DONE);