From b63ae4eed83614fb71838e8b9789d5ba5d162dbb Mon Sep 17 00:00:00 2001 From: Pavol Marko Date: Sat, 21 Aug 2004 21:08:30 +0000 Subject: [PATCH] added GetLangR, which doesn't construct a CLang object when not found; GetDef now uses GetLangR, so when users set their language to an invalid value, no such language is created. --- amxmodx/CLang.cpp | 19 ++++++++++++++++--- amxmodx/CLang.h | 2 ++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/amxmodx/CLang.cpp b/amxmodx/CLang.cpp index 3211f6a5..99e584f8 100755 --- a/amxmodx/CLang.cpp +++ b/amxmodx/CLang.cpp @@ -332,7 +332,7 @@ void CLangMngr::CLang::MergeDefinitions(CQueue &vec) const char * CLangMngr::CLang::GetDef(const char *key) { - static char nfind[1024] = "ML_NOTFOUND"; + static char nfind[1024] = "ML_NOTFOUND(KEY)"; int ikey = m_LMan->GetKeyEntry(key); if (ikey == -1) { @@ -941,12 +941,25 @@ CLangMngr::CLang * CLangMngr::GetLang(const char *name) return p; } +// Find a CLang by name, if not found, return NULL +CLangMngr::CLang * CLangMngr::GetLangR(const char *name) +{ + LangVecIter iter; + for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter) + { + if ( strcmp((*iter)->GetName(), name)==0 ) + return (*iter); + } + + return NULL; +} + const char *CLangMngr::GetDef(const char *langName, const char *key) { - CLang *lang = GetLang(langName); + CLang *lang = GetLangR(langName); if (lang) return lang->GetDef(key); - return ""; + return "ML_NOTFOUND(LANG)"; } bool CLangMngr::Save(const char *filename) diff --git a/amxmodx/CLang.h b/amxmodx/CLang.h index 080f88b1..487bd703 100755 --- a/amxmodx/CLang.h +++ b/amxmodx/CLang.h @@ -154,6 +154,8 @@ class CLangMngr // Get a lang object (construct if needed) CLang * GetLang(const char *name); + CLang * GetLangR(const char *name); + // Current global client-id for functions like client_print with first parameter 0 int m_CurGlobId; public: