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

📄 distributenetworkmsgparser.cpp

📁 [Server]Distribute.rar这个是分发服务器的源码
💻 CPP
字号:

#include "stdafx.h"
#include "DistributeNetworkMsgParser.h"
#include "ServerTable.h"
#include "Network.h"
#include "DistributeDBMsgParser.h"
#include "UserManager.h"
#include "UserTable.h"
#include "BootManager.h"

extern int g_nServerSetNum;
extern HWND g_hWnd;

DWORD g_dwMaxUser = 5000;

void MP_MonitorMsgParser(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength)
{
	MSGROOT* pTempMsg = (MSGROOT*)pMsg;
	switch(pTempMsg->Protocol)
	{
	case MP_MORNITORMAPSERVER_NOTICESEND_SYN:
		{
			// 傍瘤荤亲 
			ASSERT(0);
		}
		break;
	case MP_MORNITORMAPSERVER_PING_SYN:
		{
			pTempMsg->Protocol = MP_MORNITORMAPSERVER_PING_ACK;
			g_Network.Send2Server(dwConnectionIndex, pMsg, dwLength);
		}
		break;
	case MP_MORNITORMAPSERVER_CHANGE_USERLEVEL_SYN:
		{
			pTempMsg->Protocol = MP_MORNITORMAPSERVER_CHANGE_USERLEVEL_ACK;
			
			MSG_DWORD* pmsg = (MSG_DWORD*)pMsg;
			if( pmsg->dwData == 0 )
			{
				pmsg->dwData = gUserMGR.GetUserLevel();
			}
			else
			{
				gUserMGR.SetUserLevel( pmsg->dwData );
				g_Console.LOG(4, "Change User Level : %d", pmsg->dwData );
			}
			g_Network.Send2Server( dwConnectionIndex, pMsg, dwLength );
		}
		break;
	case MP_MORNITORMAPSERVER_QUERYUSERCOUNT_SYN:
		{
			MSGUSERCOUNT  * pmsg = (MSGUSERCOUNT  *)pMsg;
			pmsg->Protocol = MP_MORNITORMAPSERVER_QUERYUSERCOUNT_ACK;
			pmsg->dwUserCount = g_pUserTable->GetUserCount();
			g_Network.Send2Server(dwConnectionIndex, pMsg, sizeof(MSGUSERCOUNT));
		}
		break;
	case MP_MORNITORMAPSERVER_ASSERTMSGBOX_SYN:
		{
			MSG_DWORD* pmsg = (MSG_DWORD*)pMsg;
			g_bAssertMsgBox = (BOOL)pmsg->dwData;
			if(g_bAssertMsgBox)
				g_Console.LOG(4,"Assert MsgBox is On");
			else
				g_Console.LOG(4,"Assert MsgBox is Off");
		}
		break;
	case MP_MORNITORMAPSERVER_SERVEROFF_SYN:
		{
			SendMessage(g_hWnd, WM_CLOSE, 0, 0);
		}
		break;
	case MP_MORNITORMAPSERVER_QUERY_VERSION_SYN:
		{			
			MSGNOTICE msg;
			msg.Category = MP_MORNITORMAPSERVER;
			msg.Protocol = MP_MORNITORMAPSERVER_QUERY_VERSION_ACK;
			strcpy( msg.Msg, gUserMGR.GetVersion() );
			g_Network.Send2Server( dwConnectionIndex, (char*)&msg, sizeof(MSGNOTICE) );
		}
		break;
	case MP_MORNITORMAPSERVER_CHANGE_VERSION_SYN:
		{
			MSGNOTICE* pmsg = (MSGNOTICE*)pMsg;
			gUserMGR.SetVersion( pmsg->Msg );
			gUserMGR.SaveVersion();
			g_Console.LOG( 4, "Change Version : %s", pmsg->Msg );

			pmsg->Protocol = MP_MORNITORMAPSERVER_CHANGE_VERSION_ACK;
			g_Network.Send2Server( dwConnectionIndex, pMsg, sizeof(MSGNOTICE) );
		}
		break;

	case MP_MORNITORMAPSERVER_QUERY_MAXUSER_SYN:
		{
			MSG_DWORD msg;
			msg.Category = MP_MORNITORMAPSERVER;
			msg.Protocol = MP_MORNITORMAPSERVER_QUERY_MAXUSER_ACK;
			msg.dwData = g_dwMaxUser;

			g_Network.Send2Server( dwConnectionIndex, (char*)&msg, sizeof(msg) );
		}
		break;
	case MP_MORNITORMAPSERVER_CHANGE_MAXUSER_SYN:
		{
			MSG_DWORD* pmsg = (MSG_DWORD*)pMsg;
			g_dwMaxUser = pmsg->dwData;
			g_Console.LOG( 4, "Max User : %d", g_dwMaxUser );

			MSG_DWORD msg;
			msg.Category = MP_MORNITORMAPSERVER;
			msg.Protocol = MP_MORNITORMAPSERVER_CHANGE_MAXUSER_ACK;
			msg.dwData = g_dwMaxUser;

			g_Network.Send2Server( dwConnectionIndex, (char*)&msg, sizeof(msg) );
		}
		break;
	}
}

void MP_POWERUPMsgParser(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength)
{
	BOOTMNGR->NetworkMsgParse(dwConnectionIndex, pMsg, dwLength);
}

void MP_DISTRIBUTESERVERMsgParser(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength)
{
	
	MSGROOT* pTempMsg = (MSGROOT*)pMsg;
		switch(pTempMsg->Protocol)
		{
/*
		case MP_SERVER_PWRUP:
			{
				MSG_WORD * msg = (MSG_WORD *)pMsg;
				SERVERINFO * info = g_pServerTable->FindServer(msg->wData);//port
				info->dwConnectionIndex = dwConnectionIndex;
				// situation : 叼胶飘府轰飘啊 难廉 乐绊 俊捞怜飘啊 立加沁阑 锭 usercount = 0;
				if(info->wServerKind == AGENT_SERVER)
					info->wAgentUserCnt = 0;
				if(info->wServerKind == MONITOR_SERVER || info->wServerKind == MONITOR_AGENT_SERVER)
					{
						REGIST_MAP msg;
						msg.Category = MP_SERVER;
						msg.Protocol = MP_SERVER_REGISTMAP_ACK;
						msg.mapServerPort = g_pServerTable->GetSelfServer()->wPortForServer;
						msg.mapnum = g_pListCollect->GetLoadDistributeNum();
						g_Network.Send2Server(dwConnectionIndex, (char*)&msg, sizeof(msg));
					}
			}
			break;
		case MP_SERVER_REGISTMAP_SYN:
			{
				REGIST_MAP msg;
				msg.Category = MP_SERVER;
				msg.Protocol = MP_SERVER_REGISTMAP_ACK;
				msg.mapServerPort = g_pServerTable->GetSelfServer()->wPortForServer;
				msg.mapnum = g_pListCollect->GetLoadDistributeNum();
				g_Network.Send2Server(dwConnectionIndex, (char*)&msg, sizeof(msg));
			}
			break;*/

		case MP_SERVER_USERCNT:
			{
				MSG_WORD2* recv = (MSG_WORD2*)pMsg;
				WORD port = recv->wData1;		// Port
				SERVERINFO * info = g_pServerTable->FindServer(port);
				info->wAgentUserCnt = recv->wData2;
			}
			break;
		}
	
}
void MP_DISTRIBUTEAUTOPATCHMsgParser(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength)
{
	MSGROOT* pTempMsg = (MSGROOT*)pMsg;
	switch(pTempMsg->Protocol)
	{
	case MP_AUTOPATCH_TRAFFIC_SYN:
		{
			ServerTraffic * msg = (ServerTraffic *)pMsg;
			ServerTraffic sendMsg;
			sendMsg.Category = MP_AUTOPATCH;
			sendMsg.Protocol = MP_AUTOPATCH_TRAFFIC_ACK;
			sendMsg.UserNum = 0;
			sendMsg.Returnkey = msg->Returnkey;

			g_pServerTable->SetPositionHead();
			SERVERINFO * info = NULL;
			while(info = (SERVERINFO *)g_pServerTable->GetData())
			{
				if(info->wServerKind == AGENT_SERVER)
					sendMsg.UserNum += info->wAgentUserCnt;
			}
			sendMsg.UserNum = 123;
			g_Network.Send2User(dwConnectionIndex, (char *)&sendMsg, sizeof(sendMsg));
		}
		break;
	}
}

void MP_USERCONNMsgParser(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength)
{
	MSGROOT* pTempMsg = (MSGROOT*)pMsg;
	switch(pTempMsg->Protocol)
	{
	case MP_USERCONN_LOGIN_SYN:
		{
			MSG_LOGIN_SYN* pmsg = (MSG_LOGIN_SYN*)pMsg;

			// 滚怜 厚背
			if( gUserMGR.IsValidVersion(pmsg->Version) == FALSE )				// check version check
			{
				// 橇肺弊伐评父 烙矫肺 眉农 救窃.......
				if( strcmp( strupr(pmsg->id), "YUNHOZZZ" ) == 0 ||
					strcmp( strupr(pmsg->id), "BISHOP" ) == 0 ||
					strcmp( strupr(pmsg->id), "ANDYAMY" ) == 0 ||
					strcmp( strupr(pmsg->id), "PUNKORAMA" ) == 0 ||
					strcmp( strupr(pmsg->id), "TAMOO" ) == 0  || 
					strcmp( strupr(pmsg->id), "KOOUZZ" ) == 0 ) //抛胶飘 窍扁 困秦 悼绕揪 持菌澜 - hs
				{
					//////////////////////////////////////////////////////////////////////////
					// testcode
					USERINFO* pInfo = g_pUserTable->FindUser(dwConnectionIndex);
					if(pInfo)
					{
						FILE* fp = fopen("loginchk.txt","a");
						fprintf(fp,"%s\t%d\t%d\t%d\n",pmsg->id,dwConnectionIndex,(DWORD)pInfo,pInfo->dwUniqueConnectIdx);
						fclose(fp);
					}
					//////////////////////////////////////////////////////////////////////////
					
				}
				else
				{
					LoginError( dwConnectionIndex, pmsg->AuthKey, LOGIN_ERROR_INVALID_VERSION );
					return;
				}
			}
			
			//////////////////////////////////////////////////////////////////////////
			// testcode
			// 橇肺弊伐评父 烙矫肺 眉农 救窃.......
			if( strcmp( strupr(pmsg->id), "YUNHOZZZ" ) == 0 ||
				strcmp( strupr(pmsg->id), "BISHOP" ) == 0 ||
				strcmp( strupr(pmsg->id), "ANDYAMY" ) == 0 ||
				strcmp( strupr(pmsg->id), "PUNKORAMA" ) == 0 ||
				strcmp( strupr(pmsg->id), "TAMOO" ) == 0  || 
				strcmp( strupr(pmsg->id), "KOOUZZ" ) == 0 ) //抛胶飘 窍扁 困秦 悼绕揪 持菌澜 - hs
			{
				USERINFO* pInfo = g_pUserTable->FindUser(dwConnectionIndex);
				if(pInfo)
				{
					pInfo->UserLevel = eUSERLEVEL_PROGRAMMER;
					if(pInfo->UserLevel == eUSERLEVEL_PROGRAMMER)
					{
						FILE* fp = fopen("loginchk.txt","a");
						fprintf(fp,"LOGIN_SYN %s\t%d\t%d\t%d\n",pmsg->id,dwConnectionIndex,(DWORD)pInfo,pInfo->dwUniqueConnectIdx);
						fclose(fp);
					}
				}
			}
			//////////////////////////////////////////////////////////////////////////
	
			// MaxUser力茄档 LoginCheckQuery救俊辑....
			// MemberDB 背眉俊 蝶弗 2004.03.22
			char ip[20] = {0,};
			WORD port = 0;
			g_Network.GetUserAddress(dwConnectionIndex, ip, &port);

			SERVERINFO* FastInfo = g_pServerTable->GetFastServer(AGENT_SERVER);
			if(FastInfo == NULL)
			{
				LoginError(dwConnectionIndex,pmsg->AuthKey,LOGIN_ERROR_NOAGENTSERVER);
				DisconnectUser(dwConnectionIndex);
				return;
			}

			LoginCheckQuery(pmsg->id, pmsg->pw, ip, g_nServerSetNum, pmsg->AuthKey, dwConnectionIndex, g_dwMaxUser, FastInfo->wServerNum);
		}
		break;
	case MP_USERCONN_FORCE_DISCONNECT_OVERLAPLOGIN:
		{
			USERINFO* pUserInfo = g_pUserTable->FindUser(dwConnectionIndex);
			if(pUserInfo == NULL)
				return;
			if(pUserInfo->dwUserID == NULL || pUserInfo->State != 4)	// 肋给等 菩哦(酒付档 秦欧)
			{
				DisconnectUser(dwConnectionIndex);
				return;
			}
			
			MSGBASE msg;
			msg.Category = MP_USERCONN;
			msg.Protocol = MP_USERCONN_FORCE_DISCONNECT_OVERLAPLOGIN;
			msg.dwObjectID = pUserInfo->dwUserID;
			g_Network.Broadcast2AgentServer((char*)&msg,sizeof(msg));

			LoginCheckDelete(pUserInfo->dwUserID);
		}
		break;

	
	case MP_USERCONN_NOTIFY_USERLOGIN_ACK:
		{	// Agent 辑滚俊辑 柯 皋技瘤
			MSG_DWORD3* pmsg = (MSG_DWORD3*)pMsg;
			DWORD UserIdx = pmsg->dwObjectID;
			DWORD DistAuthKey = pmsg->dwData1;
			DWORD AgentAuthKey = pmsg->dwData2;
			DWORD DistConnectionIdx = pmsg->dwData3;

			SERVERINFO* pServerInfo = g_pServerTable->FindServerForConnectionIndex(dwConnectionIndex);
			if(pServerInfo == NULL)
			{
				// 秽!~ -0- Call Yunho Plz
				ASSERT(0);
				return;
			}

			USERINFO* pInfo = g_pUserTable->FindUser(DistConnectionIdx);

			if( pInfo == NULL )								// 捞固 唱埃版快
			{
				LoginCheckDelete(UserIdx);
				//俊捞怜飘肺 焊郴辑 蜡历 remove矫虐扁.
				MSG_DWORD2 msg;
				msg.Category	= MP_USERCONN;
				msg.Protocol	= MP_USERCONN_NOTIFYTOAGENT_ALREADYOUT;
				msg.dwData1		= UserIdx;
				msg.dwData2		= AgentAuthKey;
				g_Network.Send2Server(dwConnectionIndex,(char*)&msg, sizeof( msg ) );
				return;
			}
			if( pInfo->dwUniqueConnectIdx != DistAuthKey )	// 捞固 唱啊绊 促弗 逞捞 甸绢柯 版快
			{
				LoginCheckDelete(UserIdx);
				//俊捞怜飘肺 焊郴辑 蜡历 remove矫虐扁.
				MSG_DWORD2 msg;
				msg.Category	= MP_USERCONN;
				msg.Protocol	= MP_USERCONN_NOTIFYTOAGENT_ALREADYOUT;
				msg.dwData1		= UserIdx;
				msg.dwData2		= AgentAuthKey;
				g_Network.Send2Server(dwConnectionIndex,(char*)&msg, sizeof( msg ) );
				return;
			}

			MSG_LOGIN_ACK msg;
			msg.Category = MP_USERCONN;
			msg.Protocol = MP_USERCONN_LOGIN_ACK;
			msg.userIdx = UserIdx;
			msg.cbUserLevel = pInfo->UserLevel;
			strcpy(msg.agentip,pServerInfo->szIPForUser);
			msg.agentport = pServerInfo->wPortForUser;
			g_Network.Send2User(pInfo->dwConnectionIndex,(char*)&msg, sizeof(msg));
//			DisconnectUser(pInfo->dwConnectionIndex);
		}
		break;
	case MP_USERCONN_NOTIFY_USERLOGIN_NACK:		//KKK
		{	// Agent 辑滚俊辑 柯 皋技瘤
			MSG_DWORD3* pmsg = (MSG_DWORD3*)pMsg;
			DWORD UserIdx = pmsg->dwObjectID;
			DWORD DistAuthKey = pmsg->dwData1;
			DWORD ErrorReason = pmsg->dwData2;
			DWORD DistConnectionIdx = pmsg->dwData3;

			USERINFO* pInfo = g_pUserTable->FindUser(DistConnectionIdx);
			if(pInfo == NULL)		// 捞固 唱艾栏搁
				return;
			
			LoginError(pInfo->dwConnectionIndex,DistAuthKey,ErrorReason);
			DisconnectUser(pInfo->dwConnectionIndex);
		}
		break;

	case MP_USERCONN_REQUEST_DISTOUT:
		{
			USERINFO* pInfo = g_pUserTable->FindUser(dwConnectionIndex);
			if(pInfo == NULL)		// 捞固 唱艾栏搁
				return;
			pInfo->bRecvDistOut = TRUE;
			DisconnectUser(dwConnectionIndex);
		}
		break;
	}
}
/*
void MP_MORNITORTOOLMsgParser(DWORD dwConnectionIndex, char* pMsg, DWORD dwLength)
{

		MSGBASE* pTempMsg = (MSGBASE*)pMsg;
	
		switch(pTempMsg->Protocol)
		{
		case MP_MORNITORTOOL_CHECK_ON_SYN:
			{
				MAPSERVER_TRANSDATA msg;
				
				msg.Category = MP_MORNITORTOOL; 
				msg.Protocol = MP_MORNITORTOOL_CHECK_ON_ACK;
				msg.MapServerNum = g_pListCollect->GetLoadDistributeNum();
				g_Console.LOG(4, "Test Protocol Recv");
				g_Network.Send2Server(dwConnectionIndex, (char*)&msg, sizeof(MAPSERVER_TRANSDATA));
	
			}
			break;
		case MP_MORNITORTOOL_MAPSERVER_TURNOFF_SYN:
			{
				MAPSERVER_TRANSDATA msg;
				memcpy(&msg,(MAPSERVER_TRANSDATA*)pMsg,sizeof(MAPSERVER_TRANSDATA));
	
				msg.Category = MP_MORNITORTOOL; 
				msg.Protocol = MP_MORNITORTOOL_MAPSERVER_TURNOFF_ACK;
			
				g_Console.LOG(4, "Off Request received");
				g_Network.Send2Server(dwConnectionIndex, (char*)&msg, sizeof(MAPSERVER_TRANSDATA));
				ExitProcess(0);	
			}
			break;
		case MP_MORNITORTOOL_MESSAGE_SYN:
			{
				MSGBASEDATA msg;
				memcpy(&msg,(MSGBASEDATA*)pMsg,sizeof(MSGBASEDATA));
				msg.Messagebuff;
				g_Console.LOG(4, msg.Messagebuff);
			}
			break;
		case MP_MORNITORTOOL_USERLOGOUT_SYN:
			{
				//蜡历 肺弊 酒眶贸府 
				g_Console.LOG(4, "User Logout Request received");
			}
			break;
	
	
		}
	
}
*/

⌨️ 快捷键说明

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