📄 recvmsg.cpp
字号:
#include "recvmsg.h"
#include "servertable.h"
//#include "playermanager.h"
#include "monitor.h"
#include "servertable.h"
#include "mylog.h"
#include "..\mapserver.h"
#include <sqltypes.h>
#include "..\HigherLayers\defaultheader.h"
#include "..\HigherLayers\dr_network.h"
#include "..\HigherLayers\MenuServer.h"
#include "..\HigherLayers\Map.h"
// 001206 KHS
#include "..\HigherLayers\SealStone.h"
#include "..\HigherLayers\SealStoneGameServer.h"
#include "DrServerManager.h"
#include "..\HigherLayers\eventmgr.h" //021030 YGI
#include "..\HigherLayers\UserManager.h"
#include "../HigherLayers/KickOffAll.h" // BBD 040110
extern int g_LocalWarBegin; // 011215 LTS
extern CKickOffAll g_KickMgr; // BBD 040110
// 011205 KBS
extern void RMProc(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength);
extern void UpdateCharacterData(t_connection c[], int cn, bool bDirect = false);
extern void CleanUpConnection(short idServer);
extern unsigned short g_UsercountInServerSet; // BBD 040311
DWORD GetServerIDByUniqID( DWORD dwUID, DWORD dwCI )
{ // 烙矫 府聪绢辑摹.
for( int i = DRAGON_CONNECTIONS_START; i < DRAGON_MAX_CONNECTIONS; i++ )
{
if( (connections[i].dwIDForAgent == dwUID) && (connections[i].dwAgentConnectionIndex == dwCI) )
return i;
}
return (DRAGON_MAX_CONNECTIONS);
}
DWORD GetNewCN( void )
{
for (int i = DRAGON_CONNECTIONS_START; i < DRAGON_MAX_CONNECTIONS; ++i)
{
if (connections[i].dwAgentConnectionIndex == 0)
{
if (strlen(connections[i].name) == 0)
{ //< CSD-031204
CleanUpConnection(i);
g_pServerTable->SetNumOfUsers( g_pServerTable->GetNumOfUsers()+1, 300, i,0, "GetNewCn() Called");
return i;
} //> CSD-031204
}
}
return 0;
}
void __stdcall ReceivedMsgFromServer(DWORD dwConnectionIndex, char* pMsg,DWORD dwLength)
{
BYTE bID;
bID = (BYTE)pMsg[0];
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;
// -------------
// 甘辑滚侩 菩哦
// -------------
// Added by chan78 at 2001/02/20
case PTCL_AGENT_TO_MAP_REQUEST_REMOVE_GHOST_USER:
{ //< CSD-030509
LP_REQUEST_REMOVE_GHOST_USER_PACKET pPacket = (LP_REQUEST_REMOVE_GHOST_USER_PACKET)(pMsg+1);
if (pPacket->dwID <= 0)
{
MyLog( LOG_FATAL, "PTCL_AGENT_TO_MAP_REQUEST_REMOVE_GHOST_USER :: dwID is 0 !!!(From %d/%d)", dwConnectionIndex, pSender->wPort );
break;
}
DWORD dwTarget = GetServerIDByUniqID( pPacket->dwID, dwConnectionIndex);
if (dwTarget > 0)
{
MyLog( LOG_NORMAL, "PTCL_AGENT_TO_MAP_REQUEST_REMOVE_GHOST_USER :: Ghost User(%d) is Wiped(From %d/%d)", pPacket->dwID, dwConnectionIndex, pSender->wPort );
closeconnection( connections, (int)dwTarget, -220 );
}
else
{
MyLog( LOG_IMPORTANT, "PTCL_AGENT_TO_MAP_REQUEST_REMOVE_GHOST_USER :: User(%d) is Already Wiped(From %d/%d)", pPacket->dwID, dwConnectionIndex, pSender->wPort );
break;
}
break;
} //> CSD-030509
case PTCL_AGENT_TO_MAP:
{
//<! BBD 040401 蜡历 规免吝浚 俊捞傈飘俊辑 措扁吝牢 仇捞 甘辑滚俊 甸绢咳 臼凳
// if(g_KickMgr.IsKicking())
// {
// break;
// }
//> BBD 040401 蜡历 规免吝浚 俊捞傈飘俊辑 措扁吝牢 仇捞 甘辑滚俊 甸绢咳 臼凳
//< CSD-HK-030829
// 扁夯 荤捞令 八荤
if (dwLength < 1 + 4 + sizeof(t_header))
{
MyLog(LOG_NORMAL, "PTCL_USER_CMD_TO_MAP_SERVER :: Too short packet(%d)", dwLength);
}
DWORD dwUniqID = 0;
memcpy(&dwUniqID, pMsg+1, 4);
t_packet raja_packet;
memset(&raja_packet, 0, sizeof(t_packet));
memcpy(raja_packet.h.data, pMsg+1+4, sizeof(t_header));
memcpy(raja_packet.u.data, pMsg+1+4+sizeof(t_header), raja_packet.h.header.size);
// chan78's comments 2000/11/01
// ----------------------------
// dwUniqID肺 connections[]俊辑狼 index甫 search ...
// 扁粮 扼磊绰 server_id(== dwUniqID)啊 connection_index客 鞍促.
// 捞 规侥栏肺绰 促弗 MapServer俊 立加且 锭 付促 server_id甫 犁 何咯罐酒具 茄促.
// 2byte究 唱穿绢 惑困 2官捞飘绰 MapServer 锅龋, 窍困 2官捞飘绰 server_id肺 窍搁 亮阑 巴 鞍篮单...
// 努扼捞攫飘档 绊媚具 且瘤档 葛福骨肺 老窜 瞒盒洒 积阿秦焊磊.
// 烙矫 府聪绢辑摹.
DWORD ServerID = GetServerIDByUniqID(dwUniqID, dwConnectionIndex);
if (ServerID == DRAGON_MAX_CONNECTIONS && !g_KickMgr.IsKicking()) // BBD 040401
{
// 绝栏搁 货肺款 connection
ServerID = GetNewCN();
if ((ServerID >= DRAGON_CONNECTIONS_START) && (ServerID < DRAGON_MAX_CONNECTIONS))
{
connections[ServerID].dwIDForAgent = dwUniqID;
connections[ServerID].dwAgentConnectionIndex = dwConnectionIndex;
}
else
{
MyLog(LOG_FATAL, "New User(dwUniqID:%d)(Agent:%d) has tried to connect but connections[] is full!", dwUniqID, dwConnectionIndex);
break;
}
}
if (connections[ServerID].state == CONNECT_CHANGING_MAP)
{
if (raja_packet.h.header.type != CMD_CHANGE_MAP_DETECTED)
{
break;
}
}
// Raja狼 Command Handler肺 Packet阑 逞败 霖促.
HandleCommand(ServerID, &raja_packet);
break;
} //> CSD-HK-030829
case PTCL_AGENT_TO_MAP_REQUEST_ADD_USER:
{
// 泅犁 救靖.
}
break;
case PTCL_AGENT_TO_MAP_REQUEST_REMOVE_USER:
{ //< CSD-HK-030829
DWORD* dwUniqID = (DWORD *)(pMsg+1);
DWORD dwServerID = GetServerIDByUniqID(*dwUniqID, dwConnectionIndex);
if (dwServerID == DRAGON_MAX_CONNECTIONS)
{
return;
}
// 立加辆丰贸府
closeconnection(connections, dwServerID, 1);
connections[dwServerID].dwIDForAgent = 0;
connections[dwServerID].dwAgentConnectionIndex = 0;
// MyLog( LOG_IGNORE, "User(dwUniqID:%d/dwServerID:%d) has lost connection", *dwUniqID, dwServerID);
break;
} //> CSD-HK-030829
case PTCL_DB_ANSWER:
{
t_packet raja_packet;
memcpy( &raja_packet, pMsg+1+4, dwLength-1-4);
*((char *)&raja_packet + dwLength-1-4 )= 0;
// MyLog( LOG_DEBUG, "From DB Demon(type:%d, Size:%d)", raja_packet.h.header.type, raja_packet.h.header.size );
HandleCommand( DB_DEMON, &raja_packet );
}
break;
// -------------------------------------------------
// Map Change Protocol (From MapServer To MapServer)
// -------------------------------------------------
case PTCL_MAP_TO_MAP:
{
DWORD dwNewCN = 0;
LP_SERVER_DATA *pServerData = NULL;
char szMsg[MM_MAX_PACKET_SIZE];
t_packet *packet = (t_packet *)(pMsg+1);
t_packet *spacket =(t_packet *)(szMsg+1);
// Minimum Size Check
if( (dwLength-1) < sizeof(t_header) ) {
MyLog( LOG_FATAL, "PTCL_MAP_TO_MAP :: Too Short Packet(%d<sizeof(t_header))", dwLength-1);
break;
}
// Packet Size Check
if( (dwLength-1) != sizeof(t_header)+packet->h.header.size ) {
MyLog( LOG_FATAL, "PTCL_MAP_TO_MAP :: Invalid Packet Size(%d != %d)", dwLength-1, sizeof(t_header)+packet->h.header.size );
break;
}
// Packet Analysys
switch( packet->h.header.type )
{
case CMD_MAP_CHANGE_REQUEST:
{
DWORD dwMyAgentConnectionIndex;
// Packet size Check
if( sizeof(t_change_map_protocol) != (dwLength-1-sizeof(t_header)) )
{
MyLog( LOG_FATAL, "PTCL_MAP_TO_MAP :: Invalid Packet Length(Expected:%d)(Received:%d(+1))", sizeof(t_change_map_protocol), (dwLength-1));
break;
}
// 郴 Active Agent Server List俊 乐绰瘤 犬牢.
if( !g_pServerTable->GetServerData(packet->u.change_map_protocol.wAgentServerID) )
{
MyLog( LOG_FATAL, "Map Changer's Agent Server(%d) is not available in Own ACTIVE SERVERLIST", packet->u.change_map_protocol.wAgentServerID );
dwMyAgentConnectionIndex = 0;
} else {
dwMyAgentConnectionIndex = g_pServerTable->GetServerData(packet->u.change_map_protocol.wAgentServerID)->dwConnectionIndex;
}
// 货肺款 蜡历甫 罐阑荐 乐绰瘤 Check
dwNewCN = GetNewCN();
if( !dwNewCN || !dwMyAgentConnectionIndex || g_KickMgr.IsKicking()) // BBD 040329
{ // 角菩
// Modified by chan78 at 2000/11/29
// dwNewCN篮 己傍沁瘤父 促弗 捞蜡肺 角菩茄版快 立加等 荤侩磊荐 临烙.
if( dwNewCN )
{
// g_pServerTable->SetNumOfUsers( g_pServerTable->GetNumOfUsers()-1 );
g_pServerTable->SetNumOfUsers( g_pServerTable->GetNumOfUsers()-1, 400, dwNewCN,0, "ReceivedMsgFromServer()");
}
else
{
MyLog( LOG_IMPORTANT, "PTCL_MAP_TO_MAP :: Can't Accept MORE Character!" );
}
// 歹 捞惑 罐阑荐 绝澜阑 sender俊霸 舅赴促
szMsg[0] = (BYTE)PTCL_MAP_TO_MAP;
spacket->h.header.type = CMD_MAP_CHANGE_DENIED;
spacket->h.header.size = sizeof( t_map_change_result );
spacket->h.header.crc = 0;
spacket->u.map_change_result.wAgentServerID = packet->u.change_map_protocol.wAgentServerID;
spacket->u.map_change_result.dwIDForAgent = packet->u.change_map_protocol.dwIDForAgent;
spacket->u.map_change_result.TargetServerCn = 0;
spacket->u.map_change_result.FromServerCn = packet->u.change_map_protocol.FromServerCn;
if( !g_pServerTable->Send(dwConnectionIndex, szMsg, 1+sizeof(t_header)+spacket->h.header.size) )
{
MyLog( LOG_FATAL, "PTCL_MAP_TO_MAP :: Can't Answer to MapServer(ConnectionIndex:%d)", dwConnectionIndex );
break;
}
}
else
{
t_packet tp;
memset( &tp, 0, sizeof(t_packet) );
// 己傍
connections[dwNewCN].dwIDForAgent = packet->u.change_map_protocol.dwIDForAgent;
connections[dwNewCN].dwAgentConnectionIndex = dwMyAgentConnectionIndex;
connections[dwNewCN].state = CONNECT_LOGIN_KEIN; // nMap俊辑狼 惑怕..
memcpy( connections[dwNewCN].id, packet->u.change_map_protocol.id, ID_LENGTH );
memcpy( connections[dwNewCN].name, packet->u.change_map_protocol.name, NM_LENGTH );
memcpy( connections[dwNewCN].chrlst.Name, packet->u.change_map_protocol.name, NM_LENGTH );
memcpy( connections[dwNewCN].pw, packet->u.change_map_protocol.password, PW_LENGTH );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -