aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthew I <matttpt@gmail.com>2012-08-30 15:41:48 -0400
committerPerttu Ahola <celeron55@gmail.com>2012-09-05 01:17:44 +0300
commitc8895dd43b098d635ec0ae55fbbbfe5d1fe8bef9 (patch)
tree54a0207788de9e27d2615fd56933462799ca357e /src
parent5dd1d354f86692e4c08cc78f3d9743557103449e (diff)
downloadminetest-c8895dd43b098d635ec0ae55fbbbfe5d1fe8bef9.tar.gz
minetest-c8895dd43b098d635ec0ae55fbbbfe5d1fe8bef9.tar.bz2
minetest-c8895dd43b098d635ec0ae55fbbbfe5d1fe8bef9.zip
Prevent world creation if the world already exists
Diffstat (limited to 'src')
-rw-r--r--src/guiMainMenu.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp
index 4ceecbb5f..5e0a3c38f 100644
--- a/src/guiMainMenu.cpp
+++ b/src/guiMainMenu.cpp
@@ -48,10 +48,23 @@ struct CreateWorldDestMainMenu : public CreateWorldDest
{}
void accepted(std::wstring name, std::string gameid)
{
- if(!string_allowed_blacklist(wide_to_narrow(name), WORLDNAME_BLACKLISTED_CHARS))
+ std::string name_narrow = wide_to_narrow(name);
+ if(!string_allowed_blacklist(name_narrow, WORLDNAME_BLACKLISTED_CHARS))
+ {
m_menu->displayMessageMenu(wgettext("Cannot create world: Name contains invalid characters"));
- else
- m_menu->createNewWorld(name, gameid);
+ return;
+ }
+ std::vector<WorldSpec> worlds = getAvailableWorlds();
+ for(std::vector<WorldSpec>::iterator i = worlds.begin();
+ i != worlds.end(); i++)
+ {
+ if((*i).name == name_narrow)
+ {
+ m_menu->displayMessageMenu(wgettext("Cannot create world: A world by this name already exists"));
+ return;
+ }
+ }
+ m_menu->createNewWorld(name, gameid);
}
GUIMainMenu *m_menu;
};
@@ -936,4 +949,4 @@ int GUIMainMenu::getTab()
void GUIMainMenu::displayMessageMenu(std::wstring msg)
{
(new GUIMessageMenu(env, parent, -1, menumgr, msg))->drop();
-} \ No newline at end of file
+}