📄 mssystem.cpp
字号:
// MSSystem.cpp: implementation of the CMSSystem class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MSSystem.h"
#include "MonitorNetwork.h"
#include "MonitorServerTable.h"
#include "MSManager.h"
#include "MonitorUserTable.h"
#include "MASManager.h"
#include "DataBase.h"
#include "CMSDBMsgParser.h"
#include < winsock2.h >
#include "UserIPCheckMgr.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define AUTOPATCH "DarkStoryOnline" // ¿ÀÅäÆÐÄ¡CaptionÀ̸§
extern HWND gMainHwnd;
BOOL bAutoPatch = FALSE;
CMSSystem::CMSSystem()
{
m_wServerType = TYPE_NONE;
m_bInit = FALSE;
}
CMSSystem::~CMSSystem()
{
}
void CMSSystem::Start(WORD wServerType)
{
m_wServerType = wServerType;
DESC_NETWORK desc;
char host[128],ipName[2][20];
HOSTENT* hostent;
WSADATA wsaData ;
WSAStartup(0x0002,&wsaData);
gethostname(host,128);
hostent=gethostbyname(host);
//inet_ntoa ÇÔ¼ö´Â msdn¿¡¼ ã¾Æº¸±æ...
for(int n=0;n<2;++n)
{
if(hostent->h_addr_list[n] == NULL)
break;
strncpy(ipName[n],inet_ntoa(*(struct in_addr *)hostent->h_addr_list[n]),20);
}
WSACleanup();
char temp[256] = {0, };
ySWITCH(m_wServerType)
yCASE(TYPE_MS)
{
sprintf( temp, "MS_%s", SERVERTOOLVERSION );
SetWindowText(GetActiveWindow(), temp );
LOG( "MServerTable->LoadMonitorInfo()" );
// ¼¹ö Á¤º¸ ·Îµå
MServerTable->LoadMonitorInfo(TYPE_MS,ipName[0],ipName[1]);
LOG( "End MServerTable->LoadMonitorInfo()" );
CUSTOM_EVENT ev[1];
ev[0].dwPeriodicTime = 100;
ev[0].pEventFunc = CMSSystem::Process;
desc.OnAcceptServer = OnAcceptServer;
desc.OnDisconnectServer = OnDisconnectServer;
desc.OnAcceptUser = NULL;
desc.OnDisconnectUser = NULL;
desc.OnRecvFromServerTCP = ReceivedMsgFromServer;
desc.OnRecvFromUserTCP = NULL;
desc.dwCustomDefineEventNum = 1;
desc.pEvent = ev;
desc.dwMainMsgQueMaxBufferSize = 512000;
desc.dwMaxServerNum = 50;
desc.dwMaxUserNum = 0;
desc.dwServerBufferSizePerConnection = 25600;
desc.dwServerMaxTransferSize = 6500;
desc.dwUserBufferSizePerConnection = 0;
desc.dwUserMaxTransferSize = 0;
desc.dwConnectNumAtSameTime = 100;
desc.dwFlag = NULL;
MNETWORK->Init(&desc);
MNETWORK->ConnectToMAS();
}
yCASE(TYPE_MAS)
{
sprintf( temp, "MAS_%s", SERVERTOOLVERSION );
SetWindowText(GetActiveWindow(), temp );
// ¼¹ö Á¤º¸ ·Îµå
MServerTable->LoadMonitorInfo(TYPE_MAS,ipName[0],ipName[1]);
MASMGR->LoadMapServerInfo();
CUSTOM_EVENT ev[1];
ev[0].dwPeriodicTime = 100;
ev[0].pEventFunc = CMSSystem::Process;
desc.OnAcceptServer = OnAcceptServer;
desc.OnDisconnectServer = OnDisconnectServer;
desc.OnAcceptUser = OnAcceptUser;
desc.OnDisconnectUser = OnDisconnectUser;
desc.OnRecvFromServerTCP = ReceivedMsgFromServer;
desc.OnRecvFromUserTCP = ReceivedMsgFromUser;
desc.dwCustomDefineEventNum = 1;
desc.pEvent = ev;
desc.dwMainMsgQueMaxBufferSize = 5120000;
desc.dwMaxServerNum = 100;
desc.dwMaxUserNum = 50;
desc.dwServerBufferSizePerConnection = 256000;
desc.dwServerMaxTransferSize = 65000;
desc.dwUserBufferSizePerConnection = 256000;
desc.dwUserMaxTransferSize = 65000;
desc.dwConnectNumAtSameTime = 100;
desc.dwFlag = NULL;
MNETWORK->Init(&desc);
MNETWORK->StartServer(m_wServerType);
if(g_DB.Init(1, 10, TRUE) == FALSE)
MessageBox(NULL,"Fail To DataBase",0,0);
m_bInit = TRUE;
// IP Á¤º¸ ÀúÀå
TotalIpInfo( 0 );
}
yCASE(TYPE_RMS)
{
sprintf( temp, "RMToolServer_%s", RMTOOLVERSION );
SetWindowText(GetActiveWindow(), temp );
// ¼¹ö Á¤º¸ ·Îµå
MServerTable->LoadMonitorInfo(TYPE_MAS,ipName[0],ipName[1]);
CUSTOM_EVENT ev[1];
ev[0].dwPeriodicTime = 100;
ev[0].pEventFunc = CMSSystem::Process;
desc.OnAcceptServer = NULL;
desc.OnDisconnectServer = NULL;
desc.OnAcceptUser = OnAcceptUser;
desc.OnDisconnectUser = OnDisconnectUser;
desc.OnRecvFromServerTCP = NULL;
desc.OnRecvFromUserTCP = ReceivedMsgFromRMTool;
desc.dwCustomDefineEventNum = 1;
desc.pEvent = ev;
desc.dwMainMsgQueMaxBufferSize = 5120000;
desc.dwMaxServerNum = 0;
desc.dwMaxUserNum = 50;
desc.dwServerBufferSizePerConnection = 0;
desc.dwServerMaxTransferSize = 0;
desc.dwUserBufferSizePerConnection = 256000;
desc.dwUserMaxTransferSize = 65000;
desc.dwConnectNumAtSameTime = 100;
desc.dwFlag = NULL;
MNETWORK->Init(&desc);
MNETWORK->StartServer(m_wServerType);
if(g_DB.Init(1, 10, TRUE) == FALSE)
MessageBox(NULL,"Fail To DataBase",0,0);
m_bInit = TRUE;
// IP Á¤º¸ ÀúÀå
TotalIpInfo( 0 );
}
yENDSWITCH
LOG( "Start() End" );
}
void CMSSystem::End()
{
m_bInit = FALSE;
g_DB.Release();
MNETWORK->Release();
CoFreeUnusedLibraries();
}
void CMSSystem::Process()
{
ySWITCH(g_pMSSystem->m_wServerType)
yCASE(TYPE_MS)
{
DWORD tick = GetTickCount();
MServerTable->SetPositionHeadInfo();
MSERVERINFO * pInfo = NULL;
while(pInfo = MServerTable->GetDataInfo())
{
if(pInfo->wServerType != MONITOR_AGENT_SERVER && pInfo->wServerState == SERVERSTATE_ON)
{
// ASSERT(pInfo->wServerState != SERVERSTATE_OFF);
if( tick - pInfo->dwExpiredTime > 10000)
{
// ping send
MSGROOT msg;
msg.Category = MP_MORNITORMAPSERVER;
msg.Protocol = MP_MORNITORMAPSERVER_PING_SYN;
MNETWORK->SendToMapServer(pInfo->dwConnectionIndex, (char *)&msg, sizeof(MSGROOT));
}
if( tick - pInfo->dwExpiredTime > 60000)
{
MSMGR->SendServerState(SERVERSTATE_ABNORMAL, pInfo);
}
}
}
if( bAutoPatch )
AutoPatchProcess();
}
yCASE(TYPE_MAS)
{
if( g_pMSSystem->m_bInit )
g_DB.ProcessingDBMessage();
}
yCASE(TYPE_RMS)
{
if( g_pMSSystem->m_bInit )
g_DB.ProcessingDBMessage();
}
yENDSWITCH
}
void CMSSystem::AutoPatchProcess()
{
static BOOL bStart = FALSE;
static DWORD oldtick = 0;
DWORD tick = GetTickCount();
if( (tick - oldtick) > 1000 )
{
oldtick = tick;
HWND hWnd = FindWindow( NULL, AUTOPATCH );
if( bStart == FALSE ) // óÀ½
{
if( hWnd )
{
// SendStartAutoPatch;
MSGMSSTATE Msg;
Msg.Category = MP_MORNITORSERVER;
Msg.Protocol = MP_MORNITORSERVER_CHECK_AUTOPATCH_ACK;
MSERVERINFO* pInfo = MServerTable->GetMSInfo();
strcpy( Msg.MSState.sServerIP, pInfo->szIPForServer );
Msg.MSState.wServerPort = pInfo->wPortForServer;
Msg.MSState.wAutoPatchState = AUTOPATCHSTATE_START;
strcpy( Msg.MSState.sAutoPatchVersion, MSMGR->GetAutoPatchVersion() );
MNETWORK->SendToMAS( (char*)&Msg, sizeof(Msg) );
bStart = TRUE;
}
}
else if( bStart == TRUE )
{
if( hWnd )
{
// SendProcessAutoPatch; // ÁøÇà
MSGMSSTATE Msg;
Msg.Category = MP_MORNITORSERVER;
Msg.Protocol = MP_MORNITORSERVER_CHECK_AUTOPATCH_ACK;
MSERVERINFO* pInfo = MServerTable->GetMSInfo();
strcpy( Msg.MSState.sServerIP, pInfo->szIPForServer );
Msg.MSState.wServerPort = pInfo->wPortForServer;
Msg.MSState.wAutoPatchState = AUTOPATCHSTATE_PROC;
strcpy( Msg.MSState.sAutoPatchVersion, MSMGR->GetAutoPatchVersion() );
MNETWORK->SendToMAS( (char*)&Msg, sizeof(Msg) );
}
else
{
// SendEndAutoPatch; // ³¡
MSGMSSTATE Msg;
Msg.Category = MP_MORNITORSERVER;
Msg.Protocol = MP_MORNITORSERVER_CHECK_AUTOPATCH_ACK;
MSERVERINFO* pInfo = MServerTable->GetMSInfo();
strcpy( Msg.MSState.sServerIP, pInfo->szIPForServer );
Msg.MSState.wServerPort = pInfo->wPortForServer;
Msg.MSState.wAutoPatchState = AUTOPATCHSTATE_END;
MSMGR->ReadAutoPatchVersion();
strcpy( Msg.MSState.sAutoPatchVersion, MSMGR->GetAutoPatchVersion() );
MNETWORK->SendToMAS( (char*)&Msg, sizeof(Msg) );
bStart = FALSE;
bAutoPatch = FALSE;
}
}
}
}
void CMSSystem::OnConnectMASSuccess(DWORD dwConnectionIndex, void* pVoid)
{
MSERVERINFO * pInfo = (MSERVERINFO * )pVoid;
pInfo->dwConnectionIndex = dwConnectionIndex;
ySWITCH(g_pMSSystem->m_wServerType)
yCASE(TYPE_MS)
LogConsole("MAPÁ¢¼Ó¼º°ø");
MSMGR->SendMSInfo();
MNETWORK->StartServer(TYPE_MS);
yCASE(TYPE_MAS)
ASSERT(0);
yENDSWITCH
}
void CMSSystem::OnConnectMASFail(void* pVoid)
{
ASSERTMSG(0, "MAS¸¦ ¸ÕÀú ½ÇÇàÇϼ¼¿ä!");
ySWITCH(g_pMSSystem->m_wServerType)
yCASE(TYPE_MS)
yCASE(TYPE_MAS)
ASSERT(0);
yENDSWITCH
}
void CMSSystem::OnAcceptServer(DWORD dwConnectionIndex)
{
ySWITCH(g_pMSSystem->m_wServerType)
yCASE(TYPE_MS)
// map server Á¢¼ÓÇØ µé¾î¿È
LogConsole("MAPÁ¢¼Ó");
yCASE(TYPE_MAS)
// ms server Á¢¼ÓÇØ µé¾î¿È
LogConsole("MSÁ¢¼Ó");
yENDSWITCH
}
void CMSSystem::OnDisconnectServer(DWORD dwConnectionIndex)
{
ySWITCH(g_pMSSystem->m_wServerType)
yCASE(TYPE_MS)
MSERVERINFO* pInfo = MServerTable->GetServerInfoForConn(dwConnectionIndex);
if(pInfo == NULL) // MONITOR_AGENT_SERVER
{
LogConsole("MAS²÷¾îÁü");
::SendMessage(gMainHwnd,WM_CLOSE,0,0);
return;
}
switch(pInfo->wServerType)
{
case MAP_SERVER:
case AGENT_SERVER:
case DISTRIBUTE_SERVER:
{
LogConsole("MAP²÷¾îÁü");
// map server ²÷¾îÁü
// 1. ¼¹ö Å×ÀÌºí¿¡¼ »èÁ¦
// 2. mas¿¡°Ô »óÅ ¾Ë¸²
MSMGR->SendServerState(SERVERSTATE_OFF, MServerTable->GetServerInfoForConn(dwConnectionIndex));
MSMGR->ServerUnRegiest(dwConnectionIndex);
}
return;
}
LogConsole("ºñÁ¤»ó ²÷¾îÁü");
yCASE(TYPE_MAS)
// ms server ²÷¾îÁü
// »óÅ ÃʱâÈ
LogConsole("MS²÷¾îÁü");
MASMGR->SetStateInitForConn(dwConnectionIndex);
MServerTable->RemoveServerForConn( dwConnectionIndex );
MASMGR->SendServerStateAllToMCAll();
MASMGR->SendMSServerStateAllToMCAll();
yENDSWITCH
}
// In case of MS
// from mapserver
// from mas
// ¸Ê¼¹öÁ¤º¸¸¦ ¾Ë¾Æ¾ß ÇÑ´Ù.
void CMSSystem::ReceivedMsgFrom2Server(DWORD dwConnectionIndex,char* pmsg,DWORD dwLength)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -