From 255f5ea7454cc3ac1f7072e0ae9d34d94680df45 Mon Sep 17 00:00:00 2001 From: Vladimir <47463683+Wend4r@users.noreply.github.com> Date: Mon, 25 Oct 2021 21:45:24 +0300 Subject: [PATCH] Add OnClientLanguageChanged() forward (#1597) --- core/PlayerManager.cpp | 21 +++++++++++++++-- core/PlayerManager.h | 2 ++ plugins/include/clients.inc | 8 +++++++ public/IPlayerHelpers.h | 46 ++++++++++++++++++------------------- 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 9381b94b..95b92ee9 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -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() diff --git a/core/PlayerManager.h b/core/PlayerManager.h index 44a6df98..68e96b04 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -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; diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index 29a9aa7b..537d9638 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -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. * diff --git a/public/IPlayerHelpers.h b/public/IPlayerHelpers.h index 672cddb5..c0cd0c5c 100644 --- a/public/IPlayerHelpers.h +++ b/public/IPlayerHelpers.h @@ -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;