Exemple #1
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);
}
Exemple #2
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);
}