From a5b37f81c36acb8c49489e1f9c7c7b58dc249fb8 Mon Sep 17 00:00:00 2001 From: "baloh.matevz" Date: Sat, 13 Oct 2012 22:32:51 +0000 Subject: [PATCH] - Added a config option that allows the admin system to run off of data from the database. There is a config options in config.txt that dictates whether to use the new SQL based system or the legacy admins.txt system. If a server is set to use the new system, but a connection cannot be established to the database, it reverts to the legacy system, same applies if a query to the database returns empty. The config option defaults to use the legacy system. git-svn-id: http://tgstation13.googlecode.com/svn/trunk@4863 316c924e-a436-60f5-8080-3fe189b3f50e --- code/controllers/configuration.dm | 4 ++ code/modules/assembly/signaler.dm | 6 +-- code/world.dm | 65 ++++++++++++++++++++++++------- config/config.txt | 3 ++ 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index cf1613dcd2a..ee557da2413 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -89,6 +89,7 @@ var/metroid_delay = 0 var/animal_delay = 0 + var/admin_legacy_system = 0 //Defines whether the server uses the legacy admin system with admins.txt or the SQL system. /datum/configuration/New() var/list/L = typesof(/datum/game_mode) - /datum/game_mode @@ -145,6 +146,9 @@ if(type == "config") switch (name) + if ("admin_legacy_system") + config.admin_legacy_system = 1 + if ("log_ooc") config.log_ooc = 1 diff --git a/code/modules/assembly/signaler.dm b/code/modules/assembly/signaler.dm index 07e779c048d..4ff38fc751f 100644 --- a/code/modules/assembly/signaler.dm +++ b/code/modules/assembly/signaler.dm @@ -17,10 +17,6 @@ var/airlock_wire = null var/datum/radio_frequency/radio_connection - proc - signal() - - New() ..() spawn(40) @@ -103,7 +99,7 @@ return - signal() + proc/signal() if(!radio_connection) return var/datum/signal/signal = new diff --git a/code/world.dm b/code/world.dm index 481d4bfd967..9d67a7e14f3 100644 --- a/code/world.dm +++ b/code/world.dm @@ -191,24 +191,59 @@ Starting up. [time2text(world.timeofday, "hh:mm.ss")] /world/proc/load_admins() - var/text = file2text("config/admins.txt") - if (!text) - diary << "Failed to load config/admins.txt\n" + if(config.admin_legacy_system) + //Legacy admin system uses admins.txt + var/text = file2text("config/admins.txt") + if (!text) + diary << "Failed to load config/admins.txt\n" + else + var/list/lines = dd_text2list(text, "\n") + for(var/line in lines) + if (!line) + continue + + if (copytext(line, 1, 2) == ";") + continue + + var/pos = findtext(line, " - ", 1, null) + if (pos) + var/m_key = copytext(line, 1, pos) + var/a_lev = copytext(line, pos + 3, length(line) + 1) + admins[m_key] = new /datum/admins(a_lev) + diary << ("ADMIN: [m_key] = [a_lev]") else - var/list/lines = dd_text2list(text, "\n") - for(var/line in lines) - if (!line) - continue + //The current admin system uses SQL + var/user = sqlfdbklogin + var/pass = sqlfdbkpass + var/db = sqlfdbkdb + var/address = sqladdress + var/port = sqlport - if (copytext(line, 1, 2) == ";") - continue + var/DBConnection/dbcon = new() + + dbcon.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]") + if(!dbcon.IsConnected()) + diary << "Failed to connect to database in load_admins(). Reverting to legacy system." + config.admin_legacy_system + load_admins() + return + + var/DBQuery/query = dbcon.NewQuery("SELECT ckey, rank, level FROM erro_admin") + query.Execute() + while(query.NextRow()) + var/adminckey = query.item[1] + var/adminrank = query.item[2] + var/adminlevel = query.item[3] + var/datum/admins/AD = new /datum/admins(adminrank) + AD.level = adminlevel + admins[adminckey] = AD + + if(!admins) + diary << "The database query in load_admins() resulted in no admins being added to the list. Reverting to legacy system." + config.admin_legacy_system + load_admins() + return - var/pos = findtext(line, " - ", 1, null) - if (pos) - var/m_key = copytext(line, 1, pos) - var/a_lev = copytext(line, pos + 3, length(line) + 1) - admins[m_key] = new /datum/admins(a_lev) - diary << ("ADMIN: [m_key] = [a_lev]") /world/proc/load_configuration() diff --git a/config/config.txt b/config/config.txt index adb63df8e87..add31ac06b6 100644 --- a/config/config.txt +++ b/config/config.txt @@ -6,6 +6,9 @@ ALERT_RED_UPTO There is an immediate serious threat to the station. Security may ALERT_RED_DOWNTO The self-destruct mechanism has been deactivated, there is still however an immediate serious threat to the station. Security may have weapons unholstered at all times, random searches are allowed and advised. ALERT_DELTA The station's self-destruct mechanism has been engaged. All crew are instructed to obey all instructions given by heads of staff. Any violations of these orders can be punished by death. This is not a drill. +## Add a # infront of this if you want to use the SQL based admin system, the legacy system uses admins.txt +#ADMIN_LEGACY_SYSTEM + ## log OOC channel LOG_OOC