Exemple #1
0
void NetClient::SetDriverReady(bool bReady)
{
    // Get local driver index in the race driver list
    int idx = GetDriverIdx();

    NetMutexData *pNData = LockNetworkData();
    pNData->m_vecReadyStatus[idx-1] = bReady;
    UnlockNetworkData();

    PackedBuffer msg;

    try
    {
        msg.pack_ubyte(DRIVERREADY_PACKET);
        msg.pack_int(idx);
        msg.pack_int(bReady);
    }
//    catch (PackedBufferException &e)
    catch (PackedBufferException)
    {
        GfLogFatal("SetDriverReady: packed buffer error\n");
    }
    GfLogTrace("SetDriverReady: packed data length=%d\n", msg.length());

    ENetPacket *pPacket = enet_packet_create (msg.buffer(), 
            msg.length(), 
            ENET_PACKET_FLAG_RELIABLE);

    if (enet_peer_send (m_pServer, RELIABLECHANNEL, pPacket)==0)
        return;
}
Exemple #2
0
void NetClient::ReadAllDriverReadyPacket(ENetPacket *pPacket)
{
    int rsize;

    PackedBuffer msg(pPacket->data, pPacket->dataLength);
    GfLogTrace("ReadAllDriverReadyPacket: packed data length=%d\n",
            msg.length());

    try
    {
        msg.unpack_ubyte();
        rsize = msg.unpack_int();

        NetMutexData *pNData = LockNetworkData();
        pNData->m_vecReadyStatus.clear();
        pNData->m_vecReadyStatus.resize(rsize);
        for (int i=0;i<rsize;i++)
            pNData->m_vecReadyStatus[i] = msg.unpack_int() ? true : false;

        UnlockNetworkData();
        SetRaceInfoChanged(true);
    }
//    catch (PackedBufferException &e)
    catch (PackedBufferException)
    {
        GfLogFatal("ReadAllDriverReadyPacket: packed buffer error\n");
    }

    GfLogTrace("Received All Driver Ready Packet\n");
}
Exemple #3
0
void NetServer::ReadDriverReadyPacket(ENetPacket *pPacket)
{
    GfLogTrace ("Read Driver Ready Packet\n"); 
	
	int idx = 0;
	bool bReady;

        PackedBuffer msg(pPacket->data, pPacket->dataLength);
        GfLogTrace("ReadDriverReadyPacket: packed data length=%d\n",
                msg.length());

        try
        {
                msg.unpack_ubyte();
                idx = msg.unpack_int();
                bReady = msg.unpack_int();
        }
        catch (PackedBufferException &e)
        {
                GfLogFatal("SendRaceSetupPacket: packed buffer error\n");
        }
	
	NetMutexData *pNData = LockNetworkData();
	if (idx > 0)
		pNData->m_vecReadyStatus[idx-1] = bReady;
	UnlockNetworkData();

	SendDriversReadyPacket();
}
Exemple #4
0
void NetServer::SetFinishTime(double time)
{
	NetMutexData *pNData = LockNetworkData();
	pNData->m_finishTime = time;
	UnlockNetworkData();
	SendFinishTimePacket();
}
Exemple #5
0
void NetServer::SendDriversReadyPacket()
{
	
	NetMutexData *pNData = LockNetworkData();

	int rsize = pNData->m_vecReadyStatus.size();

        PackedBuffer msg;

        try
        {
                msg.pack_ubyte(ALLDRIVERREADY_PACKET);
                msg.pack_int(rsize);
                for (int i = 0; i < rsize; i++)
                {
                        msg.pack_int(pNData->m_vecReadyStatus[i]);
                }
        }
        catch (PackedBufferException &e)
        {
                GfLogFatal("SendDriversReadyPacket: packed buffer error\n");
        }
        GfLogTrace("SendDriversReadyPacket: packed data length=%d\n",
                msg.length());

	UnlockNetworkData();

	ENetPacket * pPacket = enet_packet_create (msg.buffer(), 
                                              msg.length(), 
                                              ENET_PACKET_FLAG_RELIABLE);

	BroadcastPacket(pPacket,RELIABLECHANNEL);
	m_bRefreshDisplay = true;
}
Exemple #6
0
void NetServer::SendFinishTimePacket()
{
	GfLogTrace("Sending finish Time Packet\n");
	
	NetMutexData *pNData = LockNetworkData();
	double time = pNData->m_finishTime;
	UnlockNetworkData();

	GfLogInfo("Server finish time is %lf\n",time);
        
        PackedBuffer msg;

        try
        {
                msg.pack_ubyte(FINISHTIME_PACKET);
                msg.pack_double(time);
        }
        catch (PackedBufferException &e)
        {
                GfLogFatal("SendFinishTimePacket: packed buffer error\n");
        }
        GfLogTrace("SendFinishTimePacket: packed data length=%d\n",
                msg.length());

	ENetPacket * pPacket = enet_packet_create (msg.buffer(), 
                                              msg.length(), 
                                              ENET_PACKET_FLAG_RELIABLE);
	BroadcastPacket(pPacket,RELIABLECHANNEL);
}
Exemple #7
0
void NetServer::OverrideDriverReady(int idx,bool bReady)
{
	NetMutexData *pNData = LockNetworkData();
	pNData->m_vecReadyStatus[idx-1] = bReady;
	UnlockNetworkData();

	Dump("NetServer::OverrideDriverReady");

	SetRaceInfoChanged(true);
}
Exemple #8
0
//Remove disconnected player from race track
void NetServer::RemovePlayerFromRace(unsigned int idx)
{
	GfLogTrace("Removing disconnected player\n");
	std::vector<CarStatus> vecCarStatus;
	double time = 0.0;

	int startRank = GetDriverStartRank(idx);
	CarStatus cstatus;
	cstatus.topSpeed = -1.0;
	cstatus.fuel = -1.0;
	cstatus.startRank = startRank;
	cstatus.dammage = -1;
	cstatus.state = RM_CAR_STATE_ELIMINATED;
	cstatus.time = m_currentTime;
	
	NetMutexData *pNData = LockNetworkData();
	pNData->m_vecCarStatus.push_back(cstatus);
	UnlockNetworkData();

	vecCarStatus.push_back(cstatus);

	time = m_currentTime;

	int iNumCars = vecCarStatus.size();

        PackedBuffer msg;

        try
        {
                msg.pack_ubyte(CARSTATUS_PACKET);
                msg.pack_double(time);
                msg.pack_int(iNumCars);
                for (int i=0;i<iNumCars;i++)
                {
                        msg.pack_float(vecCarStatus[i].topSpeed);
                        msg.pack_int(vecCarStatus[i].state);
                        msg.pack_int(vecCarStatus[i].startRank);
                        msg.pack_int(vecCarStatus[i].dammage);
                        msg.pack_float(vecCarStatus[i].fuel);
                }
        }
        catch (PackedBufferException &e)
        {
                GfLogFatal("RemovePlayerFromRace: packed buffer error\n");
        }
        GfLogTrace("RemovePlayerFromRace: packed data length=%d\n",
                msg.length());

	ENetPacket * pPacket = enet_packet_create (msg.buffer(), 
                                              msg.length(), 
                                              ENET_PACKET_FLAG_RELIABLE);

	BroadcastPacket(pPacket,RELIABLECHANNEL);
}
Exemple #9
0
void NetServer::Dump(const char* pszCaller)
{
	NetMutexData *pNData = LockNetworkData();
	NetServerMutexData *pSData = LockServerData();

	GfLogDebug("%s : vecReady:%u, vecPlayers:%u\n", 
			   pszCaller, pNData->m_vecReadyStatus.size(), pSData->m_vecNetworkPlayers.size());
	
	UnlockServerData();
	UnlockNetworkData();
}
Exemple #10
0
void NetServer::SetDriverReady(bool bReady)
{
	int idx = GetDriverIdx();

	NetMutexData *pNData = LockNetworkData();
	pNData->m_vecReadyStatus[idx-1] = bReady;
	UnlockNetworkData();

	Dump("NetServer::SetDriverReady");

	SendDriversReadyPacket();
}
Exemple #11
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);
}
Exemple #12
0
void NetClient::ReadFinishTimePacket(ENetPacket *pPacket)
{
    PackedBuffer msg(pPacket->data, pPacket->dataLength);
    GfLogTrace("ReadFinishTimePacket: packed data length=%d\n",
            msg.length());

    try
    {
        msg.unpack_ubyte();

        NetMutexData *pNData = LockNetworkData();
        pNData->m_finishTime = msg.unpack_double();
        UnlockNetworkData();
    }
//    catch (PackedBufferException &e)
    catch (PackedBufferException)
    {
        GfLogFatal("ReadFinishTimePacket: packed buffer error\n");
    }

    GfOut("Received finish time packet\n");
}