boba-callbacks

Introduction

This resource is to be used as a utility dependency. Routing server events via this utility means you don't need to expose them to clientsarrow-up-right for sensitive functions (e.g. adding/ removing items).

Contributions can be made by opening a pull requestarrow-up-right, or if you notice a bug please raise an issuearrow-up-right on GitHub.

circle-exclamation

Usage Examples

In this example, we'll use Luaarrow-up-right to trigger a server event securely from the client. We avoid the use of RegisterNetEventarrow-up-right, meaning the event is only exposed to server-side scripts - avoiding the possibility for malicious clients to trigger client events without requests first reaching the callbacks handler.

Client

CreateThread(function()
    local result = exports["boba-callbacks"]:ExecuteServerCallback("ResourceName:EventName", "Example value sent to the server event")
    print(result)
end)
circle-info

While it's not required to place callback exports within a new thread, to prevent issues with the main thread, we must instead execute it in a coroutine (e.g. a function).

Server

AddEventHandler("ResourceName:EventName", function(cb, src, arg)
    print(("Event triggered on the server. Value received: %s"):format(arg))

    cb("This value is sent to the client")
end)
triangle-exclamation

Last updated