-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert: esx_allowlist > bpt_allowlist
- Loading branch information
1 parent
1049698
commit 261855a
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
server-data/resources/[bpt_addons]/bpt_allowlist/server/main.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
local allowList = {} | ||
|
||
local function loadAllowList() | ||
allowList = {} | ||
|
||
local list = LoadResourceFile(GetCurrentResourceName(), 'players.json') | ||
if list then | ||
allowList = json.decode(list) | ||
end | ||
end | ||
|
||
CreateThread(loadAllowList) | ||
|
||
AddEventHandler('playerConnecting', function(name, setCallback, deferrals) | ||
local players = GetPlayers() | ||
if #players < Config.MinPlayer then return end | ||
|
||
deferrals.defer() | ||
|
||
local playerId, kickReason = source, TranslateCap('error') | ||
|
||
deferrals.update(TranslateCap('allowlist_check')) | ||
|
||
--Not for nothing was this 100 but even this is not the best solution. | ||
Wait(100) | ||
|
||
local identifier = ESX.GetIdentifier(playerId) | ||
|
||
if ESX.Table.SizeOf(allowList) == 0 then | ||
kickReason = "[BPT] " .. TranslateCap('allowlist_empty') | ||
elseif not identifier then | ||
kickReason = "[BPT] " .. TranslateCap('license_missing') | ||
elseif not allowList[identifier] then | ||
kickReason = "[BPT] " .. TranslateCap('not_allowlist') | ||
end | ||
|
||
if kickReason then return deferrals.done(kickReason) end | ||
|
||
deferrals.done() | ||
end) | ||
|
||
ESX.RegisterCommand('alrefresh', 'admin', function(xPlayer, args) | ||
loadAllowList() | ||
print('[^2INFO^7] Allowlist ^5Refreshed^7!') | ||
end, true, { help = TranslateCap('help_allowlist_load') }) | ||
|
||
ESX.RegisterCommand('aladd', 'admin', function(xPlayer, args, showError) | ||
local playerLicense = args.license:lower() | ||
|
||
if allowList[playerLicense] then | ||
showError('The player is already allowlisted on this server!') | ||
else | ||
allowList[playerLicense] = true | ||
SaveResourceFile(GetCurrentResourceName(), 'players.json', json.encode(allowList)) | ||
loadAllowList() | ||
return | ||
end | ||
end, true, { | ||
help = TranslateCap('help_allowlist_add'), | ||
validate = true, | ||
arguments = { | ||
{ name = TranslateCap('license'), help = TranslateCap('help_license'), type = 'string' } | ||
} | ||
}) | ||
|
||
ESX.RegisterCommand('alremove', 'admin', function(xPlayer, args, showError) | ||
local playerLicense = args.license:lower() | ||
|
||
if allowList[playerLicense] then | ||
allowList[playerLicense] = nil | ||
SaveResourceFile(GetCurrentResourceName(), 'players.json', json.encode(allowList)) | ||
loadAllowList() | ||
else | ||
showError(TranslateCap('identifier_not_allowlisted')) | ||
return | ||
end | ||
end, true, { | ||
help = TranslateCap('help_allowlist_remove'), | ||
validate = true, | ||
arguments = { | ||
{ name = TranslateCap('license'), help = TranslateCap('help_license'), type = 'string' } | ||
} | ||
}) |