Skip to content

Commit

Permalink
Apply servers chat trimming client side before processing
Browse files Browse the repository at this point in the history
We now process chat commands before sending them
So to keep the old formatting we also apply the servers trimming.

This fixes the chat message "!war foo " declaring war to the player "foo "
instead of the player "foo"

See #166 (comment)
  • Loading branch information
ChillerDragon committed Oct 20, 2024
1 parent 3404af7 commit 3aa98a0
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/game/client/components/chillerbot/chillerbotux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,38 @@ void CChillerBotUX::OnRender()

bool CChillerBotUX::OnSendChat(int Team, const char *pLine)
{
ReturnFromAfk(pLine);
char aTrimmedLine[512];
str_copy(aTrimmedLine, pLine);

int Length = 0;
char *p = aTrimmedLine;
char *pEnd = nullptr;
while(*p)
{
char *pStrOld = p;
int Code = str_utf8_decode((const char **)(&p));

// check if unicode is not empty
if(!str_utf8_isspace(Code))
{
pEnd = nullptr;
}
else if(pEnd == 0)
pEnd = pStrOld;

if(++Length >= 256)
{
*p = '\0';
break;
}
}
if(pEnd != nullptr)
*pEnd = '\0';

ReturnFromAfk(aTrimmedLine);

int ClientId = m_pClient->m_aLocalIds[g_Config.m_ClDummy];
if(m_pClient->m_ChatCommand.OnChatMsg(ClientId, Team, pLine))
if(m_pClient->m_ChatCommand.OnChatMsg(ClientId, Team, aTrimmedLine))
{
if(g_Config.m_ClSilentChatCommands)
return false;
Expand Down

0 comments on commit 3aa98a0

Please sign in to comment.