feat(server): add external kvp natives
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
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.
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.
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.
So perhaps a new variable on the setters to flag that kvp as allowed to be read by other resources?
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?
trigger an event that doesnt exist and check when that callback is returned you will have your answer.
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...
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?
@FabianTerhorst what if we tied this to the https://docs.fivem.net/docs/developers/sandbox/#permission-system to allow certain resources to read it ?
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.