From 8b0b09fffd98bc46e68f8c5b5b10c5ab3902dc40 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 4 May 2024 17:31:08 +0800 Subject: [PATCH] Improve skin name validation error message (Closed #8300) --- src/game/client/components/menus_settings.cpp | 6 +++--- src/game/client/components/skins.cpp | 1 + src/game/client/skin.h | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 0413df639..acc036b8c 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -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 #include #include @@ -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); diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 148ff7855..29f2ce3af 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -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; } diff --git a/src/game/client/skin.h b/src/game/client/skin.h index 2ec91e426..b67918670 100644 --- a/src/game/client/skin.h +++ b/src/game/client/skin.h @@ -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