Adds config to allow ranks only from txt

This commit is contained in:
Jordan Brown
2018-03-28 14:01:50 -04:00
committed by CitadelStationBot
parent 77f40b6be9
commit 4629039c38
5 changed files with 54 additions and 24 deletions

View File

@@ -504,7 +504,7 @@
/datum/controller/subsystem/ticker/proc/save_admin_data() /datum/controller/subsystem/ticker/proc/save_admin_data()
if(CONFIG_GET(flag/admin_legacy_system)) //we're already using legacy system so there's nothing to save if(CONFIG_GET(flag/admin_legacy_system)) //we're already using legacy system so there's nothing to save
return return
else if(load_admins()) //returns true if there was a database failure and the backup was loaded from else if(load_admins(TRUE)) //returns true if there was a database failure and the backup was loaded from
return return
var/datum/DBQuery/query_admin_rank_update = SSdbcore.NewQuery("UPDATE [format_table_name("player")] p INNER JOIN [format_table_name("admin")] a ON p.ckey = a.ckey SET p.lastadminrank = a.rank") var/datum/DBQuery/query_admin_rank_update = SSdbcore.NewQuery("UPDATE [format_table_name("player")] p INNER JOIN [format_table_name("admin")] a ON p.ckey = a.ckey SET p.lastadminrank = a.rank")
query_admin_rank_update.Execute() query_admin_rank_update.Execute()

View File

@@ -129,6 +129,9 @@
/datum/config_entry/flag/enable_localhost_rank //Gives the !localhost! rank to any client connecting from 127.0.0.1 or ::1 /datum/config_entry/flag/enable_localhost_rank //Gives the !localhost! rank to any client connecting from 127.0.0.1 or ::1
protection = CONFIG_ENTRY_LOCKED protection = CONFIG_ENTRY_LOCKED
/datum/config_entry/flag/load_legacy_ranks_only //Loads admin ranks only from legacy admin_ranks.txt, while enabled ranks are mirrored to the database
protection = CONFIG_ENTRY_LOCKED
/datum/config_entry/string/hostedby /datum/config_entry/string/hostedby
/datum/config_entry/flag/norespawn /datum/config_entry/flag/norespawn

View File

@@ -113,7 +113,7 @@ GLOBAL_PROTECT(protected_ranks)
return ((rank.rights & flag) == flag) //true only if right has everything in flag return ((rank.rights & flag) == flag) //true only if right has everything in flag
//load our rank - > rights associations //load our rank - > rights associations
/proc/load_admin_ranks(dbfail) /proc/load_admin_ranks(dbfail, no_update)
if(IsAdminAdvancedProcCall()) if(IsAdminAdvancedProcCall())
to_chat(usr, "<span class='admin prefix'>Admin Reload blocked: Advanced ProcCall detected.</span>") to_chat(usr, "<span class='admin prefix'>Admin Reload blocked: Advanced ProcCall detected.</span>")
return return
@@ -137,27 +137,38 @@ GLOBAL_PROTECT(protected_ranks)
prev = next prev = next
previous_rights = R.rights previous_rights = R.rights
if(!CONFIG_GET(flag/admin_legacy_system) || dbfail) if(!CONFIG_GET(flag/admin_legacy_system) || dbfail)
var/datum/DBQuery/query_load_admin_ranks = SSdbcore.NewQuery("SELECT rank, flags, exclude_flags, can_edit_flags FROM [format_table_name("admin_ranks")]") if(CONFIG_GET(flag/load_legacy_ranks_only))
if(!query_load_admin_ranks.Execute()) if(!no_update)
message_admins("Error loading admin ranks from database. Loading from backup.") var/list/sql_ranks = list()
log_sql("Error loading admin ranks from database. Loading from backup.")
dbfail = 1
else
while(query_load_admin_ranks.NextRow())
var/skip
var/rank_name = query_load_admin_ranks.item[1]
for(var/datum/admin_rank/R in GLOB.admin_ranks) for(var/datum/admin_rank/R in GLOB.admin_ranks)
if(R.name == rank_name) //this rank was already loaded from txt override var/sql_rank = sanitizeSQL(R.name)
skip = 1 var/sql_flags = sanitizeSQL(R.include_rights)
break var/sql_exclude_flags = sanitizeSQL(R.exclude_rights)
if(!skip) var/sql_can_edit_flags = sanitizeSQL(R.can_edit_rights)
var/rank_flags = text2num(query_load_admin_ranks.item[2]) sql_ranks += list(list("rank" = "'[sql_rank]'", "flags" = "[sql_flags]", "exclude_flags" = "[sql_exclude_flags]", "can_edit_flags" = "[sql_can_edit_flags]"))
var/rank_exclude_flags = text2num(query_load_admin_ranks.item[3]) SSdbcore.MassInsert(format_table_name("admin_ranks"), sql_ranks, duplicate_key = TRUE)
var/rank_can_edit_flags = text2num(query_load_admin_ranks.item[4]) else
var/datum/admin_rank/R = new(rank_name, rank_flags, rank_exclude_flags, rank_can_edit_flags) var/datum/DBQuery/query_load_admin_ranks = SSdbcore.NewQuery("SELECT rank, flags, exclude_flags, can_edit_flags FROM [format_table_name("admin_ranks")]")
if(!R) if(!query_load_admin_ranks.Execute())
continue message_admins("Error loading admin ranks from database. Loading from backup.")
GLOB.admin_ranks += R log_sql("Error loading admin ranks from database. Loading from backup.")
dbfail = 1
else
while(query_load_admin_ranks.NextRow())
var/skip
var/rank_name = query_load_admin_ranks.item[1]
for(var/datum/admin_rank/R in GLOB.admin_ranks)
if(R.name == rank_name) //this rank was already loaded from txt override
skip = 1
break
if(!skip)
var/rank_flags = text2num(query_load_admin_ranks.item[2])
var/rank_exclude_flags = text2num(query_load_admin_ranks.item[3])
var/rank_can_edit_flags = text2num(query_load_admin_ranks.item[4])
var/datum/admin_rank/R = new(rank_name, rank_flags, rank_exclude_flags, rank_can_edit_flags)
if(!R)
continue
GLOB.admin_ranks += R
//load ranks from backup file //load ranks from backup file
if(dbfail) if(dbfail)
var/backup_file = file("data/admins_backup.json") var/backup_file = file("data/admins_backup.json")
@@ -184,7 +195,7 @@ GLOBAL_PROTECT(protected_ranks)
testing(msg) testing(msg)
#endif #endif
/proc/load_admins() /proc/load_admins(no_update)
var/dbfail var/dbfail
if(!CONFIG_GET(flag/admin_legacy_system) && !SSdbcore.Connect()) if(!CONFIG_GET(flag/admin_legacy_system) && !SSdbcore.Connect())
message_admins("Failed to connect to database while loading admins. Loading from backup.") message_admins("Failed to connect to database while loading admins. Loading from backup.")
@@ -198,7 +209,7 @@ GLOBAL_PROTECT(protected_ranks)
GLOB.admins.Cut() GLOB.admins.Cut()
GLOB.protected_admins.Cut() GLOB.protected_admins.Cut()
GLOB.deadmins.Cut() GLOB.deadmins.Cut()
dbfail = load_admin_ranks(dbfail) dbfail = load_admin_ranks(dbfail, no_update)
//Clear profile access //Clear profile access
for(var/A in world.GetConfig("admin")) for(var/A in world.GetConfig("admin"))
world.SetConfig("APP/admin", A, null) world.SetConfig("APP/admin", A, null)

View File

@@ -82,6 +82,10 @@
if(D.rank in GLOB.protected_ranks) if(D.rank in GLOB.protected_ranks)
to_chat(usr, "<span class='admin prefix'>Editing the flags of this rank is blocked by server configuration.</span>") to_chat(usr, "<span class='admin prefix'>Editing the flags of this rank is blocked by server configuration.</span>")
return return
if(CONFIG_GET(flag/load_legacy_ranks_only) && (task == "rank" || task == "permissions"))
to_chat(usr, "<span class='admin prefix'>Database rank loading is disabled, only temporary changes can be made to an admin's rank or permissions.</span>")
use_db = FALSE
skip = TRUE
if(check_rights(R_DBRANKS, FALSE)) if(check_rights(R_DBRANKS, FALSE))
if(!skip) if(!skip)
if(!SSdbcore.Connect()) if(!SSdbcore.Connect())

View File

@@ -35,6 +35,7 @@ ROUND_END_COUNTDOWN 90
## This flag is automatically enabled if SQL_ENABLED isn't ## This flag is automatically enabled if SQL_ENABLED isn't
ADMIN_LEGACY_SYSTEM ADMIN_LEGACY_SYSTEM
<<<<<<< HEAD
## Comment this out if you want to use the SQL based mentor system, the legacy system uses mentors.txt. ## Comment this out if you want to use the SQL based mentor system, the legacy system uses mentors.txt.
## You need to set up your database to use the SQL based system. ## You need to set up your database to use the SQL based system.
## This flag is automatically enabled if SQL_ENABLED isn't ## This flag is automatically enabled if SQL_ENABLED isn't
@@ -42,6 +43,17 @@ MENTOR_LEGACY_SYSTEM
#Mentors only see ckeys by default. Uncomment to have them only see mob name #Mentors only see ckeys by default. Uncomment to have them only see mob name
#MENTORS_MOBNAME_ONLY #MENTORS_MOBNAME_ONLY
=======
##Uncomment this to stop any admins loaded by the legacy system from having their rank edited by the permissions panel
#PROTECT_LEGACY_ADMINS
##Uncomment this to stop any ranks loaded by the legacy system from having their flags edited by the permissions panel
#PROTECT_LEGACY_RANKS
>>>>>>> feb9290... Merge pull request #36554 from Jordie0608/tbhthisisntreallyalegacysystemanymore
##Uncomment this to have admin ranks only loaded from the legacy admin_ranks.txt
##If enabled, each time admins are loaded ranks the database will be updated with the current ranks and their flags
#LOAD_LEGACY_RANKS_ONLY
## Comment this out if you want to use the SQL based banning system. The legacy systems use the files in the data folder. You need to set up your database to use the SQL based system. ## Comment this out if you want to use the SQL based banning system. The legacy systems use the files in the data folder. You need to set up your database to use the SQL based system.
BAN_LEGACY_SYSTEM BAN_LEGACY_SYSTEM