fivem icon indicating copy to clipboard operation
fivem copied to clipboard

feat(server): add external kvp natives

Open outsider31000 opened this issue 11 months ago • 9 comments

Goal of this PR

Add external KVP natives to the server, matching the client-side implementation. This is useful for enabling communication between resources on the server.

How is this PR achieving the goal

Aligns the server with client KVP natives by implementing the same functionality server-side.

This PR applies to the following area(s)

Server

Successfully tested on

Game builds: ..

Platforms: Windows, Linux windows

Checklist

  • [x] Code compiles and has been tested successfully.
  • [x] Code explains itself well and/or is documented.
  • [x] My commit message explains what the changes do and what they are for.
  • [x] No extra compilation warnings are added by these changes.

Fixes issues

outsider31000 avatar May 17 '25 02:05 outsider31000

I'd prefer to have the key value db isolated on the server. Maybe there is a better way to have specific keys available between different resources. But right now best way is to only have one resource that writes that specific key.

FabianTerhorst avatar May 20 '25 12:05 FabianTerhorst

The implementation is the same as the client though. Kvp is also isolated per resource so it shouldn't matter the key being used?, Unless I'm not seeing the bigger picture here.

Without this I need to trigger events with callbacks to another resource that people might not have and the callback is never returned. Same happens with exports.

This change simplifies it. These are getters don't see what harm can it do.

Thanks for the review ofc.

outsider31000 avatar May 20 '25 13:05 outsider31000

The implementation is the same as the client though. Kvp is also isolated per resource so it shouldn't matter the key being used?, Unless I'm not seeing the bigger picture here.

Without this I need to trigger events with callbacks to another resource that people might not have and the callback is never returned. Same happens with exports.

This change simplifies it. These are getters don't see what harm can it do.

Thanks for the review ofc.

With isolation I mean that no other resource can read the key from another resource on the server. Because the key is prefixed with the resource name this is not possible currently with the other kv getters. With your change a resource could not know which other resources access the data. When a resource stores sensitive data inside the key value db this data could be grabbed from any resource.

FabianTerhorst avatar May 20 '25 13:05 FabianTerhorst

So perhaps a new variable on the setters to flag that kvp as allowed to be read by other resources?

outsider31000 avatar May 20 '25 13:05 outsider31000

I'm a bit confused by your statement of "Without this I need to trigger events with callbacks to another resource that people might not have and the callback is never returned. Same happens with exports.". 1.: The same resources should be running on the server and all clients? 2,; Following your assumption of inconsistency of resources, what difference would it make whether you do this through a callback/export or through KVP? If the resource isn't there, it isn't there, so I don't see how this would change an outcome?

theskiratta avatar May 20 '25 21:05 theskiratta

trigger an event that doesnt exist and check when that callback is returned you will have your answer.

outsider31000 avatar May 20 '25 21:05 outsider31000

exports will also error when they dont exist. using external kvp , it would not need to wait for no callback, it returns always something. it simplifies its usage and aligns it with the client natives that do the same.

Not adding this because we dont want to allow other scripts getting data from other scripts its not a valid reason in my opinion, because its no different saving to a mysql database. I would then save the same very data to a database and fecth it anyways from any resource, so why should KVP be any different...

outsider31000 avatar May 20 '25 21:05 outsider31000

exports will also error when they dont exist. using external kvp , it would not need to wait for no callback, it returns always something. it simplifies its usage and aligns it with the client natives that do the same.

Not adding this because we dont want to allow other scripts getting data from other scripts its not a valid reason in my opinion, because its no different saving to a mysql database. I would then save the same very data to a database and fecth it anyways from any resource, so why should KVP be any different...

Could be getting a bit off the trail here, but if you're having concerns with erroring exports on missing resources, couldn't using a pcall in your code fix your issue? And with events, some form of timeout function with a return value?

WLVF avatar May 21 '25 12:05 WLVF

@FabianTerhorst what if we tied this to the https://docs.fivem.net/docs/developers/sandbox/#permission-system to allow certain resources to read it ?

outsider31000 avatar May 21 '25 15:05 outsider31000

Thanks for your efforts. This functionality is fundamentally incompatible with the server, since sensitive information may be stored on the server. If you need to exchange information between resources, use function export or events.

prikolium-cfx avatar Jun 23 '25 14:06 prikolium-cfx