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

📄 room.cpp

📁 国外网游源码....除工具源码缺少之外,其余程序都全...至于,什么游戏,因为国内还没有,所以找不到测试
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void CRoom::SendAll(void *ioc, int nUserIndex)
{
	CUser *pClient;

	int i=0;
	while(i < g_cLobbyServer.m_cConfig.cfg_maxplayer)
	{
		if(m_nUserIdx[i] != -1)
		{
			pClient = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
			if((pClient->m_nState == CClient::STATE_ROOM || pClient->m_nState == CClient::STATE_GAME) &&
				pClient->m_nIndex != nUserIndex)
			{
				if(!net_broadcast(pClient->m_nIndex, ioc))
					net_disconnect(pClient->m_nIndex, false);
			}
		}
		++i;
	}

	net_endcast(ioc);
}

void CRoom::SendRoom(void *ioc)
{
	CUser *pClient;

	int i=0;
	while(i < g_cLobbyServer.m_cConfig.cfg_maxplayer)
	{
		if(m_nUserIdx[i] != -1)
		{
			pClient = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
			if(pClient->m_nState == CClient::STATE_ROOM)
			{
				if(!net_broadcast(pClient->m_nIndex, ioc))
					net_disconnect(pClient->m_nIndex, false);
			}
		}
		++i;
	}

	net_endcast(ioc);
}

void CRoom::SendRoom(void *ioc, int nUserIndex)
{
	CUser *pClient;

	int i=0;
	while(i < g_cLobbyServer.m_cConfig.cfg_maxplayer)
	{
		if(m_nUserIdx[i] != -1 && m_nUserIdx[i] != nUserIndex)
		{
			pClient = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
			if(pClient->m_nState == CClient::STATE_ROOM)
			{
				if(!net_broadcast(pClient->m_nIndex, ioc))
					net_disconnect(pClient->m_nIndex, false);
			}
		}
		++i;
	}

	net_endcast(ioc);
}

void CRoom::SendGame(void *ioc)
{
	CUser *pClient;

	int i=0;
	while(i < g_cLobbyServer.m_cConfig.cfg_maxplayer)
	{
		if(m_nUserIdx[i] != -1)
		{
			pClient = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
			if(pClient->m_nState == CClient::STATE_GAME)
			{
				if(!net_broadcast(pClient->m_nIndex, ioc))
					net_disconnect(pClient->m_nIndex, false);
			}
		}
		++i;
	}

	net_endcast(ioc);
}

void CRoom::SendGame(void *ioc, int nUserIndex)
{
	CUser *pClient;

	int i=0;
	while(i < g_cLobbyServer.m_cConfig.cfg_maxplayer)
	{
		if(m_nUserIdx[i] != -1 && m_nUserIdx[i] != nUserIndex)
		{
			pClient = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
			if(pClient->m_nState == CClient::STATE_GAME)
			{
				if(!net_broadcast(pClient->m_nIndex, ioc))
					net_disconnect(pClient->m_nIndex, false);
			}
		}
		++i;
	}

	net_endcast(ioc);
}

void CRoom::StartGame()
{
	void *ioc;

	//饭第惑怕 八荤, //评技泼 八荤
	if(!CheckReady())
	{
		if((ioc = net_message(M_LOBBYSERVER, LSC_GAME_START, ERR_GAME_READY)))
		{
			if(!net_send(m_nUserIdx[m_iCapSlot], ioc))
				net_disconnect(m_nUserIdx[m_iCapSlot], false);
		}
		return;
	}

	if((ioc = net_message(M_LOBBYSERVER, LSMS_GAMEZONE_INFO, 0)))
	{
		net_packet(ioc, &m_iChannel, 1);
		net_packet(ioc, &m_nIndex, 1);
		net_packet(ioc, &m_nUserLimit, 1);
		net_packet(ioc, &m_nUserCnt, 1);
		net_packet(ioc, &m_nMode, 1);
		net_packet(ioc, &m_nMap, 1);
		net_packet(ioc, &m_dwPlayTime, 1);
		net_packet(ioc, &m_nRepairCnt, 1);

		if(!g_cLobbyServer.SendMaster(ioc))	//付胶磐辑滚俊 傈价 角菩矫..
		{
			int i=g_cLobbyServer.m_cConfig.cfg_maxplayer;
			while(i--)
			{
				if(m_nUserIdx[i] == -1)	continue;
				net_disconnect(m_nUserIdx[i], false);	//规救狼 努扼捞攫飘 楷搬阑 葛滴 谗绰促
			}
			return;
		}
	}

	m_nState = STATE_RUNNING;
}

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

	SetTeamBalance(pUser->m_nIndex);

	IN_ADDR in_addr;
	char *ip;
	in_addr.s_addr = m_dwGameIP;
	ip = inet_ntoa(in_addr);

	void *ioc = net_message(M_LOBBYSERVER, LSC_GAME_START, 0);
	if(ioc)
	{
		net_packet(ioc, ip, LEN_IP+1);
		net_packet(ioc, &m_wGamePort, 1);
		net_packet(ioc, &m_nAuthSize, 1);
		net_packet(ioc, &m_nAuthCnt, 1);
		net_packet(ioc, m_pAuthIndex, m_nAuthCnt);
		net_packet(ioc, m_pAuthCode, m_nAuthCnt);
		net_packet(ioc, &m_nAuthCnt, 1);

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

		pUser->m_nState = CClient::STATE_JOINGAME;
		pUser->m_nReady = READY_PLAY;
	}

	//抄涝茄 蜡历狼 沥焊甫 盎脚
	lsc_member_update(m_iChannel, m_nIndex);
}

void CRoom::EndGame()
{
	void *ioc = net_message(M_LOBBYSERVER, LSC_GAME_END, 0);
	if(ioc)
	{
		CUser *pUser;

		int i=g_cLobbyServer.m_cConfig.cfg_maxplayer;
		while(i--)
		{
			if(m_nUserIdx[i] == -1)	continue;

			pUser = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
			if(pUser->m_nState < CClient::STATE_JOINGAME)
				continue;

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

		net_endcast(ioc);
	}

	m_nState = STATE_WAITING;
}

BOOL CRoom::CheckReady()
{
#ifdef _MODE_SERVICE

	CUser *pUser;
	int nTeam[TEAM_MAX]={0, };

	int i=g_cLobbyServer.m_cConfig.cfg_maxplayer;
	while(i--)
	{
		if(m_nUserIdx[i] == -1)	continue;

		pUser = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
		if(pUser->m_nState != CClient::STATE_ROOM || pUser->m_nReady == READY_OFF)
			continue;

		++nTeam[pUser->m_nTeam];
	}

	if(m_nMode == MODE_SURVIVAL && nTeam[TEAM_NONE] < 2)
		return FALSE;
	else if(nTeam[TEAM_BLUE] == 0 || nTeam[TEAM_RED] == 0)
		return FALSE;

#endif

	return TRUE;
}

void CRoom::SetTeam()
{
	if(m_nMode == MODE_SURVIVAL)	return;

	int nTeam[TEAM_MAX]={0, };

	int i=g_cLobbyServer.m_cConfig.cfg_maxplayer;
	while(i--)
	if(m_nUserIdx[i] != -1)
		++nTeam[g_cLobbyServer.m_cpUser[m_nUserIdx[i]].m_nTeam];	//泅犁 且寸等 阿阿 评狼 评盔 荐 备茄促

	i=0;
	while(i < g_cLobbyServer.m_cConfig.cfg_maxplayer)
	{
		if(m_nUserIdx[i] != -1 && g_cLobbyServer.m_cpUser[m_nUserIdx[i]].m_nTeam == TEAM_NONE)	//货肺款 蜡历啊 甸绢客 评阑 且寸罐澜
		{
			CUser *pUser = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
			if(nTeam[TEAM_BLUE] >= m_nUserLimit/2)			//喉风评捞 菜谩栏聪膊 饭靛评
				pUser->m_nTeam = TEAM_RED;
			else if(nTeam[TEAM_RED] >= m_nUserLimit/2)		//饭靛评捞 菜谩栏聪膊 喉风评
				pUser->m_nTeam = TEAM_BLUE;
			else if(nTeam[TEAM_BLUE] > nTeam[TEAM_RED])		//喉风评捞 饭靛评焊促 腹栏搁 饭靛评
				pUser->m_nTeam = TEAM_RED;
			else											//喉风评捞 饭靛评焊促 累芭唱 鞍栏搁 喉风评
				pUser->m_nTeam = TEAM_BLUE;

			break;
		}
		++i;
	}
}

void CRoom::SetTeamBalance()
{
	m_nState = STATE_PLAYING;

	if(m_nMode == MODE_SURVIVAL)	return;

	CUser *pUser;
	int nTeam[TEAM_MAX]={0, };
	int nLargeTeam, nSmallTeam;
	int nGap;
	int nPlayCnt=0;

	int i=g_cLobbyServer.m_cConfig.cfg_maxplayer;
	while(i--)
	{
		if(m_nUserIdx[i] == -1)	continue;

		pUser = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
		if(pUser->m_nReady == READY_ON)	//饭叼啊 登菌栏搁..
		{
			++nTeam[pUser->m_nTeam];	//泅犁 且寸等 阿阿 评狼 评盔 荐 备茄促
			++nPlayCnt;
		}
	}

	nGap = abs(nTeam[TEAM_BLUE] - nTeam[TEAM_RED]);

	if(nGap < 2)					return;

	if(nTeam[TEAM_BLUE] > nTeam[TEAM_RED])
	{
		nLargeTeam = TEAM_BLUE;
		nSmallTeam = TEAM_RED;
	}
	else
	{
		nLargeTeam = TEAM_RED;
		nSmallTeam = TEAM_BLUE;
	}

	i=g_cLobbyServer.m_cConfig.cfg_maxplayer;
	while(i--)
	{
		if(m_nUserIdx[i] == -1)	continue;

		pUser = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
		if(pUser->m_nTeam == nLargeTeam)
		{
			pUser->m_nTeam = nSmallTeam;
			nGap -= 2;

			if(nGap < 2)	break;
		}
	}
}

void CRoom::SetTeamBalance(short nUserIndex)
{
	if(m_nMode == MODE_SURVIVAL)	return;

	CUser *pUser = (CUser *)g_cLobbyServer.GetClient(nUserIndex);
	CUser *pClient;

	if(pUser->m_nTeam == TEAM_OBSERVER)	return;

	int nTeam[TEAM_MAX]={0, };
	BYTE nEnemy;
	int nGap;

	int i=g_cLobbyServer.m_cConfig.cfg_maxplayer;
	while(i--)
	if(m_nUserIdx[i] != -1)
	{
		pClient = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
		if(pClient->m_nReady == READY_PLAY)
			++nTeam[pClient->m_nTeam];	//泅犁 且寸等 阿阿 评狼 评盔 荐 备茄促
	}

	nGap = abs(nTeam[TEAM_BLUE] - nTeam[TEAM_RED]);

	if(nGap < 2)	return;

	nEnemy = (pUser->m_nTeam == TEAM_BLUE) ? TEAM_RED : TEAM_BLUE;

	if(nTeam[pUser->m_nTeam] < nTeam[nEnemy])	return;

	pUser->m_nTeam = nEnemy;
}

⌨️ 快捷键说明

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