Skip to content

Commit

Permalink
Config loader
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown-gd committed Nov 23, 2023
1 parent 1da5c4d commit dd6beeb
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lua/autorun/server/community-ban-lists.yue
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ print = print
AddonName = "Community Ban Lists"
Bans, URLs = {}, {}

FileName = gsub( lower( AddonName ), "[%s%p]+", "_" ) .. ".json"
if Exists( FileName, "DATA" )
json = file.Read( FileName, "DATA" )
if isstring( json )
data = util.JSONToTable( json )
if istable( data )
table.Merge( URLs, data )
else
file.Write( FileName, "[]" )
LoadConfig = ->
FileName = gsub( lower( AddonName ), "[%s%p]+", "_" ) .. ".json"
if Exists( FileName, "DATA" )
json = file.Read( FileName, "DATA" )
if isstring( json )
data = util.JSONToTable( json )
if istable( data )
table.Merge( URLs, data )
else
file.Write( FileName, "[]" )

class List
new: ( url ) =>
Expand Down Expand Up @@ -138,6 +139,7 @@ LoadLists = ->
for url in *URLs
List( url )
timer.Simple 0, LoadLists
LoadConfig!

hook_Run = hook.Run
hook.Add "CheckPassword", AddonName, ( player_steamid64, player_ip, _, __, player_nick ) ->
Expand All @@ -155,4 +157,5 @@ concommand.Add "cbl_reload", =>
return

table.Empty( Bans )
LoadConfig!
LoadLists!

0 comments on commit dd6beeb

Please sign in to comment.