Beispiel #1
0
//------------------------------------------------------------------------------
void Missile::writeStateToBitstream (RakNet::BitStream & stream, unsigned type) const
{
    if (type == OST_BOTH)
    {
        Projectile::writeStateToBitstream(stream, type);
    } else
    {
        // orientation doesn't matter for missile
        Vector v;
        v = getPosition();
        stream.WriteVector(v.x_,v.y_,v.z_);
        
        v = target_object_->getGlobalLinearVel();
        stream.WriteVector(v.x_,v.y_,v.z_);
    }
    
    stream.WriteVector(target_.x_, target_.y_, target_.z_);
}
void CPickupSendPackets::CreatePickup( unsigned int ui, float fX, float fY, float fZ )
{
	RakNet::BitStream bs;

	PreparePacket(ID_PICKUP_CREATEPICKUP, bs);

	bs.Write(ui);
	bs.WriteVector(fX, fY, fZ);

	CNet::GetInterface()->Send(&bs, HIGH_PRIORITY, RELIABLE, 0);
}
//------------------------------------------------------------------------------
void SoccerBall::writeStateToBitstream (RakNet::BitStream & stream, unsigned type) const
{
    RigidBody::writeStateToBitstream(stream, type);

//    return;
    
    RigidBody * body = (RigidBody*)game_state_->getGameObject(rel_object_id_);

    if (body)
    {
        assert(game_state_);

        stream.Write(true);
        stream.Write(rel_object_id_);
        Vector rel_pos = body->getTransform().transformPointInv(getPosition());
        stream.WriteVector(rel_pos.x_, rel_pos.y_, rel_pos.z_);
        
    } else
    {
        stream.Write(false);
    }
}
Beispiel #4
0
void Packet_PlayerSync(Packet *p)
{
	//Log("Packet_PlayerSync: %d  %d", pRakServer->GetIndexFromPlayerID(p->playerId), p->length);

	RakNet::BitStream bsPlayerSync((unsigned char *)p->data, p->length, false);
	PLAYERID playerId = pRakServer->GetIndexFromPlayerID(p->playerId);

	// clear last data
	memset(&playerInfo[playerId].onfootData, 0, sizeof(ONFOOT_SYNC_DATA));

	bsPlayerSync.IgnoreBits(8);
	bsPlayerSync.Read((PCHAR)&playerInfo[playerId].onfootData, sizeof(ONFOOT_SYNC_DATA));


	// BROADCAST DATA
	RakNet::BitStream bsOnFootBC;
	bsOnFootBC.Write((BYTE)ID_PLAYER_SYNC);
	bsOnFootBC.Write((PLAYERID)playerId);

	if(playerInfo[playerId].onfootData.lrAnalog)
	{
		bsOnFootBC.Write(true);
		bsOnFootBC.Write(playerInfo[playerId].onfootData.lrAnalog);
	}
	else
		bsOnFootBC.Write(false);

	if(playerInfo[playerId].onfootData.udAnalog)
	{
		bsOnFootBC.Write(true);
		bsOnFootBC.Write(playerInfo[playerId].onfootData.udAnalog);
	}
	else
		bsOnFootBC.Write(false);

	bsOnFootBC.Write(playerInfo[playerId].onfootData.wKeys);
	bsOnFootBC.Write(playerInfo[playerId].onfootData.vecPos[0]);
	bsOnFootBC.Write(playerInfo[playerId].onfootData.vecPos[1]);
	bsOnFootBC.Write(playerInfo[playerId].onfootData.vecPos[2]);
	bsOnFootBC.WriteNormQuat(
		playerInfo[playerId].onfootData.fQuaternion[0],
		playerInfo[playerId].onfootData.fQuaternion[1],
		playerInfo[playerId].onfootData.fQuaternion[2],
		playerInfo[playerId].onfootData.fQuaternion[3]);

	BYTE byteSyncHealthArmour=0;
	BYTE byteHealth = playerInfo[playerId].onfootData.byteHealth;
	BYTE byteArmour = playerInfo[playerId].onfootData.byteArmour;
	if( byteHealth > 0 && byteHealth < 100 ) {
		byteSyncHealthArmour = ((BYTE)(byteHealth / 7)) << 4;
	} 
	else if(byteHealth >= 100) {
		byteSyncHealthArmour = 0xF << 4;
	}

	if( byteArmour > 0 && byteArmour < 100 ) {
		byteSyncHealthArmour |=  (BYTE)(byteArmour / 7);
	}
	else if(byteArmour >= 100) {
		byteSyncHealthArmour |= 0xF;
	}
	bsOnFootBC.Write(byteSyncHealthArmour);
	bsOnFootBC.Write(playerInfo[playerId].onfootData.byteCurrentWeapon);
	bsOnFootBC.Write(playerInfo[playerId].onfootData.byteSpecialAction);
	bsOnFootBC.WriteVector(playerInfo[playerId].onfootData.vecMoveSpeed[0],
		playerInfo[playerId].onfootData.vecMoveSpeed[1], playerInfo[playerId].onfootData.vecMoveSpeed[2]);

	if(playerInfo[playerId].onfootData.wSurfInfo)
	{
		bsOnFootBC.Write(true);
		bsOnFootBC.Write(playerInfo[playerId].onfootData.wSurfInfo);
		bsOnFootBC.Write(playerInfo[playerId].onfootData.vecSurfOffsets[0]);
		bsOnFootBC.Write(playerInfo[playerId].onfootData.vecSurfOffsets[1]);
		bsOnFootBC.Write(playerInfo[playerId].onfootData.vecSurfOffsets[2]);
	}
	else
		bsOnFootBC.Write(false);

	if(playerInfo[playerId].onfootData.iCurrentAnimationID)
	{
		bsOnFootBC.Write(true);
		bsOnFootBC.Write(playerInfo[playerId].onfootData.iCurrentAnimationID);
	}
	else
		bsOnFootBC.Write(false);

	playerPool[playerId].currentVehicleID = 0;

	UpdatePosition(playerId, playerInfo[playerId].onfootData.vecPos[0], playerInfo[playerId].onfootData.vecPos[1], playerInfo[playerId].onfootData.vecPos[2]);

	pRakServer->Send(&bsOnFootBC, HIGH_PRIORITY, UNRELIABLE_SEQUENCED, 0, p->playerId, TRUE);
}
Beispiel #5
0
void Packet_VehicleSync(Packet *p)
{
	//Log("Packet_VehicleSync: %d  %d", pRakServer->GetIndexFromPlayerID(p->playerId), p->length);

	RakNet::BitStream bsVehicleSync((unsigned char *)p->data, p->length, false);
	PLAYERID playerId = pRakServer->GetIndexFromPlayerID(p->playerId);

	// clear last data
	memset(&playerInfo[playerId].incarData, 0, sizeof(INCAR_SYNC_DATA));

	bsVehicleSync.IgnoreBits(8);
	bsVehicleSync.Read((PCHAR)&playerInfo[playerId].incarData, sizeof(INCAR_SYNC_DATA));

	playerPool[playerId].currentVehicleID = playerInfo[playerId].incarData.VehicleID;

	// BROADCAST DATA
	RakNet::BitStream bsInVehicleBC;
	bsInVehicleBC.Write((BYTE)ID_VEHICLE_SYNC);
	bsInVehicleBC.Write(playerId);
	bsInVehicleBC.Write(playerInfo[playerId].incarData.VehicleID);

	bsInVehicleBC.Write(playerInfo[playerId].incarData.lrAnalog);
	bsInVehicleBC.Write(playerInfo[playerId].incarData.udAnalog);
	bsInVehicleBC.Write(playerInfo[playerId].incarData.wKeys);

	bsInVehicleBC.WriteNormQuat(
		playerInfo[playerId].incarData.fQuaternion[0],
		playerInfo[playerId].incarData.fQuaternion[1],
		playerInfo[playerId].incarData.fQuaternion[2],
		playerInfo[playerId].incarData.fQuaternion[3]);

	bsInVehicleBC.Write(playerInfo[playerId].incarData.vecPos[0]);
	bsInVehicleBC.Write(playerInfo[playerId].incarData.vecPos[1]);
	bsInVehicleBC.Write(playerInfo[playerId].incarData.vecPos[2]);

	bsInVehicleBC.WriteVector(playerInfo[playerId].incarData.vecMoveSpeed[0],
		playerInfo[playerId].incarData.vecMoveSpeed[1], playerInfo[playerId].incarData.vecMoveSpeed[2]);

	WORD wTempVehicleHealh = (WORD)playerInfo[playerId].incarData.fCarHealth;
	bsInVehicleBC.Write(wTempVehicleHealh);
	BYTE byteSyncHealthArmour=0;
	BYTE byteHealth = playerInfo[playerId].incarData.bytePlayerHealth;
	BYTE byteArmour = playerInfo[playerId].incarData.bytePlayerArmour;
	if( byteHealth > 0 && byteHealth < 100 ) {
		byteSyncHealthArmour = ((BYTE)(byteHealth / 7)) << 4;
	} 
	else if(byteHealth >= 100) {
		byteSyncHealthArmour = 0xF << 4;
	}

	if( byteArmour > 0 && byteArmour < 100 ) {
		byteSyncHealthArmour |=  (BYTE)(byteArmour / 7);
	}
	else if(byteArmour >= 100) {
		byteSyncHealthArmour |= 0xF;
	}
	bsInVehicleBC.Write(byteSyncHealthArmour);

	bsInVehicleBC.Write(playerInfo[playerId].incarData.byteCurrentWeapon);

	if(playerInfo[playerId].incarData.byteSirenOn)
		bsInVehicleBC.Write(true);
	else
		bsInVehicleBC.Write(false);

	if(playerInfo[playerId].incarData.byteLandingGearState)
		bsInVehicleBC.Write(true);
	else
		bsInVehicleBC.Write(false);

	// HYDRA THRUST ANGLE AND TRAILER ID
	bsInVehicleBC.Write(false);
	bsInVehicleBC.Write(false);

	DWORD dwTrailerID_or_ThrustAngle = 0;
	bsInVehicleBC.Write(dwTrailerID_or_ThrustAngle);

	// TRAIN SPECIAL
	bsInVehicleBC.Write(false);
	/*WORD wSpeed;
	bsSync.ReadCompressed(bTrain);
	if(bTrain)
	{
		bsSync.Read(wSpeed);
		playerInfo[playerId].incarData.fTrainSpeed = (float)wSpeed;
	}*/
	
	UpdatePosition(playerId, playerInfo[playerId].incarData.vecPos[0], playerInfo[playerId].incarData.vecPos[1], playerInfo[playerId].incarData.vecPos[2]);

	pRakServer->Send(&bsInVehicleBC, HIGH_PRIORITY, UNRELIABLE_SEQUENCED, 0, p->playerId, TRUE);
}
Beispiel #6
0
// native SendLastSyncData(playerid, toplayerid, animation = 0)
static cell AMX_NATIVE_CALL Natives::SendLastSyncData( AMX* amx, cell* params )
{
	if (!serverVersion)
		return 0;

	CHECK_PARAMS(3, "SendLastSyncData");

	int playerid = (int)params[1];
	int toplayerid = (int)params[2];
	int animation = (int)params[3];
	BYTE ps = ID_PLAYER_SYNC;
	CSyncData* d = &lastSyncData[playerid];

	RakNet::BitStream bs;
	bs.Write((BYTE)ID_PLAYER_SYNC);
	bs.Write((WORD)playerid);

	if (d->wUDAnalog) {
		bs.Write(true);
		bs.Write((WORD)d->wUDAnalog);
	} else {
		bs.Write(false);
	}

	if (d->wLRAnalog) {
		bs.Write(true);
		bs.Write((WORD)d->wLRAnalog);
	} else {
		bs.Write(false);
	}

	bs.Write((WORD)d->wKeys);

	bs.Write(d->vecPosition.fX);
	bs.Write(d->vecPosition.fY);
	bs.Write(d->vecPosition.fZ);

	if (fakeQuat[playerid] != NULL) {
		bs.Write((bool)(fakeQuat[playerid]->w<0.0f));
		bs.Write((bool)(fakeQuat[playerid]->x<0.0f));
		bs.Write((bool)(fakeQuat[playerid]->y<0.0f));
		bs.Write((bool)(fakeQuat[playerid]->z<0.0f));
		bs.Write((unsigned short)(fabs(fakeQuat[playerid]->x)*65535.0));
		bs.Write((unsigned short)(fabs(fakeQuat[playerid]->y)*65535.0));
		bs.Write((unsigned short)(fabs(fakeQuat[playerid]->z)*65535.0));
	} else {
		bs.Write((bool)(d->fQuaternionAngle<0.0f));
		bs.Write((bool)(d->vecQuaternion.fX<0.0f));
		bs.Write((bool)(d->vecQuaternion.fY<0.0f));
		bs.Write((bool)(d->vecQuaternion.fZ<0.0f));
		bs.Write((unsigned short)(fabs(d->vecQuaternion.fX)*65535.0));
		bs.Write((unsigned short)(fabs(d->vecQuaternion.fY)*65535.0));
		bs.Write((unsigned short)(fabs(d->vecQuaternion.fZ)*65535.0));
	}

	BYTE health, armour;

	if (fakeHealth[playerid] != 255) {
		health = fakeHealth[playerid];
	} else {
		health = d->byteHealth;
	}

	if (fakeArmour[playerid] != 255) {
		armour = fakeArmour[playerid];
	} else {
		armour = d->byteArmour;
	}

	if (health >= 100) {
		health = 0xF;
	} else {
		health /= 7;
	}

	if (armour >= 100) {
		armour = 0xF;
	} else {
		armour /= 7;
	}

	bs.Write((BYTE)((health << 4) | (armour)));

	bs.Write(d->byteWeapon);
	bs.Write(d->byteSpecialAction);

	// Make them appear standing still if paused
	if (GetTickCount() - lastUpdateTick[playerid] > 2000) {
		bs.WriteVector(0.0f, 0.0f, 0.0f);
	} else {
		bs.WriteVector(d->vecVelocity.fX, d->vecVelocity.fY, d->vecVelocity.fZ);
	}

	if (d->wSurfingInfo) {
		bs.Write(true);

		bs.Write(d->wSurfingInfo);
		bs.Write(d->vecSurfing.fX);
		bs.Write(d->vecSurfing.fY);
		bs.Write(d->vecSurfing.fZ);
	} else {
		bs.Write(false);
	}

	// Animations are only sent when they are changed
	if (animation) {
		bs.Write(true);
		bs.Write(animation);
	} else {
		bs.Write(false);
	}

	pRakServer->Send(&bs, HIGH_PRIORITY, RELIABLE_SEQUENCED, 0, pRakServer->GetPlayerIDFromIndex(toplayerid), false);

	return 1;
}