From 86a68cb55b918bf9d7e6b732ca3f6d08056a195a Mon Sep 17 00:00:00 2001 From: errorage Date: Mon, 22 Jul 2013 19:22:47 +0200 Subject: [PATCH 1/2] - Expands the maximum number of admin permission flags you can have from 16 to 31. To test: add these debug lines somewhere: //START COPY PASTE mob/verb/give_allrights() src.client.holder.rights = 393087 mob/verb/hasright() var/hi = input(src,"Choose a file to access:","Download",null) as null|num var/r = check_rights(hi, 1); world << "[r]" mob/verb/checkrights() for(var/i = 0; i < 32; i++) var/n = 1 << i var/r = check_rights(n , 1); world << "has right 2^[i] = [n]? [r]" //END COPY PASTE Start the game, run 'give allrights', which doesn't give all rights, but some of the rights. 128 and 131072 are missing. Then you can either run 'hasright' to check whether you have the permissions that correspond to a user defined number, or you can run 'checkrights' to check for all 31 theoretical permissions. --- code/__DEFINES.dm | 7 ++- code/__HELPERS/type2type.dm | 22 ++++++--- code/controllers/voting.dm | 2 +- code/datums/mind.dm | 4 +- code/game/verbs/ooc.dm | 6 +-- code/modules/admin/admin_ranks.dm | 6 ++- code/modules/admin/holder2.dm | 45 ++++++++++++------- .../admin/permissionverbs/permissionedit.dm | 6 +-- code/modules/admin/topic.dm | 2 +- code/modules/client/preferences.dm | 8 ++-- 10 files changed, 67 insertions(+), 41 deletions(-) diff --git a/code/__DEFINES.dm b/code/__DEFINES.dm index 399f4ade816..708c1164340 100644 --- a/code/__DEFINES.dm +++ b/code/__DEFINES.dm @@ -389,7 +389,10 @@ var/list/TAGGERLOCATIONS = list("Disposals", #define R_MAXPERMISSION 4096 //This holds the maximum value for a permission. It is used in iteration, so keep it updated. -#define R_HOST 65535 + +//IMPORTANT! The permissions system supports flags up to 2^30 (possibly 2^31), HOWEVER, once the flag 65536 +//starts being used, an edit to rights2text(rights, seperator="") needs to happen! The edit is prepared +//and commented out. Please uncomment it before assigning that flag. Once you do, delete this note. ~Errorage //Preference toggles #define SOUND_ADMINHELP 1 @@ -467,4 +470,4 @@ var/list/be_special_flags = list( #define TR_KEEPIMPLANTS 16 #define TR_KEEPSE 32 // changelings shouldn't edit the DNA's SE when turning into a monkey #define TR_DEFAULTMSG 64 -#define TR_KEEPSRC 128 +#define TR_KEEPSRC 128 diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm index 21dc90509a4..b894092185f 100644 --- a/code/__HELPERS/type2type.dm +++ b/code/__HELPERS/type2type.dm @@ -223,7 +223,15 @@ proc/tg_list2text(list/list, glue=",") //Converts a rights bitfield into a string -/proc/rights2text(rights,seperator="") +/proc/rights2text(rights, seperator="") + /* --UNCOMMENT ONCE PERMISSIONS ABOVE 2^15 START BEING USED! + if(rights >= 65536) + var/rights_pt2 = rights - 65536 + if(rights_pt2 & 1) .+= "[seperator]+NUKESERVER" + if(rights_pt2 & 2) .+= "[seperator]+DDOSALLPLAYERS" + if(rights_pt2 & 4) .+= "[seperator]+SPAWN_RL_SINGULARITY" + */ + if(rights & R_BUILDMODE) . += "[seperator]+BUILDMODE" if(rights & R_ADMIN) . += "[seperator]+ADMIN" if(rights & R_BAN) . += "[seperator]+BAN" @@ -251,23 +259,23 @@ proc/tg_list2text(list/list, glue=",") var/max = max(red,green,blue) var/min = min(red,green,blue) var/range = max-min - + var/hue=0;var/saturation=0;var/lightness=0; lightness = (max + min)/2 if(range != 0) if(lightness < 0.5) saturation = range/(max+min) else saturation = range/(2-max-min) - + var/dred = ((max-red)/(6*max)) + 0.5 var/dgreen = ((max-green)/(6*max)) + 0.5 var/dblue = ((max-blue)/(6*max)) + 0.5 - + if(max==red) hue = dblue - dgreen else if(max==green) hue = dred - dblue + (1/3) else hue = dgreen - dred + (2/3) if(hue < 0) hue++ else if(hue > 1) hue-- - + return list(hue, saturation, lightness) /proc/hsl2rgb(hue, saturation, lightness) @@ -281,11 +289,11 @@ proc/tg_list2text(list/list, glue=",") if(lightness < 0.5) b = lightness*(1+saturation) else b = (lightness+saturation) - (saturation*lightness) a = 2*lightness - b - + red = round(255 * hue2rgb(a, b, hue+(1/3))) green = round(255 * hue2rgb(a, b, hue)) blue = round(255 * hue2rgb(a, b, hue-(1/3))) - + return list(red, green, blue) /proc/hue2rgb(a, b, hue) diff --git a/code/controllers/voting.dm b/code/controllers/voting.dm index 344134e6710..0b792a2232a 100644 --- a/code/controllers/voting.dm +++ b/code/controllers/voting.dm @@ -172,7 +172,7 @@ datum/controller/vote var/trialmin = 0 if(C.holder) admin = 1 - if(C.holder.rights & R_ADMIN) + if(check_rights_for(C, R_ADMIN)) trialmin = 1 voting |= C diff --git a/code/datums/mind.dm b/code/datums/mind.dm index c271a972378..902cc4ddb44 100644 --- a/code/datums/mind.dm +++ b/code/datums/mind.dm @@ -313,7 +313,7 @@ datum/mind crystals = suplink.uses if (suplink) text += "|take" - if (usr.client.holder.rights & R_FUN) + if (check_rights(R_FUN, 0)) text += ", [crystals] crystals" else text += ", [crystals] crystals" @@ -903,7 +903,7 @@ datum/mind memory = null//Remove any memory they may have had. log_admin("[key_name_admin(usr)] removed [current]'s uplink.") if("crystals") - if (usr.client.holder.rights & R_FUN) + if (check_rights(R_FUN, 0)) var/obj/item/device/uplink/hidden/suplink = find_syndicate_uplink() var/crystals if (suplink) diff --git a/code/game/verbs/ooc.dm b/code/game/verbs/ooc.dm index 7ebf272cf4d..51c297fb101 100644 --- a/code/game/verbs/ooc.dm +++ b/code/game/verbs/ooc.dm @@ -37,7 +37,7 @@ return log_ooc("[mob.name]/[key] : [msg]") - + var/keyname = key if(prefs.unlock_content) if(prefs.toggles & MEMBER_PUBLIC) @@ -47,7 +47,7 @@ if(C.prefs.toggles & CHAT_OOC) if(holder) if(!holder.fakekey || C.holder) - if(holder.rights & R_ADMIN) + if(check_rights_for(src, R_ADMIN)) C << "OOC: [keyname][holder.fakekey ? "/([holder.fakekey])" : ""]: [msg]" else C << "OOC: [keyname][holder.fakekey ? "/([holder.fakekey])" : ""]: [msg]" @@ -68,7 +68,7 @@ var/global/normal_ooc_colour = "#002eb8" set name = "OOC Text Color" set category = "Preferences" - if(!holder || !(holder.rights & R_ADMIN)) + if(!holder || check_rights_for(src, R_ADMIN)) if(!is_content_unlocked()) return var/new_ooccolor = input(src, "Please select your OOC colour.", "OOC colour") as color|null diff --git a/code/modules/admin/admin_ranks.dm b/code/modules/admin/admin_ranks.dm index 091274814c3..0f02fe9cdb3 100644 --- a/code/modules/admin/admin_ranks.dm +++ b/code/modules/admin/admin_ranks.dm @@ -37,10 +37,14 @@ var/list/admin_ranks = list() //list of all ranks with associated rights if("stealth") rights |= R_STEALTH if("rejuv","rejuvinate") rights |= R_REJUVINATE if("varedit") rights |= R_VAREDIT - if("everything","host","all") rights |= R_HOST + if("everything","host","all") rights |= ((2 * R_MAXPERMISSION) - 1) if("sound","sounds") rights |= R_SOUNDS if("spawn","create") rights |= R_SPAWN + /* --ONCE FLAGS LARGER OR EQUAL THAN 2^16 = 65536 START BEING USED, USE THIS CODE! + if("nukeeverything") rights += R_NUKEEVERYTHING + */ + admin_ranks[rank] = rights previous_rights = rights diff --git a/code/modules/admin/holder2.dm b/code/modules/admin/holder2.dm index 832df48ee11..00c77eb7d78 100644 --- a/code/modules/admin/holder2.dm +++ b/code/modules/admin/holder2.dm @@ -52,19 +52,11 @@ you will have to do something like if(client.rights & R_ADMIN) yourself. */ /proc/check_rights(rights_required, show_msg=1) if(usr && usr.client) - if(rights_required) - if(usr.client.holder) - if(rights_required & usr.client.holder.rights) - return 1 - else - if(show_msg) - usr << "Error: You do not have sufficient rights to do that. You require one of the following flags:[rights2text(rights_required," ")]." + if (check_rights_for(usr.client, rights_required)) + return 1 else - if(usr.client.holder) - return 1 - else - if(show_msg) - usr << "Error: You are not an admin." + if(show_msg) + usr << "Error: You do not have sufficient rights to do that. You require one of the following flags:[rights2text(rights_required," ")]." return 0 //probably a bit iffy - will hopefully figure out a better solution @@ -73,9 +65,13 @@ you will have to do something like if(client.rights & R_ADMIN) yourself. if(usr.client.holder) if(!other || !other.holder) return 1 - if(usr.client.holder.rights != other.holder.rights) - if( (usr.client.holder.rights & other.holder.rights) == other.holder.rights ) - return 1 //we have all the rights they have and more + + var/usr_rights_pt2 = usr.client.holder.rights / 65536 + var/other_rights_pt2 = other.holder.rights / 65536 + if( (usr_rights_pt2 & other_rights_pt2) == other_rights_pt2 ) //Check values larger than 65535 + if(usr.client.holder.rights != other.holder.rights) //Check values smaller than 65536 + if( (usr.client.holder.rights & other.holder.rights) == other.holder.rights ) + return 1 //we have all the rights they have and more usr << "Error: Cannot proceed. They have more or equal rights to us." return 0 @@ -85,4 +81,21 @@ you will have to do something like if(client.rights & R_ADMIN) yourself. if(holder) holder.disassociate() del(holder) - return 1 \ No newline at end of file + return 1 + +//This proc checks whether subject has at least ONE of the rights specified in rights_required. +/proc/check_rights_for(client/subject, rights_required) + if(subject) + if(rights_required) + if(subject.holder) + if(rights_required >= 65536) + var/rights_required_pt2 = rights_required / 65536 + var/rights_pt2 = subject.holder.rights / 65536 + if(rights_required_pt2 & rights_pt2) + return 1 + if(rights_required & subject.holder.rights) + return 1 + else + if(subject.holder) + return 1 + return 0 \ No newline at end of file diff --git a/code/modules/admin/permissionverbs/permissionedit.dm b/code/modules/admin/permissionverbs/permissionedit.dm index 3bd563aaf58..26d1c8b88cf 100644 --- a/code/modules/admin/permissionverbs/permissionedit.dm +++ b/code/modules/admin/permissionverbs/permissionedit.dm @@ -50,8 +50,7 @@ if(!usr.client) return - if(!usr.client.holder || !(usr.client.holder.rights & R_PERMISSIONS)) - usr << "\red You do not have permission to do this!" + if (!check_rights(R_PERMISSIONS)) return establish_db_connection() @@ -100,8 +99,7 @@ if(!usr.client) return - if(!usr.client.holder || !(usr.client.holder.rights & R_PERMISSIONS)) - usr << "\red You do not have permission to do this!" + if (check_rights(R_PERMISSIONS)) return establish_db_connection() diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 3857d538d8f..df13f57172b 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -700,7 +700,7 @@ return if(M != usr) //we can jobban ourselves - if(M.client && M.client.holder && (M.client.holder.rights & R_BAN)) //they can ban too. So we can't ban them + if (check_rights_for(M, R_BAN)) //they can ban too. So we can't ban them alert("You cannot perform this action. You must be of a higher administrative rank!") return diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index cab7dd9c4ae..10898cad663 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -77,7 +77,7 @@ datum/preferences // OOC Metadata: var/metadata = "" - + var/unlock_content = 0 /datum/preferences/New(client/C) @@ -210,13 +210,13 @@ datum/preferences dat += "Adminhelp Sound: " dat += "[(toggles & SOUND_ADMINHELP)?"On":"Off"]
" - if(unlock_content || (user.client.holder && (user.client.holder.rights & R_ADMIN))) + if(unlock_content || check_rights_for(user, R_ADMIN)) dat += "OOC:     Change
" - + if(unlock_content) dat += "BYOND Membership Publicity: [(toggles & MEMBER_PUBLIC) ? "Public" : "Hidden"]
" dat += "Ghost Form: [ghost_form]
" - + dat += "" From 3307e0b01ff7ac0248f596a4423e9205cc650e17 Mon Sep 17 00:00:00 2001 From: errorage Date: Tue, 23 Jul 2013 04:35:03 +0200 Subject: [PATCH 2/2] - small bugfix. rights2text() will now work properly for values larger or equal to 65536. --- code/__HELPERS/type2type.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm index b894092185f..6d60ca502ef 100644 --- a/code/__HELPERS/type2type.dm +++ b/code/__HELPERS/type2type.dm @@ -226,7 +226,7 @@ proc/tg_list2text(list/list, glue=",") /proc/rights2text(rights, seperator="") /* --UNCOMMENT ONCE PERMISSIONS ABOVE 2^15 START BEING USED! if(rights >= 65536) - var/rights_pt2 = rights - 65536 + var/rights_pt2 = rights / 65536 if(rights_pt2 & 1) .+= "[seperator]+NUKESERVER" if(rights_pt2 & 2) .+= "[seperator]+DDOSALLPLAYERS" if(rights_pt2 & 4) .+= "[seperator]+SPAWN_RL_SINGULARITY"