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.
This commit is contained in:
nosoop 2018-11-19 07:57:00 -08:00
parent 4c38126ac3
commit 29f76a6737
3 changed files with 11 additions and 8 deletions

View File

@ -27,6 +27,14 @@ const char *HLTVClientWrapper::Password()
return m_Password.chars(); 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() bool HLTVClientWrapper::IsConnected()
{ {
return m_Client && m_Client->IsConnected(); return m_Client && m_Client->IsConnected();

View File

@ -46,6 +46,7 @@ public:
const char *Name(); const char *Name();
const char *Ip(); const char *Ip();
const char *Password(); const char *Password();
unsigned int GetLanguageId();
bool IsConnected(); bool IsConnected();
IClient *BaseClient(); IClient *BaseClient();

View File

@ -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. // 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; int iHLTVClient = hltvserver->GetHLTVServer()->GetHLTVSlot() + 1;
IGamePlayer *pHLTVClient = playerhelpers->GetGamePlayer(iHLTVClient); IGamePlayer *pHLTVClient = playerhelpers->GetGamePlayer(iHLTVClient);
pHLTVClient->SetLanguageId(pClient->GetLanguageId());
unsigned int langid = translator->GetServerLanguage();
translator->GetLanguageByName(pClient->BaseClient()->GetUserSetting("cl_language"), &langid);
pHLTVClient->SetLanguageId(langid);
int restoreTarget = translator->SetGlobalTarget(hltvserver->GetHLTVServer()->GetHLTVSlot() + 1); int restoreTarget = translator->SetGlobalTarget(hltvserver->GetHLTVServer()->GetHLTVSlot() + 1);
#endif #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. // 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; int iHLTVClient = hltvserver->GetHLTVServer()->GetHLTVSlot() + 1;
IGamePlayer *pHLTVClient = playerhelpers->GetGamePlayer(iHLTVClient); IGamePlayer *pHLTVClient = playerhelpers->GetGamePlayer(iHLTVClient);
pHLTVClient->SetLanguageId(pClient->GetLanguageId());
unsigned int langid = translator->GetServerLanguage();
translator->GetLanguageByName(pClient->BaseClient()->GetUserSetting("cl_language"), &langid);
pHLTVClient->SetLanguageId(langid);
int restoreTarget = translator->SetGlobalTarget(hltvserver->GetHLTVServer()->GetHLTVSlot() + 1); int restoreTarget = translator->SetGlobalTarget(hltvserver->GetHLTVServer()->GetHLTVSlot() + 1);
#endif #endif