From 29f76a6737457c98343fbf1ea4c21f73ae623a41 Mon Sep 17 00:00:00 2001 From: nosoop Date: Mon, 19 Nov 2018 07:57:00 -0800 Subject: [PATCH] Lay groundwork for client language property Abstract the language getter to HLTVClientWrapper::GetLanguageId so we have the option of having native setters / getters in SourcePawn to assign language. Whether we actually do something about it, I don't know. --- hltvclientwrapper.cpp | 8 ++++++++ hltvclientwrapper.h | 1 + natives.cpp | 10 ++-------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/hltvclientwrapper.cpp b/hltvclientwrapper.cpp index ca2dddc..b78e108 100644 --- a/hltvclientwrapper.cpp +++ b/hltvclientwrapper.cpp @@ -27,6 +27,14 @@ const char *HLTVClientWrapper::Password() return m_Password.chars(); } +unsigned int HLTVClientWrapper::GetLanguageId() +{ + // TODO expose natives to override spectator client language and remove native ifdefs + unsigned int langid = translator->GetServerLanguage(); + translator->GetLanguageByName(m_Client->GetUserSetting("cl_language"), &langid); + return langid; +} + bool HLTVClientWrapper::IsConnected() { return m_Client && m_Client->IsConnected(); diff --git a/hltvclientwrapper.h b/hltvclientwrapper.h index 5b2e88f..bb368ab 100644 --- a/hltvclientwrapper.h +++ b/hltvclientwrapper.h @@ -46,6 +46,7 @@ public: const char *Name(); const char *Ip(); const char *Password(); + unsigned int GetLanguageId(); bool IsConnected(); IClient *BaseClient(); diff --git a/natives.cpp b/natives.cpp index 670657b..f4db463 100644 --- a/natives.cpp +++ b/natives.cpp @@ -830,10 +830,7 @@ static cell_t Native_PrintToChat(IPluginContext *pContext, const cell_t *params) // There's no way to set the current translation without a client index, so we'll save / restore the language on the relay. int iHLTVClient = hltvserver->GetHLTVServer()->GetHLTVSlot() + 1; IGamePlayer *pHLTVClient = playerhelpers->GetGamePlayer(iHLTVClient); - - unsigned int langid = translator->GetServerLanguage(); - translator->GetLanguageByName(pClient->BaseClient()->GetUserSetting("cl_language"), &langid); - pHLTVClient->SetLanguageId(langid); + pHLTVClient->SetLanguageId(pClient->GetLanguageId()); int restoreTarget = translator->SetGlobalTarget(hltvserver->GetHLTVServer()->GetHLTVSlot() + 1); #endif @@ -903,10 +900,7 @@ static cell_t Native_PrintToConsole(IPluginContext *pContext, const cell_t *para // There's no way to set the current translation without a client index, so we'll save / restore the language on the relay. int iHLTVClient = hltvserver->GetHLTVServer()->GetHLTVSlot() + 1; IGamePlayer *pHLTVClient = playerhelpers->GetGamePlayer(iHLTVClient); - - unsigned int langid = translator->GetServerLanguage(); - translator->GetLanguageByName(pClient->BaseClient()->GetUserSetting("cl_language"), &langid); - pHLTVClient->SetLanguageId(langid); + pHLTVClient->SetLanguageId(pClient->GetLanguageId()); int restoreTarget = translator->SetGlobalTarget(hltvserver->GetHLTVServer()->GetHLTVSlot() + 1); #endif