From 6c73a7d8d1d00f580ca223741a64a5b19d19064d Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 9 Sep 2004 05:16:53 +0000 Subject: [PATCH] New module registering ability --- amxmodx/CPlugin.cpp | 2 +- amxmodx/amxmodx.cpp | 14 ++++++++++ amxmodx/amxmodx.h | 1 + amxmodx/meta_api.cpp | 10 +++++-- amxmodx/modules.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 88 insertions(+), 5 deletions(-) diff --git a/amxmodx/CPlugin.cpp b/amxmodx/CPlugin.cpp index 5ee7de64..c587be41 100755 --- a/amxmodx/CPlugin.cpp +++ b/amxmodx/CPlugin.cpp @@ -78,7 +78,7 @@ int CPluginMngr::loadPluginsFromFile( const char* filename ) debugFlag = 1; } #endif - + CPlugin* plugin = loadPlugin( pluginsDir , pluginName , error, debugFlag); if (!plugin) diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index eb521b9f..2e6e2625 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -2653,6 +2653,19 @@ static cell lang_exists(AMX *amx, cell *params) return g_langMngr.LangExists(get_amxstring(amx, params[1], 1, len)) ? 1 : 0; } +static cell register_module(AMX *amx, cell *params) +{ + int len = 0; + + String s; + + s.assign(get_amxstring(amx, params[1], 0, len)); + + CurModuleList.push(s); + + return 1; +} + AMX_NATIVE_INFO amxmod_Natives[] = { { "client_cmd", client_cmd }, { "client_print", client_print }, @@ -2752,6 +2765,7 @@ AMX_NATIVE_INFO amxmod_Natives[] = { { "register_logevent",register_logevent}, { "register_menucmd", register_menucmd }, { "register_menuid", register_menuid }, + { "register_module", register_module }, { "register_plugin", register_plugin }, { "register_srvcmd", register_srvcmd }, { "remove_cvar_flags", remove_cvar_flags }, diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index e70f6983..37979a95 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -266,6 +266,7 @@ enum ModuleCallReason extern ModuleCallReason g_ModuleCallReason; // modules.cpp extern CModule *g_CurrentlyCalledModule; // modules.cpp extern const char *g_LastRequestedFunc; // modules.cpp +extern CQueue CurModuleList; void *Module_ReqFnptr(const char *funcName); // modules.cpp diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 6ede90c8..55b9a413 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -57,6 +57,7 @@ void (*function)(void*); void (*endfunction)(void*); CLog g_log; +CQueue CurModuleList; CForwardMngr g_forwards; CList g_auth; CList g_cvars; @@ -199,7 +200,6 @@ const char* get_localinfo( const char* name , const char* def ) // Initialize AMX stuff and load it's plugins from plugins.ini list // Call precache forward function from plugins int C_Spawn( edict_t *pent ) { - g_forcedmodules = false; g_forcedsounds = false; @@ -447,7 +447,6 @@ void C_ServerDeactivate_Post() { g_FakeMeta.m_Plugins.begin()->GetDllFuncTable().pfnSpawn = C_Spawn; detachReloadModules(); - g_auth.clear(); g_forwards.clear(); g_commands.clear(); @@ -465,6 +464,13 @@ void C_ServerDeactivate_Post() { g_langMngr.Save(build_pathname("%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxmodx/data"))); g_langMngr.SaveCache(build_pathname("%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data"))); g_langMngr.Clear(); + + //clear module name cache + while (!CurModuleList.empty()) + { + CurModuleList.pop(); + } + // last memreport #ifdef MEMORY_TEST if (g_memreport_enabled) diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 160f6955..52ec3297 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -214,6 +214,63 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 return set_amxnatives(amx,error); } +//BAILOPAN +int CheckModules(AMX *amx, char error[64]) +{ + int idx = 0, flag = 1; + if (amx_FindPublic(amx, "plugin_modules", &idx) == AMX_ERR_NONE) + { + cell retVal = 0; + int err = 0; + if ( (err = amx_Exec(amx, &retVal, idx, 0)) == AMX_ERR_NONE ) + { + unsigned int i = 0; + while (!CurModuleList.empty()) + { + if (!flag) + { + CurModuleList.pop(); + continue; + } + //assume module is not found + flag = 0; + for (CList::iterator pMod = g_modules.begin(); pMod; ++pMod) + { + if (strcmpi(CurModuleList.front().c_str(), "dbi") == 0) + { + if (strstr( (*pMod).getName(), "sql") || strstr( (*pMod).getName(), "dbi" )) + { + // the module checks in + flag = 1; + break; + } + } else { + if (strcmpi( (*pMod).getName(), CurModuleList.front().c_str() ) == 0) + { + flag = 1; + break; + } + } + } + //module was not found + if (!flag) + { + sprintf(error, "Module \"%s\" required for plugin. Check modules.ini.", CurModuleList.front().c_str()); + } + CurModuleList.pop(); + } + } else { + AMXXLOG_Log("[AMXX] Run time error %d on line %ld during module check.", err, amx->curline); + //could not execute + return -1; //bad! very bad! + } + } else { + return -1; + } + + return flag; +} + int set_amxnatives(AMX* amx,char error[64]) { for ( CList::iterator a = g_modules.begin(); a ; ++a ) @@ -233,14 +290,19 @@ int set_amxnatives(AMX* amx,char error[64]) if ( amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE ) { - sprintf(error,"Function not found (name \"%s\")",no_function); + if (CheckModules(amx, error) == -1) + { + //HACKHACK + sprintf(error,"Plugin uses an unknown function (name \"%s\") - check your modules.ini.",no_function); + } return (amx->error = AMX_ERR_NATIVE); } + CheckModules(amx, error); + return AMX_ERR_NONE; } - int unload_amxscript(AMX* amx, void** program) { CList::iterator a = g_loadedscripts.find( amx );