Skip to content

feat(server): add external kvp natives #3404

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

Closed

Conversation

outsider31000
Copy link
Contributor

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

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

Fixes issues

@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label May 17, 2025
@FabianTerhorst
Copy link
Contributor

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.

@outsider31000
Copy link
Contributor Author

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.

@FabianTerhorst
Copy link
Contributor

FabianTerhorst commented May 20, 2025

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.

@outsider31000
Copy link
Contributor Author

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

@theskiratta
Copy link

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?

@outsider31000
Copy link
Contributor Author

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

@outsider31000
Copy link
Contributor Author

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...

@WLVF
Copy link

WLVF commented May 21, 2025

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?

@outsider31000
Copy link
Contributor Author

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

@prikolium-cfx
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants