Skip to content

Commit

Permalink
feat(server): Add version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
antond15 committed Apr 30, 2022
1 parent 499d756 commit 337bdb9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
ac = {
-- Whether to check for newer resource version and notify in server console.
versionCheck = true,

-- Whether to use custom notification function located in top of the 'resource/client/utils.lua' file.
-- If set to 'true', the default custom notification system is from 'ox_lib' resource.
useCustomNotify = false,
Expand Down
3 changes: 2 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ shared_script 'config.lua'

server_scripts {
'resource/server/server.lua',
'resource/server/players.lua'
'resource/server/players.lua',
'resource/server/version.lua'
}

client_scripts {
Expand Down
23 changes: 23 additions & 0 deletions resource/server/version.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Yoinked from https://github.com/overextended/ox_lib/blob/48728f0241da56b15f129fd4bcf394ccb01a95b9/resource/version/server.lua#L1
if ac.versionCheck then
SetTimeout(1000, function()
local resource = GetCurrentResourceName()

PerformHttpRequest('https://api.github.com/repos/antond15/ac_radio/releases/latest', function(status, response)
if status ~= 200 then return end

response = json.decode(response)
if response.prerelease then return end

local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
if not currentVersion then return end

local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
if not latestVersion then return end

if currentVersion >= latestVersion then return end

print(('^3An update is available for ac_radio (current version: %s)\r\n%s^0'):format(currentVersion, response.html_url))
end, 'GET')
end)
end

0 comments on commit 337bdb9

Please sign in to comment.