📄 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();
ySWITCH(m_wServerType)
yCASE(TYPE_MS)
{
SetWindowText(GetActiveWindow(), "MS_20041008");
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)
{
SetWindowText(GetActiveWindow(), "MAS_20041008");
// 辑滚 沥焊 肺靛
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) == FALSE)
MessageBox(NULL,"DataBase 檬扁拳 角菩",0,0);
m_bInit = TRUE;
// IP 沥焊 历厘
TotalIpInfo( 0 );
}
yCASE(TYPE_RMS)
{
SetWindowText(GetActiveWindow(), "RMToolServer_20041014");
// 辑滚 沥焊 肺靛
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) == FALSE)
MessageBox(NULL,"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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -