feat(storage): add warn data persistence layer

Implement server-side storage module for managing player warnings.

Provides functionality to:
- Load and save warnings from/to JSON file
- Retrieve warnings for a specific player
- Add new warnings with issuer information
- Remove individual warnings by index
- Clear all warnings for a player

Warnings are stored with issuer, issuerid, timestamp, reason, and comment.
This commit is contained in:
2026-07-20 23:29:48 +02:00
parent 63e35a534c
commit 4e436a05c3
+47
View File
@@ -0,0 +1,47 @@
BladW = BladW or {}
BladW.Warn = BladW.Warn or {}
-- stockage des warns : { [steamid64] = { { issuer, issuerid, time, reason, comment }, ... } }
local DIR = "bladw_warn"
local FILE = "bladw_warn/warns.json"
BladW.Warn.Data = BladW.Warn.Data or {}
function BladW.Warn.Save()
file.CreateDir(DIR)
file.Write(FILE, util.TableToJSON(BladW.Warn.Data))
end
function BladW.Warn.Load()
local raw = file.Read(FILE, "DATA")
BladW.Warn.Data = (raw and util.JSONToTable(raw)) or {}
end
function BladW.Warn.Get(sid)
return BladW.Warn.Data[sid] or {}
end
function BladW.Warn.AddWarn(sid, entry)
if not sid or sid == "" then return end
BladW.Warn.Data[sid] = BladW.Warn.Data[sid] or {}
table.insert(BladW.Warn.Data[sid], entry)
BladW.Warn.Save()
end
function BladW.Warn.RemoveWarn(sid, index)
local t = BladW.Warn.Data[sid]
if t and t[index] then
table.remove(t, index)
if #t == 0 then BladW.Warn.Data[sid] = nil end
BladW.Warn.Save()
return true
end
return false
end
function BladW.Warn.ClearWarns(sid)
BladW.Warn.Data[sid] = nil
BladW.Warn.Save()
end
BladW.Warn.Load()