msghandler.cpp

来自「国外网游源码....除工具源码缺少之外,其余程序都全...至于,什么游戏,因为国」· C++ 代码 · 共 1,848 行 · 第 1/5 页

CPP
1,848 行
字号
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] cms_author_code()", id);
		return;
	}
	if(pUser->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d StateError[state != STATE_CONNECT] cms_author_code() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
		return;
	}

	void *ioc;
	WORD version_hi, version_lo;

	net_data(&packet, &version_hi, 1);
	net_data(&packet, &version_lo, 1);

	char *code = packet;
	int i=0;
	while(i < g_cMasterServer.m_cConfig.sys_auth_cnt)
	{
		if(g_cMasterServer.m_cConfig.sys_auth_code[i] != code[g_cMasterServer.m_cConfig.sys_auth_index[i]])
		{
			if((ioc = net_message(M_MASTERSERVER, MSC_VERIFY, ERR_DIFFERENT_AUTHORCODE)))
			{
				if(!net_send(pUser->m_nIndex, ioc))
					net_disconnect(pUser->m_nIndex, false);
			}
			return;
		}
		++i;
	}

	if(g_cMasterServer.m_cConfig.sys_version_hi != version_hi || g_cMasterServer.m_cConfig.sys_version_lo != version_lo)
	{
		if((ioc = net_message(M_MASTERSERVER, MSC_VERIFY, ERR_DIFFERENT_VERSION)))
		{
			net_packet(ioc, &g_cMasterServer.m_cConfig.sys_version_hi, 1);
			net_packet(ioc, &g_cMasterServer.m_cConfig.sys_version_lo, 1);

			if(!net_send(pUser->m_nIndex, ioc))
				net_disconnect(pUser->m_nIndex, false);
		}
		return;
	}

	if((ioc = net_message(M_MASTERSERVER, MSC_VERIFY, 0)))
	{
		net_packet(ioc, &g_cMasterServer.m_cConfig.sys_port_udp, 1);

		if(!net_send(pUser->m_nIndex, ioc))
			net_disconnect(pUser->m_nIndex, false);
	}
}

void cms_login_info(int id, char *packet)
{
	CUser *pUser = (CUser *)g_cMasterServer.GetClient(id);
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] cms_login_info()", id);
		return;
	}
	if(pUser->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d StateError[state != STATE_CONNECT] cms_login_info() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
		return;
	}

	if(!g_cMasterServer.m_bRun)
	{
		void *ioc = net_message(M_MASTERSERVER, MSC_USER_INFO, ERR_SERVICE_STOP);
		if(ioc)
		{
			if(!net_send(pUser->m_nIndex, ioc))
				net_disconnect(pUser->m_nIndex, false);
		}
		return;
	}

	net_data(&packet, pUser->m_szID, LEN_ID+1);
	net_data(&packet, pUser->m_szPwd, LEN_PWD+1);
	net_data(&packet, &pUser->m_dwPrivateIP, 1);

	pUser->m_szID[LEN_ID] = NULL;
	pUser->m_szPwd[LEN_PWD] = NULL;

	if(!strlen(pUser->m_szID))
	{
		void *ioc = net_message(M_MASTERSERVER, MSC_USER_INFO, ERR_DIFFERENT_ID);
		if(ioc)
		{
			if(!net_send(pUser->m_nIndex, ioc))
				net_disconnect(pUser->m_nIndex, false);
		}
		return;
	}

	if(!spsel_user_info(pUser->m_nIndex))
		net_disconnect(pUser->m_nIndex, false);
}

bool msc_user_info(int id)
{
	CUser *pUser = (CUser *)g_cMasterServer.GetClient(id);
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] msc_user_info()", id);
		return false;
	}
	if(pUser->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d StateError[state != STATE_CONNECT] msc_user_info() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
		return false;
	}

	pUser->m_nState = CClient::STATE_JOINLOGIN;

	void *ioc = net_message(M_MASTERSERVER, MSC_USER_INFO, 0);
	if(ioc)
	{
#ifdef _DBG_ENGINE
		_printf("肺弊牢 沥焊\n%s(%s)\n", pUser->m_szID, pUser->m_szNick);
#endif

		MSGINFO *msg = g_cMasterServer.GetMsgObj();

		msg->uUserInfo.login_userindex = pUser->m_nIndex;

		strcpy(msg->uUserInfo.user_id, pUser->m_szID);
		strcpy(msg->uUserInfo.user_nick, pUser->m_szNick);
		memcpy(msg->uUserInfo.clan_name, pUser->m_szClan, LEN_CLANNAME+1);

		msg->uUserInfo.level = pUser->m_nLevel;
		msg->uUserInfo.exp = pUser->m_nExp;
		msg->uUserInfo.gender = pUser->m_nGender;
		msg->uUserInfo.pilot = pUser->m_nPilot;
		msg->uUserInfo.cash = pUser->m_nCash;
		msg->uUserInfo.point = pUser->m_nPoint;
		msg->uUserInfo.best_point = pUser->m_dwBestPoint;
		msg->uUserInfo.best_straight = pUser->m_dwBestStraight;
		msg->uUserInfo.win_straight = pUser->m_dwWinStraight;
		msg->uUserInfo.win = pUser->m_dwWin;
		msg->uUserInfo.lose = pUser->m_dwLose;
		msg->uUserInfo.kill = pUser->m_dwKill;
		msg->uUserInfo.death = pUser->m_dwDeath;
		msg->uUserInfo.rank = pUser->m_dwRank;
		msg->uUserInfo.quit = pUser->m_dwQuit;
		msg->uUserInfo.black = pUser->m_dwBlack;
		msg->uUserInfo.inven_cnt = pUser->m_nInvenCnt;
		msg->uUserInfo.mechanic_cnt = pUser->m_nMechanicCnt;

		net_packet(ioc, &msg->uUserInfo, 1);
		net_packet(ioc, pUser->m_cInven, pUser->m_nInvenCnt);

		int i=0;
		while(i < pUser->m_nMechanicCnt)
		{
			if(pUser->m_cMechanic[i].account)
				net_packet(ioc, (char *)&pUser->m_cMechanic[i], sizeof(msg->uMechanicInfo));

			++i;
		}

		if(!net_send(pUser->m_nIndex, ioc))
			net_disconnect(pUser->m_nIndex, false);
	}

	spupd_game_login(pUser->m_nAccount, pUser->m_dwRemoteIP, pUser->m_dwPrivateIP);
	return true;
}

void cms_udp_ping(int id)
{
	CUser *pUser = (CUser *)g_cMasterServer.GetClient(id);
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] cms_udp_ping()", id);
		return;
	}
	if(pUser->m_nState != CClient::STATE_JOINLOGIN)	//UDP捞扁 锭巩俊 磊林 惯积窍绰 沥惑利牢 抗寇
	{
		_printf("**********************************exception************************************\n");
		_printf("PC%d StateError[state != STATE_JOINLOGIN] cms_udp_ping() > 泅犁 蜡历惑怕[%s]\n", pUser->m_nIndex, pUser->GetStateLog());
		return;
	}

	WORD port[2];

	port[0] = udp_portinfo(pUser->m_nIndex, 0);
	port[1] = udp_portinfo(pUser->m_nIndex, 1);

	if(port[0] && port[1])	//滴俺狼 器飘肺 葛滴 菩哦阑 罐酒好栏搁..促澜栏肺 逞变促
	{
		pUser->m_bSymmetric = (port[0] != port[1]);	//器飘啊 辑肺 促福搁 矫皋飘腐
		pUser->m_nState = CClient::STATE_LOGIN;

#ifdef _DBG_ENGINE
		IN_ADDR in_addr;
		in_addr.s_addr = udp_addrinfo(pUser->m_nIndex);

		_printf("PC%d UDP林家沥焊 %s:%d:%d\n", pUser->m_nIndex, inet_ntoa(in_addr), port[0], port[1]);
#endif

		msc_server_list(pUser->m_nIndex);
	}
}

void msc_server_list(int id)
{
	CUser *pUser = (CUser *)g_cMasterServer.GetClient(id);
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] msc_server_list()", id);
		return;
	}
	if(pUser->m_nState != CClient::STATE_LOGIN)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d StateError[state != STATE_LOGIN] msc_server_list() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
		return;
	}

	CLocal *pLocal;
	BYTE list_len, list_type;
	void *ioc;

	int i=0;
	do
	{
		ioc = net_message(M_MASTERSERVER, MSC_SERVER_LIST, 0);
		list_len = 0;

		while(i < g_cMasterServer.m_cLocalConn.local_cnt)
		{
			pLocal = g_cMasterServer.m_cpLocal + i++;

			if(pLocal->m_nState == CClient::STATE_LOGIN && pLocal->m_nType == M_LOBBYSERVER)
			{
				MSGINFO *msg = g_cMasterServer.GetMsgObj();

				msg->uServerList.list_type = LIST_ENUM;
				msg->uServerList.lobby_serverindex = pLocal->m_nIndex;
				msg->uServerList.user_cnt = pLocal->m_nUserCnt;
				msg->uServerList.user_limit = pLocal->m_nUserLimit;
				strcpy(msg->uServerList.server_name, pLocal->m_szName);

				net_packet(ioc, &msg->uServerList, 1);

				list_len += sizeof(msg->uServerList);
				if(list_len >= LEN_LISTBUF)	//府胶飘 力茄阑 哈绢车促
					break;
			}
		}

		list_type = LIST_END;			//府胶飘 场
		net_packet(ioc, &list_type, 1);

		if(!net_send(pUser->m_nIndex, ioc))
			net_disconnect(pUser->m_nIndex, false);

	} while(i < g_cMasterServer.m_cLocalConn.local_cnt);
}

void msc_server_update(int id)
{
	CUser *pUser = (CUser *)g_cMasterServer.GetClient(id);
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] msc_server_update()", id);
		return;
	}
	if(pUser->m_nState != CClient::STATE_LOGIN)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d StateError[state != STATE_LOGIN] msc_server_update() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
		return;
	}

	CLocal *pLocal;
	BYTE list_len, list_type;
	void *ioc;

	int i=0;
	do
	{
		ioc = udp_message(M_MASTERSERVER, MSC_SERVER_LIST, 0);
		list_len = 0;

		while(i < g_cMasterServer.m_cLocalConn.local_cnt)
		{
			pLocal = g_cMasterServer.m_cpLocal + i++;

			if(pLocal->m_nState == CClient::STATE_LOGIN && pLocal->m_nType == M_LOBBYSERVER)
			{
				MSGINFO *msg = g_cMasterServer.GetMsgObj();

				msg->uServerUpdate.list_type = LIST_UPD;
				msg->uServerUpdate.lobby_serverindex = pLocal->m_nIndex;
				msg->uServerUpdate.user_cnt = pLocal->m_nUserCnt;

				net_packet(ioc, &msg->uServerUpdate, 1);

				list_len += sizeof(msg->uServerUpdate);
				if(list_len >= LEN_LISTBUF)	//府胶飘 力茄阑 哈绢车促
					break;
			}
		}

		list_type = LIST_END;			//府胶飘 场
		net_packet(ioc, &list_type, 1);

		if(!net_send(pUser->m_nIndex, ioc))
			net_disconnect(pUser->m_nIndex, false);

	} while(i < g_cMasterServer.m_cLocalConn.local_cnt);
}

void msc_server_add(int lobby_serverindex)
{
	CLocal *pLocal = (CLocal *)g_cMasterServer.GetClient(lobby_serverindex);
	if(!pLocal)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d IndexError[local == NULL] msc_server_add()", lobby_serverindex);
		return;
	}
	if(pLocal->m_nState != CClient::STATE_LOGIN)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d StateError[state != STATE_LOGIN] msc_server_add() > 泅犁 辑滚惑怕[%s]", pLocal->m_nIndex, pLocal->GetStateLog());
		return;
	}
	if(pLocal->m_nType != M_LOBBYSERVER)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d TypeError[type != M_LOBBYSERVER] msc_server_add()", pLocal->m_nIndex);
		return;
	}

	void *ioc = net_message(M_MASTERSERVER, MSC_SERVER_LIST, 0);
	if(ioc)
	{
		MSGINFO *msg = g_cMasterServer.GetMsgObj();

		msg->uServerList.list_type = LIST_ADD;
		msg->uServerList.lobby_serverindex = pLocal->m_nIndex;
		msg->uServerList.user_cnt = pLocal->m_nUserCnt;
		msg->uServerList.user_limit = pLocal->m_nUserLimit;
		strcpy(msg->uServerList.server_name, pLocal->m_szName);

		net_packet(ioc, &msg->uServerList, 1);

		g_cMasterServer.SendAll(ioc);
	}
}

void msc_server_delete(int lobby_serverindex)
{
	CLocal *pLocal = (CLocal *)g_cMasterServer.GetClient(lobby_serverindex);
	if(!pLocal)

⌨️ 快捷键说明

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