📄 recvmsgfromuser.cpp
字号:
// -------------------------------
// ReWrite by chan78 at 2001/01/11
// -------------------------------
#include "dr_agent_structures.h"
#include "usertable.h"
#include "servertable.h"
#include "mylog.h"
#include "RecvMsgFromUser.h"
#include "AgentServer.h"
#include "ServerMonitor.h"
#include "RecvMsgFromServer.h"
#include <crtdbg.h>
#include <time.h>
#include "CUseMoney.h" // 030325 kyo 怕惫 苞陛侩
extern char szMsg[MAX_PACKET_SIZE];
extern bool SendHackingUser2DB( USERINFO *pUserInfo, int type, char *cause ); // from agentserver.cpp
// FOR DEBUG by chan78 2001/02/21
DWORD dwMapChangeCounter = 0;
void __stdcall OnAcceptUser( DWORD dwConnectionIndex )
{
sockaddr_in* pSockAddrIn;
char szIP[21];
WORD wPort;
DWORD dwUserID;
// 捞 辑滚啊 皋矫瘤甫 沥惑利栏肺 罐酒辑 贸府且 荐 乐绰 惑炔牢瘤 八荤.
if( !g_pServerTable->IsServerActivated( g_pServerTable->GetOwnServerData() ) )
{
// 辑滚啊 贸府阂瓷惑怕捞骨肺 啊瞒绝捞 谗绰促.
g_pINet->CompulsiveDisconnectUser( dwConnectionIndex );
return;
}
// Address 掘扁.
{
pSockAddrIn = g_pINet->GetUserAddress( dwConnectionIndex );
_ASSERT( pSockAddrIn );
sprintf( szIP, "%d.%d.%d.%d"
, pSockAddrIn->sin_addr.S_un.S_un_b.s_b1
, pSockAddrIn->sin_addr.S_un.S_un_b.s_b2
, pSockAddrIn->sin_addr.S_un.S_un_b.s_b3
, pSockAddrIn->sin_addr.S_un.S_un_b.s_b4
);
wPort = pSockAddrIn->sin_port;
}
// 眠啊 矫档.
dwUserID = g_pUserTable->AddUser( dwConnectionIndex );
// 搬苞 贸府.
if( dwUserID )
{
// MyLog( LOG_IGNORE, "NEW USER(dwID:%d, dwConnectionIndex:%d, FromIP:%s, FromPort:%d) Added to CUserTable", dwUserID, dwConnectionIndex, szIP, wPort );
///////////////////////////////////////////////////////////
USERINFO *pUser = g_pUserTable->GetUserInfo(dwUserID);
HSEL_INITIAL init;
init.iEncryptType = HSEL_ENCRYPTTYPE_RAND;
init.iDesCount = HSEL_DES_TRIPLE;
init.iCustomize = HSEL_KEY_TYPE_DEFAULT;
init.iSwapFlag = HSEL_SWAP_FLAG_ON;
if(!pUser->en.Initial(init))
{
MyLog( LOG_FATAL, "HSEL INIT FAIL En(On Connect)", szIP, wPort );
}
if(!pUser->de.Initial(init))
{
MyLog( LOG_FATAL, "HSEL INIT FAIL De(On Connect)", szIP, wPort );
}
t_packet packet;
packet.h.header.type = CMD_ON_CONNECT;
packet.h.header.size = sizeof(t_OnConnectHselInit);
packet.h.header.crc = 0;
packet.u.OnConnectHselInit.eninit = pUser->en.GetHSELCustomizeOption();
packet.u.OnConnectHselInit.deinit = pUser->de.GetHSELCustomizeOption();
if( !g_pUserTable->SendToUserNoEncode( pUser, (char *)&packet, sizeof(t_OnConnectHselInit)+5 ) )
{
//牢勒 登绢 乐绰 菩哦阑 朝妨 霖促.
MyLog( LOG_FATAL, "User(%s:%d) Can't Recv Packet ", szIP, wPort );
}
///////////////////////////////////////////////////////////
// MyLog( LOG_FATAL, "User-->>> %d\n ",pUser);
}
else
{
MyLog( LOG_FATAL, "New User(%s:%d) Can't be ADDED ON CUserTable !!!", szIP, wPort );
g_pINet->CompulsiveDisconnectUser( dwConnectionIndex );
}
return;
}
void __stdcall OnDisconnectUser( DWORD dwConnectionIndex )
{
// 荤侩磊啊 促弗 Server俊 Entry甫 爱绊 乐绰 版快 力芭秦林绰 贸府甫 茄促.
USERINFO *pUserInfo = (USERINFO*)g_pINet->GetUserInfo(dwConnectionIndex);
// pUserInfo 八刘.
#ifdef __ON_DEBUG
ASSERT( pUserInfo );
#endif
if( !pUserInfo )
{
MyLog(LOG_IGNORE, "Connection Closed Not Authed User Index %d", dwConnectionIndex );
return;
}
// Map Server俊 楷搬等 版快.
if( pUserInfo->dwMapServerConnectionIndex )
{
szMsg[0] = (BYTE)PTCL_AGENT_TO_MAP_REQUEST_REMOVE_USER;
memcpy(szMsg+1,&pUserInfo->dwID,4);
if( !g_pServerTable->Send(pUserInfo->dwMapServerConnectionIndex,szMsg, 1+4) )
{
MyLog( LOG_IMPORTANT, "OnDisconnectUser() :: Failed to Send Notify Packet that User Lost connection to Map(%d)", pUserInfo->dwMapServerConnectionIndex );
LP_SERVER_DATA pServerData = g_pServerTable->GetServerData( pUserInfo->dwMapServerConnectionIndex );
if( pServerData == NULL )
{
MyLog( LOG_IMPORTANT, "-- PServerData(%d) is NULL!" );
}
else
{
MyLog( LOG_IMPORTANT, "-- %s(%s:%d)", GetTypedServerText(pServerData->dwServerType), pServerData->szIP, pServerData->wPort );
}
}
}
else if( pUserInfo->dwDBDemonConnectionIndex )
{
szMsg[0] = (BYTE)PTCL_AGENT_TO_DB_REQUEST_REMOVE_USER;
memcpy(szMsg+1,&pUserInfo->dwID,4);
if( !g_pServerTable->Send( pUserInfo->dwDBDemonConnectionIndex, szMsg, 5) )
{
g_pINet->CompulsiveDisconnectUser( pUserInfo->dwConnectionIndex );
MyLog( LOG_NORMAL, "Can't send request to remove User %d from DB DEMON -- Close this connection", pUserInfo->dwID );
}
}
#ifdef __ON_DEBUG
// DB Demon苞 Map SERVER俊 悼矫俊 Entry甫 爱绊 乐绰 版快. 惯积窍搁 救登绰 抗寇惑炔.
else if( pUserInfo->dwDBDemonConnectionIndex && pUserInfo->dwMapServerConnectionIndex )
{
// _asm int 3;
}
#endif
// DB狼 Log-in Table Entry俊辑 力芭茄促.
if( pUserInfo->bAmILogon )
{
// --------------
// 2001/01/29, zhh
time_t Logout;
struct tm *now;
time( &Logout );
now = localtime(&Logout);
int year = now->tm_year + 1900;
int mon = now->tm_mon+1;
int day = now->tm_mday;
int hour = now->tm_hour;
int min = now->tm_min;
int sec = now->tm_sec;
char logouttime[15];
memset(logouttime,0,15);
sprintf(logouttime,"%4d%2d%2d%2d%2d%2d", year, mon, day, hour, min, sec);
// --------------
szMsg[0] = (BYTE)PTCL_AGENT_TO_DB_REMOVE_USER_FROM_LOGIN_TABLE;
memcpy(szMsg+1,&pUserInfo->dwID,4);
memcpy(szMsg+1+4, &pUserInfo->szName, ID_LENGTH);
memcpy(szMsg+1+4+ID_LENGTH, &g_pServerTable->GetOwnServerData()->wPort, 2 );
//2001/01/29 zhh
memcpy(szMsg+1+4+ID_LENGTH+2, logouttime,15);
memcpy(szMsg+1+4+ID_LENGTH+2+15, pUserInfo->logintime,15);
//2001/08/30 zhh
memcpy(szMsg+1+4+ID_LENGTH+2+15+15, pUserInfo->szIP,20);
if( pUserInfo->dwDBDemonConnectionIndex )
{
//2001/08/30 zhh
if( !g_pServerTable->Send(pUserInfo->dwDBDemonConnectionIndex, szMsg, 1+4+ID_LENGTH+2+30+20) )
{
MyLog( LOG_IMPORTANT, "Failed To send 'PTCL_AGENT_TO_DB_REMOVE_USER_FROM_LOGIN_TABLE' to (%d)", pUserInfo->dwDBDemonConnectionIndex );
}
}
else
{
//2001/08/30 zhh
if( !g_pServerTable->SendToDBDemon( szMsg, 1+4+ID_LENGTH+2+30+20) )
{
MyLog( LOG_IMPORTANT, "Failed To send 'PTCL_AGENT_TO_DB_REMOVE_USER_FROM_LOGIN_TABLE' to DBDemon", pUserInfo->dwDBDemonConnectionIndex );
}
}
}
//< CSD-030322
static char szDummy[1 + ID_LENGTH];
memset(szDummy, 0, sizeof(szDummy));
szDummy[0] = BYTE(PTCL_PROXY_TO_LOGOUT);
memcpy(szDummy + 1, pUserInfo->szName, ID_LENGTH);
if (!g_pServerTable->SendToProxyServer(szDummy, 1 + ID_LENGTH))
{
MyLog(LOG_IMPORTANT, "Failed To send 'PTCL_PROXY_TO_LOGOUT' to Proxy");
}
//> CSD-030322
// 030206 kyo
//g_cAsyncPay.LogoutUser( pUserInfo );
g_cAsyncPay.LogoutUser( dwConnectionIndex, pUserInfo->szName );
// 角力肺 Clear.
g_pUserTable->RemoveUser(dwConnectionIndex);
return;
}
void SendCMD_CONNECT_AGENT_SERVER_CONFORM(const DWORD dwUserID, const char* szUserName, const int nResult)//
{
USERINFO* pUser = (USERINFO*)g_pINet->GetUserInfo(dwUserID);
if(!pUser){return;}
if(::stricmp(szUserName,pUser->szName))//酒鳖客 促弗 蜡历 扼搁
{
return;
}
t_packet p;
::memcpy(p.u.ConnectAgentServerConform.szUserID,pUser->szName,20);
p.h.header.type = CMD_CONNECT_AGENT_SERVER_CONFORM;
p.h.header.size = sizeof(CONNECTAGENTSERVERCONFORM);
p.u.ConnectAgentServerConform.iKey = nResult;
__try{
g_pUserTable->SendToUser( pUser, (char*)&p, sizeof(t_header)+sizeof(CONNECTAGENTSERVERCONFORM) );
}__except( EXCEPTION_EXECUTE_HANDLER )
{
MyLog( 0, "ERROR IN SendCMD_CONNECT_AGENT_SERVER_CONFORM" );
}
}
void RecvCMD_CONNECT_AGENT_SERVER_CONFORM(USERINFO *pUser, t_packet *p)//
{// 怕惫 苞陛 嘿绰 镑
__try // 030626 kyo
{ //030703 lsw 酒捞叼 辨捞 20 涝聪促. 历芭 官操瘤 付技夸 -_-..
::memcpy( pUser->szName, p->u.ConnectAgentServerConform.szUserID,ID_LENGTH); // 030626 kyo //change size ID_LENGTH -> 40
pUser->bAmILogon = false;
if(LocalMgr.IsAbleNation(THAI)&& !LocalMgr.IsFreeBeta())
{
sockaddr_in* pSockAddrIn = g_pINet->GetUserAddress(pUser->dwConnectionIndex);
char szUserIP[64] = {0, };
sprintf(szUserIP, "%d.%d.%d.%d", pSockAddrIn->sin_addr.S_un.S_un_b.s_b1,
pSockAddrIn->sin_addr.S_un.S_un_b.s_b2,
pSockAddrIn->sin_addr.S_un.S_un_b.s_b3,
pSockAddrIn->sin_addr.S_un.S_un_b.s_b4);
g_cAsyncPay.LoginUser(pUser->dwConnectionIndex,
p->u.ConnectAgentServerConform.szUserID,
p->u.ConnectAgentServerConform.szUserPASS,
CAsyncClient::GAME_ID,
CAsyncClient::USER_TYPE, szUserIP, szUserIP);
}
else
{
::SendCMD_CONNECT_AGENT_SERVER_CONFORM(pUser->dwConnectionIndex, pUser->szName, 100);//
}
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
MyLog( 0, "ERROR IN RecvCMD_CONNECT_AGENT_SERVER_CONFORM" );
}
}
inline bool RAJADecodePacket(USERINFO* pUser, t_packet *p, int iLength)
{
pUser->de.Decrypt(p->h.data,2);
pUser->de.Decrypt(p->u.data,iLength-5);
if( pUser->de.GetCRCConvertChar() != p->h.header.crc)
{
return false;
}
return true;
}
void __stdcall RecvMsgFromUser(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength )
{
t_packet *packet;
t_packet *spacket;
int cause =0;
char sMsg[MAX_PACKET_SIZE];
spacket = (t_packet *)(sMsg+1+4);
// 捞 辑滚啊 皋矫瘤甫 沥惑利栏肺 罐酒辑 贸府且 荐 乐绰 惑炔牢瘤 八荤.
if( !g_pServerTable->IsServerActivated( g_pServerTable->GetOwnServerData() ) )
{
// 辑滚啊 STATUS_SERVER_ACTIVATED 捞寇狼 惑炔捞搁 捞固 沥惑利牢 贸府啊 阂啊瓷茄 版快捞促.
// 辑滚啊 何泼吝牢 版快俊绰 USER螟 家南阑 酒抗 官牢靛窍瘤 臼芭唱, 官牢靛甫 窍歹扼档 立加 阂啊
// 菩哦阑 焊辰 饶 鼻绊 立加辆丰甫 矫虐绊, 辑滚啊 沥惑累悼吝俊 INACTIVATED 等 版快扼搁 葛电 荤
// 侩磊俊霸 鼻绊 立价辆丰甫 矫虐骨肺 捞 皋矫瘤甫 罐绰 版快绰 促澜苞 鞍促.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -