Hey @schwim, those were actually just examples of securing an existing event. By adding the init.lua file to both the server and client files of a resource, it properly preps the resource to be secured with the tokens.
In order to protect a server event, you will need to adjust it to send the security token to the server. The security token is accessible through a variable named securityToken on the client side. So you will find all existing TriggerServerEvent triggers in your client-side scripts, and add , securityToken to it so that it is sent to the server.
Before:
TriggerServerEvent('my_resource:eventName', existingVariables)
After:
TriggerServerEvent('my_resource:eventName', existingVariables, securityToken)
On the server-side, you will need to modify the event handlers to accept the token, and then add a check to make sure it was a valid token. To do this, you will go through your server-side scripts and adjust any event handlers to have a new variable (I use token typically).
Before:
RegisterNetEvent('my_resource:eventName')
AddEventHandler('my_resource:eventName', function(existingVariables)
After:
RegisterNetEvent('my_resource:eventName')
AddEventHandler('my_resource:eventName', function(existingVariables, token)
Now, just passing the security token will not prevent anything, since there’s not a check in place that it is valid. You can use my premade function using an export that will check the token and return false if it is invalid and kick them out.
Final modified server event handler:
RegisterNetEvent('my_resource:eventName')
AddEventHandler('my_resource:eventName', function(existingVariables, token)
local _source = source
if not exports['salty_tokenizer']:secureServerEvent(GetCurrentResourceName(), _source, token) then
return false
end
-- At this point, this security event is now validated and safe to continue.