[Chat]: Catch Edge Case (#937)

This commit is contained in:
Edo 2023-04-17 12:27:31 +02:00 committed by GitHub
parent bf57ab2daa
commit 0b9d41af3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,24 +40,16 @@ namespace Components
// Prevent callbacks from adding a new callback (would make the vector iterator invalid) // Prevent callbacks from adding a new callback (would make the vector iterator invalid)
CanAddCallback = false; CanAddCallback = false;
// Chat messages sent through the console do not begin with \x15 // Chat messages sent through the console do not begin with \x15. In some cases it contains \x14
auto msgIndex = 0; auto msgIndex = 0;
if (text[msgIndex] == '\x15') while (text[msgIndex] == '\x15' || text[msgIndex] == '\x14')
{ {
msgIndex = 1; ++msgIndex;
} }
if (text[msgIndex] == '/') if (text[msgIndex] == '/')
{ {
SendChat = false; SendChat = false;
if (msgIndex == 1)
{
// Overwrite / with \x15
text[msgIndex] = text[msgIndex - 1];
}
// Skip over the first character
++text;
} }
if (IsMuted(player)) if (IsMuted(player))
@ -72,7 +64,7 @@ namespace Components
Game::SV_GameSendServerCommand(player - Game::g_entities, Game::SV_CMD_RELIABLE, Utils::String::VA("%c \"Chat is disabled\"", 0x65)); Game::SV_GameSendServerCommand(player - Game::g_entities, Game::SV_CMD_RELIABLE, Utils::String::VA("%c \"Chat is disabled\"", 0x65));
} }
// Message might be empty after processing the '/' // Message might be empty after the special characters
if (text[msgIndex] == '\0') if (text[msgIndex] == '\0')
{ {
SendChat = false; SendChat = false;