diff options
author | Matthew I <matttpt@gmail.com> | 2012-09-02 16:51:17 -0400 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-09-05 01:17:28 +0300 |
commit | 5dd1d354f86692e4c08cc78f3d9743557103449e (patch) | |
tree | 1668bdb85e11e7c5faa93a8c59b47a828e4eadad /src | |
parent | a0da6bcf43d71d22b949ccf1e68153b51da53e39 (diff) | |
download | minetest-5dd1d354f86692e4c08cc78f3d9743557103449e.tar.gz minetest-5dd1d354f86692e4c08cc78f3d9743557103449e.tar.bz2 minetest-5dd1d354f86692e4c08cc78f3d9743557103449e.zip |
Enforce stricter world names using a blacklist
Blacklisted characters are: / \
Diffstat (limited to 'src')
-rw-r--r-- | src/guiMainMenu.cpp | 10 | ||||
-rw-r--r-- | src/guiMainMenu.h | 1 | ||||
-rw-r--r-- | src/subgame.h | 2 | ||||
-rw-r--r-- | src/util/string.h | 23 |
4 files changed, 35 insertions, 1 deletions
diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index cdf1bc7d5..4ceecbb5f 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "tile.h" // getTexturePath #include "filesys.h" #include "util/string.h" +#include "subgame.h" struct CreateWorldDestMainMenu : public CreateWorldDest { @@ -47,7 +48,10 @@ struct CreateWorldDestMainMenu : public CreateWorldDest {} void accepted(std::wstring name, std::string gameid) { - m_menu->createNewWorld(name, gameid); + if(!string_allowed_blacklist(wide_to_narrow(name), WORLDNAME_BLACKLISTED_CHARS)) + m_menu->displayMessageMenu(wgettext("Cannot create world: Name contains invalid characters")); + else + m_menu->createNewWorld(name, gameid); } GUIMainMenu *m_menu; }; @@ -929,3 +933,7 @@ int GUIMainMenu::getTab() return TAB_SINGLEPLAYER; // Default } +void GUIMainMenu::displayMessageMenu(std::wstring msg) +{ + (new GUIMessageMenu(env, parent, -1, menumgr, msg))->drop(); +}
\ No newline at end of file diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h index fa3d83c45..715deb47d 100644 --- a/src/guiMainMenu.h +++ b/src/guiMainMenu.h @@ -92,6 +92,7 @@ public: void createNewWorld(std::wstring name, std::string gameid); void deleteWorld(const std::vector<std::string> &paths); int getTab(); + void displayMessageMenu(std::wstring msg); private: MainMenuData *m_data; diff --git a/src/subgame.h b/src/subgame.h index e3a299cbe..bffa86e28 100644 --- a/src/subgame.h +++ b/src/subgame.h @@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <set> #include <vector> +#define WORLDNAME_BLACKLISTED_CHARS "/\\" + struct SubgameSpec { std::string id; // "" = game does not exist diff --git a/src/util/string.h b/src/util/string.h index 97b07f2ff..71b11de3d 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -243,6 +243,29 @@ inline bool string_allowed(const std::string &s, const std::string &allowed_char } /* + Checks if a string contains no blacklisted characters (opposite + function of string_allowed()) +*/ +inline bool string_allowed_blacklist(const std::string & s, const std::string & blacklisted_chars) +{ + for(unsigned int i = 0; i < s.length(); i++) + { + bool invalid = false; + for(unsigned int j = 0; j < blacklisted_chars.length(); j++) + { + if(s[i] == blacklisted_chars[j]) + { + invalid = true; + break; + } + } + if(invalid) + return false; + } + return true; +} + +/* Forcefully wraps string into rows using \n (no word wrap, used for showing paths in gui) */ |