Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ability to move server-side vehicles that are far away from the player #3391

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ void CUnoccupiedVehicleSync::Packet_UnoccupiedVehiclePushSync(CUnoccupiedVehicle
CVehicle* pVehicle = static_cast<CVehicle*>(pVehicleElement);
// Is the player syncing this vehicle and there is no driver? Also only process
// this packet if the time context matches.
if (pVehicle->GetSyncer() != pPlayer && pVehicle->GetTimeSinceLastPush() >= MIN_PUSH_ANTISPAM_RATE)
if (pVehicle->GetSyncer() != pPlayer && pVehicle->GetTimeSinceLastPush() >= MIN_PUSH_ANTISPAM_RATE &&
IsPointNearPoint3D(pVehicle->GetPosition(), pPlayer->GetPosition(), MAX_CONTACT_SYNC_RADIUS))
{
// Is there no player driver?
CPed* pOccupant = pVehicle->GetOccupant(0);
Expand Down
19 changes: 14 additions & 5 deletions Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream)
return false;
pContactElement = CElementIDs::GetElement(Temp);
}

// Player position
SPositionSync position(false);
if (!BitStream.Read(&position))
return false;

if (pContactElement != nullptr && !IsPointNearPoint3D(pSourcePlayer->GetPosition(), pContactElement->GetPosition(), MAX_CONTACT_SYNC_RADIUS))
{
pContactElement = nullptr;
// Use current player position. They are not reporting their absolute position so we have to disregard it.
position.data.vecPosition = pSourcePlayer->GetPosition();
}

CElement* pPreviousContactElement = pSourcePlayer->GetContactElement();
pSourcePlayer->SetContactElement(pContactElement);

Expand All @@ -89,11 +102,6 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream)
pSourcePlayer->CallEvent("onPlayerContact", Arguments);
}

// Player position
SPositionSync position(false);
if (!BitStream.Read(&position))
return false;

if (pContactElement)
{
pSourcePlayer->SetContactPosition(position.data.vecPosition);
Expand All @@ -102,6 +110,7 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream)
CVector vecTempPos = pContactElement->GetPosition();
position.data.vecPosition += vecTempPos;
}

pSourcePlayer->SetPosition(position.data.vecPosition);

// Player rotation
Expand Down
3 changes: 3 additions & 0 deletions Shared/sdk/net/SyncStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

// Used to make sure that any position values we receive are at least half sane
#define SYNC_POSITION_LIMIT 100000.0f

// Set a maximum radius at which we sync element collisions
#define MAX_CONTACT_SYNC_RADIUS 30.0f
// Note: Using SFloatSync < 14, 10 > also limits the range from -8191 to 8192

#pragma pack(push)
Expand Down
Loading