aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/guiMainMenu.cpp10
-rw-r--r--src/guiMainMenu.h1
-rw-r--r--src/subgame.h2
-rw-r--r--src/util/string.h23
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)
*/