📄 server.cpp
字号:
void SetCurrentDate()
{
SYSTEMTIME time;
GetLocalTime(&time);
g_wCurMonth = time.wMonth;
g_wCurDay = time.wDay;
}
//
//Added by KBS 011213
void StartEchoTimer() { g_pINet->ResumeTimer(4); }
void StopEchoTimer() { g_pINet->PauseTimer(4); }
void StartWaitTimer() { g_pINet->ResumeTimer(5); }
void StopWaitTimer() { g_pINet->PauseTimer(5); }
EchoBucket g_EchoBucket[ MAX_SERVER_NUM ]; //Echo 皋技瘤 罐阑 Bucket
DWORD g_dwEchoID = 0;
void __stdcall SendEcho(DWORD dwValue)//020511 lsw
{
g_dwEchoID++; //Echo ID 刘啊
memset(g_EchoBucket, 0, sizeof(EchoBucket)); //Bucket 檬扁拳
LP_SERVER_DATA pTargetServerData;
DWORD dwFailCounter = 0; int count=0;
for( pTargetServerData = g_pServerTable->m_pServerListHead; pTargetServerData; pTargetServerData = pTargetServerData->pNextServerData )
{
if( (pTargetServerData->dwConnectionIndex) && (pTargetServerData->dwStatus == STATUS_ACTIVATED) )
{
g_EchoBucket[ count ].bSended = 1;
g_EchoBucket[ count ].wPort = pTargetServerData->wPort;
PACKET_ECHO packet(count, pTargetServerData->wPort, g_dwEchoID);
if( !g_pINet->SendToServer( pTargetServerData->dwConnectionIndex,
(char*)&packet, packet.GetPacketSize(), FLAG_SEND_NOT_ENCRYPTION ) )
{
dwFailCounter++;
}
count++; //Bucket Index 刘啊
}
}
StartWaitTimer();
}
void __stdcall CheckEchoMessage(DWORD dwValue)//020511 lsw
{
StopWaitTimer();
DWORD dwShit = 0;
for(int i=0; i<MAX_SERVER_NUM ; i++)
{
if(g_EchoBucket[ i ].bSended && !g_EchoBucket[ i ].bReceived) //览翠 皋技瘤 给罐篮 辑滚.. Down 埃林!!
{
//咯扁辑 RMClient俊 舅覆 累诀
PACKET_DOWN_SERVER packet( g_pServerTable->m_dwServerSetNumber, g_EchoBucket[ i ].wPort);
g_pRMTable->BroadcastAllRMClient((char*)&packet, packet.GetPacketSize());
MyLog( LOG_NORMAL, " ");
MyLog( LOG_NORMAL, "Emergency!!!!! Down Server!!!! : %d", g_EchoBucket[ i ].wPort);
MyLog( LOG_NORMAL, " ");
}
}
}
//
bool StartProxyServer()
{
// 011012 KBS ; 泅犁 Day 悸泼
SetCurrentDate();
//
g_pProxy = new CProxy;
//Modified by KBS 011213
CUSTOM_EVENT ev[14];
ev[0].dwPeriodicTime = CONNECTION_CHECK_INTERVAL;
ev[0].pEventFunc = OrderToReportServerStatus;
ev[1].dwPeriodicTime = 300000; // 5盒
ev[1].pEventFunc = ReBalanceDBLoad;
ev[2].dwPeriodicTime = 1000; // 1盒
ev[2].pEventFunc = TimerForUserTable;
// 011012 KBS ; 朝楼 函版 眉农 Event 5盒
ev[3].dwPeriodicTime = 300000;
ev[3].pEventFunc = CheckDay;
//
//011213 KBS
ev[4].dwPeriodicTime = 60000; //1盒付促
ev[4].pEventFunc = SendEcho;
ev[5].dwPeriodicTime = 15000; //15檬 付促 Modified by KBS 020330
ev[5].pEventFunc = CheckEchoMessage;
//KBS
ev[6].dwPeriodicTime = 0;
ev[6].pEventFunc = ShowServerStatus;
ev[7].dwPeriodicTime = 0;
ev[7].pEventFunc = DestroyAllServers;
ev[8].dwPeriodicTime = 0;
ev[8].pEventFunc = ShowServerStatusDetail;
ev[9].dwPeriodicTime = 0;
ev[9].pEventFunc = ShowServerConnections;
ev[10].dwPeriodicTime = 0; // By Key
ev[10].pEventFunc = IncreseLimitUserLogin;
ev[11].dwPeriodicTime = 0; // By Key
ev[11].pEventFunc = DecreseLimitUserLogin;
ev[12].dwPeriodicTime = 0; // By Key
ev[12].pEventFunc = IncreseMaxUser;
ev[13].dwPeriodicTime = 0; // By Key
ev[13].pEventFunc = DecreseMaxUser;
/*
CUSTOM_EVENT ev[12];
ev[0].dwPeriodicTime = 0;
ev[0].pEventFunc = ShowServerStatus;
ev[1].dwPeriodicTime = 0;
ev[1].pEventFunc = DestroyAllServers;
ev[2].dwPeriodicTime = 0;
ev[2].pEventFunc = ShowServerStatusDetail;
ev[3].dwPeriodicTime = 0;
ev[3].pEventFunc = ShowServerConnections;
ev[4].dwPeriodicTime = CONNECTION_CHECK_INTERVAL;
ev[4].pEventFunc = OrderToReportServerStatus;
ev[5].dwPeriodicTime = 300000; // 5盒
ev[5].pEventFunc = ReBalanceDBLoad;
ev[6].dwPeriodicTime = 1000; // 1盒
ev[6].pEventFunc = TimerForUserTable;
ev[7].dwPeriodicTime = 0; // By Key
ev[7].pEventFunc = IncreseLimitUserLogin;
ev[8].dwPeriodicTime = 0; // By Key
ev[8].pEventFunc = DecreseLimitUserLogin;
ev[9].dwPeriodicTime = 0; // By Key
ev[9].pEventFunc = IncreseMaxUser;
ev[10].dwPeriodicTime = 0; // By Key
ev[10].pEventFunc = DecreseMaxUser;
// 011012 KBS ; 朝楼 函版 眉农 Event 5盒
ev[11].dwPeriodicTime = 300000;
ev[11].pEventFunc = CheckDay;
//
*/
DESC_NETWORK desc;
desc.OnAcceptServer = OnAcceptServer;
desc.OnAcceptUser = OnAcceptUser;
desc.OnDisconnectServer = OnDisconnectServer;
desc.OnDisconnectUser = OnDisconnectUser;
desc.dwMainMsgQueMaxBufferSize = 5120000;
desc.dwMaxServerNum = 120; //Modified at 020111
desc.dwMaxUserNum = 4000;
desc.dwServerBufferSizePerConnection = 256000;
desc.dwServerMaxTransferSize = 65000;
desc.dwUserBufferSizePerConnection = 65000;
desc.dwUserMaxTransferSize = 8192;
desc.OnRecvFromServerTCP = ReceivedMsgServer;
desc.OnRecvFromUserTCP = ReceivedMsgUser;
desc.dwCustomDefineEventNum = 14; // 011012 KBS ; Event 肮荐 14俺肺 函版
desc.pEvent = ev;
desc.dwConnectNumAtSameTime = 200; //Modified at 020111
// desc.dwFlag = NETDDSC_DEBUG_LOG;
// NETDDSC_DEBUG_LOG
HRESULT hr;
CoInitialize(NULL);
hr = CoCreateInstance(
CLSID_4DyuchiNET,
NULL,
CLSCTX_INPROC_SERVER,
IID_4DyuchiNET,
(void**)&g_pINet);
if (FAILED(hr))
{
MyLog( LOG_FATAL, "FAILED : NO DLL IN THAT SYSTEM");
return false;
}
// 蜡廉抛捞喉 积己 何盒.公矫窍磊.
g_pUserTable = new CUserTable(MAX_USER_NUM);
g_pServerTable = new CServerTable(PROXY_SERVER_INI_,MAX_SERVER_NUM,g_pINet);//021007 lsw
// 011106 KBS
g_pRMTable = new CRMTable( MAX_LISTENER_NUM );
g_pRMTable->GetCertainIPFromIni();
if( !g_pUserTable ) return false;
if( !g_pServerTable || !g_pServerTable->IsServerRunning() ) return false;
// added by slowboat 2001.2.28
g_pProxy->bLimitLoginTryPerSec = g_pServerTable->GetMaxUserNumPerSec();
g_pProxy->dwMaxUser = g_pServerTable->GetMaxUserNum();
MyLog( LOG_NORMAL, "CServerTable Initialized..." );
if (!g_pINet->CreateNetwork(&desc,10,10))
return false;
MyLog( LOG_NORMAL, "INetwork Initialized..." );
//Added KBS 011213
//StopWaitTimer(); // 040406 kyo
//StopEchoTimer(); // 040406 kyo
//
/*
g_pProxy->hKeyEvent[0] = g_pINet->GetCustomEventHandle(0);
g_pProxy->hKeyEvent[1] = g_pINet->GetCustomEventHandle(1);
g_pProxy->hKeyEvent[2] = g_pINet->GetCustomEventHandle(2);
g_pProxy->hKeyEvent[3] = g_pINet->GetCustomEventHandle(3);
g_pProxy->hKeyEvent[4] = g_pINet->GetCustomEventHandle(7);
g_pProxy->hKeyEvent[5] = g_pINet->GetCustomEventHandle(8);
g_pProxy->hKeyEvent[6] = g_pINet->GetCustomEventHandle(9);
g_pProxy->hKeyEvent[7] = g_pINet->GetCustomEventHandle(10);
*/
g_pProxy->hKeyEvent[0] = g_pINet->GetCustomEventHandle(6);
g_pProxy->hKeyEvent[1] = g_pINet->GetCustomEventHandle(7);
g_pProxy->hKeyEvent[2] = g_pINet->GetCustomEventHandle(8);
g_pProxy->hKeyEvent[3] = g_pINet->GetCustomEventHandle(9);
g_pProxy->hKeyEvent[4] = g_pINet->GetCustomEventHandle(10);
g_pProxy->hKeyEvent[5] = g_pINet->GetCustomEventHandle(11);
g_pProxy->hKeyEvent[6] = g_pINet->GetCustomEventHandle(12);
g_pProxy->hKeyEvent[7] = g_pINet->GetCustomEventHandle(13);
// batch connect to other server
MyLog( LOG_NORMAL, "Now Starting BatchConnect()...(It Takes some time)");
DWORD dwWorkingServers = g_pServerTable->BatchConnect();
g_pServerTable->SetServerStatus( STATUS_ACTIVATED );
return true;
}
void EndProxyServer()
{
if (g_pINet)
{
g_pINet->Release();
g_pINet = NULL;
}
if (g_pUserTable)
{
delete g_pUserTable;
g_pUserTable = NULL;
}
if (g_pServerTable)
{
delete g_pServerTable;
g_pServerTable = NULL;
}
delete g_pProxy;
g_pProxy = NULL;
// 011109 KBS : Free Listener Table
delete g_pRMTable;
g_pRMTable = NULL;
//
CoFreeUnusedLibraries();
CoUninitialize();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -