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 clients for sensitive functions (e.g. adding/ removing items).

Contributions can be made by opening a pull request, or if you notice a bug please raise an issue on GitHub.

Usage Examples

In this example, we'll use Lua to trigger a server event securely from the client. We avoid the use of RegisterNetEvent, 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)

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)

Last updated

Was this helpful?