FiveM Projects
This guide walks through the process of implementing SunLicense license management in a FiveM resource.
Prerequisites
A FiveM server
SunLicense API credentials
Your product ID and license key
Step 1: Set Up Basic Structure
Create a new file called license_check.lua in your resource's server folder:
-- license_check.lua
local SunLicenseValidator = {}
SunLicenseValidator.__index = SunLicenseValidator
-- Configuration
local CONFIG = {
API_URL = "http://localhost:8080/api/v1/validate",
LICENSE_KEY = GetConvar("sunlicense_key", "YOUR-LICENSE-KEY"),
PRODUCT_ID = 602, -- Replace with your product ID
VERSION = "1.0.0"
}Step 2: Implement the Validator Class
Add the core validation functionality:
Step 3: Initialize the License Check
Create an initialization file (init.lua):
Step 4: Configure Your Resource
Update your fxmanifest.lua:
Best Practices
License Key Security
Store your license key in server.cfg
Never expose the key in client-side code
Regularly rotate keys if possible
Error Handling
Implement proper logging
Handle network timeouts
Provide clear error messages
Validation Timing
Validate on resource start
Implement periodic validation if needed
Use reasonable retry intervals
Common Issues and Solutions
Network Connectivity Problems
Invalid License Format
Failed Validation Response
Last updated