1.1 --- a/core/PlayerManager.cpp Sat Aug 18 22:51:25 2007 +0000
1.2 +++ b/core/PlayerManager.cpp Sun Aug 19 13:25:42 2007 +0000
1.3 @@ -41,7 +41,10 @@
1.4 #include <inetchannel.h>
1.5 #include <iclient.h>
1.6 #include "TimerSys.h"
1.7 +#include "Translator.h"
1.8 +#include "ConVarManager.h"
1.9 #include "Logger.h"
1.10 +#include "HalfLife2.h"
1.11
1.12 PlayerManager g_Players;
1.13 bool g_OnMapStarted = false;
1.14 @@ -190,6 +193,17 @@
1.15 m_PassInfoVar.assign(value);
1.16 }
1.17 return ConfigResult_Accept;
1.18 + } else if (strcmp(key, "AllowClLanguageVar") == 0) {
1.19 + if (strcasecmp(value, "on") == 0)
1.20 + {
1.21 + m_QueryLang = true;
1.22 + } else if (strcasecmp(value, "off") == 0) {
1.23 + m_QueryLang = false;
1.24 + } else {
1.25 + UTIL_Format(error, maxlength, "Invalid value: must be \"on\" or \"off\"");
1.26 + return ConfigResult_Reject;
1.27 + }
1.28 + return ConfigResult_Accept;
1.29 }
1.30 return ConfigResult_Ignore;
1.31 }
1.32 @@ -486,6 +500,18 @@
1.33 pPlayer->m_Info = playerinfo->GetPlayerInfo(pEntity);
1.34 }
1.35
1.36 + /* Query the client's language */
1.37 + if (m_QueryLang)
1.38 + {
1.39 + if (!pPlayer->IsFakeClient() && !g_IsOriginalEngine)
1.40 + {
1.41 + pPlayer->m_LangCookie = g_ConVarManager.QueryClientConVar(pPlayer->GetEdict(), "cl_language", NULL, 0);
1.42 + } else {
1.43 + /* Skip the query if this is a bot or if we cant query cvars*/
1.44 + pPlayer->m_LangId = g_Translator.GetServerLanguage();
1.45 + }
1.46 + }
1.47 +
1.48 #if defined CLIENT_DEBUG
1.49 g_Logger.LogMessage("[CL_DEBUG] OnClientPutInServer() (m_Info %p)", pPlayer->m_Info);
1.50 #endif
1.51 @@ -820,6 +846,27 @@
1.52 }
1.53 }
1.54
1.55 +void PlayerManager::HandleLangQuery(int userid, const char *value, QueryCvarCookie_t cookie)
1.56 +{
1.57 + int id = GetClientOfUserId(userid);
1.58 + if (id == 0)
1.59 + {
1.60 + return;
1.61 + }
1.62 +
1.63 + CPlayer *pl = GetPlayerByIndex(id);
1.64 +
1.65 + unsigned int langid;
1.66 + if (pl->m_LangCookie == cookie)
1.67 + {
1.68 + if (value[0] != '\0' && g_Translator.GetLanguageByName(value, &langid))
1.69 + {
1.70 + pl->m_LangId = langid;
1.71 + } else {
1.72 + pl->m_LangId = g_Translator.GetServerLanguage();
1.73 + }
1.74 + }
1.75 +}
1.76
1.77 /*******************
1.78 *** PLAYER CODE ***
1.79 @@ -836,6 +883,8 @@
1.80 m_Info = NULL;
1.81 m_bAdminCheckSignalled = false;
1.82 m_LastPassword.clear();
1.83 + m_LangId = LANGUAGE_ENGLISH;
1.84 + m_LangCookie = 0;
1.85 }
1.86
1.87 void CPlayer::Initialize(const char *name, const char *ip, edict_t *pEntity)
1.88 @@ -845,6 +894,8 @@
1.89 m_Ip.assign(ip);
1.90 m_pEdict = pEntity;
1.91 m_iIndex = engine->IndexOfEdict(pEntity);
1.92 + m_LangId = g_Translator.GetServerLanguage();
1.93 + m_LangCookie = 0;
1.94
1.95 char ip2[24], *ptr;
1.96 strncopy(ip2, ip, sizeof(ip2));
1.97 @@ -1081,6 +1132,11 @@
1.98 }
1.99 }
1.100
1.101 +unsigned int CPlayer::GetLanguageId()
1.102 +{
1.103 + return m_LangId;
1.104 +}
1.105 +
1.106 int CPlayer::GetUserId()
1.107 {
1.108 if (m_UserId == -1)