From b5b920dedaa62302795b0b8f3db84a0650d236e0 Mon Sep 17 00:00:00 2001 From: faketruth Date: Tue, 1 Nov 2011 21:57:08 +0000 Subject: You can now run multiple worlds by defining them in settings.ini . However there's no way to change worlds on the fly yet Players are now stored in separate folder /players instead of in the world folder (!so move the folder!) Fixed a memory leak/error in cPickup.cpp Multiple worlds are stored in cRoot cClientHandle lists are taken out of cWorld and now stored in cServer Worlds now have names to distinguish them by Some functions in the Core plugin now distinguish between worlds git-svn-id: http://mc-server.googlecode.com/svn/trunk@40 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cRoot.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'source/cRoot.cpp') diff --git a/source/cRoot.cpp b/source/cRoot.cpp index 55ee28576..518275088 100644 --- a/source/cRoot.cpp +++ b/source/cRoot.cpp @@ -24,9 +24,15 @@ cRoot* cRoot::s_Root = 0; +typedef std::map< std::string, cWorld* > WorldMap; +struct cRoot::sRootState +{ + cWorld* pDefaultWorld; + WorldMap WorldsByName; +}; + cRoot::cRoot() : m_Server( 0 ) - , m_World( 0 ) , m_MonsterConfig( 0 ) , m_GroupManager( 0 ) , m_RecipeChecker( 0 ) @@ -37,6 +43,7 @@ cRoot::cRoot() , m_bStop( false ) , m_bRestart( false ) , m_InputThread( 0 ) + , m_pState( new sRootState ) { s_Root = this; } @@ -44,6 +51,7 @@ cRoot::cRoot() cRoot::~cRoot() { s_Root = 0; + delete m_pState; } void cRoot::InputThread(void* a_Params) @@ -93,8 +101,7 @@ void cRoot::Start() m_GroupManager = new cGroupManager(); m_RecipeChecker = new cRecipeChecker(); m_FurnaceRecipe = new cFurnaceRecipe(); - m_World = new cWorld(); - m_World->InitializeSpawn(); + LoadWorlds(); m_PluginManager = new cPluginManager(); // This should be last m_PluginManager->ReloadPluginsNow(); @@ -122,7 +129,7 @@ void cRoot::Start() delete m_FurnaceRecipe; m_FurnaceRecipe = 0; delete m_RecipeChecker; m_RecipeChecker = 0; delete m_GroupManager; m_GroupManager = 0; - delete m_World; m_World = 0; + UnloadWorlds(); //delete HeartBeat; HeartBeat = 0; delete m_Server; m_Server = 0; } @@ -130,6 +137,73 @@ void cRoot::Start() delete m_Log; m_Log = 0; } +void cRoot::LoadWorlds() +{ + cIniFile IniFile("settings.ini"); IniFile.ReadFile(); + + // First get the default world + std::string DefaultWorldName = IniFile.GetValue("Worlds", "DefaultWorld", "world"); + m_pState->pDefaultWorld = new cWorld( DefaultWorldName.c_str() ); + m_pState->pDefaultWorld->InitializeSpawn(); + m_pState->WorldsByName[ DefaultWorldName ] = m_pState->pDefaultWorld; + + // Then load the other worlds + unsigned int KeyNum = IniFile.FindKey("Worlds"); + unsigned int NumWorlds = IniFile.GetNumValues( KeyNum ); + if( NumWorlds > 0 ) + { + for(unsigned int i = 0; i < NumWorlds; i++) + { + std::string ValueName = IniFile.GetValueName(KeyNum, i ); + if( ValueName.compare("World") == 0 ) + { + std::string WorldName = IniFile.GetValue(KeyNum, i ); + if( WorldName.size() > 0 ) + { + cWorld* NewWorld = new cWorld( WorldName.c_str() ); + NewWorld->InitializeSpawn(); + m_pState->WorldsByName[ WorldName ] = NewWorld; + } + } + } + } +} + +void cRoot::UnloadWorlds() +{ + for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr ) + { + delete itr->second; + } + m_pState->WorldsByName.clear(); +} + +cWorld* cRoot::GetWorld() +{ + return GetDefaultWorld(); +} + +cWorld* cRoot::GetDefaultWorld() +{ + return m_pState->pDefaultWorld; +} + +cWorld* cRoot::GetWorld( const char* a_WorldName ) +{ + WorldMap::iterator itr = m_pState->WorldsByName.find( a_WorldName ); + if( itr != m_pState->WorldsByName.end() ) + return itr->second; + return 0; +} + +void cRoot::TickWorlds( float a_Dt ) +{ + for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr ) + { + itr->second->Tick( a_Dt ); + } +} + void cRoot::ServerCommand( const char* a_Cmd ) { //LOG("Command: %s", a_Cmd ); -- cgit v1.2.3