From a2f7f1dec4c8fed90fddb2e61cd8de26472897a0 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Thu, 3 Jan 2019 11:15:22 +0100 Subject: [PATCH] Fixed OS and mode detection (refs #61, #74) * fixed OS detection echoing errors to log when executables are not available * OS detection makes use of Unix/Windows native functions rather than environment variables which can be modified * fixed ability to override standalone mode --- luamods/wolfadmin/util/settings.lua | 66 ++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/luamods/wolfadmin/util/settings.lua b/luamods/wolfadmin/util/settings.lua index 95e2ea1..e378f8b 100644 --- a/luamods/wolfadmin/util/settings.lua +++ b/luamods/wolfadmin/util/settings.lua @@ -42,7 +42,6 @@ local data = { ["g_voteNextMapTimeout"] = 0, ["g_restrictedVotes"] = "", ["g_renameLimit"] = 80, - ["g_standalone"] = 1, ["g_debugWolfAdmin"] = 0, ["omnibot_maxbots"] = 10, ["db_type"] = "sqlite3", @@ -51,8 +50,7 @@ local data = { ["db_port"] = 3306, ["db_database"] = "wolfadmin", ["db_username"] = "", - ["db_password"] = "", - ["sv_os"] = "unix" + ["db_password"] = "" } local cfgStructure = { @@ -171,9 +169,50 @@ function settings.load() end end - local platform = string.lower(data["sv_os"]) - if not (platform == "unix" or platform == "windows") then - settings.set("sv_os", settings.determineOS()) + settings.determineOS() + settings.determineMode() + + outputDebug("WolfAdmin running in "..(settings.get("g_standalone") == 1 and "standalone" or "add-on").." mode on "..settings.get("sv_os")..".") +end + +function settings.determineOS() + -- OS has been manually specified + local os = settings.get("sv_os") and string.lower(settings.get("sv_os")) or nil + + if os == "unix" or os == "windows" then + return + end + + -- unknown os specified + if os then + outputDebug("Invalid operating system specified, determining automatically.", 3) + end + + -- 'uname' is available on Unix systems + local uname = io.popen("uname -s 2>nul"):read("*l") + if uname then + settings.set("sv_os", "unix") + + return + end + + -- 'ver' is available on Windows systems + local ver = io.popen("ver 2>nul"):read("*l") + if ver then + settings.set("sv_os", "windows") + + return + end + + outputDebug("Operating system could not be determined, falling back to 'unix'.", 3) + + settings.set("sv_os", "unix") +end + +function settings.determineMode() + -- mode has been manually specified + if settings.get("g_standalone") then + return end local mod = et.trap_Cvar_Get("fs_game") @@ -186,21 +225,6 @@ function settings.load() else settings.set("g_standalone", 0) end - - outputDebug("WolfAdmin running in "..(settings.get("g_standalone") == 1 and "standalone" or "add-on").." mode.") -end - -function settings.determineOS() - local system = io.popen("uname -s"):read("*l") - local platform - - if system then - platform = "unix" - else - platform = "windows" - end - - return platform end function settings.oninit(levelTime, randomSeed, restartMap)