From 3cba7811bd38172de8c9e3d19825adc2fd537138 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 15 Jul 2005 19:15:58 +0000 Subject: [PATCH] Committed new auto-module registering system require_module is now DEPRECATED --- amxmodx/CModule.h | 3 +- amxmodx/amx.cpp | 24 +++++++++++ amxmodx/amx.h | 5 ++- amxmodx/amxmodx.cpp | 8 ---- amxmodx/amxmodx.h | 1 - amxmodx/meta_api.cpp | 6 --- amxmodx/modules.cpp | 98 +++++++++++++++++++------------------------- 7 files changed, 73 insertions(+), 72 deletions(-) diff --git a/amxmodx/CModule.h b/amxmodx/CModule.h index 0c530be0..ce713e8e 100755 --- a/amxmodx/CModule.h +++ b/amxmodx/CModule.h @@ -57,6 +57,7 @@ struct amxx_module_info_s const char *author; const char *version; int reload; // reload on mapchange when nonzero + const char *logtag; //added in version 2 }; @@ -65,7 +66,7 @@ struct amxx_module_info_s #define AMXX_PARAM 2 /* Invalid parameter */ #define AMXX_FUNC_NOT_PRESENT 3 /* Function not present */ -#define AMXX_INTERFACE_VERSION 1 +#define AMXX_INTERFACE_VERSION 2 class CModule { diff --git a/amxmodx/amx.cpp b/amxmodx/amx.cpp index f6137495..18d57420 100755 --- a/amxmodx/amx.cpp +++ b/amxmodx/amx.cpp @@ -40,6 +40,7 @@ #endif #include +#include #include #include #include @@ -4139,3 +4140,26 @@ int AMXAPI amx_UTF8Check(const char *string) return err; } #endif /* AMX_UTF8XXX */ + +int AMXAPI amx_GetLibraries(AMX *amx) +{ + AMX_HEADER *hdr = (AMX_HEADER *)amx->base; + int numLibraries = NUMENTRIES(hdr, libraries, pubvars); + + return numLibraries; +} + +#ifdef __linux__ +#define _snprintf snprintf +#endif + +const char *AMXAPI amx_GetLibrary(AMX *amx, int index, char *buffer, int len) +{ + AMX_HEADER *hdr = (AMX_HEADER *)amx->base; + AMX_FUNCSTUB *lib; + + lib = GETENTRY(hdr, libraries, index); + _snprintf(buffer, len, "%s", GETENTRYNAME(hdr,lib)); + + return buffer; +} diff --git a/amxmodx/amx.h b/amxmodx/amx.h index bcd661e2..1ec389b5 100755 --- a/amxmodx/amx.h +++ b/amxmodx/amx.h @@ -403,7 +403,10 @@ int AMXAPI amx_StrLen(cell *cstring, int *length); int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value); int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value); int AMXAPI amx_UTF8Check(const char *string); -void amx_NullNativeTable(AMX *amx); +int AMXAPI amx_GetLibraries(AMX *amx); +const char *AMXAPI amx_GetLibrary(AMX *amx, int index, char *buffer, int len); + +//no longer used! void amx_NullNativeTable(AMX *amx); #if !defined AMX_NO_ALIGN #if defined __linux__ diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index c77f74af..6bc346e4 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -2849,14 +2849,6 @@ static cell AMX_NATIVE_CALL lang_exists(AMX *amx, cell *params) cell AMX_NATIVE_CALL require_module(AMX *amx, cell *params) { - int len = 0; - - String s; - - s.assign(get_amxstring(amx, params[1], 0, len)); - - CurModuleList.push(s); - return 1; } diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index c374905e..8226772e 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -278,7 +278,6 @@ 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_CacheFunctions(); void *Module_ReqFnptr(const char *funcName); // modules.cpp diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index f7d74310..abd861e2 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -58,7 +58,6 @@ void (*function)(void*); void (*endfunction)(void*); CLog g_log; -CQueue CurModuleList; CForwardMngr g_forwards; CList g_auth; CList g_cvars; @@ -465,11 +464,6 @@ void C_ServerDeactivate_Post() { g_langMngr.Save(build_pathname_r(file, sizeof(file)-1, "%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxmodx/data"))); g_langMngr.SaveCache(build_pathname_r(file, sizeof(file)-1, "%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 diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index b3eca036..5342f448 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -253,64 +253,64 @@ const char *StrCaseStr(const char *as, const char *bs) return strstr(a,b); } -//BAILOPAN -int CheckModules(AMX *amx, char error[64]) +//returns 0 for module not found, 1 for "everything's okay" +int CheckModules(AMX *amx, char error[128]) { - int idx = 0, flag = -1; - if (amx_FindPublic(amx, "plugin_modules", &idx) == AMX_ERR_NONE) + int numLibraries = amx_GetLibraries(amx); + char buffer[32]; + bool found = false; + bool isdbi = false; + CList::iterator a; + const amxx_module_info_s *info; + + for (int i=0; i::iterator pMod = g_modules.begin(); pMod; ++pMod) - { - if (strcmpi(CurModuleList.front().c_str(), "dbi") == 0) + if (isdbi) { - if (StrCaseStr( (*pMod).getName(), "sql") || strstr( (*pMod).getName(), "dbi" )) + if (info->logtag + && (StrCaseStr(info->logtag, "sql") + || + StrCaseStr(info->logtag, "dbi")) + ) { - // the module checks in - flag = 1; + found = true; break; } } else { - if (strcmpi( (*pMod).getName(), CurModuleList.front().c_str() ) == 0) + if (info->logtag && (strcmpi(info->logtag, buffer) == 0)) { - flag = 1; + found = true; 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; + if (!found) + { + sprintf(error, "Module \"%s\" required for plugin. Check modules.ini.", buffer); + return 0; + } } - return flag; + return 1; } -int set_amxnatives(AMX* amx,char error[64]) +int set_amxnatives(AMX* amx,char error[128]) { for ( CList::iterator a = g_modules.begin(); a ; ++a ) { @@ -327,29 +327,17 @@ int set_amxnatives(AMX* amx,char error[64]) amx_Register(amx, time_Natives, -1); amx_Register(amx, vault_Natives, -1); - if ( amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE ) + if (CheckModules(amx, error)) { - //HACKHACK - if we get here, nullify the plugin's native table - //then reregister the one native we need - // - BAILOPAN - String save; - save.assign(no_function); - amx_NullNativeTable(amx); - AMX_NATIVE_INFO p[] = { - { "require_module", require_module }, - { NULL, NULL }, - }; - amx_Register(amx, p, -1); - if (CheckModules(amx, error) == -1 || *error == 0) + if ( amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE ) { - sprintf(error,"Plugin uses an unknown function (name \"%s\") - check your modules.ini.",save.c_str()); + sprintf(error, "Plugin uses an unknown function (name \"%s\") - check your modules.ini.", no_function); } - return (amx->error = AMX_ERR_NATIVE); + + return AMX_ERR_NONE; } - CheckModules(amx, error); - - return AMX_ERR_NONE; + return (amx->error = AMX_ERR_NATIVE); } int unload_amxscript(AMX* amx, void** program)