📄 rmproc.cpp
字号:
#include "stdafx.h"
#include "inetwork.h"
#include "RMTable.h"
#include "ServerTable.h"
#include "Proxy.h"
#include "DRServerManager.h"
#include "dr_agent_structures.h"
extern I4DyuchiNET* g_pINet;
extern CServerTable* g_pServerTable;
extern EchoBucket g_EchoBucket[ MAX_SERVER_NUM ]; //Echo 皋技瘤 罐阑 Bucket
extern DWORD g_dwEchoID;
void ForceLogoffUser( const char* szUserID ); // 030224 kyo
void ForceLogoffUserAllStart(); // BBD 040110
void ForceLogoffUserSeveral(); // BBD 040110
void AllowedAgentJoin(); // BBD 040110
inline void MgrSend(DWORD dwConnectionIndex, void* pMsg, DWORD dwLength)
{
//Modified by KBS 020330
g_pINet->SendToUser(dwConnectionIndex, (char*)pMsg, dwLength, FLAG_SEND_NOT_ENCRYPTION);
}
inline BOOL CheckValidConnectionIndex(DWORD dwConnectionIndex)
{
char szIp[20]; memset(szIp,0,20);
WORD wPort = 0;
g_pINet->GetServerAddress(dwConnectionIndex ,szIp,&wPort);
//Modified by KBS 020330
//g_pINet->GetUserAddress(dwConnectionIndex ,szIp,&wPort);
if(!strcmp(szIp,"") && !wPort)
return FALSE;
else
return TRUE;
}
void RMProc(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength)
{
BYTE header;
memcpy(&header,pMsg+1, 1);
static bool s_bKickOffState = false; // BBD 040110 疟坷橇 惑怕甫 RM俊辑 舅扁困秦辑
switch(header)
{
//--------------------------------------------------------------------------------------------
// Tool( Client ) Packet
//--------------------------------------------------------------------------------------------
case MSG_RM_LOGIN:
{
PACKET_RM_LOGIN *packet = (PACKET_RM_LOGIN*)pMsg;
if(g_pRMTable->CheckCertainIP(dwConnectionIndex, packet->IP))
{
//肺弊牢 铰牢 皋技瘤.. 磊脚捞 辑滚悸 逞滚客 窃膊..
PACKET_RM_LOGIN_OK pck(g_pServerTable->m_dwServerSetNumber);
MgrSend(dwConnectionIndex, &pck, pck.GetPacketSize());
}
else
{
//殿废等 IP啊 酒囱磊府俊辑 肺弊牢 茄 版快
PACKET_RM_LOGIN_FAIL pck;
MgrSend(dwConnectionIndex, &pck, pck.GetPacketSize());
}
g_pRMTable->AddClient(dwConnectionIndex, packet);
if(g_pRMTable->GetClientNum() == 1) //RMClient啊 窍唱扼档 立加等 惑怕搁 眉农 矫累!
{
StopWaitTimer();
StartEchoTimer(); //辑滚 促款灯唱 救灯唱 眉农 累诀 矫累
}
}
break;
case MSG_RM_REQUEST_ALL_SEBSERVER_INFO:
{
PACKET_REQUEST_ALL_SUBSERVER_INFO *packet = (PACKET_REQUEST_ALL_SUBSERVER_INFO*)pMsg;
WORD wServerNum = g_pServerTable->GetNumOfServers(); // 磊扁 磊脚(Proxy)甫 力寇茄 傈眉 Server 狼 荐.
int nSize = 1/*header*/ + 1 + 1 + 4 + 4 + 2/*num*/ + (sizeof(ServerStatusInfo) * wServerNum);
//1 + 1 + 1 + 4 + 2 +(Server沥焊甸).......
char *pPacket = new char[ nSize ];
int offset = 0;
pPacket[0] = MSG_RM_REPLY_ALL_SEBSERVER_INFO; //皋技瘤 庆歹
pPacket[1] = g_pServerTable->m_dwServerSetNumber; //辑滚 悸飘 逞滚
pPacket[2] = packet->bOpenTemplate; //捞 皋技瘤甫 罐疽阑锭 货肺款 辑滚 袍敲复阑 肺靛窍蠢衬 付蠢衬 咯何
memcpy(pPacket + 3, &packet->dwFrameID, sizeof(DWORD)); //皋技瘤甫 罐阑 FrameID
memcpy(pPacket + 7, &g_pServerTable->m_dwNumOfUsersInServerSet, sizeof(DWORD)); //Proxy辑滚俊 立加登绢乐绰 醚 蜡历荐
memcpy(pPacket + 11, &wServerNum, sizeof(WORD)); //捞 辑滚悸俊 拱妨乐绰 醚 辑滚肮荐
offset = 13;
LP_SERVER_DATA pServerData;
for( pServerData = g_pServerTable->m_pServerListHead; pServerData; pServerData = pServerData->pNextServerData )
{
ServerStatusInfo info;
info.wPort = pServerData->wPort; //器飘锅龋肺 备盒窍扁 困秦
info.dwStatus = pServerData->dwStatus; //辑滚 泅犁 惑怕
info.dwNumOfUsers = pServerData->dwNumOfUsers; //立加 蜡历荐
memcpy(pPacket + offset, &info, sizeof(info));
offset += sizeof(info);
//if( pServerData->wPort == wServerID )
//{
// return pServerData;
//}
}
MgrSend(dwConnectionIndex, pPacket, offset);
delete pPacket;
}
break;
case MSG_RM_REQUEST_ALL_LISTENER_INFO:
{
PACKET_REQUEST_ALL_LISTENER_INFO *packet = (PACKET_REQUEST_ALL_LISTENER_INFO*)pMsg;
WORD wListenerNum = g_pRMTable->m_ListenerTable.m_wConnect + g_pRMTable->m_ListenerTable.m_wNotConnect;
int nSize = 8 + (wListenerNum * 5);
DWORD ip;
char *pPacket = new char[ nSize ];
int offset = 0;
pPacket[0] = MSG_RM_REPLY_ALL_LISTENER_INFO; //皋技瘤 庆歹
pPacket[1] = g_pServerTable->m_dwServerSetNumber; //辑滚 悸飘 逞滚
memcpy(pPacket + 2, &packet->dwFrameID, 4); //皋技瘤甫 罐阑 FrameID
memcpy(pPacket + 6, &wListenerNum, 2); //府胶磐 肮荐
offset = 8;
RM_LISTENER_INFO* cur = NULL;
RM_LISTENER_INFO* next = NULL;
for(DWORD i=0; i<g_pRMTable->m_ListenerTable.m_dwMaxBucketNum; i++)
{
cur = g_pRMTable->m_ListenerTable.m_ppInfoTable[i];
while (cur)
{
next = cur->pNextInfo;
pPacket[ offset ] = i; //Listener啊 Proxy俊 立加 登绢乐唱 救登绢乐唱 咯何 1捞搁 立加 登乐绰巴 0捞搁 立加 救登绢乐绰巴
offset += 1;
ip = inet_addr(cur->szIP);
memcpy(pPacket + offset, &ip, 4);
offset += 4;
cur = next;
}
}
MgrSend(dwConnectionIndex, pPacket, offset);
delete pPacket;
}
break;
case MSG_RM_CHECK_LISTENER_CONNECTION:
{
PACKET_CHECK_LISTENER_CONNECTION *packet = (PACKET_CHECK_LISTENER_CONNECTION*)pMsg;
char ip[16]; memset(ip,0,16); int count = 0;
WORD port = 0;
DWORD dwTemp[ 30 ]; memset(dwTemp, 0, sizeof(dwTemp));
RM_LISTENER_INFO* cur = NULL;
RM_LISTENER_INFO* next = NULL;
cur = g_pRMTable->m_ListenerTable.m_ppInfoTable[ 1 ]; //1捞 立加 茄 惑怕捞聪...
while (cur)
{
next = cur->pNextInfo;
g_pINet->GetServerAddress(cur->dwConnectionIndex ,ip,&port);
if(!strcmp(ip,"") && !port)
{
for(int i=0; i<30; i++)
{
if(!dwTemp[i])
{
dwTemp[i] = cur->dwConnectionIndex;
count++;
break;
}
}
}
cur = next;
}
if(count > 0)
{
MyLog(LOG_NORMAL,"MSG_RM_CHECK_LISTENER_CONNECTION :: Pseudo index num %d",count);
}
PACKET_CHECK_LISTENER_CONNECTION_RESULT packet2(count);
MgrSend(dwConnectionIndex, &packet2, packet2.GetPacketSize());
}
break;
//瘤沥茄 辑滚肺 ShutDown 皋技瘤 朝覆 ..
case MSG_RM_SHUTDOWN_SERVER:
{
BYTE bCount = pMsg[2];
int offset = 3;
WORD wPort;
PACKET_SHUT_DOWN packet;
for(int i=0; i<bCount; i++)
{
memcpy(&wPort,pMsg+offset,2);
offset += 2;
LP_SERVER_DATA pServerData;
for( pServerData = g_pServerTable->m_pServerListHead; pServerData; pServerData = pServerData->pNextServerData )
{
if( pServerData->wPort == wPort )
{
g_pINet->SendToServer(pServerData->dwConnectionIndex ,
(char*)&packet, sizeof(packet),FLAG_SEND_NOT_ENCRYPTION);
break;
}
}
}
//g_pServerTable->DestroyServer( FINISH_TYPE_NORMAL );
}
break;
case MSG_RM_USER_ACCEPT_ALLOWED:
{
if ( g_pServerTable->ToggleUserAcceptAllowed() == true )
{
MyLog( LOG_NORMAL, "USER ACCEPT ALLOWED by RMTool" );
}
else
{
MyLog( LOG_NORMAL, "USER ACCEPT STOPED by RMTool" );
}
}
break;
case MSG_RM_SHUTDOWN_SUBSERVER:
{
PACKET_SHUTDOWN_SUBSERVER *rcvpacket = (PACKET_SHUTDOWN_SUBSERVER*)pMsg;
PACKET_SHUT_DOWN packet;
switch(rcvpacket->bServerType)
{
case 0: //Proxy
{
g_pServerTable->DestroyServer( FINISH_TYPE_NORMAL );
}
break;
case 1: //Agent
{
g_pServerTable->BroadCastAgentServer((char*)&packet,2);
}
break;
case 2: //DBDemon
{
g_pServerTable->BroadCastDBDemon((char*)&packet,2);
}
break;
case 3: //MAP
{
g_pServerTable->BroadCastMapServer((char*)&packet,2);
}
break;
}
}
break;
case MSG_RM_REBOOT_SERVER:
{
int num = pMsg[2];
int offset = 3;
DWORD dwIndex = 0;
WORD wPort;
for(int i=0; i<num; i++)
{
memcpy(&wPort, pMsg+offset, 2);
offset += 2;
dwIndex = g_pRMTable->GetListenerConnectionIndex(wPort);
if(!dwIndex) continue;
if(!CheckValidConnectionIndex(dwIndex))
{
//Added by KBS 020110
MyLog(LOG_NORMAL,"MSG_RM_REBOOT_SERVER :: Invalid Listener connection index(port: %d).", wPort);
break;
}
PACKET_LISTENER_SERVER_REBOOT packet;
g_pINet->SendToServer(dwIndex, (char*)&packet,packet.GetPacketSize(),FLAG_SEND_NOT_ENCRYPTION);
}
}
break;
case MSG_RM_CONNECT_ALL_LISTENER:
{
PACKET_CONNECT_ALL_LISTENER *packet = (PACKET_CONNECT_ALL_LISTENER*)pMsg;
g_pRMTable->ConnectAllDisconnectedListener();
MyLog( LOG_NORMAL, "Connected All Disconnect Listener by RMTool" );
PACKET_LISTENER_CONNECT_COMPLETE packet2(packet->dwFrameID);
MgrSend(dwConnectionIndex, &packet2, packet2.GetPacketSize());
}
break;
case MSG_RM_PROXY_CONTROL:
{
PACKET_RM_PROXY_CONTROL *packet = (PACKET_RM_PROXY_CONTROL*)pMsg;
g_pServerTable->m_bIsUserAcceptAllowed = packet->bUserAccept;
//User Accept Control
EnterCriticalSection( &g_pServerTable->m_IsUserAcceptAllowedCriticalSection );
g_pServerTable->m_bIsUserAcceptAllowed = packet->bUserAccept;
if( g_pServerTable->m_bIsUserAcceptAllowed == true )
MyLog( LOG_NORMAL, "USER ACCEPT ALLOWED BY RMTool" );
else
MyLog( LOG_NORMAL, "USER ACCEPT STOPED BY RMTool" );
LeaveCriticalSection( &g_pServerTable->m_IsUserAcceptAllowedCriticalSection );
//Max User Control
g_pProxy->dwMaxUser = packet->wMaxUser;
MyLog( LOG_NORMAL, "MAX USER ADJUST By RMTool: %d users can login this set.",g_pProxy->dwMaxUser);
//Try to Connect
g_pProxy->bLimitLoginTryPerSec = packet->bTryToConnect;
if (g_pProxy->bLimitLoginTryPerSec)
MyLog( LOG_NORMAL, "Login Try LIMIT BY RMTool: %d users can login per sec now.",g_pProxy->bLimitLoginTryPerSec);
else
MyLog( LOG_NORMAL, "Login Try UNLIMIT BY RMTool.");
}
break;
case MSG_RM_EXECUTE_SERVER:
{
BYTE count, filelen, servertype;;
WORD port;
DWORD dwIndex;
char szExeName[ MAX_PATH ]; memset(szExeName, 0, MAX_PATH);
memcpy(&filelen, pMsg+2, 1);
memcpy(szExeName, pMsg+3, filelen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -