[MIRROR] Make req_[one_]access lazy

This commit is contained in:
Chompstation Bot
2021-06-14 17:35:25 +00:00
parent 7e0da20bae
commit b9a1195de7
3 changed files with 17 additions and 22 deletions

View File

@@ -39,7 +39,7 @@
#define LAZYACCESSASSOC(L, I, K) L ? L[I] ? L[I][K] ? L[I][K] : null : null : null
// Null-safe L.Cut()
#define LAZYCLEARLIST(L) if(L) L.Cut()
#define LAZYCLEARLIST(L) if(L) { L.Cut(); L = null; }
// Reads L or an empty list if L is not a list. Note: Does NOT assign, L may be an expression.
#define SANITIZE_LIST(L) ( islist(L) ? L : list() )

View File

@@ -205,13 +205,19 @@ SUBSYSTEM_DEF(supply)
else if(islist(SP.access) && SP.one_access)
var/list/L = SP.access // access var is a plain var, we need a list
A.req_one_access = L.Copy()
<<<<<<< HEAD
if(A.req_access) //Chompstation Edit (TODO: Figure out why the fuck this works for others but not us)
A.req_access.Cut() //Chompstation Edit
A.req_access = null
||||||| parent of 8973063282... Merge pull request #10640 from VOREStation/upstream-merge-8122
A.req_access = null
=======
LAZYCLEARLIST(A.req_access)
>>>>>>> 8973063282... Merge pull request #10640 from VOREStation/upstream-merge-8122
else if(islist(SP.access) && !SP.one_access)
var/list/L = SP.access
A.req_access = L.Copy()
A.req_one_access = null
LAZYCLEARLIST(A.req_one_access)
else
log_debug("<span class='danger'>Supply pack with invalid access restriction [SP.access] encountered!</span>")

View File

@@ -28,32 +28,21 @@
return has_access(req_access, req_one_access, L)
/proc/has_access(var/list/req_access, var/list/req_one_access, var/list/accesses)
// Doesn't have access lists, always works
if(!LAZYLEN(req_access) && !LAZYLEN(req_one_access))
return TRUE
// Didn't pass anything to compare
if(!LAZYLEN(accesses))
return FALSE
// req_access list has priority if set
// Requires at least every access in list
if(LAZYLEN(req_access))
for(var/req in req_access)
if(!(req in accesses))
return FALSE
// Wasn't missing any accesses
return TRUE
for(var/req in req_access)
if(!(req in accesses))
return FALSE
// req_one_access is secondary if set
// Requires at least one access in list
for(var/req in req_one_access)
if(req in accesses)
// Found at least one
return TRUE
if(LAZYLEN(req_one_access))
for(var/req in req_one_access)
if(req in accesses)
return TRUE
return FALSE
// Didn't find anything that matched
return FALSE
return TRUE
/proc/get_centcom_access(job)
switch(job)