Skip to content
Browse files

Prevent world creation if the world already exists

  • Loading branch information...
1 parent 5dd1d35 commit c8895dd43b098d635ec0ae55fbbbfe5d1fe8bef9 @matttpt matttpt committed with Aug 30, 2012
Showing with 17 additions and 4 deletions.
  1. +17 −4 src/guiMainMenu.cpp
View
21 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();
-}
+}

0 comments on commit c8895dd

Please sign in to comment.
Something went wrong with that request. Please try again.