Commit 80eeb39c authored by Jonah's avatar Jonah

starting from scratch

parent 278e693b
--[[
A Simple ULX Module that enables banning players from interacting with props in TTT
Credits: The XGUI portion of this addon is a modified version of the default ulx ban page, located here: https://github.com/Nayruden/Ulysses/tree/master/ulx
This module requires mysqloo
Make sure you properly configure your SQL server below
--]]
require("mysqloo")
local db_prefix = "" --Leave this if you don't know what to do here
local db_hostname = "" --DB ip address or hostname
local db_port = 0 --Port of SQL DB
local db_name = "" --Name of database
local db_username = ""
local db_password = ""
local propban_database = mysqloo.connect(db_hostname, db_username, db_password, db_name, db_port)
local menuLimit = 100 --number of bans to include in the xgui menu
local pbRefreshTime = 90 --seconds between xgui refreshes
local announceBanNumber = true --announce number of prop bans upon server entry
--Admins who will get ban count notifications when players join
local admins = {
["admin"] = true,
["superadmin"] = true
}
local apiErrorCount = 0
local apiLastCheck = apiLastCheck or 0
local pbQueue = pbQueue or {}
pbTable = pbTable or {}
--DB functions
local function pbSQLQuery(sql, qTab)
local ply = qTab.ply
local steamid = qTab.steamid
local callback = qTab.cb
local aid = qTab.aid
local wait = qTab.wait
local result
local query = propban_database:query(sql)
if not query then
ServerLog("PropBan Query is empty\n")
if (propban_database:status() ~= mysqloo.DATABASE_CONNECTED) then
propban_database:connect()
ErrorNoHalt("PropBan Empty query, attempting reconnection")
return
else
error("PropBan empty query, already connected.\n")
end
end
query.onSuccess = function(_, data)
if not callback then
result = data
else
callback(data, qTab)
end
end
query.onError = function(_, err, sql)
ServerLog("PropBan ERROR "..err.."\n")
ServerLog("PropBan ERROR"..sql.."\n")
if ((propban_database:status() ~= mysqloo.DATABASE_CONNECTED) and callback) then
table.insert(pbQueue, {sql,qTab})
propban_database:connect()
return
else
propban_database:connect()
propban_database:wait()
end
if (propban_database:status() ~= mysqloo.DATABASE_CONNECTED) then
ErrorNoHalt("PropBan Reconnection to the db server failed. \n")
return
end
end
query:start()
if not callback then
if wait then query:wait() end
return result
end
end
propban_database.onConnected = function()
ServerLog("PropBan Mysql successfully connected \n")
pbSQLQuery("SET NAMES UTF8", {})
if pbQueue then
for k, v in pairs(pbQueue) do
pbSQLQuery(v[1], v[2])
end
pbQueue = {}
end
end
propban_database.onConnectionFailed = function (db, err)
ServerLog("PropBan Mysql failed to connect\n")
ServerLog("PropBan Mysql Error:"..tostring(err).."\n")
end
propban_database:connect()
--local functions
local function ReportBlock(bid, name)
local ostime = os.time();
local qTab = {}
qTab.wait = false
local query = "INSERT INTO "..db_prefix.."banlog (sid, time, name, bid)"
query = query.." VALUES ("..ostime..", '"..propban_database:escape(name).."', "..bid..");"
pbSQLQuery(query, qTab)
end
local function StillBanned(ply, bid, reason)
if not IsValid(ply) then return end
ReportBlock(bid,ply:Nick())
end
ULib.ucl.registerAccess( "ulx unpropbanall", ULib.ACCESS_SUPERADMIN, "Ability to unban all propban entries", "Other" ) -- Permission for admins to unban players banned by other admins.
ULib.ucl.registerAccess( "ulx editpropbanall", ULib.ACCESS_SUPERADMIN, "Ability to edit all propban entries", "Other" ) -- Permission for admins to edit bans made by other admins.
--Global functions
function pb_doban(inip, steamid, name, length, reason, callingadmin)
local adminid = callingadmin.SteamID or 0
local ip = string.Explode(":", inip)[1]
local qTab = {}
qTab.wait = false
local time = os.time();
local query = "INSERT INTO "..db_prefix.."bans (ip, authid, name, created, ends, length, reason, aid) "
query = query.." VALUES ('"..propban_database:escape(ip).."', '"..propban_database:escape(steamid).."', '"..propban_database:escape(name).."',"..time..", "..(time + length)..", "..length..", '"..propban_database:escape(reason).."', "..adminid..");"
pbSQLQuery(query, qTab)
XGUIRefreshBans()
end
function pb_banplayer(ply, length, reason, callingadmin)
local ip = string.Explode(":",ply:IPAddress())[1]
local steamid = ply:SteamID()
local name = ply:Nick()
pb_doban(ip,steamid,name,length,reason,callingadmin)
end
function pb_unban(steamid,ply,unreason)
local adminID = ply.SteamID() or 0
local qTab = {}
qTab.wait = false
pbSQLQuery("UPDATE "..db_prefix.."bans SET RemovedOn = "..os.time()..", RemovedBy = "..adminID..", RemoveType = 'U', ureason = '"..propban_database:escape(ureason).."' WHERE authid = '"..propban_database:escape(steamid).."' and RemoveType is null", qTab)
XGUIRefreshBans()
end
function pb_canunban(steamid, ply)
local adminID = ply:SteamID() or 0
local query = "SELECT * FROM "..db_prefix.."bans WHERE authid = '"..propban_database:escape(steamid).."' and RemoveType is null"
if not ULib.ucl.query( ply, "ulx unpropbanall" ) then
query = query .. " and aid = "..adminID
end
local qTab = {}
qTab.wait = true
return #pbSQLQuery(query, qTab) > 0
end
function pb_updateban(steamid, ply, bantime, reason, name)
local updateName = "[Unknown]"
if name and string.len(name) > 0 then
updateName = name
end
local qTab = {}
qTab.wait = false
local query = "UPDATE "..db_prefix.."bans SET ends = created + "..bantime
query = query .. ", length = "..bantime..", name = '"..propban_database:escape(updateName).."', reason = '"..propban_database:escape(reason).."' WHERE authid = '"..propban_database:escape(steamid).."' and RemoveType is null"
pbSQLQuery(query, qTab)
XGUIRefreshBans()
end
--UI Section
local function UpdateBanList(result, qTab)
local tempTable = {}
for k,v in pairs(result) do
tempTable[v.authid] = {}
tempTable[v.authid].bid = v.bid
tempTable[v.authid].sid = tonumber(v.sid) > 0 and v.sid or "TTT MC"
tempTable[v.authid].admin = v.admin
tempTable[v.authid].adminid = v.aid
tempTable[v.authid].name = v.name
tempTable[v.authid].reason = v.reason
tempTable[v.authid].steamID = v.authid
tempTable[v.authid].time = v.created
tempTable[v.authid].unban = v.created == v.ends and 0 or v.ends
end
pbTable = tempTable
end
function pbRetrieveBans()
local qTab = {}
qTab.cb = function(result, qTab) UpdateBanList(result, qTab) end
if not banRetrieveLimit or type(banRetrieveLimit) ~= number then
banRetrieveLimit = 150
end
pbSQLQuery("SELECT a.user as admin, b.aid, b.bid, b.sid, b.name, b.reason, b.authid, b.created, b.ends FROM " ..db_prefix.. "bans b INNER JOIN " ..db_prefix.. "admins a ON b.aid = a.aid WHERE b.RemoveType is null ORDER BY b.created DESC LIMIT "..menuLimit, qTab)
end
hook.Add("InitPostEntity", "LoadPropBans", pbRetrieveBans)
timer.Create("UpdatePBListPls", pbRefreshTime, 0, pbRetrieveBans)
--nope
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment