Exemple #1
0
void NetServer::SendStartTimePacket(int &startTime)
{
	//Wait RACESTARTDELEAY seconds to start race
	m_racestarttime = GfTimeClock()+RACESTARTDELEAY;

        PackedBuffer msg;

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

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

	BroadcastPacket(pPacket,RELIABLECHANNEL);

	GfLogInfo("Server Start time is %lf\n",m_racestarttime);
}
Exemple #2
0
void NetServer::SendTimePacket(ENetPacket *pPacketRec, ENetPeer * pPeer)
{
	GfLogTrace("Sending Time Packet\n");

	double time = GfTimeClock();
	GfLogTrace("\nServer time is %lf",time);

        PackedBuffer msg;

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

	//TODO change to peer send
	ENetPacket * pPacket = enet_packet_create (msg.buffer(), 
                                              msg.length(), 
                                              ENET_PACKET_FLAG_UNSEQUENCED);

	enet_peer_send (pPeer, UNRELIABLECHANNEL, pPacket);
}
Exemple #3
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 #4
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);
}