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

Persistent Vehicles #567

Closed
Manason opened this issue Sep 13, 2024 · 0 comments · Fixed by #568
Closed

Persistent Vehicles #567

Manason opened this issue Sep 13, 2024 · 0 comments · Fixed by #568
Labels
enhancement New feature or request

Comments

@Manason
Copy link
Contributor

Manason commented Sep 13, 2024

The problem

There is a bug in FiveM that makes it so server spawned vehicles can be deleted. This can happen even when a player is driving it.

Ideal solution

When a vehicle is deleted, it is respawned at the position it was deleted, with the same vehicle properties.

Using the server side entityRemoved event, we can intercept the entity deletion to cache some data about the vehicle, such as the vehicleId, plate, and coords. Then, we can lookup the vehicle in the database to determine whether it is an owned vehicle and respawn it. This could result in stale vehicle properties however, as the database may not have been recently updated.

Therefore, in addition to the above solution, we should also save vehicle properties to the database on an on-demand basis. That is, whenever it changes. Only a client can read the vehicle properties, and would need to send this to the server when it changed. Therefore I propose that when a client is occupying the driver seat of a vehicle, regardless of whether it is the entity owner or not it should do the following:

  1. cache the vehicle properties
  2. every few seconds, check if the vehicle properties have changed
  3. send the diff (if there is one) to the server

The server will then

  1. receive the diff from the client
  2. read the vehicle from the database
  3. overwrite diffed fields
  4. save the vehicle properties back

If this proves to be too much of a performance cost, the server could save to a buffer, and flush the buffer on a less regular cadence, but this should only be done if there proves to be an issue, not before as it adds its own complications, drawbacks, and edge cases.

Exploits in this solution aren't entirely preventable, as the client is the source of truth for the vehicle property data. To prevent exploits to the extent possible, the following can be done:

  • Only fields changed outside of other events need be accepted by the server. Changing the owner of a vehicle, or its mods for example should result in a separate event on its own rather than be changed through a regular properties detection solution. The vehicles the server could accept would be limited to damage and fuel fields.
  • if there is a non RPC server native to get the data, the server will use it rather than trust the value sent by the client
  • anomalous diffs could be detected. i.e. if a vehicle is repaired, we might expect the event to be sent by the script that did the repairing, and so a regular client diff would point to lua injection. This isn't recommended however, as it would assume that all scripts which repair vehicles would be sending property update events to the server.

Alternative solutions

No response

Additional context

No response

@Manason Manason added the enhancement New feature or request label Sep 13, 2024
@qbox-duck qbox-duck bot added this to Issues Sep 13, 2024
@github-project-automation github-project-automation bot moved this to Todo in Issues Sep 13, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Issues Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant