Skip to content

Commit e3338c2

Browse files
authored
Fix ability to move server-side vehicles that are far away from the player (#3391)
* Fix ability to move server-side vehicles that are far away from the player * Fix wrongly named radius define * Add vehicle contact sync radius server setting * Add vehicle_contact_sync_radius to mtaserver.conf template * Add dimension checks
1 parent 79f8ed6 commit e3338c2

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,7 @@ const std::vector<SIntSetting>& CMainConfig::GetIntSettingList()
14551455
{true, true, 10, 50, 1000, "update_cycle_messages_limit", &m_iUpdateCycleMessagesLimit, &CMainConfig::ApplyNetOptions},
14561456
{true, true, 50, 100, 400, "ped_syncer_distance", &g_TickRateSettings.iPedSyncerDistance, &CMainConfig::OnTickRateChange},
14571457
{true, true, 50, 130, 400, "unoccupied_vehicle_syncer_distance", &g_TickRateSettings.iUnoccupiedVehicleSyncerDistance, &CMainConfig::OnTickRateChange},
1458+
{true, true, 0, 30, 130, "vehicle_contact_sync_radius", &g_TickRateSettings.iVehicleContactSyncRadius, &CMainConfig::OnTickRateChange},
14581459
{false, false, 0, 1, 2, "compact_internal_databases", &m_iCompactInternalDatabases, NULL},
14591460
{true, true, 0, 1, 2, "minclientversion_auto_update", &m_iMinClientVersionAutoUpdate, NULL},
14601461
{true, true, 0, 0, 100, "server_logic_fps_limit", &m_iServerLogicFpsLimit, NULL},

Server/mods/deathmatch/logic/CUnoccupiedVehicleSync.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,9 @@ void CUnoccupiedVehicleSync::Packet_UnoccupiedVehiclePushSync(CUnoccupiedVehicle
487487
CVehicle* pVehicle = static_cast<CVehicle*>(pVehicleElement);
488488
// Is the player syncing this vehicle and there is no driver? Also only process
489489
// this packet if the time context matches.
490-
if (pVehicle->GetSyncer() != pPlayer && pVehicle->GetTimeSinceLastPush() >= MIN_PUSH_ANTISPAM_RATE)
490+
if (pVehicle->GetSyncer() != pPlayer && pVehicle->GetTimeSinceLastPush() >= MIN_PUSH_ANTISPAM_RATE &&
491+
IsPointNearPoint3D(pVehicle->GetPosition(), pPlayer->GetPosition(), g_TickRateSettings.iVehicleContactSyncRadius)
492+
&& pVehicle->GetDimension() == pPlayer->GetDimension())
491493
{
492494
// Is there no player driver?
493495
CPed* pOccupant = pVehicle->GetOccupant(0);

Server/mods/deathmatch/logic/packets/CPlayerPuresyncPacket.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "CElementIDs.h"
1515
#include "CWeaponNames.h"
1616
#include "Utils.h"
17+
#include "CTickRateSettings.h"
1718
#include <net/SyncStructures.h>
1819

1920
extern CGame* g_pGame;
@@ -70,6 +71,21 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream)
7071
return false;
7172
pContactElement = CElementIDs::GetElement(Temp);
7273
}
74+
75+
// Player position
76+
SPositionSync position(false);
77+
if (!BitStream.Read(&position))
78+
return false;
79+
80+
if (pContactElement != nullptr &&
81+
(!IsPointNearPoint3D(pSourcePlayer->GetPosition(), pContactElement->GetPosition(), g_TickRateSettings.iVehicleContactSyncRadius) ||
82+
pSourcePlayer->GetDimension() != pContactElement->GetDimension()))
83+
{
84+
pContactElement = nullptr;
85+
// Use current player position. They are not reporting their absolute position so we have to disregard it.
86+
position.data.vecPosition = pSourcePlayer->GetPosition();
87+
}
88+
7389
CElement* pPreviousContactElement = pSourcePlayer->GetContactElement();
7490
pSourcePlayer->SetContactElement(pContactElement);
7591

@@ -89,11 +105,6 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream)
89105
pSourcePlayer->CallEvent("onPlayerContact", Arguments);
90106
}
91107

92-
// Player position
93-
SPositionSync position(false);
94-
if (!BitStream.Read(&position))
95-
return false;
96-
97108
if (pContactElement)
98109
{
99110
pSourcePlayer->SetContactPosition(position.data.vecPosition);
@@ -102,6 +113,7 @@ bool CPlayerPuresyncPacket::Read(NetBitStreamInterface& BitStream)
102113
CVector vecTempPos = pContactElement->GetPosition();
103114
position.data.vecPosition += vecTempPos;
104115
}
116+
105117
pSourcePlayer->SetPosition(position.data.vecPosition);
106118

107119
// Player rotation

Server/mods/deathmatch/mtaserver.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@
135135
Values: 0 - disabled , 1 - enabled ; default value: 1. -->
136136
<bullet_sync>1</bullet_sync>
137137

138+
<!-- This parameter specifies the radius in which any contact with a vehicle will turn the player into its syncer.
139+
Available range: 0 to 130. Default - 30 -->
140+
<vehicle_contact_sync_radius>30</vehicle_contact_sync_radius>
141+
138142
<!-- This parameter sets the amount of extrapolation that clients will apply to remote vehicles. This can reduce
139143
some of the latency induced location disparency by predicting where the remote vehicles will probably be.
140144
Depending on the gamemode, an incorrect prediction may have a negative effect. Therefore this setting

Server/mods/deathmatch/mtaserver.conf.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@
136136
Values: 0 - disabled , 1 - enabled ; default value: 1. -->
137137
<bullet_sync>1</bullet_sync>
138138

139+
<!-- This parameter specifies the radius in which any contact with a vehicle will turn the player into its syncer.
140+
Available range: 0 to 130. Default - 30 -->
141+
<vehicle_contact_sync_radius>30</vehicle_contact_sync_radius>
142+
139143
<!-- This parameter sets the amount of extrapolation that clients will apply to remote vehicles. This can reduce
140144
some of the latency induced location disparency by predicting where the remote vehicles will probably be.
141145
Depending on the gamemode, an incorrect prediction may have a negative effect. Therefore this setting

Shared/mods/deathmatch/logic/CTickRateSettings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct CTickRateSettings
2525
iNearListUpdate = 100;
2626
iPedSyncerDistance = 100;
2727
iUnoccupiedVehicleSyncerDistance = 130;
28+
iVehicleContactSyncRadius = 30;
2829
}
2930

3031
int iPureSync;
@@ -39,6 +40,7 @@ struct CTickRateSettings
3940
int iNearListUpdate;
4041
int iPedSyncerDistance;
4142
int iUnoccupiedVehicleSyncerDistance;
43+
int iVehicleContactSyncRadius;
4244
};
4345

4446
extern CTickRateSettings g_TickRateSettings;

0 commit comments

Comments
 (0)