Skip to content

Commit

Permalink
Check for skin name length when loading, refactoring
Browse files Browse the repository at this point in the history
Remove obsolete check for duplicate skins, as the storage handles this already.
  • Loading branch information
Robyt3 committed Oct 22, 2023
1 parent 9f8d87d commit 8bd9871
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/game/client/components/skins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,29 @@ struct SSkinScanUser

int CSkins::SkinScan(const char *pName, int IsDir, int DirType, void *pUser)
{
auto *pUserReal = (SSkinScanUser *)pUser;
auto *pUserReal = static_cast<SSkinScanUser *>(pUser);
CSkins *pSelf = pUserReal->m_pThis;

if(IsDir || !str_endswith(pName, ".png"))
const char *pSuffix = str_endswith(pName, ".png");
if(IsDir || pSuffix == nullptr)
return 0;

char aNameWithoutPng[128];
str_copy(aNameWithoutPng, pName);
aNameWithoutPng[str_length(aNameWithoutPng) - 4] = 0;

if(g_Config.m_ClVanillaSkinsOnly && !IsVanillaSkin(aNameWithoutPng))
char aSkinName[IO_MAX_PATH_LENGTH];
str_truncate(aSkinName, sizeof(aSkinName), pName, pSuffix - pName);
if(str_length(aSkinName) >= (int)CSkin::MAX_NAME_LENGTH)
{
char aBuf[64 + IO_MAX_PATH_LENGTH];
str_format(aBuf, sizeof(aBuf), "Skin name too long (maximum %d characters): '%s'", (int)CSkin::MAX_NAME_LENGTH - 1, aSkinName);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "game", aBuf);
return 0;
}

// Don't add duplicate skins (one from user's config directory, other from
// client itself)
if(pSelf->m_Skins.find(aNameWithoutPng) != pSelf->m_Skins.end())
if(g_Config.m_ClVanillaSkinsOnly && !IsVanillaSkin(aSkinName))
return 0;

char aBuf[IO_MAX_PATH_LENGTH];
str_format(aBuf, sizeof(aBuf), "skins/%s", pName);
pSelf->LoadSkin(aNameWithoutPng, aBuf, DirType);
char aPath[IO_MAX_PATH_LENGTH];
str_format(aPath, sizeof(aPath), "skins/%s", pName);
pSelf->LoadSkin(aSkinName, aPath, DirType);
pUserReal->m_SkinLoadedFunc((int)pSelf->m_Skins.size());
return 0;
}
Expand Down

0 comments on commit 8bd9871

Please sign in to comment.