Add OnClientLanguageChanged() forward (#1597)

This commit is contained in:
Vladimir 2021-10-25 21:45:24 +03:00 committed by GitHub
parent a343410793
commit 79d594aca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 25 deletions

View File

@ -196,6 +196,7 @@ void PlayerManager::OnSourceModAllInitialized()
m_clcommandkv_post = forwardsys->CreateForward("OnClientCommandKeyValues_Post", ET_Ignore, 2, NULL, Param_Cell, Param_Cell);
m_clinfochanged = forwardsys->CreateForward("OnClientSettingsChanged", ET_Ignore, 1, p2);
m_clauth = forwardsys->CreateForward("OnClientAuthorized", ET_Ignore, 2, NULL, Param_Cell, Param_String);
m_cllang = forwardsys->CreateForward("OnClientLanguageChanged", ET_Ignore, 2, NULL, Param_Cell, Param_Cell);
m_onActivate = forwardsys->CreateForward("OnServerLoad", ET_Ignore, 0, NULL);
m_onActivate2 = forwardsys->CreateForward("OnMapStart", ET_Ignore, 0, NULL);
@ -246,6 +247,7 @@ void PlayerManager::OnSourceModShutdown()
forwardsys->ReleaseForward(m_clcommandkv_post);
forwardsys->ReleaseForward(m_clinfochanged);
forwardsys->ReleaseForward(m_clauth);
forwardsys->ReleaseForward(m_cllang);
forwardsys->ReleaseForward(m_onActivate);
forwardsys->ReleaseForward(m_onActivate2);
@ -520,6 +522,8 @@ bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const
{
unsigned int langid;
pPlayer->m_LangId = (translator->GetLanguageByName(name, &langid)) ? langid : translator->GetServerLanguage();
OnClientLanguageChanged(client, pPlayer->m_LangId);
} else {
pPlayer->m_LangId = translator->GetServerLanguage();
}
@ -1415,6 +1419,13 @@ void PlayerManager::OnClientSettingsChanged(edict_t *pEntity)
}
}
void PlayerManager::OnClientLanguageChanged(int client, unsigned int language)
{
m_cllang->PushCell(client);
m_cllang->PushCell(language);
m_cllang->Execute(NULL);
}
int PlayerManager::GetMaxClients()
{
return m_maxClients;
@ -2022,7 +2033,9 @@ bool PlayerManager::HandleConVarQuery(QueryCvarCookie_t cookie, int client, EQue
if (m_Players[i].m_LanguageCookie == cookie)
{
unsigned int langid;
m_Players[i].m_LangId = (translator->GetLanguageByName(cvarValue, &langid)) ? langid : translator->GetServerLanguage();
unsigned int new_langid = (translator->GetLanguageByName(cvarValue, &langid)) ? langid : translator->GetServerLanguage();
m_Players[i].m_LangId = new_langid;
OnClientLanguageChanged(i, new_langid);
return true;
}
@ -2618,7 +2631,11 @@ unsigned int CPlayer::GetLanguageId()
void CPlayer::SetLanguageId(unsigned int id)
{
m_LangId = id;
if(m_LangId != id)
{
m_LangId = id;
g_Players.OnClientLanguageChanged(m_iIndex, id);
}
}
int CPlayer::GetUserId()

View File

@ -192,6 +192,7 @@ public:
#endif
void OnClientSettingsChanged(edict_t *pEntity);
//void OnClientSettingsChanged_Pre(edict_t *pEntity);
void OnClientLanguageChanged(int client, unsigned int language);
void OnServerHibernationUpdate(bool bHibernating);
void OnClientPrintf(edict_t *pEdict, const char *szMsg);
void OnPrintfFrameAction(unsigned int serial);
@ -253,6 +254,7 @@ private:
IForward *m_clcommandkv_post;
IForward *m_clinfochanged;
IForward *m_clauth;
IForward *m_cllang;
IForward *m_onActivate;
IForward *m_onActivate2;
CPlayer *m_Players;

View File

@ -225,6 +225,14 @@ forward void OnClientPostAdminFilter(int client);
*/
forward void OnClientPostAdminCheck(int client);
/**
* Called when the language was received from the player.
*
* @param client Client index.
* @param language Language number.
*/
forward void OnClientLanguageChanged(int client, int language);
/**
* This function is deprecated. Use the MaxClients variable instead.
*

View File

@ -199,29 +199,29 @@ namespace SourceMod
*
* @return True if authorized, false otherwise.
*/
virtual bool IsAuthorized() =0;
/**
* @brief Kicks the client with a message
*
* @param message The message shown to the client when kicked
*/
virtual void Kick(const char *message) =0;
/**
* @brief Returns whether the client is marked as being in the kick
* queue. The client doesn't necessarily have to be in the actual kick
* queue for this function to return true.
*
* @return True if in the kick queue, false otherwise.
*/
virtual bool IsInKickQueue() =0;
/**
* @brief Marks the client as being in the kick queue. They are not
* actually added to the kick queue. Use IGameHelpers::AddDelayedKick()
* to actually add them to the queue.
*/
virtual bool IsAuthorized() =0;
/**
* @brief Kicks the client with a message
*
* @param message The message shown to the client when kicked
*/
virtual void Kick(const char *message) =0;
/**
* @brief Returns whether the client is marked as being in the kick
* queue. The client doesn't necessarily have to be in the actual kick
* queue for this function to return true.
*
* @return True if in the kick queue, false otherwise.
*/
virtual bool IsInKickQueue() =0;
/**
* @brief Marks the client as being in the kick queue. They are not
* actually added to the kick queue. Use IGameHelpers::AddDelayedKick()
* to actually add them to the queue.
*/
virtual void MarkAsBeingKicked() =0;
virtual void SetLanguageId(unsigned int id) =0;