diff --git a/code/__DEFINES.dm b/code/__DEFINES.dm index 3c076d306ca..b5f7a43b1c3 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 diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm index 21dc90509a4..6d60ca502ef 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 6aeb278db91..bce844da53c 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" @@ -900,7 +900,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 14a450937db..188eb303330 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -210,7 +210,7 @@ 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)