diff --git a/luamods/wolfadmin/auth/auth.lua b/luamods/wolfadmin/auth/auth.lua index cb23d54..86b2e50 100644 --- a/luamods/wolfadmin/auth/auth.lua +++ b/luamods/wolfadmin/auth/auth.lua @@ -15,6 +15,8 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local db = require (wolfa_getLuaPath()..".db.db") + local events = require (wolfa_getLuaPath()..".util.events") local settings = require (wolfa_getLuaPath()..".util.settings") @@ -116,6 +118,13 @@ auth.PERM_IMMUNE = "immune" -- this, but it will suffice. function auth.onGameInit() if settings.get("g_standalone") == 1 then + if not db.isConnected() then + -- FIXME simple workaround to deny any commands + function auth.isPlayerAllowed() return false end + + return + end + srv = require (wolfa_getLuaPath()..".auth.acl") srv.readPermissions() diff --git a/luamods/wolfadmin/commands/server/acl.lua b/luamods/wolfadmin/commands/server/acl.lua index 64ba131..ac912e6 100644 --- a/luamods/wolfadmin/commands/server/acl.lua +++ b/luamods/wolfadmin/commands/server/acl.lua @@ -17,6 +17,8 @@ local acl = require (wolfa_getLuaPath()..".auth.acl") +local db = require (wolfa_getLuaPath()..".db.db") + local commands = require (wolfa_getLuaPath()..".commands.commands") local settings = require (wolfa_getLuaPath()..".util.settings") @@ -195,4 +197,4 @@ function commandAcl(command, action, ...) return true end -commands.addserver("acl", commandAcl, (settings.get("g_standalone") == 0)) +commands.addserver("acl", commandAcl, (settings.get("g_standalone") == 0 or not db.isConnected())) diff --git a/luamods/wolfadmin/db/db.lua b/luamods/wolfadmin/db/db.lua index 7f9740e..a30aaed 100644 --- a/luamods/wolfadmin/db/db.lua +++ b/luamods/wolfadmin/db/db.lua @@ -36,12 +36,16 @@ function db.oninit() elseif settings.get("db_type") == "mysql" then con = require (wolfa_getLuaPath()..".db.mysql") else - error("invalid database system (none|sqlite3|mysql)") + outputDebug("Invalid database system (none|sqlite3|mysql), defaulting to 'none'.") + + return end setmetatable(db, {__index = con}) - db.start() + if not db.start() then + outputDebug("Database could not be loaded, only limited functionality is available.", 3) + end end end events.handle("onGameInit", db.oninit) diff --git a/luamods/wolfadmin/db/mysql.lua b/luamods/wolfadmin/db/mysql.lua index aac1020..d084372 100644 --- a/luamods/wolfadmin/db/mysql.lua +++ b/luamods/wolfadmin/db/mysql.lua @@ -514,11 +514,18 @@ function mysql.start() con = env:connect(settings.get("db_database"), settings.get("db_username"), settings.get("db_password"), settings.get("db_hostname"), settings.get("db_port")) if not con then - error("could not connect to database") + outputDebug("Could not connect to database.", 3) + + return false elseif not mysql.isSchemaExistent() then mysql.close() - error("schema does not exist") + + outputDebug("Database schema does not exist.", 3) + + return false end + + return true end function mysql.close(doSave) diff --git a/luamods/wolfadmin/db/sqlite3.lua b/luamods/wolfadmin/db/sqlite3.lua index 4f477c7..4296e9d 100644 --- a/luamods/wolfadmin/db/sqlite3.lua +++ b/luamods/wolfadmin/db/sqlite3.lua @@ -522,15 +522,22 @@ function sqlite3.start() con = env:connect(uri) if not con then - error("could not connect to database") + outputDebug("Could not connect to database.", 3) + + return false elseif not sqlite3.isSchemaExistent() then sqlite3.close() - error("schema does not exist") + + outputDebug("Database schema does not exist.", 3) + + return false end -- enable foreign key enforcement assert(con:execute("PRAGMA foreign_keys=1")) assert(con:execute("PRAGMA synchronous=0")) + + return true end function sqlite3.close(doSave)