⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 recvmsg.cpp

📁 Proxy in c++ for DragonRaja
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "struct.h"
#include "servertable.h"
#include "usertable.h"
#include "recvmsg.h"
#include "packed.h"
#include "server.h"
#include "monitor.h"
#include "proxy.h"
#include "mylog.h"
#include "dr_agent_structures.h"
#include "DrServerManager.h"
// 011106 KBS
#include "RMTable.h"
//#include "RMDefine.h"
//< CSD-030322
#include "UserManager.h"
extern CUserManager g_mgrUser;
//> CSD-030322

void OnConnectUser(DWORD dwConnectionIndex);
void OnConnectServer(DWORD dwConnectionIndex);

char txt[512];
char szMsg[MM_MAX_PACKET_SIZE];

// 011106 KBS
extern void RMProc(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength);

// Added by chan78 at 2000/12/17
bool RequestClearPayTable( DWORD dwConnectionIndex )
{
	// 刚历 秦寸 AGENT狼 沥焊甫 备窃.
	LP_SERVER_DATA pServerData = g_pServerTable->GetServerData( dwConnectionIndex );

	if( !pServerData )
	{
		return false;
	}
	if( pServerData->dwServerType != SERVER_TYPE_AGENT )
	{
		return false;
	}

	// 贸府且 DB Demon阑 急沥
	LP_SERVER_DATA pDBDemon = g_pServerTable->GetServerListHead();
	DWORD dwTargetDBDemonCI = 0;
	for(; pDBDemon; pDBDemon = pDBDemon->pNextServerData )
	{
		if( pDBDemon->dwConnectionIndex && (pDBDemon->dwServerType == SERVER_TYPE_DB) )
		{
			dwTargetDBDemonCI = pDBDemon->dwConnectionIndex;
			break;
		}
	}

	if( dwTargetDBDemonCI == 0 )
	{
		return false;
	}

	// 菩哦父惦
	char szMsg[64+1];

	szMsg[0] = (BYTE)PTCL_ORDER_TO_CLEAR_PAY_TABLE;
	memcpy( szMsg+1, &pServerData->wPort, 2 );

	if( !g_pServerTable->Send( dwTargetDBDemonCI, szMsg, 1+2 ) )
	{
		MyLog( LOG_FATAL, "RequestClearPayTable() :: Failed to Send Packet(TargetCI:%d, AgentPort:%d)", dwTargetDBDemonCI, pServerData->wPort );
		return false;
	}

	// 己傍利栏肺 辆丰.
	return true;
}

void __stdcall OnAcceptUser(DWORD dwConnectionIndex)
{
	char msg[23];

	g_pProxy->dwTotalLogUser++;
	
	LP_SERVER_DATA pToAssign = g_pServerTable->GetAssignableAgentServer();
	// Max user check per Set
	if (g_pServerTable->GetNumOfUsersInServerSet() > g_pProxy->dwMaxUser)
	{
		g_pProxy->bLimitMaxUser = 0;
	}
	else g_pProxy->bLimitMaxUser = 1;
	// if proxy limit login try
	if (g_pProxy->bLimitLoginTryPerSec)
	{
		g_pProxy->bTryLoginThisSec++;
		if (g_pProxy->bLimitLoginTryPerSec < g_pProxy->bTryLoginThisSec)
			g_pProxy->bLimit = 0;
		else g_pProxy->bLimit = 1;
	} 
	else g_pProxy->bLimit = 1;
	
	if (!pToAssign || !g_pServerTable->IsUserAcceptAllowed() || g_pProxy->bLimit == 0 || g_pProxy->bLimitMaxUser == 0)
	{
		t_header buffer;
		if (g_pProxy->bLimit == 0 && g_pServerTable->IsUserAcceptAllowed() )
			buffer.type = 13005;
		else if (g_pProxy->bLimitMaxUser == 0 && g_pServerTable->IsUserAcceptAllowed() )
			buffer.type = 13005;
		else
			buffer.type = 10174;
		buffer.size = 0;

		// 泅犁 立加且 辑滚啊 绝澜阑 焊辰促.
		g_pINet->SendToUser(dwConnectionIndex,(char*)&buffer,5,FLAG_SEND_NOT_ENCRYPTION);

		if ( g_pServerTable->IsUserAcceptAllowed() )
		{
//			MyLog( LOG_IMPORTANT, "WARNING : No Agent server are ready to service" );
		}
		else if (g_pProxy->bLimit == 0)
		{
			MyLog( LOG_JUST_DISPLAY, "INFO : Proxy LIMIT User login try per Sec");
		}
		else if (g_pProxy->bLimitMaxUser == 0)
		{
			MyLog( LOG_JUST_DISPLAY, "INFO : MAX USER LIMIT at this server set");
		}
		g_pProxy->dwFailtoAllocUserNum++;
	}
	else
	{
       // 立加茄 蜡历俊霸 Agent狼 IP甫 焊郴霖促. 
		t_header buffer;
		buffer.type = 8930;
		buffer.size = 18;
		memcpy(msg,&buffer,5);
		memcpy(msg+5,pToAssign->szIPForUser,18);

		if( !g_pINet->SendToUser(dwConnectionIndex,msg,23,FLAG_SEND_NOT_ENCRYPTION) )
		{
			MyLog( LOG_NORMAL, "Failed To Send To User (%d)", dwConnectionIndex );
		}
		pToAssign->dwNumOfUsers++;
		 
		//MyLog( LOG_NORMAL, "OK : User(%d) push to %s", dwConnectionIndex, pToAssign->szIPForUser);

		// add by slowboat
		g_pServerTable->AddNumOfUsersInServerSet();
	}

	// List俊 眠啊.
	DWORD dwNewUserID = g_pUserTable->AddUser( dwConnectionIndex );
	if( dwNewUserID )
	{
		USERINFO *pNewUserInfo;
		pNewUserInfo = g_pUserTable->GetUserInfo( dwNewUserID );
		if( !pNewUserInfo )
		{
			MyLog( LOG_FATAL, "OnConnectUser() :: pNewUserInfo is NULL!!!(CI:%d/dwID:%d)", dwConnectionIndex, dwNewUserID );
			g_pINet->CompulsiveDisconnectUser( dwConnectionIndex );
		}
		else
		{
			if(LocalMgr.IsAbleNation(CHINA))//021007 lsw
			{
				MyLog( 0, "CLIENT at (CI:%d, IP:%s, PORT:%d)", dwConnectionIndex, pNewUserInfo->szIP, pNewUserInfo->wPort );
			}
			g_pUserTable->DisconnectUserBySuggest( pNewUserInfo );// 5檬饶俊 谗扁档废 茄促.
		}
	}
	else
	{
		// CUserTable俊 眠啊窍瘤 给茄 版快.
		g_pINet->CompulsiveDisconnectUser( dwConnectionIndex );
	}
	return;
}


void __stdcall OnAcceptServer(DWORD dwConnectionIndex)
{
	int k=0;
}

void __stdcall ReceivedMsgServer(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;
	}

	// 011106 KBS
	if( bID == PTCL_RM || bID == PTCL_RM_FROM_PROXY )
	{
		BYTE header;
		memcpy(&header,pMsg+1, 1);
		if( header == MSG_RM_LOGIN ) return;
		RMProc(dwConnectionIndex, pMsg, dwLength);
		return;
	}
	//



	LP_SERVER_DATA pSender = g_pServerTable->GetConnectedServerData( dwConnectionIndex );

	if( !pSender ) return;

	switch (bID)
	{
	// -------------
	// 扁夯菩哦 
	// -------------
		// PROXY 傈侩
	case PTCL_REQUEST_SET_SERVER_LIST:
	case PTCL_REQUEST_TO_CONNECT_SERVER_LIST:
	case PTCL_REQUEST_SET_DB_DEMON:
	case PTCL_SERVER_LIST_SETTING_RESULT:
	case PTCL_SERVER_CONNECTING_RESULT:
	case PTCL_DB_DEMON_SETTING_RESULT:
	case PTCL_REPORT_SERVER_DATAS:
	case PTCL_REPORT_SERVER_DESTROY:
	case PTCL_REPORT_SERVER_STATUS:
	case PTCL_REPORT_SERVER_CONNECTION_STATUS_CHANGE:

		// 傍烹
	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/03/16
	// -----------------------------
	case PTCL_MANAGER_QUERY:
		{
			// 乐阑 荐 绝促.
			MyLog( LOG_FATAL, "PTCL_MANAGER_QUERY :: has received!!!(%d)", pSender->wPort );
			g_pServerTable->DestroyServer( FINISH_TYPE_UNKNOWN_ERROR);
		}
		break;
	// Added by chan78 at 2001/03/16
	case PTCL_MANAGER_ANSWER:
		{
			if( !AnswerToManager( (LP_MANAGER_PACKET)pMsg, dwLength ) )
			{
				MyLog( LOG_FATAL, "PTCL_MANAGER_ANSWER :: AnswerToManager() has return false(%d)", pSender->wPort );
				break;
			}
		}
		break;
	case PTCL_PROXY_TO_ACCESS:
		{	//< CSD-030509
			t_packet* pPacket = (t_packet*)(pMsg + 5);

			const char* pID = pPacket->u.server_accept_login.id;

			if (g_mgrUser.IsExistLogin(pID))
			{
				MyLog(LOG_NORMAL, "Exist Login : %s", pID);
				break;
			}

			if (g_mgrUser.IsExistLogout(pID))
			{
				MyLog(LOG_NORMAL, "Exist Logout : %s", pID);
				break;
			}
			
			g_mgrUser.AddLogin(pID);

			pMsg[0] = BYTE(PTCL_AGENT_TO_COMMIT);

			if (!g_pServerTable->Send(dwConnectionIndex, pMsg, dwLength))
			{
				MyLog(LOG_IMPORTANT, "Failed To send 'PTCL_AGENT_TO_COMMIT' to Agent");
			}

			break;
		}	//> CSD-030509
	case PTCL_PROXY_TO_LOGOUT:
		{	//< CSD-030509
			const char* pName = pMsg + 1;

			if (g_mgrUser.IsExistLogin(pName))
			{
				if (!g_mgrUser.IsExistLogout(pName))
				{
					g_mgrUser.AddLogout(pName);
				}
			}
			
			g_mgrUser.DelLogin(pName);

			break;
		}	//> CSD-030509
//<! BBD 040311	甘栏肺何磐狼 悼立荐 夸没
	case PTCL_SERVERSET_USERNUM_REQUEST:
		{
			pMsg[0] = BYTE(PTCL_SERVERSET_USERNUM_REQUEST);

			unsigned short count = g_pServerTable->m_dwNumOfUsersInServerSet;
			memcpy(&(pMsg[1]), &count, sizeof(count));

			g_pServerTable->Send(dwConnectionIndex, pMsg, 1 + sizeof(count));
			break;
		}
//> BBD 040311	甘栏肺何磐狼 悼立荐 夸没
	default:
		{
			MyLog( LOG_FATAL, "Unknown bID(%d) Received. From %s(wPort:%d) Size(%d) ConnectionID(%d)", bID, GetTypedServerText(pSender->dwServerType), pSender->wPort, dwLength, dwConnectionIndex);
#ifdef __ON_DEBUG
//			_asm int 3;
#endif
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -