mirror of
https://github.com/CFC-Servers/cfc_ulx_commands.git
synced 2025-03-04 03:13:28 -05:00
Add extra data column
This commit is contained in:
parent
c68ef79b68
commit
348cc46354
@ -26,11 +26,12 @@ function Data:setupTables()
|
||||
query( [[
|
||||
CREATE TABLE IF NOT EXISTS cfc_timed_punishments(
|
||||
id INTEGER PRIMARY KEY,
|
||||
steamid64 TEXT NOT NULL,
|
||||
expiration INTEGER NOT NULL,
|
||||
issuer TEXT NOT NULL,
|
||||
punishment TEXT NOT NULL,
|
||||
reason TEXT
|
||||
steamid64 TEXT NOT NULL ,
|
||||
expiration INTEGER NOT NULL ,
|
||||
issuer TEXT NOT NULL ,
|
||||
punishment TEXT NOT NULL ,
|
||||
reason TEXT ,
|
||||
extraData TEXT ,
|
||||
)
|
||||
]] )
|
||||
|
||||
@ -75,13 +76,13 @@ function Data:removeExpired()
|
||||
]], now )
|
||||
end
|
||||
|
||||
function Data:createPunishment( punishment, steamID64, expiration, issuer, reason )
|
||||
function Data:createPunishment( punishment, steamID64, expiration, issuer, reason, extraData )
|
||||
query( [[
|
||||
INSERT OR REPLACE INTO
|
||||
cfc_timed_punishments (steamid64, expiration, issuer, punishment, reason )
|
||||
cfc_timed_punishments (steamid64, expiration, issuer, punishment, reason, extraData )
|
||||
VALUES
|
||||
(%s, %s, %s, %s, %s)
|
||||
]], steamID64, expiration, issuer, punishment, reason )
|
||||
]], steamID64, expiration, issuer, punishment, reason, extraData )
|
||||
end
|
||||
|
||||
function Data:removePunishment( punishment, steamID64 )
|
||||
@ -98,7 +99,7 @@ end
|
||||
function Data:getPunishments( steamID64 )
|
||||
local result = query( [[
|
||||
SELECT
|
||||
expiration, punishment
|
||||
expiration, punishment, extraData
|
||||
FROM
|
||||
cfc_timed_punishments
|
||||
WHERE
|
||||
@ -110,7 +111,15 @@ function Data:getPunishments( steamID64 )
|
||||
if result == false then return ErrorNoHaltWithStack( steamID64 ) end
|
||||
|
||||
for _, p in ipairs( result ) do
|
||||
punishments[p.punishment] = tonumber( p.expiration )
|
||||
local extraData = p.extraData
|
||||
if extraData then
|
||||
extraData = util.JSONToTable( extraData )
|
||||
end
|
||||
|
||||
punishments[p.punishment] = {
|
||||
expiration = tonumber( p.expiration ),
|
||||
extraData = extraData
|
||||
}
|
||||
end
|
||||
|
||||
return punishments
|
||||
|
@ -26,13 +26,13 @@ function TP.Register( punishment, enable, disable )
|
||||
}
|
||||
end
|
||||
|
||||
function TP.Punish( steamID64, punishment, expiration, issuer, reason )
|
||||
Data:createPunishment( punishment, steamID64, expiration, issuer, reason )
|
||||
function TP.Punish( steamID64, punishment, expiration, issuer, reason, extraData )
|
||||
Data:createPunishment( punishment, steamID64, expiration, issuer, reason, extraData )
|
||||
|
||||
local ply = player.GetBySteamID64( steamID64 )
|
||||
if not IsValid( ply ) then return end
|
||||
|
||||
Punishments[punishment].enable( ply )
|
||||
Punishments[punishment].enable( ply, extraData )
|
||||
end
|
||||
|
||||
function TP.Unpunish( steamID64, punishment )
|
||||
@ -50,8 +50,15 @@ hook.Add( "PlayerInitialSpawn", "CFC_TimedPunishments_Check", function( ply )
|
||||
local steamID64 = ply:SteamID64()
|
||||
local punishments = Data:getPunishments( steamID64 )
|
||||
|
||||
for punishment, expiration in pairs( punishments or none ) do
|
||||
Punishments[punishment].enable( ply )
|
||||
local now = os.time()
|
||||
|
||||
for punishment, fields in pairs( punishments or none ) do
|
||||
local expiration = fields.expiration
|
||||
|
||||
if expiration == 0 or expiration > now then
|
||||
local extraData = fields.extraData
|
||||
Punishments[punishment].enable( ply, extraData )
|
||||
end
|
||||
end
|
||||
|
||||
ply.TimedPunishments = punishments
|
||||
@ -65,7 +72,9 @@ hook.Add( "Initialize", "CFC_TimedPunishments_Init", function()
|
||||
local steamID64 = ply:SteamID64()
|
||||
local punishments = ply.TimedPunishments or none
|
||||
|
||||
for punishment, expiration in pairs( punishments ) do
|
||||
for punishment, fields in pairs( punishments ) do
|
||||
local expiration = fields.expiration
|
||||
|
||||
if expiration > 0 and expiration <= now then
|
||||
ply.TimedPunishments[punishment] = nil
|
||||
TP.Unpunish( steamID64, punishment )
|
||||
|
Loading…
Reference in New Issue
Block a user