From 61bf48c1edd238cabdf2fed4076ee77e4d98da65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 21 Feb 2023 20:27:05 +0100 Subject: [PATCH 1/3] Add chat message constants from upstream, remove redundant comments Add `CLIENT_MSG = -2` and `SERVER_MSG = -1` constants from upstream. Remove comments for self-documenting code. --- src/game/client/components/chat.cpp | 39 +++++++++++------------------ src/game/client/components/chat.h | 5 +++- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index d790b6aa1..b060f9cf1 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -147,7 +147,7 @@ void CChat::ConchainChatOld(IConsole::IResult *pResult, void *pUserData, IConsol void CChat::Echo(const char *pString) { - AddLine(-2, 0, pString); + AddLine(CLIENT_MSG, 0, pString); } void CChat::OnConsoleInit() @@ -637,7 +637,7 @@ void CChat::StoreSave(const char *pText) void CChat::AddLine(int ClientID, int Team, const char *pLine) { if(*pLine == 0 || - (ClientID == -1 && !g_Config.m_ClShowChatSystem) || + (ClientID == SERVER_MSG && !g_Config.m_ClShowChatSystem) || (ClientID >= 0 && (m_pClient->m_aClients[ClientID].m_aName[0] == '\0' || // unknown client m_pClient->m_aClients[ClientID].m_ChatIgnore || (m_pClient->m_Snap.m_LocalClientID != ClientID && g_Config.m_ClShowChatFriends && !m_pClient->m_aClients[ClientID].m_Friend) || @@ -698,9 +698,9 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine) ChatLogColor = color_cast(ColorHSLA(g_Config.m_ClMessageFriendColor)); else if(pLine_->m_Team) ChatLogColor = color_cast(ColorHSLA(g_Config.m_ClMessageTeamColor)); - else if(pLine_->m_ClientID == -1) // system + else if(pLine_->m_ClientID == SERVER_MSG) ChatLogColor = color_cast(ColorHSLA(g_Config.m_ClMessageSystemColor)); - else if(pLine_->m_ClientID == -2) // client + else if(pLine_->m_ClientID == CLIENT_MSG) ChatLogColor = color_cast(ColorHSLA(g_Config.m_ClMessageClientColor)); else // regular message ChatLogColor = color_cast(ColorHSLA(g_Config.m_ClMessageColor)); @@ -848,7 +848,7 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine) // play sound int64_t Now = time(); - if(ClientID == -1) + if(ClientID == SERVER_MSG) { if(Now - m_aLastSoundPlayed[CHAT_SERVER] >= time_freq() * 3 / 10) { @@ -859,7 +859,7 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine) } } } - else if(ClientID == -2) // Client message + else if(ClientID == CLIENT_MSG) { // No sound yet } @@ -1063,33 +1063,24 @@ void CChat::OnPrepareLines() // render name ColorRGBA NameColor; - if(m_aLines[r].m_ClientID == -1) // system - { + if(m_aLines[r].m_ClientID == SERVER_MSG) NameColor = color_cast(ColorHSLA(g_Config.m_ClMessageSystemColor)); - } - else if(m_aLines[r].m_ClientID == -2) // client - { + else if(m_aLines[r].m_ClientID == CLIENT_MSG) NameColor = color_cast(ColorHSLA(g_Config.m_ClMessageClientColor)); - } else if(m_aLines[r].m_Team) - { NameColor = CalculateNameColor(ColorHSLA(g_Config.m_ClMessageTeamColor)); - } else if(m_aLines[r].m_NameColor == TEAM_RED) - NameColor = ColorRGBA(1.0f, 0.5f, 0.5f, 1.f); // red + NameColor = ColorRGBA(1.0f, 0.5f, 0.5f, 1.f); else if(m_aLines[r].m_NameColor == TEAM_BLUE) - NameColor = ColorRGBA(0.7f, 0.7f, 1.0f, 1.f); // blue + NameColor = ColorRGBA(0.7f, 0.7f, 1.0f, 1.f); else if(m_aLines[r].m_NameColor == TEAM_SPECTATORS) - NameColor = ColorRGBA(0.75f, 0.5f, 0.75f, 1.f); // spectator + NameColor = ColorRGBA(0.75f, 0.5f, 0.75f, 1.f); else if(m_aLines[r].m_ClientID >= 0 && g_Config.m_ClChatTeamColors && m_pClient->m_Teams.Team(m_aLines[r].m_ClientID)) - { NameColor = color_cast(ColorHSLA(m_pClient->m_Teams.Team(m_aLines[r].m_ClientID) / 64.0f, 1.0f, 0.75f)); - } else NameColor = ColorRGBA(0.8f, 0.8f, 0.8f, 1.f); TextRender()->TextColor(NameColor); - TextRender()->CreateOrAppendTextContainer(m_aLines[r].m_TextContainerIndex, &Cursor, aName); if(m_aLines[r].m_TimesRepeated > 0) @@ -1106,13 +1097,13 @@ void CChat::OnPrepareLines() // render line ColorRGBA Color; - if(m_aLines[r].m_ClientID == -1) // system + if(m_aLines[r].m_ClientID == SERVER_MSG) Color = color_cast(ColorHSLA(g_Config.m_ClMessageSystemColor)); - else if(m_aLines[r].m_ClientID == -2) // client + else if(m_aLines[r].m_ClientID == CLIENT_MSG) Color = color_cast(ColorHSLA(g_Config.m_ClMessageClientColor)); - else if(m_aLines[r].m_Highlighted) // highlighted + else if(m_aLines[r].m_Highlighted) Color = color_cast(ColorHSLA(g_Config.m_ClMessageHighlightColor)); - else if(m_aLines[r].m_Team) // team message + else if(m_aLines[r].m_Team) Color = color_cast(ColorHSLA(g_Config.m_ClMessageTeamColor)); else // regular message Color = color_cast(ColorHSLA(g_Config.m_ClMessageColor)); diff --git a/src/game/client/components/chat.h b/src/game/client/components/chat.h index 66fde6e04..a077413c4 100644 --- a/src/game/client/components/chat.h +++ b/src/game/client/components/chat.h @@ -62,9 +62,12 @@ class CChat : public CComponent CLine m_aLines[MAX_LINES]; int m_CurrentLine; - // chat enum { + // client IDs for special messages + CLIENT_MSG = -2, + SERVER_MSG = -1, + MODE_NONE = 0, MODE_ALL, MODE_TEAM, From 284f3326a7dfad38eba3d22e928cac1cfc14c41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 21 Feb 2023 20:34:12 +0100 Subject: [PATCH 2/3] Use em dash for client messages in chat like on upstream --- src/game/client/components/chat.cpp | 7 ++++++- src/game/client/components/menus_settings.cpp | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index b060f9cf1..aac739e3b 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -781,11 +781,16 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine) pCurrentLine->m_Highlighted = Highlighted; - if(pCurrentLine->m_ClientID < 0) // server or client message + if(pCurrentLine->m_ClientID == SERVER_MSG) { str_copy(pCurrentLine->m_aName, "*** "); str_copy(pCurrentLine->m_aText, pLine); } + else if(pCurrentLine->m_ClientID == CLIENT_MSG) + { + str_copy(pCurrentLine->m_aName, "— "); + str_copy(pCurrentLine->m_aText, pLine); + } else { if(m_pClient->m_aClients[ClientID].m_Team == TEAM_SPECTATORS) diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index e00fbc106..f0d5d99a0 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -2906,7 +2906,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) Graphics()->DrawRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX + RealMsgPaddingTee, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); TempY += RealOffsetY; - Width = TextRender()->TextWidth(RealFontSize, "*** Echo command executed", -1, -1); + Width = TextRender()->TextWidth(RealFontSize, "— Echo command executed", -1, -1); Graphics()->DrawRectExt(X - RealMsgPaddingX / 2.0f, TempY - RealMsgPaddingY / 2.0f, Width + RealMsgPaddingX, RealFontSize + RealMsgPaddingY, RealBackgroundRounding, IGraphics::CORNER_ALL); Graphics()->QuadsEnd(); @@ -2997,7 +2997,7 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView) // Client TextRender()->TextColor(ClientColor); - TextRender()->TextEx(&Cursor, "*** Echo command executed", -1); + TextRender()->TextEx(&Cursor, "— Echo command executed", -1); TextRender()->SetCursorPosition(&Cursor, X, Y); TextRender()->TextColor(TextRender()->DefaultTextColor()); From 541115022a8565360bf7af43c0668fae73076c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 21 Feb 2023 20:43:24 +0100 Subject: [PATCH 3/3] Fix client crash when echoing client message to chat The client crashes when printing a client message to the chat from a config file or from the command line, as the graphics have not been initialized at that point. Closes #6350. --- src/game/client/components/chat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index aac739e3b..b38484bc4 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -156,7 +156,7 @@ void CChat::OnConsoleInit() Console()->Register("say_team", "r[message]", CFGFLAG_CLIENT, ConSayTeam, this, "Say in team chat"); Console()->Register("chat", "s['team'|'all'] ?r[message]", CFGFLAG_CLIENT, ConChat, this, "Enable chat with all/team mode"); Console()->Register("+show_chat", "", CFGFLAG_CLIENT, ConShowChat, this, "Show chat"); - Console()->Register("echo", "r[message]", CFGFLAG_CLIENT, ConEcho, this, "Echo the text in chat window"); + Console()->Register("echo", "r[message]", CFGFLAG_CLIENT | CFGFLAG_STORE, ConEcho, this, "Echo the text in chat window"); Console()->Chain("cl_chat_old", ConchainChatOld, this); }