Ban refactor part 3 - Job bans with CDL (#17283)

This commit is contained in:
AffectedArc07
2022-01-03 20:01:21 +01:00
committed by GitHub
parent 5363c10afa
commit 6519fe884a
10 changed files with 163 additions and 208 deletions
+6
View File
@@ -120,6 +120,9 @@
/// The client's karma holder
var/datum/karma_holder/karmaholder
/// The client's job ban holder
var/datum/job_ban_holder/jbh = new()
/client/vv_edit_var(var_name, var_value)
switch(var_name)
// I know we will never be in a world where admins are editing client vars to let people bypass TOS
@@ -132,4 +135,7 @@
// or this
if("karmaholder")
return FALSE
// or this
if("jbh")
return FALSE
return ..()
+72
View File
@@ -0,0 +1,72 @@
/// Holder for job bans
/datum/job_ban_holder
/// Assoc list of job banned:ban holder
var/list/datum/job_ban/job_bans = list()
// Get us a query
/datum/job_ban_holder/proc/get_query(client/C)
var/datum/db_query/query = SSdbcore.NewQuery({"
SELECT bantime, bantype, reason, job, duration, expiration_time, a_ckey FROM ban
WHERE ckey LIKE :ckey AND ((bantype LIKE 'JOB_TEMPBAN' AND expiration_time > NOW()) OR (bantype LIKE 'JOB_PERMABAN')) AND ISNULL(unbanned)
ORDER BY bantime DESC LIMIT 100"}, // If someone has 100 job bans we have bigger problems
list("ckey" = C.ckey)
)
return query
// Uses the query from above
/datum/job_ban_holder/proc/process_query(datum/db_query/Q)
while(Q.NextRow())
var/datum/job_ban/JB = new()
JB.bantime = Q.item[1]
JB.bantype = Q.item[2]
JB.reason = Q.item[3]
JB.job = Q.item[4]
JB.duration = Q.item[5]
JB.expiration_time = Q.item[6]
JB.a_ckey = Q.item[7]
job_bans[JB.job] = JB // Save it assoc
// Check if someone is job banned
/datum/job_ban_holder/proc/is_banned(job)
if(job in job_bans)
return TRUE
return FALSE
// Reload the job bans
/datum/job_ban_holder/proc/reload_jobbans(client/C)
var/datum/db_query/data = get_query(C)
if(!data.warn_execute())
qdel(data)
return
job_bans.Cut() // Empty it
process_query(data)
qdel(data)
// dont mess with this
/datum/job_ban_holder/vv_edit_var(var_name, var_value)
return FALSE
/datum/job_ban_holder/CanProcCall(procname)
return FALSE
// Job ban data "model"
/datum/job_ban
/// Time of ban
var/bantime
/// Type of ban
var/bantype
/// Reason for ban
var/reason
/// Job banned itself
var/job
/// Duration (if temp)
var/duration
/// Expiry time (if temp)
var/expiration_time
/// Admin who did it
var/a_ckey
// or this
/datum/job_ban/vv_edit_var(var_name, var_value)
return FALSE
@@ -0,0 +1,10 @@
/datum/client_login_processor/load_jobbans
priority = 25
// These look pretty useless, but it allows the client jobban holder to reload bans without proc calling here,
// and we can re-use the same queries and handlers
/datum/client_login_processor/load_jobbans/get_query(client/C)
return C.jbh.get_query(C)
/datum/client_login_processor/load_jobbans/process_result(datum/db_query/Q, client/C)
C.jbh.process_query(Q)