diff --git a/amxmodx/CLang.cpp b/amxmodx/CLang.cpp index 643ed712..6d975edc 100755 --- a/amxmodx/CLang.cpp +++ b/amxmodx/CLang.cpp @@ -217,7 +217,7 @@ const char * CLangMngr::CLang::GetDef(int key, int &status) if (!def.definition) { - status = LANG_STATUS_KLNOTFOUND; + status = ERR_BADKEY; return NULL; } @@ -340,6 +340,7 @@ int CLangMngr::GetKeyEntry(String &key) #define MAX_LEVELS 4 size_t do_amx_format(AMX *amx, cell *params, int *param, const char **lex, char *output, size_t maxlen, int level); +THash BadLang_Table; size_t do_amx_format_parameter(AMX *amx, cell *params, const char **fmtstr, int *param, char *output, size_t maxlen, int level) { @@ -443,16 +444,36 @@ size_t do_amx_format_parameter(AMX *amx, cell *params, const char **fmtstr, int FMTPM_NEXTPARAM(); key = get_amxstring(amx, _addr, 1, tmpLen); def = g_langMngr.GetDef(pLangName, key, status); + + bool debug = (strcmp(CVAR_GET_STRING("amx_mldebug"), "")) ? true : false; + + if (debug) + { + int debug_status; + bool validlang = true; + const char *testlang = CVAR_GET_STRING("amx_mldebug"); + + if (!g_langMngr.LangExists(testlang)) + { + AMXXLOG_Log("[AMXX] \"%s\" is an invalid debug language", testlang); + validlang = false; + } + + g_langMngr.GetDef(testlang, key, debug_status); + + if (validlang && debug_status == ERR_BADKEY) + AMXXLOG_Log("[AMXX] Language key \"%s\" not found for language \"%s\", check \"%s\"", key, testlang, GetFileName(amx)); + } if (def == NULL) { - bool a = true; - if (status == LANG_STATUS_LNOTFOUND) + if (debug) { - AMXXLOG_Log("[AMXX] Language \"%s\" not found", pLangName); - } else if (status == LANG_STATUS_KLNOTFOUND) { - a = false; - AMXXLOG_Log("[AMXX] Language key \"%s\" not found for language \"%s\"", key, pLangName); + if (status == ERR_BADLANG && (BadLang_Table[pLangName].last + 120.0f < gpGlobals->time)) + { + AMXXLOG_Log("[AMXX] Language \"%s\" not found", pLangName); + BadLang_Table[pLangName].last = gpGlobals->time; + } } if (addr[0] != LANG_SERVER) @@ -464,8 +485,6 @@ size_t do_amx_format_parameter(AMX *amx, cell *params, const char **fmtstr, int if (!def) { return _snprintf(output, maxlen, "ML_NOTFOUND: %s", key); - if (a) - AMXXLOG_Log("[AMXX] Language key \"%s\" not found, check \"%s\"", key, GetFileName(amx)); } } return do_amx_format(amx, params, param, &def, output, maxlen, level + 1); @@ -976,10 +995,10 @@ const char *CLangMngr::GetDef(const char *langName, const char *key, int &status keytbl_val val = KeyTable[key]; if (lang == NULL) { - status = LANG_STATUS_LNOTFOUND; + status = ERR_BADLANG; return NULL; } else if (val.index == -1) { - status = LANG_STATUS_KLNOTFOUND; + status = ERR_BADKEY; return NULL; } else { return lang->GetDef(val.index, status); diff --git a/amxmodx/CLang.h b/amxmodx/CLang.h index 3ee2864f..77f650cf 100755 --- a/amxmodx/CLang.h +++ b/amxmodx/CLang.h @@ -37,9 +37,8 @@ #define LANG_SERVER 0 #define LANG_PLAYER -1 -#define LANG_STATUS_OK 0 // OK -#define LANG_STATUS_KLNOTFOUND 1 // Lang key not found in the lang.txt -#define LANG_STATUS_LNOTFOUND 3 // Invalid lang +#define ERR_BADKEY 1 // Lang key not found +#define ERR_BADLANG 2 // Invalid lang struct md5Pair { @@ -53,6 +52,14 @@ struct sKeyDef int key; }; +struct lang_err +{ + lang_err() : last(0.0f) + { + }; + float last; +}; + class defentry { public: diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index e73f9b39..6d5fb92d 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -126,6 +126,7 @@ int g_srvindex; cvar_t init_amxmodx_version = {"amxmodx_version", "", FCVAR_SERVER | FCVAR_SPONLY}; cvar_t init_amxmodx_modules = {"amxmodx_modules", "", FCVAR_SPONLY}; cvar_t init_amxmodx_debug = {"amx_debug", "1", FCVAR_SPONLY}; +cvar_t init_amxmodx_mldebug = {"amx_mldebug", "", FCVAR_SPONLY}; cvar_t* amxmodx_version = NULL; cvar_t* amxmodx_modules = NULL; cvar_t* hostname = NULL; @@ -1264,6 +1265,7 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m CVAR_REGISTER(&init_amxmodx_version); CVAR_REGISTER(&init_amxmodx_modules); CVAR_REGISTER(&init_amxmodx_debug); + CVAR_REGISTER(&init_amxmodx_mldebug); amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name);