functions/punishments.lua
Adapter de punições — jail, temp_ban, kick, perm_ban, whitelist.
Globals esperadas
getPunishmentHistory(userId)getActivePunishments(userId)jailPlayer(userId, minutes, reason)tempBanPlayer(userId, minutes, reason)permBanPlayer(userId, reason)kickPlayer(userId, reason)removeWhitelist(userId, reason)addWhitelist(userId)unjailPlayer(userId)unbanPlayer(userId)
Histórico — tabela auto-criada
Na inicialização, o adapter cria a tabela Config.PunishmentsHistoryTableName se não existir:
sql
CREATE TABLE IF NOT EXISTS `elite_saas_punishments_history` (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
type VARCHAR(32) NOT NULL,
reason TEXT NULL,
duration_minutes INT NULL,
expires_at DATETIME NULL,
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP,
applied_by VARCHAR(128) NULL,
reverted_at DATETIME NULL,
reverted_by VARCHAR(128) NULL,
status VARCHAR(16) DEFAULT 'active',
INDEX (user_id, applied_at)
);Tabelas vRP envolvidas
vrp_user_bans—(user_id, banned BOOL, until DATETIME, reason).vrp_user_data—(user_id, dkey, dvalue)— flag de whitelist quando o servidor não tem grupo dedicado.
jailPlayer — exemplo
functions/punishments.lua·lua
function jailPlayer(userId, minutes, reason)
-- Persiste histórico
local expiresAt = os.date("%Y-%m-%d %H:%M:%S", os.time() + (minutes * 60))
local insertId = exports.oxmysql:insert_async(
"INSERT INTO "..Config.PunishmentsHistoryTableName..
" (user_id, type, reason, duration_minutes, expires_at, status)"..
" VALUES (?, 'jail', ?, ?, ?, 'active')",
{ userId, reason, minutes, expiresAt }
)
-- Aplica via vRP (compatível com vrp_prison)
local src = vRP.getUserSource(userId)
if src then
if vRP.jail then
vRP.jail(userId, minutes * 60)
else
TriggerEvent("vrp_prison:put", src, minutes * 60, reason)
end
end
-- Notifica o Live Feed
if EliteSaaSEvents then
EliteSaaSEvents.punishment("jail", vRP.getUserIdentity(userId).name, userId, reason)
end
return insertId
endtempBanPlayer / permBanPlayer
lua
function tempBanPlayer(userId, minutes, reason)
local untilTs = os.date("%Y-%m-%d %H:%M:%S", os.time() + (minutes * 60))
exports.oxmysql:execute_async(
"INSERT INTO vrp_user_bans (user_id, banned, until, reason)"..
" VALUES (?, 1, ?, ?)"..
" ON DUPLICATE KEY UPDATE banned=1, until=VALUES(until), reason=VALUES(reason)",
{ userId, untilTs, reason }
)
local src = vRP.getUserSource(userId)
if src then DropPlayer(src, "Banido até "..untilTs..": "..(reason or "")) end
exports.oxmysql:insert_async(
"INSERT INTO "..Config.PunishmentsHistoryTableName..
" (user_id, type, reason, duration_minutes, expires_at, status)"..
" VALUES (?, 'temp_ban', ?, ?, ?, 'active')",
{ userId, reason, minutes, untilTs }
)
end
function permBanPlayer(userId, reason)
exports.oxmysql:execute_async(
"INSERT INTO vrp_user_bans (user_id, banned, until, reason)"..
" VALUES (?, 1, NULL, ?)"..
" ON DUPLICATE KEY UPDATE banned=1, until=NULL, reason=VALUES(reason)",
{ userId, reason }
)
local src = vRP.getUserSource(userId)
if src then DropPlayer(src, "Banido permanentemente: "..(reason or "")) end
exports.oxmysql:insert_async(
"INSERT INTO "..Config.PunishmentsHistoryTableName..
" (user_id, type, reason, status) VALUES (?, 'perm_ban', ?, 'active')",
{ userId, reason }
)
endAdapter ≠ source of truth
Não confie só no histórico desta tabela para decidir se um usuário está banido — o vRP usa
vrp_user_bans. O histórico é trilha de auditoria; a aplicação real continua no banco do framework.getActivePunishments(userId)
lua
function getActivePunishments(userId)
local out = { jail = false, temp_ban = false, perm_ban = false, wl_remove = false }
local bans = exports.oxmysql:query_async(
"SELECT `until` FROM vrp_user_bans WHERE user_id = ? AND banned = 1 LIMIT 1",
{ userId }
)
if bans and bans[1] then
if bans[1].until then out.temp_ban = true else out.perm_ban = true end
end
-- jail: depende de implementação; consulte vrp_prison ou flag em vrp_user_data
return out
end