Skip to content

Commit

Permalink
Removed cfg system and added checks for database availability/connect…
Browse files Browse the repository at this point in the history
…ivity (issue #59)
  • Loading branch information
Timo Smit committed Aug 7, 2016
1 parent 1be2b0f commit bb67eb3
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 221 deletions.
4 changes: 2 additions & 2 deletions luascripts/admin/admin.lua
Expand Up @@ -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"
end

if settings.get("db_type") ~= "cfg" then
if db.isconnected() then
admin.updatePlayer(clientId)
admin.updateAlias(clientId)
end
Expand Down Expand Up @@ -160,7 +160,7 @@ function stats.oninfochange(clientId)

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)
end

Expand Down
5 changes: 3 additions & 2 deletions luascripts/commands/admin/dewarn.lua
Expand Up @@ -15,12 +15,13 @@
-- 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 db = require "luascripts.wolfadmin.db.db"
local settings = require "luascripts.wolfadmin.util.settings"
local commands = require "luascripts.wolfadmin.commands.commands"
local warns = require "luascripts.wolfadmin.admin.warns"

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.\";")

return true
Expand Down Expand Up @@ -56,4 +57,4 @@ function commandRemoveWarn(clientId, cmdArguments)

return true
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)
4 changes: 2 additions & 2 deletions luascripts/commands/admin/listaliases.lua
Expand Up @@ -23,7 +23,7 @@ local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats"

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.\";")

return true
Expand Down Expand Up @@ -76,4 +76,4 @@ function commandListAliases(clientId, cmdArguments)

return true
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)
4 changes: 2 additions & 2 deletions luascripts/commands/admin/listlevels.lua
Expand Up @@ -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)\";")

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.\";")

return true
Expand Down Expand Up @@ -93,4 +93,4 @@ function commandListLevels(clientId, cmdArguments)

return true
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)"))
7 changes: 7 additions & 0 deletions luascripts/commands/admin/resetsprees.lua
Expand Up @@ -15,11 +15,18 @@
-- 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 db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local game = require "luascripts.wolfadmin.game.game"
local sprees = require "luascripts.wolfadmin.game.sprees"

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
sprees.reset(true)

Expand Down
3 changes: 2 additions & 1 deletion luascripts/commands/admin/setlevel.lua
Expand Up @@ -16,6 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local settings = require "luascripts.wolfadmin.util.settings"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local admin = require "luascripts.wolfadmin.admin.admin"

Expand All @@ -37,7 +38,7 @@ function commandSetLevel(clientId, cmdArguments)
-- plays a promotion sound
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

admin.setPlayerLevel(cmdClient, tonumber(cmdArguments[2]), clientId)
Expand Down
4 changes: 2 additions & 2 deletions luascripts/commands/admin/showwarns.lua
Expand Up @@ -24,7 +24,7 @@ local commands = require "luascripts.wolfadmin.commands.commands"
local warns = require "luascripts.wolfadmin.admin.warns"

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.\";")

return true
Expand Down Expand Up @@ -66,4 +66,4 @@ function commandShowWarns(clientId, cmdArguments)

return true
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)
7 changes: 7 additions & 0 deletions luascripts/commands/admin/sprees.lua
Expand Up @@ -16,9 +16,16 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local commands = require "luascripts.wolfadmin.commands.commands"
local db = require "luascripts.wolfadmin.db.db"
local sprees = require "luascripts.wolfadmin.game.sprees"

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()

if not (records["ksrecord"] or records["dsrecord"] or records["rsrecord"]) then
Expand Down
3 changes: 2 additions & 1 deletion luascripts/commands/admin/warn.lua
Expand Up @@ -16,11 +16,12 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local settings = require "luascripts.wolfadmin.util.settings"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local warns = require "luascripts.wolfadmin.admin.warns"

function commandAddWarn(clientId, cmdArguments)
if settings.get("g_warnHistory") == 0 then
if settings.get("g_warnHistory") == 0 or not db.isconnected() then
return false
elseif #cmdArguments < 2 then
return false
Expand Down
205 changes: 0 additions & 205 deletions luascripts/db/cfg.lua

This file was deleted.

6 changes: 5 additions & 1 deletion luascripts/db/mysql.lua
Expand Up @@ -299,7 +299,11 @@ function mysql.isconnected()
end

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

function mysql.close(doSave)
Expand Down
6 changes: 5 additions & 1 deletion luascripts/db/sqlite3.lua
Expand Up @@ -299,7 +299,11 @@ function sqlite3.isconnected()
end

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
cur = assert(con:execute("PRAGMA foreign_keys=1"))
Expand Down

0 comments on commit bb67eb3

Please sign in to comment.