Skip to content

Commit

Permalink
Fix mentor deadminning and admin loading (BeeStation#10426)
Browse files Browse the repository at this point in the history
* Fix mentor deadminning and admin loading

* Fix admin-mentors not keeping their verbs after deadminning
  • Loading branch information
itsmeow authored and DrDuckedGoose committed May 11, 2024
1 parent 8b70b36 commit c3f9605
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
46 changes: 25 additions & 21 deletions code/modules/admin/holder2.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ GLOBAL_PROTECT(href_token)
deadmined = FALSE
if (GLOB.directory[target])
associate(GLOB.directory[target]) //find the client for a ckey if they are connected and associate them with us
load_mentors()

/datum/admins/proc/deactivate()
if(IsAdminAdvancedProcCall())
Expand All @@ -101,7 +100,6 @@ GLOBAL_PROTECT(href_token)
disassociate()
C.add_verb(/client/proc/readmin)
C.update_special_keybinds()
load_mentors()

/datum/admins/proc/associate(client/C)
if(IsAdminAdvancedProcCall())
Expand All @@ -110,32 +108,38 @@ GLOBAL_PROTECT(href_token)
log_admin("[key_name(usr)][msg]")
return

if(istype(C))
if(C.ckey != target)
var/msg = " has attempted to associate with [target]'s admin datum"
message_admins("[key_name_admin(C)][msg]")
log_admin("[key_name(C)][msg]")
return
if (deadmined)
activate()
owner = C
owner.holder = src
owner.add_admin_verbs() //TODO <--- todo what? the proc clearly exists and works since its the backbone to our entire admin system
owner.remove_verb(/client/proc/readmin)
owner.update_special_keybinds()
GLOB.admins |= C
if(!istype(C))
return
if(C.ckey != target)
var/msg = " has attempted to associate with [target]'s admin datum"
message_admins("[key_name_admin(C)][msg]")
log_admin("[key_name(C)][msg]")
return
if (deadmined)
activate()
owner = C
owner.holder = src
owner.add_admin_verbs() //TODO <--- todo what? the proc clearly exists and works since its the backbone to our entire admin system
owner.remove_verb(/client/proc/readmin)
owner.update_special_keybinds()
GLOB.admins |= C
if(istype(owner.mentor_datum))
owner.mentor_datum.activate()

/datum/admins/proc/disassociate()
if(IsAdminAdvancedProcCall())
var/msg = " has tried to elevate permissions!"
message_admins("[key_name_admin(usr)][msg]")
log_admin("[key_name(usr)][msg]")
return
if(owner)
GLOB.admins -= owner
owner.remove_admin_verbs()
owner.holder = null
owner = null
if(!owner)
return
GLOB.admins -= owner
owner.remove_admin_verbs()
if(istype(owner.mentor_datum))
owner.mentor_datum.deactivate()
owner.holder = null
owner = null

/datum/admins/proc/check_for_rights(rights_required)
if(rights_required && !(rights_required & rank.rights))
Expand Down
38 changes: 36 additions & 2 deletions code/modules/mentor/mentor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
var/href_token
/// The Mentor Ticket Manager interface
var/datum/help_ui/mentor/mentor_interface
/// If this mentor datum is inactive due to de-adminning.
var/dementored = FALSE
/// If this mentor datum was created due to someone being an admin, but not a mentor.
/// This is used so that deadminning doesn't remove verbs if someone is both a mentor and an admin.
var/for_admin = FALSE

/datum/mentors/New(ckey)
/datum/mentors/New(ckey, for_admin)
if(!ckey)
QDEL_IN(src, 0)
stack_trace("Mentor datum created without a ckey: [ckey]")
Expand All @@ -23,6 +28,7 @@
return
name = "[ckey]'s mentor datum"
href_token = GenerateToken()
src.for_admin = for_admin
GLOB.mentor_datums[target] = src
// If they're logged in, let's assign their mentor datum now.
var/client/C = GLOB.directory[ckey]
Expand All @@ -37,7 +43,10 @@
return
owner = C
owner.mentor_datum = src
owner.add_mentor_verbs()
if(for_admin)
activate()
else
owner.add_mentor_verbs()
if(!check_rights_for(owner, R_ADMIN)) // add nonadmins to the mentor list.
GLOB.mentors |= owner

Expand Down Expand Up @@ -77,6 +86,9 @@
log_href_exploit(usr, " Tried to use the mentor panel without having the correct mentor datum.")
return

if(dementored)
return

if(!CheckMentorHREF(href, href_list))
return

Expand All @@ -90,3 +102,25 @@
else if(href_list["mhelp_tickets"])
GLOB.mhelp_tickets.BrowseTickets(usr)


/datum/mentors/proc/activate()
if(!for_admin)
return
if(IsAdminAdvancedProcCall())
var/msg = " has tried to elevate permissions!"
message_admins("[key_name_admin(usr)][msg]")
log_admin("[key_name(usr)][msg]")
return
dementored = FALSE
owner.add_mentor_verbs()

/datum/mentors/proc/deactivate()
if(!for_admin)
return
if(IsAdminAdvancedProcCall())
var/msg = " has tried to elevate permissions!"
message_admins("[key_name_admin(usr)][msg]")
log_admin("[key_name(usr)][msg]")
return
dementored = TRUE
owner.remove_mentor_verbs()
6 changes: 3 additions & 3 deletions code/modules/mentor/mentor_loading.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
continue
if(findtextEx(line, "#", 1, 2))
continue
new /datum/mentors(line)
new /datum/mentors(line, for_admin = FALSE)
return TRUE

/// Loads mentors from the ss13_mentors table
Expand All @@ -51,7 +51,7 @@
if(!ckey)
stack_trace("Invalid mentor row in database with null ckey with id: [id] and raw data: [raw_ckey]")
continue
new /datum/mentors(ckey)
new /datum/mentors(ckey, for_admin = FALSE)
qdel(query_load_mentors)
return TRUE

Expand All @@ -69,6 +69,6 @@
return TRUE
// They're an admin, but not a mentor. Create them a mentor datum. This is automatically assigned.
else if(check_rights_for(src, R_ADMIN))
new /datum/mentors(ckey)
new /datum/mentors(ckey, for_admin = TRUE)
return TRUE
return FALSE

0 comments on commit c3f9605

Please sign in to comment.