示例#1
0
void NetClient::ConnectToClients()
{
    std::vector<NetDriver> vecDrivers;

    RobotXml robotxml;
    robotxml.ReadRobotDrivers(NETWORKROBOT,vecDrivers);

    for(unsigned int i=0;i<vecDrivers.size();i++)
    {
        ConnectToDriver(vecDrivers[i]);
    }

}
示例#2
0
void NetClient::SetCarInfo(const char *pszName)
{
    std::vector<NetDriver> vecDrivers;

    RobotXml robotxml;
    robotxml.ReadRobotDrivers(NETWORKROBOT,vecDrivers);

    for (unsigned int i=0;i<vecDrivers.size();i++)
    {
        if (vecDrivers[i].name == m_strDriverName)
        {
            strncpy(vecDrivers[i].car,pszName,64);
            SendDriverInfoPacket(&vecDrivers[i]);
        }
    }
}
示例#3
0
void NetServer::SetCarInfo(const char *pszName)
{
	std::vector<NetDriver> vecDrivers;

	RobotXml robotxml;
	robotxml.ReadRobotDrivers(NETWORKROBOT,vecDrivers);

	for (unsigned int i=0;i<vecDrivers.size();i++)
	{
		if (vecDrivers[i].name == m_strDriverName)
		{
			strncpy(vecDrivers[i].car,pszName,64);
			UpdateDriver(vecDrivers[i]);
			break;
		}
	}
}
示例#4
0
void NetServer::UpdateDriver(NetDriver & driver)
{
	assert(m_strRaceXMLFile!="");
	bool bNewDriver = true;

	NetServerMutexData *pSData = LockServerData();

	// Search for the driver in m_vecNetworkPlayers, and update its car name if found.
	for(unsigned int i=0;i<pSData->m_vecNetworkPlayers.size();i++)
	{
		if (strcmp(driver.name,pSData->m_vecNetworkPlayers[i].name)==0)
		{
			bNewDriver = false;
			strncpy(pSData->m_vecNetworkPlayers[i].car,driver.car,64);
			break;
		}
	}

	// If not found, append it to m_vecNetworkPlayers
	if (bNewDriver)
	{
		driver.idx = pSData->m_vecNetworkPlayers.size()+1;

		if (!driver.client)
		{
			driver.address = m_pServer->address;
		}

		pSData->m_vecNetworkPlayers.push_back(driver);
		
		NetMutexData *pNData = LockNetworkData();
		pNData->m_vecReadyStatus.push_back(false);
		UnlockNetworkData();
	}

	GenerateDriversForXML();
	
	RobotXml rXml;
	rXml.CreateRobotFile("networkhuman",pSData->m_vecNetworkPlayers);

	UnlockServerData();
	
	Dump("NetServer::UpdateDriver");

	SetRaceInfoChanged(true);
}
示例#5
0
void NetServer::RemoveDriver(ENetEvent event)
{
	int playerStartIndex;
	ENetAddress address = event.peer->address;

	char hostName[256];
	enet_address_get_host_ip (&address,hostName,256);

    GfLogTrace ("Client Player Info disconnect from %s\n",hostName); 
	
	std::vector<NetDriver>::iterator p;

	if (m_vecWaitForPlayers.size()>0)
	{
		p = m_vecWaitForPlayers.begin();

		while(p!=m_vecWaitForPlayers.end())
		{

			if ((p->address.host == address.host)&&(p->hostPort == address.port))
			{
				m_vecWaitForPlayers.erase(p);
				break;
			}

			p++;
		}

		if (m_vecWaitForPlayers.size()==0)
			m_bBeginRace = true;
	}

	//look for driver id
	NetServerMutexData *pSData = LockServerData();
	for (p = pSData->m_vecNetworkPlayers.begin();p!=pSData->m_vecNetworkPlayers.end();p++)
	{
		if (p->client)
		{
			if ((p->address.host == address.host)&&(p->hostPort == address.port))
			{
				if(m_bRaceActive)
				{
					playerStartIndex = p->idx-1;
					pSData->m_vecNetworkPlayers.erase(p);
					RemovePlayerFromRace(playerStartIndex);
					GenerateDriversForXML();
					RobotXml rXml;
					rXml.CreateRobotFile("networkhuman",pSData->m_vecNetworkPlayers);
					SetRaceInfoChanged(true);
				}
				else
				{
					pSData->m_vecNetworkPlayers.erase(p);
					GenerateDriversForXML();
					RobotXml rXml;
					rXml.CreateRobotFile("networkhuman",pSData->m_vecNetworkPlayers);
					SetRaceInfoChanged(true);
				}

				UnlockServerData();
				return;
			}
		}
	}

	UnlockServerData();
}