Add GetClientOriginalLanguage (#1810)
Creates a native which will return the language the client connected with.
This commit is contained in:
parent
e5ebd65176
commit
9321229321
@ -528,6 +528,7 @@ bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const
|
||||
pPlayer->m_LangId = translator->GetServerLanguage();
|
||||
}
|
||||
#endif
|
||||
pPlayer->m_OriginalLangId = pPlayer->m_LangId;
|
||||
}
|
||||
|
||||
List<IClientListener *>::iterator iter;
|
||||
@ -2035,6 +2036,7 @@ bool PlayerManager::HandleConVarQuery(QueryCvarCookie_t cookie, int client, EQue
|
||||
unsigned int langid;
|
||||
unsigned int new_langid = (translator->GetLanguageByName(cvarValue, &langid)) ? langid : translator->GetServerLanguage();
|
||||
m_Players[i].m_LangId = new_langid;
|
||||
m_Players[i].m_OriginalLangId = new_langid;
|
||||
OnClientLanguageChanged(i, new_langid);
|
||||
|
||||
return true;
|
||||
@ -2063,6 +2065,7 @@ void CPlayer::Initialize(const char *name, const char *ip, edict_t *pEntity)
|
||||
m_pEdict = pEntity;
|
||||
m_iIndex = IndexOfEdict(pEntity);
|
||||
m_LangId = translator->GetServerLanguage();
|
||||
m_OriginalLangId = m_LangId;
|
||||
|
||||
m_Serial.bits.index = m_iIndex;
|
||||
m_Serial.bits.serial = g_PlayerSerialCount++;
|
||||
@ -2629,6 +2632,11 @@ unsigned int CPlayer::GetLanguageId()
|
||||
return m_LangId;
|
||||
}
|
||||
|
||||
unsigned int CPlayer::GetOriginalLanguageId()
|
||||
{
|
||||
return m_OriginalLangId;
|
||||
}
|
||||
|
||||
void CPlayer::SetLanguageId(unsigned int id)
|
||||
{
|
||||
if(m_LangId != id)
|
||||
|
@ -96,6 +96,7 @@ public:
|
||||
bool IsInKickQueue();
|
||||
IPlayerInfo *GetPlayerInfo();
|
||||
unsigned int GetLanguageId();
|
||||
unsigned int GetOriginalLanguageId();
|
||||
void SetLanguageId(unsigned int id);
|
||||
int GetUserId();
|
||||
bool RunAdminCacheChecks();
|
||||
@ -145,6 +146,7 @@ private:
|
||||
bool m_bAdminCheckSignalled = false;
|
||||
int m_iIndex;
|
||||
unsigned int m_LangId = SOURCEMOD_LANGUAGE_ENGLISH;
|
||||
unsigned int m_OriginalLangId = SOURCEMOD_LANGUAGE_ENGLISH;
|
||||
int m_UserId = -1;
|
||||
bool m_bFakeClient = false;
|
||||
bool m_bIsSourceTV = false;
|
||||
|
@ -144,6 +144,18 @@ static cell_t sm_SetClientLanguage(IPluginContext *pContext, const cell_t *param
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t sm_GetClientOriginalLanguage(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
|
||||
|
||||
if (!player || !player->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid client index %d", params[1]);
|
||||
}
|
||||
|
||||
return player->GetOriginalLanguageId();
|
||||
}
|
||||
|
||||
static cell_t sm_GetLanguageByCode(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
char *code;
|
||||
@ -181,6 +193,7 @@ REGISTER_NATIVES(langNatives)
|
||||
{"GetLanguageCount", sm_GetLanguageCount},
|
||||
{"GetLanguageInfo", sm_GetLanguageInfo},
|
||||
{"SetClientLanguage", sm_SetClientLanguage},
|
||||
{"GetClientOriginalLanguage", sm_GetClientOriginalLanguage},
|
||||
{"GetLanguageByCode", sm_GetLanguageByCode},
|
||||
{"GetLanguageByName", sm_GetLanguageByName},
|
||||
{NULL, NULL},
|
||||
|
@ -99,6 +99,15 @@ native void GetLanguageInfo(int language, char[] code="", int codeLen=0, char[]
|
||||
*/
|
||||
native void SetClientLanguage(int client, int language);
|
||||
|
||||
/**
|
||||
* Retrieves the language number a client had when they connected.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @return Language number client originally had.
|
||||
* @error Invalid client index or client not connected.
|
||||
*/
|
||||
native int GetClientOriginalLanguage(int client);
|
||||
|
||||
/**
|
||||
* Retrieves the language number from a language code.
|
||||
*
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include <IAdminSystem.h>
|
||||
|
||||
#define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager"
|
||||
#define SMINTERFACE_PLAYERMANAGER_VERSION 21
|
||||
#define SMINTERFACE_PLAYERMANAGER_VERSION 22
|
||||
|
||||
struct edict_t;
|
||||
class IPlayerInfo;
|
||||
@ -294,6 +294,14 @@ namespace SourceMod
|
||||
* @return Steam3 Id on success or NULL if not available.
|
||||
*/
|
||||
virtual const char *GetSteam3Id(bool validated = true) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the original language id the client had when
|
||||
* they connected.
|
||||
*
|
||||
* @return Language id.
|
||||
*/
|
||||
virtual unsigned int GetOriginalLanguageId() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user