diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp index 971c642f7..3aa9ae721 100644 --- a/src/game/client/components/voting.cpp +++ b/src/game/client/components/voting.cpp @@ -179,11 +179,12 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) m_Closetime = time_get() + time_freq() * pMsg->m_Timeout; if(pMsg->m_ClientID != -1) { + char aLabel[64]; + CGameClient::GetPlayerLabel(aLabel, sizeof(aLabel), pMsg->m_ClientID, m_pClient->m_aClients[pMsg->m_ClientID].m_aName); switch(pMsg->m_Type) { case VOTE_START_OP: - str_format(aBuf, sizeof(aBuf), Localize("'%2d: %s' called vote to change server option '%s' (%s)"), pMsg->m_ClientID, - g_Config.m_ClShowsocial ? m_pClient->m_aClients[pMsg->m_ClientID].m_aName : "", pMsg->m_pDescription, pMsg->m_pReason); + str_format(aBuf, sizeof(aBuf), Localize("'%s' called vote to change server option '%s' (%s)"), aLabel, pMsg->m_pDescription, pMsg->m_pReason); str_copy(m_aDescription, pMsg->m_pDescription, sizeof(m_aDescription)); m_pClient->m_pChat->AddLine(-1, 0, aBuf); break; @@ -192,8 +193,7 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) char aName[4]; if(!g_Config.m_ClShowsocial) str_copy(aName, pMsg->m_pDescription, sizeof(aName)); - str_format(aBuf, sizeof(aBuf), Localize("'%2d: %s' called for vote to kick '%s' (%s)"), pMsg->m_ClientID, - g_Config.m_ClShowsocial ? m_pClient->m_aClients[pMsg->m_ClientID].m_aName : "", g_Config.m_ClShowsocial ? pMsg->m_pDescription : aName, pMsg->m_pReason); + str_format(aBuf, sizeof(aBuf), Localize("'%s' called for vote to kick '%s' (%s)"), aLabel, g_Config.m_ClShowsocial ? pMsg->m_pDescription : aName, pMsg->m_pReason); str_format(m_aDescription, sizeof(m_aDescription), "Kick '%s'", g_Config.m_ClShowsocial ? pMsg->m_pDescription : aName); m_pClient->m_pChat->AddLine(-1, 0, aBuf); break; @@ -203,8 +203,7 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) char aName[4]; if(!g_Config.m_ClShowsocial) str_copy(aName, pMsg->m_pDescription, sizeof(aName)); - str_format(aBuf, sizeof(aBuf), Localize("'%2d: %s' called for vote to move '%s' to spectators (%s)"), pMsg->m_ClientID, - g_Config.m_ClShowsocial ? m_pClient->m_aClients[pMsg->m_ClientID].m_aName : "", g_Config.m_ClShowsocial ? pMsg->m_pDescription : aName, pMsg->m_pReason); + str_format(aBuf, sizeof(aBuf), Localize("'%s' called for vote to move '%s' to spectators (%s)"), aLabel, g_Config.m_ClShowsocial ? pMsg->m_pDescription : aName, pMsg->m_pReason); str_format(m_aDescription, sizeof(m_aDescription), "Move '%s' to spectators", g_Config.m_ClShowsocial ? pMsg->m_pDescription : aName); m_pClient->m_pChat->AddLine(-1, 0, aBuf); } diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index f5058f6f9..77487efd4 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -105,6 +105,16 @@ const char *CGameClient::GetTeamName(int Team, bool Teamplay) const return Localize("spectators", "'X joined the ' (server message)"); } +void CGameClient::GetPlayerLabel(char* aBuf, int BufferSize, int ClientID, const char* ClientName) +{ + if(!g_Config.m_ClShowsocial) + str_format(aBuf, BufferSize, "%2d:", ClientID); + else if(g_Config.m_ClShowUserId) + str_format(aBuf, BufferSize, "%2d: %s", ClientID, ClientName); + else + str_format(aBuf, BufferSize, "%s", ClientName); +} + enum { DO_CHAT=0, @@ -556,12 +566,15 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker) case GAMEMSG_CTF_CAPTURE: m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_CAPTURE); int ClientID = clamp(aParaI[1], 0, MAX_CLIENTS - 1); + char aLabel[64]; + GetPlayerLabel(aLabel, sizeof(aLabel), ClientID, m_aClients[ClientID].m_aName); + if(aParaI[2] <= 60*Client()->GameTickSpeed()) - str_format(aBuf, sizeof(aBuf), Localize("The %s was captured by '%2d: %s' (%.2f seconds)"), aParaI[0] ? Localize("blue flag") : Localize("red flag"), - ClientID, g_Config.m_ClShowsocial ? m_aClients[ClientID].m_aName : "", aParaI[2]/(float)Client()->GameTickSpeed()); + str_format(aBuf, sizeof(aBuf), Localize("The %s was captured by '%s' (%.2f seconds)"), aParaI[0] ? Localize("blue flag") : Localize("red flag"), + aLabel, aParaI[2]/(float)Client()->GameTickSpeed()); else - str_format(aBuf, sizeof(aBuf), Localize("The %s was captured by '%2d: %s'"), aParaI[0] ? Localize("blue flag") : Localize("red flag"), - ClientID, g_Config.m_ClShowsocial ? m_aClients[ClientID].m_aName : ""); + str_format(aBuf, sizeof(aBuf), Localize("The %s was captured by '%s'"), aParaI[0] ? Localize("blue flag") : Localize("red flag"), + aLabel); m_pChat->AddLine(-1, 0, aBuf); } return; @@ -1401,18 +1414,20 @@ void CGameClient::CClientData::Reset(CGameClient *pGameClient) void CGameClient::DoEnterMessage(const char *pName, int ClientID, int Team) { - char aBuf[128]; - str_format(aBuf, sizeof(aBuf), Localize("'%2d: %s' entered and joined the %s"), ClientID, g_Config.m_ClShowsocial ? pName : "", GetTeamName(Team, m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)); + char aBuf[128], aLabel[64]; + GetPlayerLabel(aLabel, sizeof(aLabel), ClientID, pName); + str_format(aBuf, sizeof(aBuf), Localize("'%s' entered and joined the %s"), aLabel, GetTeamName(Team, m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)); m_pChat->AddLine(-1, 0, aBuf); } void CGameClient::DoLeaveMessage(const char *pName, int ClientID, const char *pReason) { - char aBuf[128]; + char aBuf[128], aLabel[64]; + GetPlayerLabel(aLabel, sizeof(aLabel), ClientID, pName); if(pReason[0]) - str_format(aBuf, sizeof(aBuf), Localize("'%2d: %s' has left the game (%s)"), ClientID, g_Config.m_ClShowsocial ? pName : "", pReason); + str_format(aBuf, sizeof(aBuf), Localize("'%s' has left the game (%s)"), aLabel, pReason); else - str_format(aBuf, sizeof(aBuf), Localize("'%2d: %s' has left the game"), ClientID, g_Config.m_ClShowsocial ? pName : ""); + str_format(aBuf, sizeof(aBuf), Localize("'%s' has left the game"), aLabel); m_pChat->AddLine(-1, 0, aBuf); } diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 31c88560e..efa2e1676 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -250,6 +250,7 @@ public: virtual const char *NetVersion() const; virtual int ClientVersion() const; const char *GetTeamName(int Team, bool Teamplay) const; + static void GetPlayerLabel(char* aBuf, int BufferSize, int ClientID, const char* ClientName); // void DoEnterMessage(const char *pName, int ClientID, int Team);