📄 masterserver.cpp
字号:
break;
case 'U':
ServerInfoManager::Instance()->Clear();
m_pAccountDBProxySession->SendReqServerInfo();
break;
}
}
return TRUE;
}
VOID MasterServer::ConnectToServer( NetworkObject *pNetworkObject, char *pszIP, WORD wPort )
{
m_pIOCPServer->Connect( IOHANDLER_KEY, pNetworkObject, pszIP, wPort );
}
VOID MasterServer::UpdateFPS()
{
// FPS Check
static int cnt = 0;
static DWORD prevTick = GetTickCount();
cnt++;
DWORD curTick = GetTickCount();
if( prevTick + 1000 < curTick )
{
m_dwFPS = cnt;
//printf( "%d FPS\n", cnt );
prevTick = curTick;
cnt = 0;
if( m_dwFPS < 10 )
{
DISPMSG( "============================================================\n" );
DISPMSG( "============================================================\n" );
DISPMSG( "[MasterServer::UpdateFPS] FPS Warning!!! [%d] \n", m_dwFPS );
DISPMSG( "============================================================\n" );
DISPMSG( "============================================================\n" );
}
}
}
VOID MasterServer::DisplayServerInfo()
{
printf( "======== Master Server ========\n" );
printf( " Frame per Second: %d\n", m_dwFPS );
printf( " Total Connection: %d\n", m_pIOCPServer->GetNumberOfConnections( IOHANDLER_KEY ) );
if( !m_pAccountDBProxySession->IsConnected() )
{
printf( ">> Warning: Not connected to account DB proxy server.\n" );
}
if( !m_pOpServerSession->IsConnected() )
{
printf( ">> Warning: Not connected to operating server(RTTA).\n" );
}
}
BOOL MasterServer::IsConnectedTo( eSERVER_TYPE eServerType )
{
switch( eServerType )
{
case ACCOUNT_DBPROXY:
return m_pAccountDBProxySession->IsConnected();
}
assert( !"弊繁 辑滚 鸥涝篮 绝绢夸" );
return FALSE;
}
VOID MasterServer::SetMoney( SERVER_KEY serverkey, DWORD &dwGetMoney, DWORD &dwLoseMoney, DWORD &dwUserMoney )
{
SERVER_MONEY_INFO *pServer = m_pServerMoneyInfoTable->GetData( serverkey );
if(pServer == NULL)
{
// 绝栏搁 父甸绢
pServer = new SERVER_MONEY_INFO;
pServer->byWorldID = serverkey.GetWorldID();
pServer->byChannelID = serverkey.GetChannelID();
pServer->byServerType = serverkey.GetServerType();
pServer->byServerID = serverkey.GetServerID();
pServer->dwTotalGetMoney = dwGetMoney;
pServer->dwTotalLoseMoney = dwLoseMoney;
pServer->dwTotalUserMoney = dwUserMoney;
m_pServerMoneyInfoTable->Add( pServer, serverkey );
}
}
BOOL MasterServer::GetMoney( SERVER_KEY serverkey, DWORD &dwGetMoney, DWORD &dwLoseMoney, DWORD &dwUserMoney )
{
SERVER_MONEY_INFO *pServer = m_pServerMoneyInfoTable->GetData( serverkey );
if( pServer == NULL )
{
return FALSE;
}
dwGetMoney = pServer->dwTotalGetMoney;
dwLoseMoney = pServer->dwTotalLoseMoney;
dwUserMoney = pServer->dwTotalUserMoney;
return TRUE;
}
VOID MasterServer::RemoveMoney( SERVER_KEY serverkey )
{
SERVER_MONEY_INFO *pServer = m_pServerMoneyInfoTable->GetData( serverkey );
if( pServer == NULL )
{
return;
}
m_pServerMoneyInfoTable->Remove( serverkey );
}
DWORD MasterServer::GetMoneyInfoNum()
{
return m_pServerMoneyInfoTable->GetDataNum();
}
VOID MasterServer::SetMoneyInfoFirst()
{
m_pServerMoneyInfoTable->SetFirst();
}
SERVER_MONEY_INFO* MasterServer::GetMoneyInfoNext()
{
return m_pServerMoneyInfoTable->GetNext();
}
// 辆丰矫懦 辑滚 眠啊
BOOL MasterServer::AddExitServer( SERVER_KEY sServerKey )
{
SERVER_KEY *pServerKey = new SERVER_KEY;
pServerKey->dwKey = sServerKey.dwKey;
return m_pExitServerTable->Add( pServerKey, pServerKey->dwKey );
}
// 辆丰矫懦 辑滚 昏力
VOID MasterServer::RemoveExitServer( SERVER_KEY serverKey )
{
SERVER_KEY *pServerKey = m_pExitServerTable->GetData( serverKey.dwKey );
if( pServerKey )
{
m_pExitServerTable->Remove( serverKey.dwKey );
delete pServerKey;
MessageOut( eFULL_LOG, "RemoveExitServer - delete [%u/%u/%u/%u]", serverKey.GetWorldID(),
serverKey.GetChannelID(),
serverKey.GetServerType(),
serverKey.GetServerID() );
SetSendExit( FALSE ); // 促 焊陈促
return;
}
SetSendExit( FALSE ); // 促 焊陈促
MessageOut( eFULL_LOG, "RemoveExitServer [%u/%u/%u/%u]", serverKey.GetWorldID(),
serverKey.GetChannelID(),
serverKey.GetServerType(),
serverKey.GetServerID() );
}
BOOL MasterServer::CheckExitServer()
{
// 沥惑 辆丰 橇肺技胶吝牢瘤 犬牢茄促
if( !m_bExitServer )
{
return FALSE;
}
static DWORD dwLastTick = GetTickCount();
DWORD dwTickCount = GetTickCount();
if( m_bSendExit )
{
if( m_ExitTimer.IsExpired() )
{
// 10檬 捞惑 览翠 绝栏搁 辆丰 菩哦 坷幅
MessageOut( eCRITICAL_LOG, "ExitServer Error - [%u/%u/%u/%u] No Response", m_ExitServerKey.GetWorldID(),
m_ExitServerKey.GetChannelID(),
m_ExitServerKey.GetServerType(),
m_ExitServerKey.GetServerID() );
// 坷幅甫 舅妨林绊 促澜 辑滚肺 逞绢埃促
SERVER_KEY *pExitServerKey = m_pExitServerTable->GetHeadData();
if( pExitServerKey )
{
// 坷幅 傈价
MSG_MO_RTTG_SERVERSHUTDOWN_ANS sendMsg;
sendMsg.dwError = 1;
sendMsg.m_ServerKey = *pExitServerKey;
sendMsg.dwKey = GetExitKey();
ServerSession* pOpServer = ServerSessionManager::Instance()->GetOpServer();
if( !pOpServer )
{
MessageOut( eCRITICAL_LOG, "RTTA ServerShutDown TimeOut Error - No RTTA Server");
return FALSE;
}
pOpServer->Send( (BYTE*)&sendMsg, sizeof(MSG_MO_RTTG_SERVERSHUTDOWN_ANS) );
// 捞固 贸府茄 辑滚虐绰 昏力
m_pExitServerTable->Remove( pExitServerKey->dwKey );
delete pExitServerKey;
MessageOut( eFULL_LOG, "RTTA SERVERSHUTDOWN TimeOut Error Return" );
}
SetSendExit( FALSE );
dwLastTick = GetTickCount();
}
}
else
{
// 辆丰且 辑滚啊 抛捞喉俊 甸绢 乐绰瘤 犬牢
if( m_pExitServerTable->GetDataNum() > 0 )
{
// 菊俊 窍唱 瘤款促
util::SolarHashTable<SERVER_KEY *>::iterator iter = m_pExitServerTable->begin();
SERVER_KEY ExitServerKey = *(*iter);
ServerSession *pSession = ServerSessionManager::Instance()->FindServer( ExitServerKey );
if( !pSession )
{
//捞固 辆丰
m_pExitServerTable->erase( iter ); // 单捞磐父 瘤款促
if( 0 == m_pExitServerTable->GetDataNum() )
{
// 辆丰且 辑滚 促 辆丰 沁栏搁 场~
m_bExitServer = FALSE;
}
}
else // 辑滚 乐栏搁 辆丰
{
// DB Proxy 辑滚扼搁
if( pSession->GetServerType() == GAME_DBPROXY || ACCOUNT_DBPROXY )
{
// 促弗 辑滚 辆丰窍绰 矫埃 悼救 措扁窍扁 困秦 5檬 霖促
if( dwLastTick + 5000 > dwTickCount )
{
return FALSE;
}
dwLastTick = GetTickCount();
}
// 辑滚 鸥涝俊 蝶扼
MSG_SERVERCOMMON_SERVERSHUTDOWN_REQ sendMsg;
sendMsg.m_byCategory = 0;
sendMsg.m_byProtocol = SERVERCOMMON_SERVERSHUTDOWN_REQ;
pSession->Send( (BYTE*)&sendMsg, sizeof(MSG_SERVERCOMMON_SERVERSHUTDOWN_REQ) );
SetSendExit( TRUE ); // 辆丰 夸没 焊陈促!
MessageOut( eFULL_LOG, "Send ServerExit Message [%u/%u/%u/%u]", pSession->GetServerKey().GetWorldID(),
pSession->GetServerKey().GetChannelID(),
pSession->GetServerKey().GetServerType(),
pSession->GetServerKey().GetServerID() );
m_ExitTimer.Reset();
dwLastTick = GetTickCount();
}
}
else
{
m_bExitServer = FALSE;
// 促 场车促~
}
}
if( IsExitServer() && !IsSendExit() && m_pExitServerTable->GetDataNum() == 0 )
{
// 肯傈 辆丰 惑炔捞搁!
SetExitServer( FALSE );
// 辆丰登菌促绰 览翠阑 RTTA俊 焊辰促
MSG_MO_RTTG_SERVERSHUTDOWN_ANS sendMsg;
sendMsg.dwError = 0;
sendMsg.dwKey = GetExitKey();
ServerSession* pOpServer = ServerSessionManager::Instance()->GetOpServer();
if( !pOpServer )
{
MessageOut( eCRITICAL_LOG, "RTTA ServerShutDown_ACK Error - No RTTA Server");
return FALSE;
}
pOpServer->Send( (BYTE*)&sendMsg, sizeof(MSG_MO_RTTG_SERVERSHUTDOWN_ANS) );
MessageOut( eFULL_LOG, "RTTA SERVERSHUTDOWN_ACK Return" );
// 促 场车促~
SetExitServer( FALSE );
// 辑滚 傈眉 辆丰扼搁 磊扁 磊脚档 辆丰茄促
if( m_ExitServerKey.GetWorldID() == 0 )
{
return TRUE;
}
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -