multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.42k stars 437 forks source link

Get a data from server #3619

Open HYPER-00 opened 4 months ago

HYPER-00 commented 4 months ago

Is your feature request related to a problem? Please describe.

To get data from the server, you need to trigger an event from the client and bind a function to handle the incoming data. Once the data is received, you can store it and proceed with the desired actions.

Describe the solution you'd like

I would like to make a client function that takes one argument for the data identifier (data name, ...) and another one that is server side, that sends a response / handles that signal. finally send that data to the client

For example (lua script):

-- client.lua
data = RequestServerData("data-identifier-or-anything")
outputChatBox("Requested Data: " .. data)  -- Requested Data: MTA:SA 1.6
-- server.lua
SetDefaultRequestData("data-identifier-or-anything", "MTA:SA 1.6")

The MTA Client will request the server for a data, then the server will respond it with MTA:SA 1.6

Describe alternatives you've considered

No response

Additional context

I was developing an anticheat system and realized that storing some data on the client isn't safe. Therefore, requesting it from the server is a better idea, though it makes handling the server response a bit more complex (involving coroutines, yielding, resuming, etc.).

This idea came to me as a solution to this issue.

Security Policy

G-Moris commented 3 months ago

I have an idea how it is possible to implement this, I will try it soon.