Skip to content

Commit 049e5a0

Browse files
committed
feat(server): repository metadata checks
also improved the version check by detecting forks as best I can
1 parent eaf585b commit 049e5a0

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

fxmanifest.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ game('gta5')
66
name('mad_goon')
77
version('1.0.1')
88
description('Talk to your AI Concierge')
9+
repository('ThatMadCap/mad_goon')
910
author('MadCap')
1011

1112
-- https://madcap-scripts.tebex.io

locales/en.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@
3838
"command_desc_select": "Select your preferred ${ai} character",
3939
"command_desc_address": "Select how your ${ai} addresses you",
4040
"command_desc_random": "Consult your ${ai} for a random comment",
41-
"command_desc_menu": "${open} ${ai} ${menu}"
41+
"command_desc_menu": "${open} ${ai} ${menu}",
42+
43+
"fork_detected": "Detected fork by '%s', skipping version check",
44+
"not_author": "You did not make this %s",
45+
"resource_name_changed": "Please do not rename the resource. Change it from '%s' back to 'mad_goon'"
4246
}

server/sv_main.lua

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,54 @@ local serverConfig = lib.require('config.server')
77
local logs = lib.require('modules.server.logs')
88

99
-- Localised Functions ----------------------------------------------
10-
local AddEventHandler = AddEventHandler
10+
local string = string
11+
local gsub = string.gsub
12+
local match = string.match
1113
local GetCurrentResourceName = GetCurrentResourceName
1214
local TriggerClientEvent = TriggerClientEvent
15+
local GetResourceMetadata = GetResourceMetadata
16+
local AddEventHandler = AddEventHandler
1317

1418
-- Local Variables ----------------------------------------------
1519
local resourceName = GetCurrentResourceName()
1620

1721
-- Functions ------------------------------------------------------
22+
---Checks resource metadata for cheeky gits
23+
local function checkResourceMeta()
24+
local currentAuthor = GetResourceMetadata(resourceName, 'author', 0)
25+
assert(currentAuthor == 'MadCap', locale('not_author', currentAuthor or 'unknown'))
26+
27+
local currentResourceName = GetResourceMetadata(resourceName, 'name', 0)
28+
assert(currentResourceName == 'mad_goon', locale('resource_name_changed', currentResourceName or 'unknown'))
29+
end
30+
31+
---Checks if the resource is a fork
32+
---@return boolean isFork Whether the resource is a fork
33+
---@return string repo The repository string (owner/repo)
34+
---@return string owner The repository owner
35+
local function isFork()
36+
local originalRepo = 'ThatMadCap/mad_goon'
37+
38+
local repo = GetResourceMetadata(resourceName, 'repository', 0) or originalRepo
39+
repo = gsub(repo, 'https?://github%.com/', '')
40+
41+
local owner = match(repo, '^([^/]+)/')
42+
43+
return repo ~= originalRepo, repo, owner
44+
end
45+
46+
---Performs version check unless forked
47+
local function versionCheck()
48+
local forked, repo, owner = isFork()
49+
50+
if forked then
51+
lib.print.warn(locale('fork_detected', owner))
52+
return
53+
end
54+
55+
lib.versionCheck(repo)
56+
end
57+
1858
---Broadcast speech to nearby players
1959
---@param src number Source player
2060
---@param data SpeechData
@@ -58,6 +98,9 @@ end)
5898

5999
-- Initialisation -----------------------------------------------------
60100
local function init()
101+
versionCheck()
102+
checkResourceMeta()
103+
61104
if not nlp.isModelReady() then
62105
nlp.initNLP()
63106
end
@@ -69,8 +112,6 @@ local function init()
69112
commands.initCommands()
70113
end
71114

72-
lib.versionCheck('ThatMadCap/mad_goon')
73-
74115
-- Event Handlers --------------------------------------------------
75116
AddEventHandler('onResourceStart', function(resName)
76117
if resourceName ~= resName then

0 commit comments

Comments
 (0)