255 lines
5.4 KiB
C++
255 lines
5.4 KiB
C++
#include "StdAfx.h"
|
|
#include "World.h"
|
|
#include "Channel.h"
|
|
#include "PacketStruct_SMA.h"
|
|
#include "ServerSession.h"
|
|
#include "ServerSessionManager.h"
|
|
#include "UnitServer.h"
|
|
|
|
|
|
World::World()
|
|
{
|
|
m_byWorldKey = 0;
|
|
|
|
m_ChannelHash.Initialize( DEFAULT_CHANNEL_POOL_SIZE );
|
|
|
|
m_pChannelPool = new CMemoryPoolFactory<Channel>;
|
|
m_pChannelPool->Initialize( DEFAULT_CHANNEL_POOL_SIZE, DEFAULT_CHANNEL_POOL_SIZE/2 );
|
|
}
|
|
|
|
World::~World()
|
|
{
|
|
SAFE_RELEASENDELETE( m_pChannelPool );
|
|
}
|
|
|
|
VOID World::Init( BYTE byWorldKey )
|
|
{
|
|
m_byWorldKey = byWorldKey;
|
|
}
|
|
|
|
VOID World::Release()
|
|
{
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
pChannel->Release();
|
|
}
|
|
m_ChannelHash.clear();
|
|
}
|
|
|
|
Channel* World::AllocChannel( BYTE byChannelKey )
|
|
{
|
|
Channel *pChannel = FindChannel( byChannelKey );
|
|
if( pChannel )
|
|
return pChannel;
|
|
|
|
pChannel = m_pChannelPool->Alloc();
|
|
|
|
pChannel->Init( m_byWorldKey, byChannelKey );
|
|
|
|
m_ChannelHash.Add( pChannel, byChannelKey );
|
|
|
|
return pChannel;
|
|
}
|
|
|
|
VOID World::FreeChannel( Channel *pChannel )
|
|
{
|
|
m_ChannelHash.Remove( pChannel->GetKey() );
|
|
m_pChannelPool->Free( pChannel );
|
|
}
|
|
|
|
UnitServer* World::FindUnitServer( DWORD dwAgentKey, BYTE byServerType )
|
|
{
|
|
UnitServer *pFindServer = NULL;
|
|
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
|
|
pFindServer = pChannel->FindUnitServerByAgent( dwAgentKey, (eGAME_SERVER_TYPE)byServerType );
|
|
if( pFindServer ) return pFindServer;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
#ifdef _NA_006543_20130318_HEARTBEAT
|
|
UnitServer* World::FindFirstUnitServerByAgentKey( DWORD dwAgentKey )
|
|
{
|
|
UnitServer *pFindServer = NULL;
|
|
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
|
|
pFindServer = pChannel->FindFirstUnitServerByAgentKey( dwAgentKey );
|
|
if( pFindServer ) return pFindServer;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
#endif
|
|
|
|
VOID World::ExecuteStart( DWORD dwUserKey )
|
|
{
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
pChannel->ExecuteStart( dwUserKey );
|
|
}
|
|
}
|
|
|
|
VOID World::ExecuteEnd( DWORD dwUserKey )
|
|
{
|
|
MSG_MO_RTTG_SERVERSHUTDOWN_REQ ReqMsg;
|
|
ReqMsg.dwKey = dwUserKey;
|
|
ReqMsg.m_byWorldID = m_byWorldKey; ReqMsg.m_byChannelID = 0xff;
|
|
ReqMsg.m_byServerType = 0; ReqMsg.m_byServerID = 0;
|
|
|
|
ServerSession *pMasterSession = ServerSessionManager::Instance()->FindMasterSession();
|
|
if( !pMasterSession )
|
|
{
|
|
DISPMSG( "[World::ExecuteEnd] pMasterSession is disconnected!\n" );
|
|
return;
|
|
}
|
|
|
|
pMasterSession->SendPacket( (BYTE*)&ReqMsg, sizeof(ReqMsg) );
|
|
}
|
|
|
|
BOOL World::ExecutePatch( DWORD dwUserKey )
|
|
{
|
|
// 월드단위에서 패치가 이루어 진다.
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
if( !pChannel->ExecutePatch( dwUserKey ) )
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
VOID World::SerializeServerInfoStream( SERVER_TOTAL_INFO & OUT rServerTotInfo )
|
|
{
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
pChannel->SerializeServerInfoStream( rServerTotInfo );
|
|
}
|
|
}
|
|
|
|
#ifdef __20080312__SOLARAUTH_SERVER_PATCH
|
|
VOID World::SerializeScriptFolderInfoStream( SCRIPTFOLDER_TOTAL_INFO& OUT rSCFolderTotInfo, DWORD dwUserGUID )
|
|
{
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
pChannel->SerializeScriptFolderInfoStream( rSCFolderTotInfo, dwUserGUID );
|
|
}
|
|
}
|
|
#endif
|
|
|
|
VOID World::SerializeServerInfoStreamForUser( SERVER_TOTAL_INFO & OUT rServerTotInfo, DWORD dwUserGUID )
|
|
{
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
pChannel->SerializeServerInfoStreamForUser( rServerTotInfo, dwUserGUID );
|
|
}
|
|
}
|
|
|
|
VOID World::SerializeFtpInfoStreamForUser( FTP_TOTAL_INFO & OUT rFtpTotInfo, DWORD dwUserGUID )
|
|
{
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
pChannel->SerializeFtpInfoStreamForUser( rFtpTotInfo, dwUserGUID );
|
|
}
|
|
}
|
|
|
|
VOID World::ExecuteForceDisconnect( DWORD dwUserKey )
|
|
{
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
pChannel->ExecuteForceDisconnect( dwUserKey );
|
|
}
|
|
}
|
|
|
|
VOID World::SetServerStatus( eSERVER_STATUS status )
|
|
{
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
pChannel->SetServerStatus( status );
|
|
}
|
|
}
|
|
|
|
// 해당월드내에 CheckStatus가 하나라도 있으면 TRUE리턴,
|
|
// 없으면 FALSE리턴
|
|
BOOL World::CheckServerStatus( eSERVER_STATUS CheckStatus )
|
|
{
|
|
Channel * pChannel = NULL;
|
|
for( CHANNEL_HASH_ITR it = m_ChannelHash.begin(); it != m_ChannelHash.end(); ++it )
|
|
{
|
|
pChannel = *it;
|
|
if( !pChannel->CheckServerStatus( CheckStatus ) )
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
BOOL World::CheckPatching()
|
|
{
|
|
UnitServer* pUnitServer = FindSunServer();
|
|
if( pUnitServer )
|
|
{
|
|
if( pUnitServer->GetServerStatus() == SERVER_STATUS_PATCHING )
|
|
return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
UnitServer* World::FindSunServer()
|
|
{
|
|
Channel * pChannel = FindChannel( 0 );
|
|
if( !pChannel ) return NULL;
|
|
return pChannel->FindUnitServer( SUN_SERVER, 1 );
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|