#include "stdafx.h" #include #include "ManagerClient.h" ManagerClient::ManagerClient() { } ManagerClient::~ManagerClient() { } bool ManagerClient::AddClient( RTTAgent* client ) { m_listClient.push_back( client ); #ifdef _DEBUG OutputDebug("[ManagerClient::AddClient] %s(%d) \n", client->GetIPAddress(), m_listClient.size()); #endif return true; } void ManagerClient::RemoveClient( RTTAgent* client ) { for(ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; iter++ ) { if( *iter == client ) { m_listClient.erase( iter ); break; } } #ifdef _DEBUG OutputDebug("[ManagerClient::RemoveClient] %s(%d) \n", client->GetIPAddress(), m_listClient.size()); #endif } void ManagerClient::AddMasterServerIP(DWORD dwWorldID, char* pIP) { eXtreme::Guard < eXtreme::Mutex > lock( m_mutexMasterClient ); MapMasterClient::iterator iter = m_mapMasterClientIP.find(dwWorldID); if( iter == m_mapMasterClientIP.end() ) { char* szIP = new char[IP_MAX_LEN]; memset(szIP, 0, IP_MAX_LEN); strncpy(szIP, pIP, IP_MAX_LEN); szIP[IP_MAX_LEN-1] = '\0'; m_mapMasterClientIP.insert( MapMasterClient::value_type( dwWorldID, szIP ) ); OutputDebug("[ManagerClient::AddMasterServerIP] %d World(%s), Total %d IP(s)\n", dwWorldID, szIP, m_mapMasterClientIP.size()); } } void ManagerClient::MakeClientList( RTTAgent* list[], DWORD bufferSize, DWORD* listCount ) { *listCount = 0; for(ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; iter++ ) { if( *listCount >= bufferSize ) break; list[*listCount] = *iter; ( *listCount )++; } } RTTAgent* ManagerClient::FindClient( DWORD type ) { RTTAgent* client = NULL; for(ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; iter++ ) { client = *iter; if( ( client->GetContainType() & type ) == type ) return client; } return NULL; } RTTAgent* ManagerClient::FindClient( char* ipAddress ) { RTTAgent* client = NULL; for(ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; iter++ ) { client = *iter; if( strncmp( client->GetIPAddress(), ipAddress, IP_MAX_LEN ) == 0 ) return client; } return NULL; } RTTAgent* ManagerClient::FindClient( DWORD dwWorldID, DWORD dwChannelID, DWORD dwServerType, DWORD dwServerID ) { RTTAgent* pRTTAgent = NULL; for(ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; iter++ ) { pRTTAgent = *iter; if(pRTTAgent->m_worldID == (short)dwWorldID && pRTTAgent->m_channelID == (short)dwChannelID && pRTTAgent->m_serverType == (short)dwServerType && pRTTAgent->m_serverID == (short)dwServerID) { return pRTTAgent; } } return NULL; } void ManagerClient::Broadcast( char* buffer, int size ) { RTTAgent* client = NULL; for(ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; iter++ ) { client = *iter; client->SendPacket( buffer, size ); } } void ManagerClient::Broadcast( DWORD worldID, DWORD channelID, char* buffer, int size ) { RTTAgent* client = NULL; for(ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; iter++ ) { client = *iter; if( worldID == 0 || // Àüü World¿¡ º¸³½´Ù. // ÇØ´ç WorldÀÇ Àüü Channel¿¡ º¸³½´Ù. ( worldID != 0 && channelID == CHANNEL_ALL && client->m_worldID == (short)worldID ) || // World¿Í ChannelÀ» ÇÊÅ͸µÇÑ´Ù. ( worldID != 0 && channelID != CHANNEL_ALL && client->m_worldID == (short)worldID && client->m_channelID == (short)channelID ) ) { OutputDebug( "[RTTAgent Broadcast info] %d, %d, %d, %d, %s\n", client->m_worldID, client->m_channelID, client->m_serverType, client->m_serverID, client->GetIPAddress() ); client->SendPacket( buffer, size ); } } } void ManagerClient::Broadcast( DWORD worldID, DWORD channelID, DWORD serverType, DWORD serverID, char* buffer, int size ) { RTTAgent* client = NULL; bool bBroadCast = false; // broadcast ´ë»óÀÌ °Ë»öµÇ¾ú´ÂÁö ¿©ºÎ for(ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; iter++ ){ client = *iter; bBroadCast = false; if(worldID==0 || (short)worldID == client->m_worldID) // Àüü world ¶Ç´Â ƯÁ¤ world { if(channelID==CHANNEL_ALL || (short)channelID==client->m_channelID) // Àüü channel ¶Ç´Â ƯÁ¤ channel { if(serverType==0 || (short)serverType==client->m_serverType) // Àüü servertype ¶Ç´Â ƯÁ¤ servertype { if(serverID==0 || (short)serverID==client->m_serverID) // Àüü serverid ¶Ç´Â ƯÁ¤ serverid { bBroadCast = true; } } } } if(bBroadCast==true){ OutputDebug( "[RTTAgent Broadcast info] %d, %d, %d, %d, %s\n", client->m_worldID, client->m_channelID, client->m_serverType, client->m_serverID, client->GetIPAddress() ); client->SendPacket( buffer, size ); } } } bool ManagerClient::SendToMasterClient( MSG_HEADER8& packet, DWORD dwWorldID ) { RTTAgent* pMaster = NULL; bool IsSend = false; // ¿ùµå°¡ 0 À̰ųª ¸¶½ºÅÍ ¼­¹ö°¡ 1°³¸é ºê·Îµåij½ºÆ®, ¿ùµå°¡ 1 ÀÌ»óÀ̸鼭 ¸¶½ºÅͰ¡ 2°³ ÀÌ»óÀ̸é ÇØ´ç ¿ùµå¸¸... if( (0 != dwWorldID) && (1 < static_cast( m_mapMasterClientIP.size())) ) { for( ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; ++iter ) { pMaster = *iter; // ±Û·Î¹ú ¹öÀü ¸¶½ºÅ͸¸ 2°³Àε¥ ¼­¹ö ±¸¼º»ó ¸¶½ºÅÍÀÇ WorldID°¡ °ÔÀÓÀÇ WorldID¿Í µ¿ÀÏÇÏ¿© ¸¶½ºÅͰ¡ ¼³Ä¡µÈ RTTAgent¸¦ ãÀ»¶§ // WorldID±îÁö ºñ±³ÇÒ ¼ö ÀÖÀ¸³ª ÀÌ¿ÜÀÇ ¹öÀüÀº ´Ù¸¥ ¸Ó½Å¿¡ ¼³Ä¡µÇ¾î ¾Õ¼­ ¸»ÇÑ µÎ °³ÀÇ World°¡ µ¿ÀÏÇÏÁö ¾ÊÀ¸¹Ç·Î Çʵå Ãß°¡µîÀÇ // Ãß°¡ÀûÀÎ Á¶Ä¡¸¦ ÇØ¾ßÇÏÁö¸¸ °ÔÀÓÂʵµ °íÃľßÇϱ⠶§¹®¿¡ Çö½Ç»ó Èûµê. ±×·²¶© ±×³É ºê·Îµåij½ºÆ®...¤Ñ,.¤Ñ; // ¾Æ¹«Æ° ÀÌ·± 󸮵µ ÇöÀç´Â ±Û·Î¹ú Àü¿ëÀÌ°í ´Ù¸¥ ±¹°¡¿¡ ÀÌ·±½ÄÀ¸·Î ¸¶½ºÅÍ ¼­¹ö°¡ 2°³ ÀÌ»ó ¼³Ä¡µÇ´Â °æ¿ì °ÔÀÓÀÇ WOrldID¿Í // ¸¶½ºÅͼ­¹öÀÇ WorldID°¡ ´Ù¸¦ ¼ö ÀÖÀ¸¹Ç·Î ÀÌ ¶§´Â ÀÌ ·ÎÁ÷À» ¹Ù²Ù¾î¾ß ÇÔ if( ((short)dwWorldID == pMaster->m_worldID) && ( ( pMaster->GetContainType() & SERVERTYPE_MASTER ) == SERVERTYPE_MASTER ) ) { pMaster->SendMessage(packet); IsSend = true; break; } } } else { eXtreme::Guard < eXtreme::Mutex > lock( m_mutexMasterClient ); int SendCount = 0; for( ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; ++iter ) { pMaster = *iter; if( ( pMaster->GetContainType() & SERVERTYPE_MASTER ) == SERVERTYPE_MASTER ) { pMaster->SendMessage(packet); IsSend = true; SendCount++; OutputDebug( "[ManagerClient::SendToMasterClient::MSG_HEADER8&] Send To Master(%s)\n", pMaster->GetIPAddress() ); } } if( SendCount < static_cast( m_mapMasterClientIP.size() ) ) { OutputDebug( "[ManagerClient::SendToMasterClient::MSG_HEADER8&] Broadcast Failed\n"); OutputDebug( "[ManagerClient::SendToMasterClient::MSG_HEADER8&] Master IP List\n"); for( MapMasterClient::iterator iter = m_mapMasterClientIP.begin() ; iter != m_mapMasterClientIP.end() ; ++iter ) { OutputDebug( "[ManagerClient::SendToMasterClient::MSG_HEADER8&] %d, %s\n", (*iter).first, (*iter).second ); } } } return IsSend; } bool ManagerClient::SendToMasterClient( eXtreme::Stream& stream, DWORD dwWorldID ) { RTTAgent* pMaster = NULL; bool IsSend = false; // ¿ùµå°¡ 0 À̰ųª ¸¶½ºÅÍ ¼­¹ö°¡ 1°³¸é ºê·Îµåij½ºÆ®, ¿ùµå°¡ 1 ÀÌ»óÀ̸鼭 ¸¶½ºÅͰ¡ 2°³ ÀÌ»óÀ̸é ÇØ´ç ¿ùµå¸¸... if( (0 != dwWorldID) && (1 < static_cast( m_mapMasterClientIP.size())) ) { for( ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; ++iter ) { pMaster = *iter; // ±Û·Î¹ú ¹öÀü ¸¶½ºÅ͸¸ 2°³Àε¥ ¼­¹ö ±¸¼º»ó ¸¶½ºÅÍÀÇ WorldID°¡ °ÔÀÓÀÇ WorldID¿Í µ¿ÀÏÇÏ¿© ¸¶½ºÅͰ¡ ¼³Ä¡µÈ RTTAgent¸¦ ãÀ»¶§ // WorldID±îÁö ºñ±³ÇÒ ¼ö ÀÖÀ¸³ª ÀÌ¿ÜÀÇ ¹öÀüÀº ´Ù¸¥ ¸Ó½Å¿¡ ¼³Ä¡µÇ¾î ¾Õ¼­ ¸»ÇÑ µÎ °³ÀÇ World°¡ µ¿ÀÏÇÏÁö ¾ÊÀ¸¹Ç·Î Çʵå Ãß°¡µîÀÇ // Ãß°¡ÀûÀÎ Á¶Ä¡¸¦ ÇØ¾ßÇÏÁö¸¸ °ÔÀÓÂʵµ °íÃľßÇϱ⠶§¹®¿¡ Çö½Ç»ó Èûµê. ±×·²¶© ±×³É ºê·Îµåij½ºÆ®...¤Ñ,.¤Ñ; // ¾Æ¹«Æ° ÀÌ·± 󸮵µ ÇöÀç´Â ±Û·Î¹ú Àü¿ëÀÌ°í ´Ù¸¥ ±¹°¡¿¡ ÀÌ·±½ÄÀ¸·Î ¸¶½ºÅÍ ¼­¹ö°¡ 2°³ ÀÌ»ó ¼³Ä¡µÇ´Â °æ¿ì °ÔÀÓÀÇ WOrldID¿Í // ¸¶½ºÅͼ­¹öÀÇ WorldID°¡ ´Ù¸¦ ¼ö ÀÖÀ¸¹Ç·Î ÀÌ ¶§´Â ÀÌ ·ÎÁ÷À» ¹Ù²Ù¾î¾ß ÇÔ if( ((short)dwWorldID == pMaster->m_worldID) && ( ( pMaster->GetContainType() & SERVERTYPE_MASTER ) == SERVERTYPE_MASTER ) ) { pMaster->SendPacket(stream); IsSend = true; break; } } } else { eXtreme::Guard < eXtreme::Mutex > lock( m_mutexMasterClient ); int SendCount = 0; for( ListClient::iterator iter = m_listClient.begin() ; iter != m_listClient.end() ; ++iter ) { pMaster = *iter; if( ( pMaster->GetContainType() & SERVERTYPE_MASTER ) == SERVERTYPE_MASTER ) { pMaster->SendPacket(stream); IsSend = true; SendCount++; OutputDebug( "[ManagerClient::SendToMasterClient::eXtreme::Stream&] Send To Master(%s)\n", pMaster->GetIPAddress() ); } } if( SendCount < static_cast( m_mapMasterClientIP.size() ) ) { OutputDebug( "[ManagerClient::SendToMasterClient::eXtreme::Stream&] Broadcast Failed\n"); OutputDebug( "[ManagerClient::SendToMasterClient::eXtreme::Stream&] Master IP List\n"); for( MapMasterClient::iterator iter = m_mapMasterClientIP.begin() ; iter != m_mapMasterClientIP.end() ; ++iter ) { OutputDebug( "[ManagerClient::SendToMasterClient::eXtreme::Stream&] %d, %s\n", (*iter).first, (*iter).second ); } } } return IsSend; } /** Database¿Í ¿¬°áÀÌ ²÷±ä °æ¿ì ¸ðµç ¼ÒÄÏÀ» Á¤¸®¸¦ ÇØ¾ß ÇÑ´Ù. */ void ManagerClient::DisconnectAll() { ListClient::iterator iter; RTTAgent* client = NULL; while(!m_listClient.empty()) { iter = m_listClient.begin(); client = *iter; m_listClient.erase( iter ); client->SetKill(); } }