mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-22 19:47:22 +01:00
Ban refactor part 3 - Job bans with CDL (#17283)
This commit is contained in:
+40
-140
@@ -1,159 +1,59 @@
|
||||
GLOBAL_VAR(jobban_runonce) // Updates legacy bans with new info
|
||||
GLOBAL_LIST_INIT(jobban_keylist, new()) // Linear list of jobban strings, kept around for the legacy system
|
||||
GLOBAL_LIST_INIT(jobban_assoclist, new()) // Associative list, for efficiency
|
||||
|
||||
// Matches string-based jobbans into ckey, rank, and reason groups
|
||||
GLOBAL_DATUM_INIT(jobban_regex, /regex, regex("(\[\\S]+) - (\[^#]+\[^# ])(?: ## (.+))?"))
|
||||
|
||||
/proc/jobban_assoc_insert(ckey, rank, reason)
|
||||
if(!ckey || !rank)
|
||||
return
|
||||
if(!GLOB.jobban_assoclist[ckey])
|
||||
GLOB.jobban_assoclist[ckey] = list()
|
||||
GLOB.jobban_assoclist[ckey][rank] = reason || "Reason Unspecified"
|
||||
|
||||
/proc/jobban_fullban(mob/M, rank, reason)
|
||||
if(!M || !M.key)
|
||||
return
|
||||
GLOB.jobban_keylist.Add(text("[M.ckey] - [rank] ## [reason]"))
|
||||
jobban_assoc_insert(M.ckey, rank, reason)
|
||||
|
||||
/proc/jobban_client_fullban(ckey, rank)
|
||||
if(!ckey || !rank)
|
||||
return
|
||||
GLOB.jobban_keylist.Add(text("[ckey] - [rank]"))
|
||||
jobban_assoc_insert(ckey, rank)
|
||||
|
||||
//returns a reason if M is banned from rank, returns 0 otherwise
|
||||
// Returns a reason if M is banned from rank, returns null otherwise
|
||||
/proc/jobban_isbanned(mob/M, rank)
|
||||
if(!M || !rank)
|
||||
return 0
|
||||
|
||||
if(GLOB.configuration.jobs.guest_job_ban && check_job_karma(rank))
|
||||
if(IsGuestKey(M.key))
|
||||
return "Guest Job-ban"
|
||||
|
||||
if(GLOB.jobban_assoclist[M.ckey])
|
||||
return GLOB.jobban_assoclist[M.ckey][rank]
|
||||
else
|
||||
return 0
|
||||
|
||||
/proc/jobban_isbanned_ckey(ckey, rank)
|
||||
if(!ckey || !rank)
|
||||
if(!M || !M.client || !rank)
|
||||
return null
|
||||
|
||||
if(GLOB.configuration.jobs.guest_job_ban && check_job_karma(rank))
|
||||
if(IsGuestKey(ckey))
|
||||
return "Guest Job-ban"
|
||||
if(GLOB.configuration.jobs.guest_job_ban && IsGuestKey(M.key))
|
||||
return "Guest Job-ban"
|
||||
|
||||
if(GLOB.jobban_assoclist[ckey])
|
||||
return GLOB.jobban_assoclist[ckey][rank]
|
||||
if(rank in M.client.jbh.job_bans)
|
||||
var/datum/job_ban/JB = M.client.jbh.job_bans[rank]
|
||||
return JB.reason
|
||||
|
||||
return null
|
||||
|
||||
/proc/jobban_loadbans()
|
||||
if(!SSdbcore.IsConnected())
|
||||
log_world("Database connection failed. Job bans not loaded.")
|
||||
return
|
||||
|
||||
//Job permabans
|
||||
var/datum/db_query/permabans = SSdbcore.NewQuery("SELECT ckey, job FROM ban WHERE bantype = 'JOB_PERMABAN' AND isnull(unbanned)")
|
||||
|
||||
if(!permabans.warn_execute(async=FALSE))
|
||||
qdel(permabans)
|
||||
return FALSE
|
||||
|
||||
while(permabans.NextRow())
|
||||
var/ckey = permabans.item[1]
|
||||
var/job = permabans.item[2]
|
||||
GLOB.jobban_keylist.Add("[ckey] - [job]")
|
||||
jobban_assoc_insert(ckey, job)
|
||||
|
||||
qdel(permabans)
|
||||
|
||||
// Job tempbans
|
||||
var/datum/db_query/tempbans = SSdbcore.NewQuery("SELECT ckey, job FROM ban WHERE bantype = 'JOB_TEMPBAN' AND isnull(unbanned) AND expiration_time > Now()")
|
||||
|
||||
if(!tempbans.warn_execute(async=FALSE))
|
||||
qdel(tempbans)
|
||||
return FALSE
|
||||
|
||||
while(tempbans.NextRow())
|
||||
var/ckey = tempbans.item[1]
|
||||
var/job = tempbans.item[2]
|
||||
GLOB.jobban_keylist.Add("[ckey] - [job]")
|
||||
jobban_assoc_insert(ckey, job)
|
||||
|
||||
qdel(tempbans)
|
||||
|
||||
/proc/jobban_savebanfile()
|
||||
var/savefile/S=new("data/job_full.ban")
|
||||
S["keys[0]"] << GLOB.jobban_keylist
|
||||
|
||||
/proc/jobban_unban(mob/M, rank)
|
||||
jobban_remove("[M.ckey] - [rank]")
|
||||
|
||||
/proc/jobban_unban_client(ckey, rank)
|
||||
jobban_remove("[ckey] - [rank]")
|
||||
|
||||
/proc/jobban_remove(X)
|
||||
for(var/i = 1; i <= length(GLOB.jobban_keylist); i++)
|
||||
if( findtext(GLOB.jobban_keylist[i], "[X]") )
|
||||
// This need to be here, instead of jobban_unban, due to direct calls to jobban_remove
|
||||
if(GLOB.jobban_regex.Find(X))
|
||||
var/ckey = GLOB.jobban_regex.group[1]
|
||||
var/rank = GLOB.jobban_regex.group[2]
|
||||
if(GLOB.jobban_assoclist[ckey] && GLOB.jobban_assoclist[ckey][rank])
|
||||
GLOB.jobban_assoclist[ckey] -= rank
|
||||
else
|
||||
log_runtime(EXCEPTION("Attempted to remove non-existent job ban: [X]"))
|
||||
else
|
||||
log_runtime(EXCEPTION("Failed to remove malformed job ban from associative list: [X]"))
|
||||
GLOB.jobban_keylist.Remove(GLOB.jobban_keylist[i])
|
||||
return 1
|
||||
return 0
|
||||
|
||||
/mob/verb/displayjobbans()
|
||||
set category = "OOC"
|
||||
set name = "Display Current Jobbans"
|
||||
set desc = "Displays all of your current jobbans."
|
||||
|
||||
if(!client || !ckey)
|
||||
return
|
||||
|
||||
var/is_actually_banned = FALSE
|
||||
var/datum/db_query/select_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)
|
||||
// Gets all the job bans for a ckey incase they are offline
|
||||
/proc/get_jobbans_for_offline_ckey(ckey)
|
||||
var/datum/db_query/query = SSdbcore.NewQuery({"
|
||||
SELECT job 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"},
|
||||
list("ckey" = ckey)
|
||||
)
|
||||
|
||||
if(!select_query.warn_execute())
|
||||
qdel(select_query)
|
||||
if(!query.warn_execute())
|
||||
qdel(query)
|
||||
return FALSE
|
||||
|
||||
while(select_query.NextRow())
|
||||
var/list/jobs = list()
|
||||
|
||||
var/bantime = select_query.item[1]
|
||||
var/bantype = select_query.item[2]
|
||||
var/reason = select_query.item[3]
|
||||
var/job = select_query.item[4]
|
||||
var/duration = select_query.item[5]
|
||||
var/expiration = select_query.item[6]
|
||||
var/ackey = select_query.item[7]
|
||||
while(query.NextRow())
|
||||
jobs += query.item[1]
|
||||
|
||||
if(bantype == "JOB_PERMABAN")
|
||||
to_chat(src, "<span class='warning'>[bantype]: [job] - REASON: [reason], by [ackey]; [bantime]</span>")
|
||||
else if(bantype == "JOB_TEMPBAN")
|
||||
to_chat(src, "<span class='warning'>[bantype]: [job] - REASON: [reason], by [ackey]; [bantime]; [duration]; expires [expiration]</span>")
|
||||
return jobs
|
||||
|
||||
is_actually_banned = TRUE
|
||||
/client/verb/displayjobbans()
|
||||
set category = "OOC"
|
||||
set name = "Display Current Jobbans"
|
||||
set desc = "Displays all of your current jobbans."
|
||||
|
||||
qdel(select_query)
|
||||
// Ok. I know this verb here is scoped to client, I know.
|
||||
// But sometimes when executing, the src will be a mob
|
||||
// I have no idea why, but this is a workaround.
|
||||
jbh.reload_jobbans(usr.client)
|
||||
|
||||
if(is_actually_banned)
|
||||
if(GLOB.configuration.url.banappeals_url)
|
||||
to_chat(src, "<span class='warning'>You can appeal the bans at: [GLOB.configuration.url.banappeals_url]</span>")
|
||||
else
|
||||
if(!length(jbh.job_bans))
|
||||
to_chat(src, "<span class='warning'>You have no active jobbans!</span>")
|
||||
return
|
||||
|
||||
for(var/ban in jbh.job_bans)
|
||||
var/datum/job_ban/JB = jbh.job_bans[ban] // Remember. Its assoc.
|
||||
switch(JB.bantype)
|
||||
if("JOB_PERMABAN")
|
||||
to_chat(src, "<span class='warning'>[JB.bantype]: [JB.job] - REASON: [JB.reason], by [JB.a_ckey]; [JB.bantime]</span>")
|
||||
if("JOB_TEMPBAN")
|
||||
to_chat(src, "<span class='warning'>[JB.bantype]: [JB.job] - REASON: [JB.reason], by [JB.a_ckey]; [JB.bantime]; [JB.duration]; expires [JB.expiration_time]</span>")
|
||||
|
||||
if(GLOB.configuration.url.banappeals_url)
|
||||
to_chat(src, "<span class='warning'>You can appeal the bans at: [GLOB.configuration.url.banappeals_url]</span>")
|
||||
|
||||
|
||||
@@ -179,7 +179,11 @@
|
||||
qdel(banned_mob.client)
|
||||
|
||||
if(isjobban)
|
||||
jobban_client_fullban(ckey, job)
|
||||
// See if they are online
|
||||
var/client/C = GLOB.directory[ckey(ckey)]
|
||||
if(C)
|
||||
// Reload their job ban holder
|
||||
C.jbh.reload_jobbans(C)
|
||||
else
|
||||
flag_account_for_forum_sync(ckey)
|
||||
|
||||
@@ -265,7 +269,11 @@
|
||||
|
||||
DB_ban_unban_by_id(ban_id)
|
||||
if(isjobban)
|
||||
jobban_unban_client(ckey, job)
|
||||
// See if they are online
|
||||
var/client/C = GLOB.directory[ckey(ckey)]
|
||||
if(C)
|
||||
// Reload their job ban holder
|
||||
C.jbh.reload_jobbans(C)
|
||||
else
|
||||
flag_account_for_forum_sync(ckey)
|
||||
|
||||
@@ -346,7 +354,11 @@
|
||||
if(alert("Unban [pckey]?", "Unban?", "Yes", "No") == "Yes")
|
||||
DB_ban_unban_by_id(banid)
|
||||
if(job && length(job))
|
||||
jobban_unban_client(pckey, job)
|
||||
// See if they are online
|
||||
var/client/C = GLOB.directory[ckey(pckey)]
|
||||
if(C)
|
||||
// Reload their job ban holder
|
||||
C.jbh.reload_jobbans(C)
|
||||
return
|
||||
else
|
||||
to_chat(usr, "Cancelled")
|
||||
@@ -410,6 +422,11 @@
|
||||
message_admins("[key_name_admin(usr)] has lifted [pckey]'s ban.")
|
||||
log_admin("[key_name(usr)] has lifted [pckey]'s ban.")
|
||||
flag_account_for_forum_sync(pckey)
|
||||
// See if they are online
|
||||
var/client/C = GLOB.directory[ckey(pckey)]
|
||||
if(C)
|
||||
// Reload their job ban holder
|
||||
C.jbh.reload_jobbans(C)
|
||||
|
||||
|
||||
/datum/admins/proc/DB_ban_panel(playerckey = null, adminckey = null, playerip = null, playercid = null, dbbantype = null, match = null)
|
||||
|
||||
+12
-20
@@ -219,8 +219,9 @@
|
||||
if(multi_job)
|
||||
//Create a list of unbanned jobs within joblist
|
||||
var/list/notbannedlist = list()
|
||||
var/list/banned_list = get_jobbans_for_offline_ckey(banckey) // They might be offline, you never know
|
||||
for(var/job in jobs_to_ban)
|
||||
if(!jobban_isbanned_ckey(banckey, job))
|
||||
if(!(job in banned_list))
|
||||
notbannedlist += job
|
||||
|
||||
for(var/job in notbannedlist)
|
||||
@@ -773,11 +774,13 @@
|
||||
for(var/job in notbannedlist)
|
||||
log_admin("[key_name(usr)] temp-jobbanned [key_name(M)] from [job] for [mins] minutes")
|
||||
DB_ban_record(BANTYPE_JOB_TEMP, M, mins, reason, job)
|
||||
jobban_fullban(M, job, "[reason]; By [usr.ckey] on [time2text(world.realtime)]") //Legacy banning does not support temporary jobbans.
|
||||
if(!msg)
|
||||
msg = job
|
||||
else
|
||||
msg += ", [job]"
|
||||
|
||||
// Reload their job ban holder (refresh this round)
|
||||
M.client.jbh.reload_jobbans(M.client)
|
||||
add_note(M.ckey, "Banned from [msg] - [reason]", null, usr.ckey, 0)
|
||||
message_admins("<span class='notice'>[key_name_admin(usr)] banned [key_name_admin(M)] from [msg] for [mins] minutes</span>", 1)
|
||||
to_chat(M, "<span class='warning'><big><b>You have been jobbanned by [usr.client.ckey] from: [msg].</b></big></span>")
|
||||
@@ -793,9 +796,13 @@
|
||||
for(var/job in notbannedlist)
|
||||
log_admin("[key_name(usr)] perma-banned [key_name(M)] from [job]")
|
||||
DB_ban_record(BANTYPE_JOB_PERMA, M, -1, reason, job)
|
||||
jobban_fullban(M, job, "[reason]; By [usr.ckey] on [time2text(world.realtime)]")
|
||||
if(!msg) msg = job
|
||||
else msg += ", [job]"
|
||||
if(!msg)
|
||||
msg = job
|
||||
else
|
||||
msg += ", [job]"
|
||||
|
||||
// Reload their job ban holder (refresh this round)
|
||||
M.client.jbh.reload_jobbans(M.client)
|
||||
add_note(M.ckey, "Banned from [msg] - [reason]", null, usr.ckey, 0)
|
||||
message_admins("<span class='notice'>[key_name_admin(usr)] banned [key_name_admin(M)] from [msg]</span>", 1)
|
||||
to_chat(M, "<span class='warning'><big><b>You have been jobbanned by [usr.client.ckey] from: [msg].</b></big></span>")
|
||||
@@ -883,21 +890,6 @@
|
||||
usr << browse(edit_log,"window=noteedits")
|
||||
qdel(query_noteedits)
|
||||
|
||||
else if(href_list["removejobban"])
|
||||
if(!check_rights(R_BAN)) return
|
||||
|
||||
var/t = href_list["removejobban"]
|
||||
if(t)
|
||||
if((alert("Do you want to unjobban [t]?","Unjobban confirmation", "Yes", "No") == "Yes") && t) //No more misclicks! Unless you do it twice.
|
||||
log_admin("[key_name(usr)] removed [t]")
|
||||
message_admins("<span class='notice'>[key_name_admin(usr)] removed [t]</span>", 1)
|
||||
jobban_remove(t)
|
||||
href_list["ban"] = 1 // lets it fall through and refresh
|
||||
var/t_split = splittext(t, " - ")
|
||||
var/key = t_split[1]
|
||||
var/job = t_split[2]
|
||||
DB_ban_unban(ckey(key), BANTYPE_JOB_PERMA, job)
|
||||
|
||||
else if(href_list["newban"])
|
||||
if(!check_rights(R_BAN)) return
|
||||
|
||||
|
||||
@@ -119,42 +119,6 @@
|
||||
load_admins(run_async=TRUE)
|
||||
SSblackbox.record_feedback("tally", "admin_verb", 1, "Reload Admins") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
|
||||
|
||||
|
||||
/client/proc/print_jobban_old()
|
||||
set name = "Print Jobban Log"
|
||||
set desc = "This spams all the active jobban entries for the current round to standard output."
|
||||
set category = "Debug"
|
||||
|
||||
if(!check_rights(R_DEBUG))
|
||||
return
|
||||
|
||||
to_chat(usr, "<b>Jobbans active in this round.</b>")
|
||||
for(var/t in GLOB.jobban_keylist)
|
||||
to_chat(usr, "[t]")
|
||||
|
||||
message_admins("[key_name_admin(usr)] has printed the jobban log")
|
||||
log_admin("[key_name(usr)] has printed the jobban log")
|
||||
|
||||
/client/proc/print_jobban_old_filter()
|
||||
set name = "Search Jobban Log"
|
||||
set desc = "This searches all the active jobban entries for the current round and outputs the results to standard output."
|
||||
set category = "Debug"
|
||||
|
||||
if(!check_rights(R_DEBUG))
|
||||
return
|
||||
|
||||
var/filter = clean_input("Contains what?","Filter")
|
||||
if(!filter)
|
||||
return
|
||||
|
||||
to_chat(usr, "<b>Jobbans active in this round.</b>")
|
||||
for(var/t in GLOB.jobban_keylist)
|
||||
if(findtext(t, filter))
|
||||
to_chat(usr, "[t]")
|
||||
|
||||
message_admins("[key_name_admin(usr)] has searched the jobban log for [filter]")
|
||||
log_admin("[key_name(usr)] has searched the jobban log for [filter]")
|
||||
|
||||
/client/proc/vv_by_ref()
|
||||
set name = "VV by Ref"
|
||||
set desc = "Give this a ref string, and you will see its corresponding VV panel if it exists"
|
||||
|
||||
@@ -14,8 +14,6 @@ GLOBAL_LIST_INIT(admin_verbs_show_debug_verbs, list(
|
||||
/client/proc/cmd_admin_areatest,
|
||||
/client/proc/cmd_admin_rejuvenate,
|
||||
/datum/admins/proc/show_traitor_panel,
|
||||
/client/proc/print_jobban_old,
|
||||
/client/proc/print_jobban_old_filter,
|
||||
/client/proc/forceEvent,
|
||||
/client/proc/admin_redo_space_transitions,
|
||||
/client/proc/make_turf_space_map,
|
||||
|
||||
Reference in New Issue
Block a user