From 73d70aff2918c03e90782a674223fe7afa98e0c8 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 11 Sep 2005 04:43:40 +0000 Subject: [PATCH] added module_exists --- amxmodx/amxmodx.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ amxmodx/modules.h | 1 + 2 files changed, 49 insertions(+) diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 79e7b73a..65851ba4 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -31,6 +31,7 @@ #include #include "amxmodx.h" +#include "natives.h" static cell AMX_NATIVE_CALL get_xvar_id(AMX *amx, cell *params) { @@ -3035,6 +3036,52 @@ static cell AMX_NATIVE_CALL amx_abort(AMX *amx, cell *params) return 1; } +static cell AMX_NATIVE_CALL module_exists(AMX *amx, cell *params) +{ + int len; + char *module = get_amxstring(amx, params[1], 0, len); + + CList::iterator a; + + bool isdbi = false, found = false; + const amxx_module_info_s *info; + if (stricmp(module, "dbi")==0) + isdbi = true; + + for (a=g_modules.begin(); a; ++a) + { + if ( (*a).getStatusValue() == MODULE_LOADED ) + { + info = (*a).getInfoNew(); + if (info) + { + if (isdbi) + { + if (info->logtag + && (StrCaseStr(info->logtag, "sql") + || + StrCaseStr(info->logtag, "dbi")) + ) + { + found = true; + break; + } + } else { + if (info->logtag && (stricmp(info->logtag, module) == 0)) + { + found = true; + break; + } + } + } + } + } + if (!found) + found = LibraryExists(module); + + return (found ? 1 : 0); +} + AMX_NATIVE_INFO amxmodx_Natives[] = { {"abort", amx_abort}, {"callfunc_begin", callfunc_begin}, @@ -3139,6 +3186,7 @@ AMX_NATIVE_INFO amxmodx_Natives[] = { {"md5_file", amx_md5_file}, {"message_begin", message_begin}, {"message_end", message_end}, + {"module_exists", module_exists}, {"mkdir", amx_mkdir}, {"num_to_word", num_to_word}, {"parse_loguser", parse_loguser}, diff --git a/amxmodx/modules.h b/amxmodx/modules.h index 704f4456..5a29a03d 100755 --- a/amxmodx/modules.h +++ b/amxmodx/modules.h @@ -49,5 +49,6 @@ #define STATIC_MODULE 1 int CheckModules(AMX *amx, char error[128]); +const char *StrCaseStr(const char *as, const char *bs); #endif // __MODULES_H__