mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
- 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
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user