#include "stdafx.h" #include "ServerSessionManager.h" #include #include #include "SolarAuthServerSession.h" typedef util::PoolRouter SERVER_SESSION_ROUTER; static struct sServerSessionManagerInternal { ServerSessionManager* m_ServerSessionManager; SERVER_SESSION_ROUTER* m_pPoolRouter; } s_ServerSessionManagerInternal = { NULL, }; ServerSessionManager::ServerSessionManager() { s_ServerSessionManagerInternal.m_pPoolRouter = new SERVER_SESSION_ROUTER; sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; SERVER_SESSION_ROUTER& rRouter = *rINTERNAL.m_pPoolRouter; //rRouter.Register rRouter.Register(AGENT_SERVER); rRouter.Register(FIELD_SERVER); rRouter.Register(BATTLE_SERVER); rRouter.Register(GAME_DBPROXY); rRouter.Register(WORLD_SERVER); //rRouter.Register(MASTER_SERVER); rRouter.Register(GUILD_SERVER); rRouter.Register(ACCOUNT_DBPROXY); //rRouter.Register(OP_SERVER); rRouter.Register(TEMP_SERVER); //rRouter.Register(GAME_SERVER); #if !defined(_NA002635_GP_DP_PROTOCOL_UINIFICATION) rRouter.Register(PORTAL_SERVER); #endif rRouter.Register(SOLARAUTH_SERVER); rRouter.Initialize( AGENT_SERVER, 50, 10 ); rRouter.Initialize( FIELD_SERVER, 100, 10 ); rRouter.Initialize( BATTLE_SERVER, 200, 20 ); rRouter.Initialize( GAME_DBPROXY, 10, 2 ); rRouter.Initialize( WORLD_SERVER, 10, 2 ); rRouter.Initialize( GUILD_SERVER, 10, 2 ); rRouter.Initialize( ACCOUNT_DBPROXY, 1, 1 ); rRouter.Initialize( OP_SERVER, 1, 1 ); rRouter.Initialize( TEMP_SERVER, 200, 10 ); #if !defined(_NA002635_GP_DP_PROTOCOL_UINIFICATION) rRouter.Initialize( PORTAL_SERVER, 10, 2 ); #endif rRouter.Initialize( SOLARAUTH_SERVER, 1, 1 ); SolarAuthServerSessionCrypted::CreateCode(); } ServerSessionManager::~ServerSessionManager() { //m_ServerTree ´Â ¾Ë¾Æ¼­ Á¦°ÅµÉ °ÍÀÌ´Ù. // (CHANGES)(20100312)(hukim) m_pPoolRouter¸¦ »ý¼ºÀÚ¿¡¼­ »ý¼ºÇϰí ÀÖÀ¸¹Ç·Î ¼Ò¸ê ½ÃÁ¡Àº ¼Ò¸êÀÚ°¡ // µÈ´Ù. m_ServerSessionManager´Â CreateInstance()¿¡¼­ »ý¼ºÇϰí DestroyInstance()¿¡¼­ ¼Ò¸êµÈ´Ù. SERVER_SESSION_ROUTER*& session_router = s_ServerSessionManagerInternal.m_pPoolRouter; SAFE_DELETE(session_router); } BOOL ServerSessionManager::CreateInstance() { sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; ServerSessionManager*& rManager = rINTERNAL.m_ServerSessionManager; if( rManager == NULL ) rManager = new ServerSessionManager(); return TRUE; } BOOL ServerSessionManager::DestroyInstance() { sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; ServerSessionManager*& rManager = rINTERNAL.m_ServerSessionManager; SAFE_DELETE( rManager ); return TRUE; } //==================================================================================== // // ServerSession* ServerSessionManager::AllocNewSession( eSERVER_TYPE serverType ) { sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; SERVER_SESSION_ROUTER& rRouter = *rINTERNAL.m_pPoolRouter; ServerSession* pSession = (ServerSession*)rRouter.Alloc( serverType ); return pSession; } BOOL ServerSessionManager::FreeSession( ServerSession* pSession ) { eSERVER_TYPE serverType = pSession->GetServerType(); sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; SERVER_SESSION_ROUTER& rRouter = *rINTERNAL.m_pPoolRouter; return rRouter.Free( (DWORD)serverType, pSession ); } // //==================================================================================== BOOL ServerSessionManager::AddServer( ServerSessionEx* pServer ) { sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; ServerSessionManager*& rManager = rINTERNAL.m_ServerSessionManager; ServerTreeNODE& rTREE = rManager->m_ServerTree; SERVER_KEY skServerKey = pServer->GetServerKey(); ServerSessionEx* pFindSession = rManager->FindServer( skServerKey ); if( pFindSession != NULL ) { SERVER_KEY& rServerKey = pServer->GetServerKey(); MessageOut( eCRITICAL_LOG, _T("Warning: ¼­¹öŰ Áߺ¹(%u/%u/%u/%u)À̹ǷΠ¿¬°áÀ» ²÷½À´Ï´Ù. DB ServerInfo Å×À̺í Á¤º¸¸¦ È®ÀÎÇϼ¼¿ä."), rServerKey.GetWorldID(), rServerKey.GetChannelID(), rServerKey.GetServerType(), rServerKey.GetServerID() ); // // ÀÌ ·çƾÀÌ ¿©±â À־ ¹®Á¦°¡ ¾ø´Â°¡? pServer->Disconnect(); return FALSE; } eSERVER_TYPE stType = pServer->GetServerType(); sSERVER_NODE node; node.m_ServerType = stType; node.m_ServerKey = skServerKey; node.m_pServerSession = pServer; rTREE.AddServer( skServerKey, &node ); __WAVERIX_SOLAR_AUTH_DEBUG_CODE( printf( "[AddServer] ServerType[%d] \n", pServer->GetServerType() ); ); //------------------------------------------------------------------------------------ // ´ÙÀ½ ·çƾÀº OP_SERVER¿¡ Ãß°¡ ¿¬°áµÈ ¼­¹ö¿¡ ´ëÇÑ Á¤º¸¸¦ º¸³»´Â ·çƾÀÌ´Ù. // 1) Ãß°¡µÇ´Â ¼­¹ö°¡ OP_SERVERÀÎ °æ¿ì¸¦ Á¦¿ÜÇϰí, // 2) OP_SERVER°¡ ¿¬°áµÈ »óÅ¿¡¼­ // 3) OP_SERVER¿¡ ÇöÀç Ãß°¡ ¿¬°áµÈ ¼­¹ö¿¡ ´ëÇÑ Á¤º¸¸¦ º¸³½´Ù. if( OP_SERVER == stType ) return TRUE; MasterServerEx* pMasterServer = MasterServerEx::GetMainFrame(); OpServerSession* pOpServer = pMasterServer->ConnectSessions.SessionOpServer(); if( pOpServer && pOpServer->IsConnected() ) { #ifdef __WAVERIX_SOLAR_AUTH_SERVER_IMPLEMENTATION__ MSG_MO_RTTG_ALL_SERVER_STATUS_NTF* pMsgNTF = new (PACKET_CONTROL_SM::GetBasePacketPtr4Send()) MSG_MO_RTTG_ALL_SERVER_STATUS_NTF; #else MSG_MO_RTTG_ALL_SERVER_STATUS_NTF pMsgNTF[1]; #endif //__WAVERIX_SOLAR_AUTH_SERVER_IMPLEMENTATION__ pMsgNTF->m_Count = 1; MSG_MO_RTTG_ALL_SERVER_STATUS_NTF::ServerConnectInfo& rConnectInfo = pMsgNTF->m_ServerConnectInfo[0]; SERVER_KEY skOldServerKey = SWAP_32BIT_DATATYPE((DWORD)skServerKey); rConnectInfo.m_ServerKey = skOldServerKey; rConnectInfo.m_bConnected = (BYTE)TRUE; pOpServer->Send( (BYTE*)pMsgNTF, (WORD)pMsgNTF->GetSize() ); } return TRUE; } VOID ServerSessionManager::RemoveServer( SERVER_KEY skServerKey ) { sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; ServerSessionManager*& rManager = rINTERNAL.m_ServerSessionManager; ServerTreeNODE& rTREE = rManager->m_ServerTree; sSERVER_NODE* pNODE = rTREE.FindServer( skServerKey ); if( !(pNODE && pNODE->m_pServerSession) ) { //MessageOut( eCRITICAL_LOG, // _T("À߸øµÈ ¼­¹öŰÀ̰ųª ¼­¹ö °ü¸® µ¿±âÈ­°¡ ±úÁ³À» °¡´É¼º Á¸Àç ¼­¹öŰ [%u:%u:%u:%u]"), // skServerKey.GetWorldID(), skServerKey.GetChannelID(), skServerKey.GetServerType(), skServerKey.GetServerID() // ); return; } ServerSessionEx* pSession = pNODE->m_pServerSession; //¹é¾÷¿ë rTREE.RemoveServer( skServerKey ); //------------------------------------------------------------------------------------------------ // TempServerSessionÀº ¸Å´ÏÁ®¿¡ Ãß°¡µÇÁö ¾Ê´Â´Ù.(½ÇÁ¦ »ç¿ëµÉ ¼¼¼ÇÀ¸·Î RedirectµÈ ÈÄ¿¡ Ãß°¡µÊ) // ±×·¯´Ï±î TempServerSesssion::OnDisconnect¿¡¼­ ÀÌ ÇÔ¼ö¸¦ È£ÃâÇØµµ ¹«½ÃÇÏÀÚ. //------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ // ´ÙÀ½ ·çƾÀº OP_SERVER¿¡ ¼­¹ö ¿¬°áÀÌ ²÷¾îÁø °æ¿ì¿¡ ´ëÇÑ Á¤º¸¸¦ º¸³»´Â ·çƾÀÌ´Ù. // 1) Ãß°¡µÇ´Â ¼­¹ö°¡ OP_SERVERÀÎ °æ¿ì¸¦ Á¦¿ÜÇϰí, // 2) GAME_SERVERÀÇ °æ¿ì´Â Money°ü·Ã Á¤º¸¸¦ Á¦°ÅÇϸç, // 3) OP_SERVER°¡ ¿¬°áµÈ »óÅ¿¡¼­ // 4) OP_SERVER¿¡ ÇöÀç ¿¬°áÀÌ ²÷¾îÁø ¼­¹ö¿¡ ´ëÇÑ Á¤º¸¸¦ º¸³½´Ù. eSERVER_TYPE stType = pSession->GetServerType(); if( OP_SERVER == stType ) return; //const DWORD bitMask = (DWORD)( (1<ConnectSessions.SessionOpServer(); if( pOpServer && pOpServer->IsConnected() ) { #ifdef __WAVERIX_SOLAR_AUTH_SERVER_IMPLEMENTATION__ MSG_MO_RTTG_ALL_SERVER_STATUS_NTF* pMsgNTF = new (PACKET_CONTROL_SM::GetBasePacketPtr4Send()) MSG_MO_RTTG_ALL_SERVER_STATUS_NTF; #else MSG_MO_RTTG_ALL_SERVER_STATUS_NTF pMsgNTF[1]; #endif __WAVERIX_SOLAR_AUTH_SERVER_IMPLEMENTATION__ pMsgNTF->m_Count = 1; MSG_MO_RTTG_ALL_SERVER_STATUS_NTF::ServerConnectInfo& rConnectInfo = pMsgNTF->m_ServerConnectInfo[0]; SERVER_KEY skOldServerKey = SWAP_32BIT_DATATYPE((DWORD)skServerKey); rConnectInfo.m_ServerKey = skOldServerKey; rConnectInfo.m_bConnected = (BYTE)FALSE; pOpServer->Send( (BYTE*)pMsgNTF, (WORD)pMsgNTF->GetSize() ); } } ServerSessionEx* ServerSessionManager::FindServer( SERVER_KEY skServerKey ) { sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; ServerSessionManager*& rManager = rINTERNAL.m_ServerSessionManager; ServerTreeNODE& rTREE = rManager->m_ServerTree; sSERVER_NODE* pNode = rTREE.FindServer( skServerKey ); if( pNode ) return pNode->m_pServerSession; return NULL; } // ƯÁ¤ ¼­¹öŸÀԵ鿡 ´ëÇØ ¾î¶°ÇÑ Ã³¸®¸¦ ¼öÇàÅä·Ï ÇÏ´Â ±â´ÉÀÌ ÀÖ¾î¾ß ÇÑ´Ù. // ¾Æ´Ï¸é ƯÁ¤ ±×·ì VOID ServerSessionManager::GetWorldServerList( sPTR_SERVER_NODE_ARRAY* OUT pServerList ) { const DWORD bitMask = (DWORD)(1<m_ServerTree; rTREE.GetPtrList( bitMask, pServerList ); } VOID ServerSessionManager::GetAgentServerList( sPTR_SERVER_NODE_ARRAY* OUT pServerList ) { const DWORD bitMask = (DWORD)(1<m_ServerTree; rTREE.GetPtrList( bitMask, pServerList ); } VOID ServerSessionManager::GetGameServerList( sPTR_SERVER_NODE_ARRAY* OUT pServerList ) { const DWORD bitMask = (DWORD)( (1<m_ServerTree; rTREE.GetPtrList( bitMask, pServerList ); } VOID ServerSessionManager::GetGameDBProxyList( sPTR_SERVER_NODE_ARRAY* OUT pServerList ) { const DWORD bitMask = (DWORD)(1<m_ServerTree; rTREE.GetPtrList( bitMask, pServerList ); } ServerTreeNODE* ServerSessionManager::GetServerTree() { sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; ServerSessionManager*& rManager = rINTERNAL.m_ServerSessionManager; return &(rManager->m_ServerTree); } // ÇöÀç ¿¬°áµÈ °ÔÀÓ¼­¹öµé¿¡ ºê·Îµåij½ºÆÃ VOID ServerSessionManager::SendToGameServers( MSG_BASE* pMsg, WORD wSize ) { const DWORD bitMask = (DWORD)( (1<GetServerTree(); DWORD dwUpperBound; sSERVER_NODE* pNODEs = pTREE->GetServerArrayList( dwUpperBound ); sSERVER_NODE* pNODE = pNODEs; for( DWORD i=0 ; im_ServerType)) & bitMask ) { ServerSessionEx* pSession = pNODE->m_pServerSession; if( pSession ) { pSession->SendPacket( pMsg, wSize ); } } } } //VOID SendAllServerOnOffInfo( ServerSession *pOPServer ); //int AddExitServerList( SERVER_KEY serverKey ); // Á¾·áÇÒ ¼­¹ö ¼¼ÆÃ(¸®ÅϰªÀº AddµÈ ¼­¹ö °³¼ö) //inline ServerSession* GetOpServer() { return m_pOpServer; } //VOID SendGameServer( BYTE* pMsg, WORD wSize ); // °ÔÀÓ¼­¹öµé¿¡ ºê·Îµåij½ºÆÃ #ifdef __WAVERIX_SOLAR_AUTH_SERVER_IMPLEMENTATION__ #include #include VOID ServerSessionManager::SEND_PHASE_SHIFT_CMD( ServerSessionEx* pServerSession, ePHASE_SHIFT shiftCMD, ePHASE_SHIFT exceptedStatus ) { if( !pServerSession ) return; // ÀÌ ÇÔ¼ö´Â TempServerSession¿¡ Àû¿ëµÇÁö ¾Ê´Â´Ù. Services4Session& rSERVICE = pServerSession->Services(); if( rSERVICE.GetPhaseStatus() & exceptedStatus ) return; PacketHandlerShared::SEND_SERVERCOMMON_PHASESHIFT_CMD( pServerSession, shiftCMD ); } VOID ServerSessionManager::SEND_PHASE_SHIFT_CMD_BROADCAST( ePHASE_SHIFT shiftCMD, ePHASE_SHIFT exceptedStatus ) { // PHASE_SHIFT_CMD´Â °øÅë CATEGORY&PROTOCOL·Î Á¤ÇÏÀÚ sServerSessionManagerInternal& rINTERNAL = s_ServerSessionManagerInternal; ServerSessionManager*& rManager = rINTERNAL.m_ServerSessionManager; ServerTreeNODE& rTREE = rManager->m_ServerTree; DWORD dwUpperBound; sSERVER_NODE* pNODEs = rTREE.GetServerArrayList( dwUpperBound ); sSERVER_NODE* pNODE = pNODEs; for( DWORD i=0 ; im_ServerType ) continue; ServerSessionEx* pServerSession = pNODE->m_pServerSession; SEND_PHASE_SHIFT_CMD( pServerSession, shiftCMD, exceptedStatus ); } } #endif //__WAVERIX_SOLAR_AUTH_SERVER_IMPLEMENTATION__