From 768d95dce4968a98146bb7a3194c27686900e477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 5 Oct 2024 16:59:28 +0200 Subject: [PATCH] Add `MAX_SKIN_LENGTH` constant Add constant to replace the magic number `24` used for the size of skin names. Skin names in the server info/browser were sized `24 + 1` but the additional byte was unnecessary. --- src/engine/serverbrowser.h | 2 +- src/engine/shared/protocol.h | 1 + src/engine/shared/serverinfo.h | 2 +- src/game/client/components/ghost.cpp | 4 ++-- src/game/client/components/menus.h | 2 +- src/game/client/components/skins.cpp | 2 +- src/game/client/components/skins.h | 4 ++-- src/game/client/gameclient.h | 2 +- src/game/client/skin.h | 6 +++++- src/game/server/teeinfo.h | 4 +++- 10 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/engine/serverbrowser.h b/src/engine/serverbrowser.h index 0b3f58eac54..b0a7fba4ac5 100644 --- a/src/engine/serverbrowser.h +++ b/src/engine/serverbrowser.h @@ -72,7 +72,7 @@ class CServerInfo bool m_Afk; // skin info - char m_aSkin[24 + 1]; + char m_aSkin[MAX_SKIN_LENGTH]; bool m_CustomSkinColors; int m_CustomSkinColorBody; int m_CustomSkinColorFeet; diff --git a/src/engine/shared/protocol.h b/src/engine/shared/protocol.h index e0f807b10e8..363e35c9412 100644 --- a/src/engine/shared/protocol.h +++ b/src/engine/shared/protocol.h @@ -96,6 +96,7 @@ enum MAX_NAME_LENGTH = 16, MAX_CLAN_LENGTH = 12, + MAX_SKIN_LENGTH = 24, // message packing MSGFLAG_VITAL = 1, diff --git a/src/engine/shared/serverinfo.h b/src/engine/shared/serverinfo.h index 4e4c28902c6..b8ec2f18ce9 100644 --- a/src/engine/shared/serverinfo.h +++ b/src/engine/shared/serverinfo.h @@ -21,7 +21,7 @@ class CServerInfo2 int m_Score; bool m_IsPlayer; bool m_IsAfk; - char m_aSkin[24 + 1]; + char m_aSkin[MAX_SKIN_LENGTH]; bool m_CustomSkinColors; int m_CustomSkinColorBody; int m_CustomSkinColorFeet; diff --git a/src/game/client/components/ghost.cpp b/src/game/client/components/ghost.cpp index 26272d36908..175cfe3a328 100644 --- a/src/game/client/components/ghost.cpp +++ b/src/game/client/components/ghost.cpp @@ -385,7 +385,7 @@ void CGhost::OnRender() void CGhost::InitRenderInfos(CGhostItem *pGhost) { - char aSkinName[24]; + char aSkinName[MAX_SKIN_LENGTH]; IntsToStr(&pGhost->m_Skin.m_Skin0, 6, aSkinName, std::size(aSkinName)); CTeeRenderInfo *pRenderInfo = &pGhost->m_RenderInfo; @@ -685,7 +685,7 @@ void CGhost::OnRefreshSkins() const auto &&RefindSkin = [&](auto &Ghost) { if(Ghost.Empty()) return; - char aSkinName[24]; + char aSkinName[MAX_SKIN_LENGTH]; IntsToStr(&Ghost.m_Skin.m_Skin0, 6, aSkinName, std::size(aSkinName)); CTeeRenderInfo *pRenderInfo = &Ghost.m_RenderInfo; if(aSkinName[0] != '\0') diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 4595bd1eebb..4338b712a06 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -369,7 +369,7 @@ class CMenus : public CComponent bool m_IsPlayer; bool m_IsAfk; // skin - char m_aSkin[24 + 1]; + char m_aSkin[MAX_SKIN_LENGTH]; bool m_CustomSkinColors; int m_CustomSkinColorBody; int m_CustomSkinColorFeet; diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 9e66d065162..456f70a8b33 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -461,7 +461,7 @@ void CSkins::RandomizeSkin(int Dummy) } const size_t SkinNameSize = Dummy ? sizeof(g_Config.m_ClDummySkin) : sizeof(g_Config.m_ClPlayerSkin); - char aRandomSkinName[24]; + char aRandomSkinName[MAX_SKIN_LENGTH]; str_copy(aRandomSkinName, "default", SkinNameSize); if(!m_pClient->m_Skins.GetSkinsUnsafe().empty()) { diff --git a/src/game/client/components/skins.h b/src/game/client/components/skins.h index cf648f6ad93..748f85b9da6 100644 --- a/src/game/client/components/skins.h +++ b/src/game/client/components/skins.h @@ -30,7 +30,7 @@ class CSkins : public CComponent struct CDownloadSkin { private: - char m_aName[24]; + char m_aName[MAX_SKIN_LENGTH]; public: std::shared_ptr m_pTask; @@ -82,7 +82,7 @@ class CSkins : public CComponent std::unordered_map> m_DownloadSkins; CSkin m_PlaceholderSkin; size_t m_DownloadingSkins = 0; - char m_aEventSkinPrefix[24]; + char m_aEventSkinPrefix[MAX_SKIN_LENGTH]; bool LoadSkinPng(CImageInfo &Info, const char *pName, const char *pPath, int DirType); const CSkin *LoadSkin(const char *pName, const char *pPath, int DirType); diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 8e911f51bbd..619f2d2fcbe 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -376,7 +376,7 @@ class CGameClient : public IGameClient char m_aName[MAX_NAME_LENGTH]; char m_aClan[MAX_CLAN_LENGTH]; int m_Country; - char m_aSkinName[24]; + char m_aSkinName[MAX_SKIN_LENGTH]; int m_SkinColor; int m_Team; int m_Emoticon; diff --git a/src/game/client/skin.h b/src/game/client/skin.h index b6791867081..714df154ce2 100644 --- a/src/game/client/skin.h +++ b/src/game/client/skin.h @@ -1,16 +1,20 @@ #ifndef GAME_CLIENT_SKIN_H #define GAME_CLIENT_SKIN_H + #include #include #include + #include +#include + #include // do this better and nicer struct CSkin { private: - char m_aName[24]; + char m_aName[MAX_SKIN_LENGTH]; public: struct SSkinTextures diff --git a/src/game/server/teeinfo.h b/src/game/server/teeinfo.h index d3997cf4208..921063d35d8 100644 --- a/src/game/server/teeinfo.h +++ b/src/game/server/teeinfo.h @@ -1,10 +1,12 @@ #ifndef GAME_SERVER_TEEINFO_H #define GAME_SERVER_TEEINFO_H +#include + class CTeeInfo { public: - char m_aSkinName[24] = {'\0'}; + char m_aSkinName[MAX_SKIN_LENGTH] = ""; int m_UseCustomColor = 0; int m_ColorBody = 0; int m_ColorFeet = 0;