Various things:

- Fixed inline translations when using %T
- "Improved" caching of server language
- Renamed Translator::GetServerLanguageCode() to GetServerLanguage()
- Added some more comments to sm_globals.h
- Natives folder in project file mysteriously was moved inside Interfaces, so moved it back o_O
- DS hates empty if statements :o

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40675
This commit is contained in:
Scott Ehlert 2007-04-05 10:55:40 +00:00
parent 5ee48f60a2
commit e677d5d5de
7 changed files with 139 additions and 141 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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<unsigned int>(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;
}

View File

@ -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;

View File

@ -457,94 +457,6 @@
RelativePath="..\..\public\IUserMessages.h"
>
</File>
<Filter
Name="Natives"
>
<File
RelativePath="..\smn_admin.cpp"
>
</File>
<File
RelativePath="..\smn_bitbuffer.cpp"
>
</File>
<File
RelativePath="..\smn_console.cpp"
>
</File>
<File
RelativePath="..\smn_core.cpp"
>
</File>
<File
RelativePath="..\smn_datapacks.cpp"
>
</File>
<File
RelativePath="..\smn_entities.cpp"
>
</File>
<File
RelativePath="..\smn_events.cpp"
>
</File>
<File
RelativePath="..\smn_fakenatives.cpp"
>
</File>
<File
RelativePath="..\smn_filesystem.cpp"
>
</File>
<File
RelativePath="..\smn_float.cpp"
>
</File>
<File
RelativePath="..\smn_functions.cpp"
>
</File>
<File
RelativePath="..\smn_halflife.cpp"
>
</File>
<File
RelativePath="..\smn_handles.cpp"
>
</File>
<File
RelativePath="..\smn_keyvalues.cpp"
>
</File>
<File
RelativePath="..\smn_lang.cpp"
>
</File>
<File
RelativePath="..\smn_player.cpp"
>
</File>
<File
RelativePath="..\smn_sorting.cpp"
>
</File>
<File
RelativePath="..\smn_string.cpp"
>
</File>
<File
RelativePath="..\smn_textparse.cpp"
>
</File>
<File
RelativePath="..\smn_timers.cpp"
>
</File>
<File
RelativePath="..\smn_usermsgs.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="Systems"
@ -790,6 +702,94 @@
>
</File>
</Filter>
<Filter
Name="Natives"
>
<File
RelativePath="..\smn_admin.cpp"
>
</File>
<File
RelativePath="..\smn_bitbuffer.cpp"
>
</File>
<File
RelativePath="..\smn_console.cpp"
>
</File>
<File
RelativePath="..\smn_core.cpp"
>
</File>
<File
RelativePath="..\smn_datapacks.cpp"
>
</File>
<File
RelativePath="..\smn_entities.cpp"
>
</File>
<File
RelativePath="..\smn_events.cpp"
>
</File>
<File
RelativePath="..\smn_fakenatives.cpp"
>
</File>
<File
RelativePath="..\smn_filesystem.cpp"
>
</File>
<File
RelativePath="..\smn_float.cpp"
>
</File>
<File
RelativePath="..\smn_functions.cpp"
>
</File>
<File
RelativePath="..\smn_halflife.cpp"
>
</File>
<File
RelativePath="..\smn_handles.cpp"
>
</File>
<File
RelativePath="..\smn_keyvalues.cpp"
>
</File>
<File
RelativePath="..\smn_lang.cpp"
>
</File>
<File
RelativePath="..\smn_player.cpp"
>
</File>
<File
RelativePath="..\smn_sorting.cpp"
>
</File>
<File
RelativePath="..\smn_string.cpp"
>
</File>
<File
RelativePath="..\smn_textparse.cpp"
>
</File>
<File
RelativePath="..\smn_timers.cpp"
>
</File>
<File
RelativePath="..\smn_usermsgs.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>

View File

@ -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) */
};
/**

View File

@ -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;