diff -r 47bf177d07e2 -r 4241c756c278 core/PlayerManager.cpp --- a/core/PlayerManager.cpp Sat Aug 18 22:51:25 2007 +0000 +++ b/core/PlayerManager.cpp Sun Aug 19 13:25:42 2007 +0000 @@ -41,7 +41,10 @@ #include #include #include "TimerSys.h" +#include "Translator.h" +#include "ConVarManager.h" #include "Logger.h" +#include "HalfLife2.h" PlayerManager g_Players; bool g_OnMapStarted = false; @@ -190,6 +193,17 @@ m_PassInfoVar.assign(value); } return ConfigResult_Accept; + } else if (strcmp(key, "AllowClLanguageVar") == 0) { + if (strcasecmp(value, "on") == 0) + { + m_QueryLang = true; + } else if (strcasecmp(value, "off") == 0) { + m_QueryLang = false; + } else { + UTIL_Format(error, maxlength, "Invalid value: must be \"on\" or \"off\""); + return ConfigResult_Reject; + } + return ConfigResult_Accept; } return ConfigResult_Ignore; } @@ -486,6 +500,18 @@ pPlayer->m_Info = playerinfo->GetPlayerInfo(pEntity); } + /* Query the client's language */ + if (m_QueryLang) + { + if (!pPlayer->IsFakeClient() && !g_IsOriginalEngine) + { + pPlayer->m_LangCookie = g_ConVarManager.QueryClientConVar(pPlayer->GetEdict(), "cl_language", NULL, 0); + } else { + /* Skip the query if this is a bot or if we cant query cvars*/ + pPlayer->m_LangId = g_Translator.GetServerLanguage(); + } + } + #if defined CLIENT_DEBUG g_Logger.LogMessage("[CL_DEBUG] OnClientPutInServer() (m_Info %p)", pPlayer->m_Info); #endif @@ -820,6 +846,27 @@ } } +void PlayerManager::HandleLangQuery(int userid, const char *value, QueryCvarCookie_t cookie) +{ + int id = GetClientOfUserId(userid); + if (id == 0) + { + return; + } + + CPlayer *pl = GetPlayerByIndex(id); + + unsigned int langid; + if (pl->m_LangCookie == cookie) + { + if (value[0] != '\0' && g_Translator.GetLanguageByName(value, &langid)) + { + pl->m_LangId = langid; + } else { + pl->m_LangId = g_Translator.GetServerLanguage(); + } + } +} /******************* *** PLAYER CODE *** @@ -836,6 +883,8 @@ m_Info = NULL; m_bAdminCheckSignalled = false; m_LastPassword.clear(); + m_LangId = LANGUAGE_ENGLISH; + m_LangCookie = 0; } void CPlayer::Initialize(const char *name, const char *ip, edict_t *pEntity) @@ -845,6 +894,8 @@ m_Ip.assign(ip); m_pEdict = pEntity; m_iIndex = engine->IndexOfEdict(pEntity); + m_LangId = g_Translator.GetServerLanguage(); + m_LangCookie = 0; char ip2[24], *ptr; strncopy(ip2, ip, sizeof(ip2)); @@ -1081,6 +1132,11 @@ } } +unsigned int CPlayer::GetLanguageId() +{ + return m_LangId; +} + int CPlayer::GetUserId() { if (m_UserId == -1)