Removed cfg system and added checks for database availability/connectivity (issue #59)

This commit is contained in:
Timo Smit 2016-08-07 18:55:26 +02:00
parent 1be2b0f2eb
commit bb67eb3f69
13 changed files with 40 additions and 221 deletions

View file

@ -124,7 +124,7 @@ function admin.onconnect(clientId, firstTime, isBot)
return "\n\nIt appears you do not have a ^7GUID^9/^7etkey^9. In order to play on this server, enable ^7PunkBuster ^9(use ^7\pb_cl_enable^9) ^9and/or create an ^7etkey^9.\n\nMore info: ^7www.etkey.org" return "\n\nIt appears you do not have a ^7GUID^9/^7etkey^9. In order to play on this server, enable ^7PunkBuster ^9(use ^7\pb_cl_enable^9) ^9and/or create an ^7etkey^9.\n\nMore info: ^7www.etkey.org"
end end
if settings.get("db_type") ~= "cfg" then if db.isconnected() then
admin.updatePlayer(clientId) admin.updatePlayer(clientId)
admin.updateAlias(clientId) admin.updateAlias(clientId)
end end
@ -160,7 +160,7 @@ function stats.oninfochange(clientId)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \""..old.." ^7is now known as "..new.."\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \""..old.." ^7is now known as "..new.."\";")
if settings.get("db_type") ~= "cfg" then if db.isconnected() then
admin.updateAlias(clientId) admin.updateAlias(clientId)
end end

View file

@ -15,12 +15,13 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
local db = require "luascripts.wolfadmin.db.db"
local settings = require "luascripts.wolfadmin.util.settings" local settings = require "luascripts.wolfadmin.util.settings"
local commands = require "luascripts.wolfadmin.commands.commands" local commands = require "luascripts.wolfadmin.commands.commands"
local warns = require "luascripts.wolfadmin.admin.warns" local warns = require "luascripts.wolfadmin.admin.warns"
function commandRemoveWarn(clientId, cmdArguments) function commandRemoveWarn(clientId, cmdArguments)
if settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg" then if settings.get("g_warnHistory") == 0 or not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn: ^9warn history is disabled.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^ddewarn: ^9warn history is disabled.\";")
return true return true
@ -56,4 +57,4 @@ function commandRemoveWarn(clientId, cmdArguments)
return true return true
end end
commands.addadmin("dewarn", commandRemoveWarn, "R", "remove a warning for a certain player", "^9[^3name|slot#^9] ^9[^3warn#^9]", function() return (settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg") end) commands.addadmin("dewarn", commandRemoveWarn, "R", "remove a warning for a certain player", "^9[^3name|slot#^9] ^9[^3warn#^9]", function() return (settings.get("g_warnHistory") == 0 or not db.isconnected()) end)

View file

@ -23,7 +23,7 @@ local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats" local stats = require "luascripts.wolfadmin.players.stats"
function commandListAliases(clientId, cmdArguments) function commandListAliases(clientId, cmdArguments)
if settings.get("db_type") == "cfg" then if not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases: ^9alias history is disabled.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases: ^9alias history is disabled.\";")
return true return true
@ -76,4 +76,4 @@ function commandListAliases(clientId, cmdArguments)
return true return true
end end
commands.addadmin("listaliases", commandListAliases, "f", "display all known aliases for a player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (settings.get("db_type") == "cfg") end) commands.addadmin("listaliases", commandListAliases, "f", "display all known aliases for a player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (not db.isconnected()) end)

View file

@ -53,7 +53,7 @@ function commandListLevels(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dlistlevels: ^9"..levelsCount.." available levels (open console for the full list)\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dlistlevels: ^9"..levelsCount.." available levels (open console for the full list)\";")
return true return true
elseif settings.get("db_type") == "cfg" then elseif not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9level history is disabled.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9level history is disabled.\";")
return true return true
@ -93,4 +93,4 @@ function commandListLevels(clientId, cmdArguments)
return true return true
end end
commands.addadmin("listlevels", commandListLevels, "s", "display all levels on the server", (settings.get("db_type") == "cfg" and nil or "^9(^3name|slot#^9) ^9(^hoffset^9)")) commands.addadmin("listlevels", commandListLevels, "s", "display all levels on the server", (not db.isconnected() and nil or "^9(^3name|slot#^9) ^9(^hoffset^9)"))

View file

@ -15,11 +15,18 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands" local commands = require "luascripts.wolfadmin.commands.commands"
local game = require "luascripts.wolfadmin.game.game" local game = require "luascripts.wolfadmin.game.game"
local sprees = require "luascripts.wolfadmin.game.sprees" local sprees = require "luascripts.wolfadmin.game.sprees"
function commandResetSprees(clientId, cmdArguments) function commandResetSprees(clientId, cmdArguments)
if not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsprees: ^9spree records are disabled.\";")
return true
end
if cmdArguments[1] and cmdArguments[1] == "all" then if cmdArguments[1] and cmdArguments[1] == "all" then
sprees.reset(true) sprees.reset(true)

View file

@ -16,6 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
local settings = require "luascripts.wolfadmin.util.settings" local settings = require "luascripts.wolfadmin.util.settings"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands" local commands = require "luascripts.wolfadmin.commands.commands"
local admin = require "luascripts.wolfadmin.admin.admin" local admin = require "luascripts.wolfadmin.admin.admin"
@ -37,7 +38,7 @@ function commandSetLevel(clientId, cmdArguments)
-- plays a promotion sound -- plays a promotion sound
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound \"/sound/vo/general/axis/hq_promogen.wav\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound \"/sound/vo/general/axis/hq_promogen.wav\";")
if settings.get("db_type") ~= "cfg" then if db.isconnected() then
cmdArguments[2] = tonumber(cmdArguments[2]) or 0 cmdArguments[2] = tonumber(cmdArguments[2]) or 0
admin.setPlayerLevel(cmdClient, tonumber(cmdArguments[2]), clientId) admin.setPlayerLevel(cmdClient, tonumber(cmdArguments[2]), clientId)

View file

@ -24,7 +24,7 @@ local commands = require "luascripts.wolfadmin.commands.commands"
local warns = require "luascripts.wolfadmin.admin.warns" local warns = require "luascripts.wolfadmin.admin.warns"
function commandShowWarns(clientId, cmdArguments) function commandShowWarns(clientId, cmdArguments)
if settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg" then if settings.get("g_warnHistory") == 0 or not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns: ^9warn history is disabled.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns: ^9warn history is disabled.\";")
return true return true
@ -66,4 +66,4 @@ function commandShowWarns(clientId, cmdArguments)
return true return true
end end
commands.addadmin("showwarns", commandShowWarns, "R", "display warnings for a specific player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg") end) commands.addadmin("showwarns", commandShowWarns, "R", "display warnings for a specific player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (settings.get("g_warnHistory") == 0 or not db.isconnected()) end)

View file

@ -16,9 +16,16 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
local commands = require "luascripts.wolfadmin.commands.commands" local commands = require "luascripts.wolfadmin.commands.commands"
local db = require "luascripts.wolfadmin.db.db"
local sprees = require "luascripts.wolfadmin.game.sprees" local sprees = require "luascripts.wolfadmin.game.sprees"
function commandShowSprees(clientId, cmdArguments) function commandShowSprees(clientId, cmdArguments)
if not db.isconnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsprees: ^9spree records are disabled.\";")
return true
end
local records = sprees.get() local records = sprees.get()
if not (records["ksrecord"] or records["dsrecord"] or records["rsrecord"]) then if not (records["ksrecord"] or records["dsrecord"] or records["rsrecord"]) then

View file

@ -16,11 +16,12 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
local settings = require "luascripts.wolfadmin.util.settings" local settings = require "luascripts.wolfadmin.util.settings"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands" local commands = require "luascripts.wolfadmin.commands.commands"
local warns = require "luascripts.wolfadmin.admin.warns" local warns = require "luascripts.wolfadmin.admin.warns"
function commandAddWarn(clientId, cmdArguments) function commandAddWarn(clientId, cmdArguments)
if settings.get("g_warnHistory") == 0 then if settings.get("g_warnHistory") == 0 or not db.isconnected() then
return false return false
elseif #cmdArguments < 2 then elseif #cmdArguments < 2 then
return false return false

View file

@ -1,205 +0,0 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2016 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local constants = require "luascripts.wolfadmin.util.constants"
local util = require "luascripts.wolfadmin.util.util"
local events = require "luascripts.wolfadmin.util.events"
local files = require "luascripts.wolfadmin.util.files"
local settings = require "luascripts.wolfadmin.util.settings"
local stats = require "luascripts.wolfadmin.players.stats"
local cfg = {}
local maps = {}
local records = {}
function cfg.addmap(mapname, lastplayed)
table.insert(records, {
["map"] = mapname,
})
end
function cfg.updatemap(mapid, lastplayed)
end
function cfg.getmap(mapname)
for id, record in ipairs(records) do
if record["map"] == mapname then
return {["id"] = id}
end
end
end
function cfg.addrecord(mapid, recorddate, recordtype, record, playerid)
cfg.updaterecord(mapid, recorddate, recordtype, record, playerid)
end
function cfg.updaterecord(mapid, recorddate, recordtype, record, playerid)
local typestr = ""
if recordtype == constants.RECORD_KILL then
typestr = "ks"
elseif recordtype == constants.RECORD_DEATH then
typestr = "ds"
elseif recordtype == constants.RECORD_REVIVE then
typestr = "rs"
end
records[mapid][typestr.."record"] = record
records[mapid][typestr.."name"] = playerid
end
function cfg.removeallrecords()
records = {}
end
function cfg.removerecords(mapid)
records[mapid] = {
["map"] = records[mapid]["map"],
}
end
function cfg.getrecords(mapid)
return records[mapid]
end
function cfg.getrecordscount(mapid)
return #records
end
function cfg.getrecord(mapid, recordtype)
local row = records[mapid]
if row then
local record, typestr = {}, ""
if recordtype == constants.RECORD_KILL then
typestr = "ks"
elseif recordtype == constants.RECORD_DEATH then
typestr = "ds"
elseif recordtype == constants.RECORD_REVIVE then
typestr = "rs"
end
if not record[typestr.."player"] then return end
record[typestr.."player"] = tonumber(row["player"])
record[typestr.."record"] = tonumber(row["record"])
return record
end
end
function cfg.addplayer(guid, ip)
end
function cfg.updateplayer(guid, ip)
end
function cfg.getplayerid(clientid)
if type(clientid) == "number" then
return stats.get(clientid, "playerName")
end
return clientid
end
function cfg.isplayerbot(clientid)
return string.match(stats.get(clientid, "playerGUID"), 'OMNIBOT%d%d%d+')
end
function cfg.getplayer(guid)
end
function cfg.addalias(playerid, alias, lastused)
end
function cfg.updatealias(aliasid, lastused)
end
function cfg.getaliases(playerid)
end
function cfg.getaliasbyid(aliasid)
end
function cfg.getaliasbyname(playerid, aliasname)
end
function cfg.getlastalias(playerid)
return {["alias"] = playerid}
end
function cfg.addsetlevel(playerid, level, adminid, datetime)
end
function cfg.getlevels(playerid)
end
function cfg.addwarn(playerid, reason, adminid, datetime)
end
function cfg.removewarn(warnid)
end
function cfg.getwarns(playerid)
end
function cfg.getwarn(warnid)
end
function cfg.isconnected()
end
function cfg.start()
local fileName = settings.get("g_fileSprees")
if fileName == "" then
return
end
local amount, array = files.loadCFG(fileName, "record", true)
records = array["record"] or {}
for id, record in ipairs(records) do
record["ksrecord"] = tonumber(record["ksrecord"])
record["dsrecord"] = tonumber(record["dsrecord"])
record["rsrecord"] = tonumber(record["rsrecord"])
end
end
function cfg.close(doSave)
-- in case of a map restart for example
if not doSave then return end
local fileName = settings.get("g_fileSprees")
if fileName == "" then
return true
end
local array = {["record"] = {}}
-- add back the indices we removed
for _, record in ipairs(records) do
table.insert(array["record"], record)
end
files.save(fileName, array)
end
return cfg

View file

@ -299,7 +299,11 @@ function mysql.isconnected()
end end
function mysql.start() function mysql.start()
con = assert(env:connect(settings.get("db_database"), settings.get("db_username"), settings.get("db_password"), settings.get("db_hostname"), settings.get("db_port"))) 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
return
end
end end
function mysql.close(doSave) function mysql.close(doSave)

View file

@ -299,7 +299,11 @@ function sqlite3.isconnected()
end end
function sqlite3.start() function sqlite3.start()
con = assert(env:connect(settings.get("db_file"))) con = env:connect(settings.get("db_file"))
if not con then
return
end
-- enable foreign key enforcement -- enable foreign key enforcement
cur = assert(con:execute("PRAGMA foreign_keys=1")) cur = assert(con:execute("PRAGMA foreign_keys=1"))

View file

@ -91,8 +91,7 @@ end
function sprees.oninit(levelTime, randomSeed, restartMap) function sprees.oninit(levelTime, randomSeed, restartMap)
if if
(settings.get("db_type") == "cfg" and settings.get("g_fileSprees") ~= "") or (db.isconnected() and settings.get("g_spreeRecords") ~= 0)
(settings.get("db_type") ~= "cfg" and settings.get("g_spreeRecords") ~= 0)
then then
sprees.load() sprees.load()