function SunLicenseValidator.new()
local self = setmetatable({}, SunLicenseValidator)
self.authenticated = false
return self
end
function SunLicenseValidator:validate()
-- Construct the payload according to SunLicense specifications
local payload = json.encode({
licenseKey = CONFIG.LICENSE_KEY,
productId = CONFIG.PRODUCT_ID,
productVersion = CONFIG.VERSION,
hwid = self:getHWID(),
macAddress = "", -- Optional field
operatingSystem = "", -- Optional field
operatingSystemVersion = "", -- Optional field
operatingSystemArchitecture = "", -- Optional field
javaVersion = "" -- Optional field
})
PerformHttpRequest(CONFIG.API_URL, function(errorCode, resultData, headers)
if errorCode == 200 then
local success, data = pcall(json.decode, resultData)
if success and data then
if data.status == "valid" then
self.authenticated = true
print("^2[SunLicense] License validated successfully^0")
else
print("^1[SunLicense] License validation failed^0")
Wait(5000)
os.exit()
end
end
else
print("^1[SunLicense] Failed to connect to license server^0")
Wait(5000)
os.exit()
end
end, 'POST', payload, {
['Content-Type'] = 'application/json',
['Content-Length'] = #payload
})
end
-- Generate a unique hardware identifier
function SunLicenseValidator:getHWID()
-- You can implement your own HWID generation logic here
-- This is a simple example that combines server information
local serverID = GetConvar("sv_licenseIdentifier", "")
local port = GetConvar("endpoint_port", "")
return string.format("fivem-server-%s-%s", serverID, port)
end