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/cServer.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source/cServer.cpp') diff --git a/source/cServer.cpp b/source/cServer.cpp index 8ea00a523..e6d475f46 100644 --- a/source/cServer.cpp +++ b/source/cServer.cpp @@ -48,6 +48,8 @@ extern "C" { bool g_bWaterPhysics = false; +typedef std::list< cClientHandle* > ClientList; + struct cServer::sServerState { sServerState() @@ -61,6 +63,8 @@ struct cServer::sServerState cThread* pListenThread; bool bStopListenThread; cThread* pTickThread; bool bStopTickThread; + ClientList Clients; + cEvent RestartEvent; std::string ServerID; }; @@ -230,14 +234,11 @@ cServer::~cServer() // TODO - Need to modify this or something, so it broadcasts to all worlds? And move this to cWorld? void cServer::Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude /* = 0 */ ) { - //m_World->LockClientHandle(); - cWorld* World = cRoot::Get()->GetWorld(); - for( cWorld::ClientList::iterator itr = World->GetClients().begin(); itr != World->GetClients().end(); ++itr) + for( ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end(); ++itr) { if( *itr == a_Exclude || !(*itr)->IsLoggedIn() ) continue; (*itr)->Send( a_Packet ); } - //m_World->UnlockClientHandle(); } // TODO - Need to move this to cWorld I think @@ -263,10 +264,7 @@ void cServer::StartListenClient() LOG("%s connected!", ClientIP); cClientHandle *NewHandle = new cClientHandle( SClient ); - cWorld* World = cRoot::Get()->GetWorld(); // TODO - I don't think the world cares for the client at this stage, besides for calling the tick function - World->LockClientHandle(); - World->AddClient( NewHandle ); - World->UnlockClientHandle(); + m_pState->Clients.push_back( NewHandle ); // TODO - lock list } } @@ -284,11 +282,11 @@ bool cServer::Tick(float a_Dt) m_Millisecondsf = m_Millisecondsf - (int)m_Millisecondsf; } - cWorld* World = cRoot::Get()->GetWorld(); // TODO - Iterate through all worlds, or give all worlds their own thread - World->Tick(a_Dt); - World->LockClientHandle(); - for( cWorld::ClientList::iterator itr = World->GetClients().begin(); itr != World->GetClients().end();) + cRoot::Get()->TickWorlds( a_Dt ); // TODO - Maybe give all worlds their own thread? + + //World->LockClientHandle(); // TODO - Lock client list + for( ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end();) { (*itr)->HandlePendingPackets(); @@ -297,13 +295,14 @@ bool cServer::Tick(float a_Dt) cClientHandle* RemoveMe = *itr; ++itr; - cRoot::Get()->GetWorld()->RemoveClient( RemoveMe ); + m_pState->Clients.remove( RemoveMe ); + delete RemoveMe; continue; } (*itr)->Tick(a_Dt); ++itr; } - World->UnlockClientHandle(); + //World->UnlockClientHandle(); cRoot::Get()->GetPluginManager()->Tick( a_Dt ); @@ -506,13 +505,14 @@ void cServer::Shutdown() cRoot::Get()->GetWorld()->SaveAllChunks(); - cWorld* World = cRoot::Get()->GetWorld(); - World->LockClientHandle(); - while( World->GetClients().begin() != World->GetClients().end() ) + //cWorld* World = cRoot::Get()->GetWorld(); + //World->LockClientHandle(); // TODO - Lock client list + for( ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end(); ++itr ) { - World->RemoveClient( *World->GetClients().begin() ); + delete *itr; } - World->UnlockClientHandle(); + m_pState->Clients.clear(); + //World->UnlockClientHandle(); } -- cgit v1.2.3