Merge pull request #8301 from ChillerDragon/pr_skin_warn

Improve skin name validation error message (Closed #8300)
This commit is contained in:
Jupeyy 2024-05-04 12:57:48 +00:00 committed by GitHub
commit 9336b4cb37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 3 deletions

View file

@ -1,5 +1,6 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/log.h>
#include <base/math.h>
#include <base/system.h>
@ -480,9 +481,8 @@ void CMenus::Con_AddFavoriteSkin(IConsole::IResult *pResult, void *pUserData)
const char *pStr = pResult->GetString(0);
if(!CSkin::IsValidName(pStr))
{
char aError[IConsole::CMDLINE_LENGTH + 64];
str_format(aError, sizeof(aError), "Favorite skin name '%s' is not valid", pStr);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "menus/settings", aError);
log_error("menus/settings", "Favorite skin name '%s' is not valid", pStr);
log_error("menus/settings", "%s", CSkin::m_aSkinNameRestrictions);
return;
}
pSelf->m_SkinFavorites.emplace(pStr);

View file

@ -83,6 +83,7 @@ int CSkins::SkinScan(const char *pName, int IsDir, int DirType, void *pUser)
if(!CSkin::IsValidName(aSkinName))
{
log_error("skins", "Skin name is not valid: %s", aSkinName);
log_error("skins", "%s", CSkin::m_aSkinNameRestrictions);
return 0;
}

View file

@ -155,6 +155,7 @@ public:
const char *GetName() const { return m_aName; }
// has to be kept in sync with m_aSkinNameRestrictions
static bool IsValidName(const char *pName)
{
if(pName[0] == '\0' || str_length(pName) >= (int)sizeof(CSkin("").m_aName))
@ -171,6 +172,7 @@ public:
}
return true;
}
static constexpr char m_aSkinNameRestrictions[] = "Skin names must be valid filenames shorter than 24 characters.";
};
#endif