www.pudn.com > [Server]Distribute.rar > DistributeNetworkMsgParser.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; 
	 
	 
		} 
	 
} 
*/