diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index 9adbf70c..f969b271 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -47,13 +47,13 @@ void CoreConfig::OnRootConsoleCommand(const char *command, unsigned int argcount char error[255]; - ConfigResult err = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error)); + ConfigResult res = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error)); - if (err == ConfigResult_Reject) + if (res == ConfigResult_Reject) { - g_RootMenu.ConsolePrint("Could not set config option \"%s\" to \"%s\" (%s)", option, value, error); - } else if (err == ConfigResult_Ignore) { - g_RootMenu.ConsolePrint("No such config option \"%s\" exists.", option); + g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\" (%s)", option, value, error); + } else if (res == ConfigResult_Ignore) { + g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option); } else { g_RootMenu.ConsolePrint("Config option \"%s\" successfully set to \"%s.\"", option, value); } @@ -82,8 +82,7 @@ void CoreConfig::Initialize() g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetModPath(), corecfg); /* Parse config file */ - if ((err=g_TextParser.ParseFile_SMC(filePath, this, NULL, NULL)) - != SMCParse_Okay) + if ((err=g_TextParser.ParseFile_SMC(filePath, this, NULL, NULL)) != SMCParse_Okay) { /* :TODO: This won't actually log or print anything :( - So fix that somehow */ const char *error = g_TextParser.GetSMCErrorString(err); diff --git a/core/Logger.cpp b/core/Logger.cpp index 36b5246b..1af6a9a7 100644 --- a/core/Logger.cpp +++ b/core/Logger.cpp @@ -34,10 +34,11 @@ ConfigResult Logger::OnSourceModConfigChanged(const char *key, { if (strcasecmp(key, "Logging") == 0) { - bool state = true; + bool state; if (strcasecmp(value, "on") == 0) { + state = true; } else if (strcasecmp(value, "off") == 0) { state = false; } else { @@ -47,12 +48,7 @@ ConfigResult Logger::OnSourceModConfigChanged(const char *key, if (source == ConfigSource_Console) { - if (state && !m_Active) - { - EnableLogging(); - } else if (!state && m_Active) { - DisableLogging(); - } + state ? EnableLogging() : DisableLogging(); } else { m_InitialState = state; } @@ -412,7 +408,7 @@ void Logger::EnableLogging() return; } m_Active = true; - LogMessage("Logging enabled manually by user."); + LogMessage("[SM] Logging enabled manually by user."); } void Logger::DisableLogging() @@ -421,7 +417,7 @@ void Logger::DisableLogging() { return; } - LogMessage("Logging disabled manually by user."); + LogMessage("[SM] Logging disabled manually by user."); m_Active = false; } diff --git a/core/Translator.cpp b/core/Translator.cpp index e47093d5..e883d9b7 100644 --- a/core/Translator.cpp +++ b/core/Translator.cpp @@ -580,11 +580,11 @@ const char *CPhraseFile::GetFilename() ** MAIN TRANSLATOR CODE ** **************************/ -Translator::Translator() +Translator::Translator() : m_ServerLang(LANGUAGE_ENGLISH) { m_pStringTab = new BaseStringTable(2048); m_pLCodeLookup = sm_trie_create(); - strncopy(m_ServerLangCode, "en", sizeof(m_ServerLangCode)); + strncopy(m_InitialLang, "en", sizeof(m_InitialLang)); } Translator::~Translator() @@ -620,9 +620,11 @@ ConfigResult Translator::OnSourceModConfigChanged(const char *key, UTIL_Format(error, maxlength, "Language code \"%s\" is not registered", value); return ConfigResult_Reject; } - } - strncopy(m_ServerLangCode, value, sizeof(m_ServerLangCode)); + m_ServerLang = index; + } else { + strncopy(m_InitialLang, value, sizeof(m_InitialLang)); + } return ConfigResult_Accept; } @@ -712,6 +714,18 @@ void Translator::RebuildLanguageDatabase(const char *lang_header_file) g_Logger.LogError("[SM] Parse error (line %d, column %d): %s", line, col, str_err); } + void *serverLang; + + if (!sm_trie_retrieve(m_pLCodeLookup, m_InitialLang, &serverLang)) + { + g_Logger.LogError("Server language was set to bad language \"%s\" -- reverting to English", m_InitialLang); + + strncopy(m_InitialLang, "en", sizeof(m_InitialLang)); + m_ServerLang = LANGUAGE_ENGLISH; + } + + m_ServerLang = reinterpret_cast(serverLang); + if (!m_Languages.size()) { g_Logger.LogError("[SM] Fatal error, no languages found! Translation will not work."); @@ -829,15 +843,11 @@ TransError Translator::CoreTrans(int client, } /* Using server lang temporarily until client lang stuff is implemented */ - unsigned int serverLang; - if (!sm_trie_retrieve(m_pLCodeLookup, m_ServerLangCode, (void **)&serverLang)) - { - return Trans_BadLanguage; - } + unsigned int serverLang = GetServerLanguage(); Translation trans; TransError err; - if ((err=g_pCorePhrases->GetTranslation(phrase, serverLang, &trans)) != Trans_Okay) + if ((err=g_pCorePhrases->GetTranslation(phrase, m_ServerLang, &trans)) != Trans_Okay) { return err; } @@ -852,20 +862,7 @@ TransError Translator::CoreTrans(int client, return Trans_Okay; } -unsigned int Translator::GetServerLanguageCode() +unsigned int Translator::GetServerLanguage() { - void *serverLang; - - /* :TODO: there is absolutely no reason this shouldn't be cached - * I don't even know why it was returning a string originally - */ - - if (!sm_trie_retrieve(m_pLCodeLookup, m_ServerLangCode, &serverLang)) - { - g_Logger.LogError("Server language was set to bad language \"%s\" -- reverting to English", m_ServerLangCode); - strncopy(m_ServerLangCode, "en", sizeof(m_ServerLangCode)); - return LANGUAGE_ENGLISH; - } - - return (unsigned int)serverLang; + return m_ServerLang; } diff --git a/core/Translator.h b/core/Translator.h index 65836dc6..92cf610f 100644 --- a/core/Translator.h +++ b/core/Translator.h @@ -127,7 +127,7 @@ public: const char *phrase, void **params, size_t *outlen=NULL); - unsigned int GetServerLanguageCode(); + unsigned int GetServerLanguage(); private: bool AddLanguage(const char *langcode, const char *description); private: @@ -137,7 +137,8 @@ private: Trie *m_pLCodeLookup; bool m_InLanguageSection; String m_CustomError; - char m_ServerLangCode[3]; + unsigned int m_ServerLang; + char m_InitialLang[3]; }; extern CPhraseFile *g_pCorePhrases; diff --git a/core/msvc8/sourcemod_mm.vcproj b/core/msvc8/sourcemod_mm.vcproj index 1867cdbc..3126cad1 100644 --- a/core/msvc8/sourcemod_mm.vcproj +++ b/core/msvc8/sourcemod_mm.vcproj @@ -457,94 +457,6 @@ RelativePath="..\..\public\IUserMessages.h" > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/sm_globals.h b/core/sm_globals.h index bedf9d9e..2a2b312b 100644 --- a/core/sm_globals.h +++ b/core/sm_globals.h @@ -28,19 +28,22 @@ using namespace SourcePawn; using namespace SourceMod; /** - * @brief Lists error codes possible from attempting to set a core configuration option. + * @brief Lists result codes possible from attempting to set a core configuration option. */ enum ConfigResult { - ConfigResult_Accept = 0, - ConfigResult_Reject = 1, - ConfigResult_Ignore = 2 + ConfigResult_Accept = 0, /**< Config option was successfully set */ + ConfigResult_Reject = 1, /**< Config option was given an invalid value and was rejected */ + ConfigResult_Ignore = 2 /**< Config option was invalid, but ignored */ }; +/** + * @brief Lists possible sources of a config option change + */ enum ConfigSource { - ConfigSource_File = 0, - ConfigSource_Console = 1, + ConfigSource_File = 0, /**< Config option was set from config file (core.cfg) */ + ConfigSource_Console = 1, /**< Config option was set from console command (sm config) */ }; /** diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index 5682645b..a27aed01 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -73,9 +73,9 @@ size_t Translate(char *buffer, size_t maxlen, IPluginContext *pCtx, const char * try_serverlang: if (target == LANG_SERVER) { - langid = g_Translator.GetServerLanguageCode(); + langid = g_Translator.GetServerLanguage(); } else if ((target >= 1) && (target <= g_Players.GetMaxClients())) { - langid = g_Translator.GetServerLanguageCode(); + langid = g_Translator.GetServerLanguage(); } else { pCtx->ThrowNativeErrorEx(SP_ERROR_PARAM, "Translation failed: invalid client index %d", target); goto error_out; @@ -736,9 +736,11 @@ reswitch: char *key; bool error; size_t res; - cell_t target = params[arg++]; + cell_t *target; + pCtx->LocalToPhysAddr(params[arg++], &target); pCtx->LocalToString(params[arg++], &key); - res = Translate(buf_p, llen, pCtx, key, target, params, &arg, &error); + printf("target = %d\n", target); + res = Translate(buf_p, llen, pCtx, key, *target, params, &arg, &error); if (error) { return 0;