added language debug

This commit is contained in:
Borja Ferrer 2006-01-24 18:47:08 +00:00
parent 018b4645e8
commit 7c7422a553
3 changed files with 42 additions and 14 deletions

View File

@ -217,7 +217,7 @@ const char * CLangMngr::CLang::GetDef(int key, int &status)
if (!def.definition) if (!def.definition)
{ {
status = LANG_STATUS_KLNOTFOUND; status = ERR_BADKEY;
return NULL; return NULL;
} }
@ -340,6 +340,7 @@ int CLangMngr::GetKeyEntry(String &key)
#define MAX_LEVELS 4 #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); size_t do_amx_format(AMX *amx, cell *params, int *param, const char **lex, char *output, size_t maxlen, int level);
THash<String, lang_err> BadLang_Table;
size_t do_amx_format_parameter(AMX *amx, cell *params, const char **fmtstr, int *param, char *output, size_t maxlen, int level) size_t do_amx_format_parameter(AMX *amx, cell *params, const char **fmtstr, int *param, char *output, size_t maxlen, int level)
{ {
@ -444,15 +445,35 @@ size_t do_amx_format_parameter(AMX *amx, cell *params, const char **fmtstr, int
key = get_amxstring(amx, _addr, 1, tmpLen); key = get_amxstring(amx, _addr, 1, tmpLen);
def = g_langMngr.GetDef(pLangName, key, status); 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) if (def == NULL)
{ {
bool a = true; if (debug)
if (status == LANG_STATUS_LNOTFOUND) {
if (status == ERR_BADLANG && (BadLang_Table[pLangName].last + 120.0f < gpGlobals->time))
{ {
AMXXLOG_Log("[AMXX] Language \"%s\" not found", pLangName); AMXXLOG_Log("[AMXX] Language \"%s\" not found", pLangName);
} else if (status == LANG_STATUS_KLNOTFOUND) { BadLang_Table[pLangName].last = gpGlobals->time;
a = false; }
AMXXLOG_Log("[AMXX] Language key \"%s\" not found for language \"%s\"", key, pLangName);
} }
if (addr[0] != LANG_SERVER) 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) if (!def)
{ {
return _snprintf(output, maxlen, "ML_NOTFOUND: %s", key); 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); 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]; keytbl_val val = KeyTable[key];
if (lang == NULL) if (lang == NULL)
{ {
status = LANG_STATUS_LNOTFOUND; status = ERR_BADLANG;
return NULL; return NULL;
} else if (val.index == -1) { } else if (val.index == -1) {
status = LANG_STATUS_KLNOTFOUND; status = ERR_BADKEY;
return NULL; return NULL;
} else { } else {
return lang->GetDef(val.index, status); return lang->GetDef(val.index, status);

View File

@ -37,9 +37,8 @@
#define LANG_SERVER 0 #define LANG_SERVER 0
#define LANG_PLAYER -1 #define LANG_PLAYER -1
#define LANG_STATUS_OK 0 // OK #define ERR_BADKEY 1 // Lang key not found
#define LANG_STATUS_KLNOTFOUND 1 // Lang key not found in the lang.txt #define ERR_BADLANG 2 // Invalid lang
#define LANG_STATUS_LNOTFOUND 3 // Invalid lang
struct md5Pair struct md5Pair
{ {
@ -53,6 +52,14 @@ struct sKeyDef
int key; int key;
}; };
struct lang_err
{
lang_err() : last(0.0f)
{
};
float last;
};
class defentry class defentry
{ {
public: public:

View File

@ -126,6 +126,7 @@ int g_srvindex;
cvar_t init_amxmodx_version = {"amxmodx_version", "", FCVAR_SERVER | FCVAR_SPONLY}; cvar_t init_amxmodx_version = {"amxmodx_version", "", FCVAR_SERVER | FCVAR_SPONLY};
cvar_t init_amxmodx_modules = {"amxmodx_modules", "", 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_debug = {"amx_debug", "1", FCVAR_SPONLY};
cvar_t init_amxmodx_mldebug = {"amx_mldebug", "", FCVAR_SPONLY};
cvar_t* amxmodx_version = NULL; cvar_t* amxmodx_version = NULL;
cvar_t* amxmodx_modules = NULL; cvar_t* amxmodx_modules = NULL;
cvar_t* hostname = 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_version);
CVAR_REGISTER(&init_amxmodx_modules); CVAR_REGISTER(&init_amxmodx_modules);
CVAR_REGISTER(&init_amxmodx_debug); CVAR_REGISTER(&init_amxmodx_debug);
CVAR_REGISTER(&init_amxmodx_mldebug);
amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name); amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name);