4163: CServer::ProcessClientPacket(): Refactor the debug on unknown message received r=def- a=Kaffeine

<!-- What is the motivation for the changes of this pull request -->
I knew that there is `str_hex()` in `system.h` and then I accidentally noticed `char aHex[] = "0123456789ABCDEF";` here in CServer.

I compiled the server and checked that it works as before this change.
However, I've not triggered/checked this debug message.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Alexander Akulich <akulichalexander@gmail.com>
This commit is contained in:
bors[bot] 2021-09-14 20:21:45 +00:00 committed by GitHub
commit f179d21e70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1716,16 +1716,9 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
{
if(g_Config.m_Debug)
{
char aHex[] = "0123456789ABCDEF";
char aBuf[512];
for(int b = 0; b < pPacket->m_DataSize && b < 32; b++)
{
aBuf[b * 3] = aHex[((const unsigned char *)pPacket->m_pData)[b] >> 4];
aBuf[b * 3 + 1] = aHex[((const unsigned char *)pPacket->m_pData)[b] & 0xf];
aBuf[b * 3 + 2] = ' ';
aBuf[b * 3 + 3] = 0;
}
constexpr int MaxDumpedDataSize = 32;
char aBuf[MaxDumpedDataSize * 3 + 1];
str_hex(aBuf, sizeof(aBuf), pPacket->m_pData, minimum(pPacket->m_DataSize, MaxDumpedDataSize));
char aBufMsg[256];
str_format(aBufMsg, sizeof(aBufMsg), "strange message ClientID=%d msg=%d data_size=%d", ClientID, Msg, pPacket->m_DataSize);