Production topic restrictions rework

- Production access checks now use the `allowed` proc before attempting normal ID checks.
- Each successful return case now uses a unique DEFINE to allow future control over access types.
- Topic checks use a separate function
- Feedback messages have been moved out of the access check procs
This commit is contained in:
Darius
2023-03-07 20:51:05 -05:00
parent 720b4be2c1
commit f30815b889
4 changed files with 62 additions and 29 deletions

View File

@@ -0,0 +1,6 @@
// Returns used by production machinery
// Based on access type that passed the check
#define PROTOLOCK_ACCESS_NORMAL 1
#define PROTOLOCK_ACCESS_LOWPOP 2
#define PROTOLOCK_ACCESS_CAPTAIN 3
#define PROTOLOCK_ACCESS_MINERAL 4

View File

@@ -33,51 +33,68 @@
// This is intended for low populations
if((!PROTOLOCK_DURING_LOWPOP) && (!JOB_MINIMAL_ACCESS))
// Allow unrestricted use
return TRUE
return PROTOLOCK_ACCESS_LOWPOP
// Define machine user
var/mob/living/carbon/human/machine_user = src
// Check if user exists
if(!istype(machine_user))
return TRUE
// Check if user has access to this machine
if(machine_target.allowed(src))
return PROTOLOCK_ACCESS_NORMAL
// Define user ID card
var/obj/item/card/id/user_id = machine_user.get_idcard()
var/obj/item/card/id/user_id = get_idcard()
// Check if ID card was found
if(!istype(user_id))
// Warn in local chat, then return
machine_target.say("Access denied: Unable to scan user ID card.")
return FALSE
// Check for Captain
if(ACCESS_CAPTAIN in user_id.access)
// Allow usage
return TRUE
return PROTOLOCK_ACCESS_CAPTAIN
// Check if access requirements are met
if(machine_target.check_access(user_id))
// Allow use
return TRUE
// User does not have normal access
// Check for ORM access
if(ACCESS_MINERAL_STOREROOM in user_id.access)
// Check if already on material screen
if(machine_target.screen != RESEARCH_FABRICATOR_SCREEN_MATERIALS)
// Warn in local chat
machine_target.say("Access limited: Configuring for ORM remote control mode.")
// Set to material screen
machine_target.screen = RESEARCH_FABRICATOR_SCREEN_MATERIALS
// Allow use
return TRUE
return PROTOLOCK_ACCESS_MINERAL
// User has no access
// Warn in local chat, then return
machine_target.say("Access denied: No valid departmental or mineral credentials detected.")
return FALSE
/mob/proc/can_use_production_topic(obj/machinery/rnd/production/machine_target, raw, ls)
// Basic actions that are always permitted
// This includes syncing research and switching screens
if(ls["sync_research"] || ls["switch_screen"])
return TRUE
// Define user's access type
var/user_access = usr.can_use_production(machine_target)
// Switch result based on access type
// This currently doesn't do anything special
switch(user_access)
// Type: Low population
if(PROTOLOCK_ACCESS_LOWPOP)
return TRUE
// Type: Standard
if(PROTOLOCK_ACCESS_NORMAL)
return TRUE
// Type: Captain
if(PROTOLOCK_ACCESS_CAPTAIN)
return TRUE
// Type: Mineral / ORM
if(PROTOLOCK_ACCESS_MINERAL)
// Check if permitted topic
if(ls["ejectsheet"])
return TRUE
// Topic prohibited
// Deny usage
else
return FALSE
// Default to false
return FALSE
#undef JOB_MINIMAL_ACCESS

View File

@@ -11,6 +11,8 @@
// Check if user can use machine
if(!user.can_use_production(src))
// Warn in local chat and return
say("Access denied: No valid departmental or mineral credentials detected.")
return
// Return normally
@@ -22,7 +24,14 @@
return ..()
// Check if user can use machine
if(!usr.can_use_production(src))
if(!usr.can_use_production_topic(src, raw, ls))
// Alert in local chat
usr.visible_message(span_warning("[usr] pushes a button on [src], causing it to chime with the familiar sound of rejection."), span_warning("The machine buzzes with a soft chime. It seems you don't have access to that button."))
// Play sound
playsound(loc, 'sound/machines/uplinkerror.ogg', 70, 0)
// Return
return
// Return normally

View File

@@ -235,6 +235,7 @@
#include "code\__HELPERS\sorts\InsertSort.dm"
#include "code\__HELPERS\sorts\MergeSort.dm"
#include "code\__HELPERS\sorts\TimSort.dm"
#include "code\__SANDCODE\DEFINES\access.dm"
#include "code\__SANDCODE\DEFINES\chat.dm"
#include "code\__SANDCODE\DEFINES\DNA.dm"
#include "code\__SANDCODE\DEFINES\keybindings.dm"