From 38cae7edcfb35b78c01fb144c354ee90d968cb38 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Tue, 23 Apr 2024 16:06:13 +0800 Subject: [PATCH] Use NUM_SKINPARTS instead of magic number --- src/game/server/gamecontext.cpp | 10 +++++----- src/game/server/teeinfo.cpp | 17 +++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 9e806cd33..807e71343 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1584,7 +1584,7 @@ void CGameContext::OnClientEnter(int ClientId) NewClientInfoMsg.m_Country = Server()->ClientCountry(ClientId); NewClientInfoMsg.m_Silent = false; - for(int p = 0; p < 6; p++) + for(int p = 0; p < protocol7::NUM_SKINPARTS; p++) { NewClientInfoMsg.m_apSkinPartNames[p] = pNewPlayer->m_TeeInfos.m_apSkinPartNames[p]; NewClientInfoMsg.m_aUseCustomColors[p] = pNewPlayer->m_TeeInfos.m_aUseCustomColors[p]; @@ -1614,7 +1614,7 @@ void CGameContext::OnClientEnter(int ClientId) ClientInfoMsg.m_Country = Server()->ClientCountry(i); ClientInfoMsg.m_Silent = 0; - for(int p = 0; p < 6; p++) + for(int p = 0; p < protocol7::NUM_SKINPARTS; p++) { ClientInfoMsg.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p]; ClientInfoMsg.m_aUseCustomColors[p] = pPlayer->m_TeeInfos.m_aUseCustomColors[p]; @@ -1882,7 +1882,7 @@ void *CGameContext::PreProcessMsg(int *pMsgId, CUnpacker *pUnpacker, int ClientI protocol7::CNetMsg_Sv_SkinChange Msg; Msg.m_ClientId = ClientId; - for(int p = 0; p < 6; p++) + for(int p = 0; p < protocol7::NUM_SKINPARTS; p++) { Msg.m_apSkinPartNames[p] = pMsg->m_apSkinPartNames[p]; Msg.m_aSkinPartColors[p] = pMsg->m_aSkinPartColors[p]; @@ -2630,7 +2630,7 @@ void CGameContext::OnChangeInfoNetMessage(const CNetMsg_Cl_ChangeInfo *pMsg, int Info.m_Silent = true; Info.m_Team = pPlayer->GetTeam(); - for(int p = 0; p < 6; p++) + for(int p = 0; p < protocol7::NUM_SKINPARTS; p++) { Info.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p]; Info.m_aSkinPartColors[p] = pPlayer->m_TeeInfos.m_aSkinPartColors[p]; @@ -2650,7 +2650,7 @@ void CGameContext::OnChangeInfoNetMessage(const CNetMsg_Cl_ChangeInfo *pMsg, int { protocol7::CNetMsg_Sv_SkinChange Msg; Msg.m_ClientId = ClientId; - for(int p = 0; p < 6; p++) + for(int p = 0; p < protocol7::NUM_SKINPARTS; p++) { Msg.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p]; Msg.m_aSkinPartColors[p] = pPlayer->m_TeeInfos.m_aSkinPartColors[p]; diff --git a/src/game/server/teeinfo.cpp b/src/game/server/teeinfo.cpp index 27b7f4d37..250d77623 100644 --- a/src/game/server/teeinfo.cpp +++ b/src/game/server/teeinfo.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "teeinfo.h" @@ -7,9 +8,9 @@ struct StdSkin { char m_aSkinName[24]; // body, marking, decoration, hands, feet, eyes - char m_apSkinPartNames[6][24]; - bool m_aUseCustomColors[6]; - int m_aSkinPartColors[6]; + char m_apSkinPartNames[protocol7::NUM_SKINPARTS][24]; + bool m_aUseCustomColors[protocol7::NUM_SKINPARTS]; + int m_aSkinPartColors[protocol7::NUM_SKINPARTS]; }; static StdSkin g_aStdSkins[] = { @@ -38,9 +39,9 @@ CTeeInfo::CTeeInfo(const char *pSkinName, int UseCustomColor, int ColorBody, int m_ColorFeet = ColorFeet; } -CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], const int *pUseCustomColors, const int *pSkinPartColors) +CTeeInfo::CTeeInfo(const char *apSkinPartNames[protocol7::NUM_SKINPARTS], const int *pUseCustomColors, const int *pSkinPartColors) { - for(int i = 0; i < 6; i++) + for(int i = 0; i < protocol7::NUM_SKINPARTS; i++) { str_copy(m_apSkinPartNames[i], apSkinPartNames[i], sizeof(m_apSkinPartNames[i])); m_aUseCustomColors[i] = pUseCustomColors[i]; @@ -51,7 +52,7 @@ CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], const int *pUseCustomColors, void CTeeInfo::ToSixup() { // reset to default skin - for(int p = 0; p < 6; p++) + for(int p = 0; p < protocol7::NUM_SKINPARTS; p++) { str_copy(m_apSkinPartNames[p], g_aStdSkins[0].m_apSkinPartNames[p], 24); m_aUseCustomColors[p] = g_aStdSkins[0].m_aUseCustomColors[p]; @@ -63,7 +64,7 @@ void CTeeInfo::ToSixup() { if(!str_comp(m_aSkinName, StdSkin.m_aSkinName)) { - for(int p = 0; p < 6; p++) + for(int p = 0; p < protocol7::NUM_SKINPARTS; p++) { str_copy(m_apSkinPartNames[p], StdSkin.m_apSkinPartNames[p], 24); m_aUseCustomColors[p] = StdSkin.m_aUseCustomColors[p]; @@ -102,7 +103,7 @@ void CTeeInfo::FromSixup() for(auto &StdSkin : g_aStdSkins) { bool match = true; - for(int p = 0; p < 6; p++) + for(int p = 0; p < protocol7::NUM_SKINPARTS; p++) { if(str_comp(m_apSkinPartNames[p], StdSkin.m_apSkinPartNames[p]) || m_aUseCustomColors[p] != StdSkin.m_aUseCustomColors[p] || (m_aUseCustomColors[p] && m_aSkinPartColors[p] != StdSkin.m_aSkinPartColors[p])) {