📄 recvmsgfromserver.cpp
字号:
// --------------------------------
// Re-Wrote by chan78 at 2001/01/10
// --------------------------------
#include "stdafx.h"//010909 lsw
#include "struct.h"
#include "monitor.h"
#include "servertable.h"
#include "usertable.h"
#include "RecvMsgFromServer.h"
#include "mylog.h"
#include "RecvMsgFromUser.h"
#include "AgentServer.h"
#include "dr_agent_structures.h"
#include <time.h>
#include "DrServerManager.h"
#include <mmsystem.h>
#include <stdlib.h>
char txt[128];
char szMsg[MAX_PACKET_SIZE];
// FOR DEBUG by chan78 2001/02/21
extern DWORD dwMapChangeCounter;
// 011205 KBS
extern void RMProc(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength);
// ==========================================================================================
void __stdcall OnAcceptServer(DWORD dwConnectionIndex)
{
SOCKADDR_IN* paddr = NULL;
paddr = g_pINet->GetServerAddress(dwConnectionIndex);
MyLog( LOG_NORMAL, "New Server-side Connection From [%d.%d.%d.%d] (Total:%d)", paddr->sin_addr.S_un.S_un_b.s_b1
, paddr->sin_addr.S_un.S_un_b.s_b2
, paddr->sin_addr.S_un.S_un_b.s_b3
, paddr->sin_addr.S_un.S_un_b.s_b4
, g_pServerTable->GetNumOfConnectedServers());
return;
}
// ==========================================================================================
// ==========================================================================================
void __stdcall OnDisconnectServer(DWORD dwConnectionIndex)
{
// 公瘤 吝夸茄 糕滚 窃荐
g_pServerTable->RemoveConnectedServerDataFromHashTable(dwConnectionIndex);
return;
}
// ==========================================================================================
// ==========================================================================================
void __stdcall RecvMsgFromServer( DWORD dwConnectionIndex, char *pMsg, DWORD dwLength )
{
BYTE bID;
bID = (BYTE)pMsg[0];
USERINFO *pUser;
if (dwConnectionIndex == 0)
{
#ifdef __ON_DEBUG
// _asm int 3;
#endif
return;
}
if( bID == (BYTE)PTCL_NOTIFY_SERVER_UP )
{
if( g_pServerTable->OnRecvServerUpMsg(dwConnectionIndex, *(WORD*)(pMsg+1)) )
{
#ifdef __ON_DEBUG
// _asm int 3;
#endif
}
return;
}
LP_SERVER_DATA pSender = g_pServerTable->GetConnectedServerData( dwConnectionIndex );
if( !pSender ) return;
switch (bID)
{
// -------------
// 扁夯菩哦
// -------------
// 傈侩
case PTCL_ORDER_SET_SERVER_LIST:
case PTCL_ORDER_CONNECT_TO_SERVERS:
case PTCL_ORDER_SET_DB_DEMON:
case PTCL_ORDER_TO_REPORT_SERVER_DATAS:
case PTCL_NOTIFY_YOU_ARE_CERTIFIED:
//傍烹
case PTCL_ORDER_DESTROY_SERVER:
case PTCL_NOTIFY_SERVER_STATUS:
case PTCL_SERVER_TRY_TO_CHECK_CONNECTION:
case PTCL_SERVER_CONNECTION_OK:
case PTCL_ORDER_TO_REPORT_SERVER_STATUS:
{
if( !g_pServerTable->OnRecvNegotiationMsgs( pSender, bID, pMsg+1, dwLength-1 ) )
{
MyLog( LOG_FATAL, "OnRecvNegotiationMsg() Failed :: (pSender(%d), bId(%d), MsgLength(%d))", pSender->wPort, bID, dwLength );
#ifdef __ON_DEBUG
// _asm int 3;
#endif
}
}
break;
// ---------------
// AGENT 傈侩 菩哦
// ---------------
case PTCL_MAP_TO_AGENT_CHECK_IS_USER_GHOST:
{ //< CSD-030515
char szAnswer[64+1];
LP_REQUEST_REMOVE_GHOST_USER_PACKET pAnswer = (LP_REQUEST_REMOVE_GHOST_USER_PACKET)(szAnswer + 1);
LP_CHECK_IS_USER_GHOST_PACKET pPacket = (LP_CHECK_IS_USER_GHOST_PACKET)(pMsg + 1);
if (pPacket->dwID <= 0)
{
MyLog( LOG_FATAL, "PTCL_MAP_TO_AGENT_CHECK_IS_USER_GHOST :: dwID < 0 !!! (From %d/%d)", dwConnectionIndex, pSender->wPort );
break;
}
pUser = g_pUserTable->GetUserInfo(pPacket->dwID);
if (pUser == NULL)
{ // 绝促. 捞扒 GHOST!
szAnswer[0] = PTCL_AGENT_TO_MAP_REQUEST_REMOVE_GHOST_USER;
pAnswer->dwID = pPacket->dwID;
if( !g_pServerTable->Send(dwConnectionIndex, szAnswer, sizeof(BYTE)+sizeof(REQUEST_REMOVE_GHOST_USER_PACKET)))
{
MyLog(LOG_FATAL, "PTCL_MAP_TO_AGENT_CHECK_IS_USER_GHOST :: Failed To Answer!!! (From %d/%d)", dwConnectionIndex, pSender->wPort);
}
// Proxy俊辑 肺弊酒眶阑 窍档废 窃
static char szDummy[1 + ID_LENGTH];
memset(szDummy, 0, sizeof(szDummy));
szDummy[0] = BYTE(PTCL_PROXY_TO_LOGOUT);
memcpy(szDummy + 1, pPacket->szID, ID_LENGTH);
if (!g_pServerTable->SendToProxyServer(szDummy, 1 + ID_LENGTH))
{
MyLog(LOG_IMPORTANT, "Failed To send 'PTCL_PROXY_TO_LOGOUT' to Proxy");
}
MyLog(LOG_FATAL, "PTCL_MAP_TO_AGENT_CHECK_IS_USER_GHOST :: User Name : %s!!! (From %d/%d)", pPacket->szID, dwConnectionIndex, pSender->wPort);
}
break;
} //> CSD-030515
case PTCL_BROADCAST_TO_SERVERS:
{
t_packet raja_packet;
memset(&raja_packet,0,sizeof(t_packet));
memcpy(raja_packet.h.data, pMsg+1, 5);
memcpy(raja_packet.u.data, pMsg+1+5, raja_packet.h.header.size);
char szName[21];
// 菩哦救狼 捞抚 沥焊甫 墨乔窍绊 澄胶飘傅阑 持绰促
memcpy(szName,raja_packet.u.login_close_login_id.id,20);
szName[20] = NULL;
if (raja_packet.h.header.type == CMD_CLOSE_LOGIN_ID)
{
USERINFO* cur = NULL;
USERINFO* next = NULL;
USERINFO** pTable = g_pUserTable->GetUserInfoTable();
for (DWORD i=0; i<g_pUserTable->GetBucketNum(); i++)
{
cur = pTable[i];
while (cur)
{
next = cur->pNextUserInfo;
if (strcmp(cur->szName,szName ) == 0)
{
// 秦寸 蜡历俊霸 谗档废 鼻绊茄促.
g_pUserTable->DisconnectUserBySuggest( cur, CMD_CLOSE_CONNECTION_SAME_ID_LOGON );
}
cur = next;
}
}
}
break;
}
case PTCL_DB_TO_AGENT_REQUEST_DISCONNECT_USER_BY_ID:
case PTCL_MAP_TO_AGENT_REQUEST_DISCONNECT_USER:
{
DWORD *dwUniqID;
dwUniqID = (DWORD *)(pMsg+1);
pUser = g_pUserTable->GetUserInfo(*dwUniqID);
if (pUser != NULL)
{ //< CSD-030322
static char szDummy[1 + ID_LENGTH];
memset(szDummy, 0, sizeof(szDummy));
szDummy[0] = BYTE(PTCL_PROXY_TO_LOGOUT);
memcpy(szDummy + 1, pUser->szName, ID_LENGTH);
if (!g_pServerTable->SendToProxyServer(szDummy, 1 + ID_LENGTH))
{
MyLog(LOG_IMPORTANT, "Failed To send 'PTCL_PROXY_TO_LOGOUT' to Proxy");
}
// 立加阑 谗档废 鼻绊茄促.
g_pUserTable->DisconnectUserBySuggest( pUser, CMD_CLOSE_CONNECTION_NORMAL );
MyLog( LOG_NORMAL, "User(%d) SUGGESTED to DISCONNECT by %s(%d)", pUser->dwConnectionIndex, GetTypedServerText(pSender->dwServerType), dwConnectionIndex );
} //> CSD-030322
break;
}
case PTCL_DB_ANSWER:
{
DWORD *dwUniqID;
bool redirect_to_client = true; // default must be true
dwUniqID = (DWORD *)(pMsg+1);
t_packet *p = (t_packet *)(pMsg + 1 + 4);
pUser = g_pUserTable->GetUserInfo(*dwUniqID);
if (pUser)
{
switch( p->h.header.type ) {
// ---------------------------
// Client俊霸 焊郴瘤 臼阑 菩哦
// ---------------------------
// Modified by chan78 at 2000/12/09 :: 悼老 ID 悼矫立加
case CMD_CLOSE_LOGIN_ID:
{
char szName[21];
// 菩哦救狼 捞抚 沥焊甫 墨乔窍绊 澄胶飘傅阑 持绰促
memcpy( szName, p->u.login_close_login_id. id, 20 );
szName[20] = 0;
if( !strcmp( szName, pUser->szName ) )
{
// 秦寸 蜡历甫 谗绰促.
g_pUserTable->DisconnectUserBySuggest( pUser, CMD_CLOSE_CONNECTION_SAME_ID_LOGON );
//g_pINet->CompulsiveDisconnectUser(pUser->dwConnectionIndex);
}
else
{
MyLog( LOG_IMPORTANT, "CMD_CLOSE_LOGIN_ID: Name is not match!!! '%s', '%s'", szName, pUser->szName );
}
}
redirect_to_client = false;
break;
// ---------------------------------
// 咯扁辑何磐绰 Client俊霸 焊尘 菩哦
// ---------------------------------
case CMD_CONNECT_INFO:
{
// Setting Server informations
WORD port = p->u.server_connect_info.port;
if( g_pUserTable->GetUserInfo( *dwUniqID ) && g_pServerTable->GetConnectedServerData(port) ) {
g_pUserTable->GetUserInfo( *dwUniqID )->dwMapServerConnectionIndex = g_pServerTable->GetConnectedServerData(port)->dwConnectionIndex;
} else {
MyLog( LOG_FATAL, "Invalid dwUniqID(%d) or ServerID(%d)", *dwUniqID, port );
}
//MyLog( LOG_IGNORE, "User %d took map Server %d(%d)", *dwUniqID, p->u.server_connect_info.port, g_pUserTable->GetUserInfo( *dwUniqID )->dwMapServerConnectionIndex );
// LOGIN 苞沥俊辑 DB俊 扁废等 荤侩磊 沥焊狼 力芭甫 夸没茄促.
szMsg[0] = (BYTE)PTCL_AGENT_TO_DB_REQUEST_REMOVE_USER;
memcpy(szMsg+1,dwUniqID,4); // (dwUniqID == &(*dwUniqID) 秦彬府瘤 付技夸.
if( pUser->dwDBDemonConnectionIndex )
{
if( !g_pServerTable->Send( pUser->dwDBDemonConnectionIndex, szMsg, 5) )
{
g_pUserTable->DisconnectUserBySuggest( pUser, CMD_CLOSE_CONNECTION_ABNORMAL );
MyLog( LOG_IMPORTANT, "Failed To send 'PTCL_AGENT_TO_DB_REQUEST_REMOVE_USER' to (%d)", pUser->dwDBDemonConnectionIndex );
}
}
else
{
if( !g_pServerTable->SendToDBDemon( szMsg, 5 ) )
{
g_pUserTable->DisconnectUserBySuggest( pUser, CMD_CLOSE_CONNECTION_ABNORMAL );
MyLog( LOG_IMPORTANT, "Failed To send 'PTCL_AGENT_TO_DB_REQUEST_REMOVE_USER' to (%d)", pUser->dwDBDemonConnectionIndex );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -