Beispiel #1
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);
}
Beispiel #2
0
bool NetClient::SendDriverInfoPacket(NetDriver *pDriver)
{
    SetDriverName(pDriver->name);
    pDriver->address.port = m_pHost->address.port;

    GfLogTrace("SendDriverInfoPacket: pDriver\n");
    GfLogTrace("->host=%d\n", pDriver->address.host);
    GfLogTrace("->port=%d\n", pDriver->address.port);
    GfLogTrace("->idx=%d\n", pDriver->idx);
    GfLogTrace("->name=%s\n", pDriver->name);
    GfLogTrace("->sname=%s\n", pDriver->sname);
    GfLogTrace("->cname=%s\n", pDriver->cname);
    GfLogTrace("->car=%s\n", pDriver->car);
    GfLogTrace("->team=%s\n", pDriver->team);
    GfLogTrace("->author=%s\n", pDriver->author);
    GfLogTrace("->racenumber=%d\n", pDriver->racenumber);
    GfLogTrace("->skilllevel=%s\n", pDriver->skilllevel);
    GfLogTrace("->red=%.1f\n", pDriver->red);
    GfLogTrace("->green=%.1f\n", pDriver->green);
    GfLogTrace("->blue=%.1f\n", pDriver->blue);
    GfLogTrace("->module=%s\n", pDriver->module);
    GfLogTrace("->type=%s\n", pDriver->type);
    GfLogTrace("->client=%d\n", pDriver->client);

    PackedBuffer msg;

    try
    {
        msg.pack_ubyte(PLAYERINFO_PACKET);
        msg.pack_int(pDriver->idx);
        msg.pack_string(pDriver->name, sizeof pDriver->name);
        msg.pack_string(pDriver->sname, sizeof pDriver->sname);
        msg.pack_string(pDriver->cname, sizeof pDriver->cname);
        msg.pack_string(pDriver->car, sizeof pDriver->car);
        msg.pack_string(pDriver->team, sizeof pDriver->team);
        msg.pack_string(pDriver->author, sizeof pDriver->author);
        msg.pack_int(pDriver->racenumber);
        msg.pack_string(pDriver->skilllevel,
                sizeof pDriver->skilllevel);
        msg.pack_float(pDriver->red);
        msg.pack_float(pDriver->green);
        msg.pack_float(pDriver->blue);
        msg.pack_string(pDriver->module, sizeof pDriver->module);
        msg.pack_string(pDriver->type, sizeof pDriver->type);
        msg.pack_int(pDriver->client);
    }
//    catch (PackedBufferException &e)
    catch (PackedBufferException)
    {
        GfLogFatal("SendDriverInfoPacket: packed buffer error\n");
    }
    GfLogTrace("SendDriverInfoPacket: 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 true;

    return false;
}