From f17df67a9b155f79209383cef75fbff1c6c276f1 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Fri, 3 Feb 2017 11:07:36 +0100 Subject: [PATCH 01/10] Fixed paginated lists returning too many results (refs #54) --- luascripts/commands/admin/listaliases.lua | 2 +- luascripts/commands/admin/listlevels.lua | 2 +- luascripts/commands/admin/showwarns.lua | 2 +- luascripts/util/pagination.lua | 8 +++----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/luascripts/commands/admin/listaliases.lua b/luascripts/commands/admin/listaliases.lua index a09f7e1..43e70a3 100644 --- a/luascripts/commands/admin/listaliases.lua +++ b/luascripts/commands/admin/listaliases.lua @@ -71,7 +71,7 @@ function commandListAliases(clientId, cmdArguments) et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^7"..spaces..alias["alias"].." ^7"..string.format("%8s", alias["used"]).." times\";") end - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..limit.." ^9of ^7"..count.."^9.\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..(offset + limit).." ^9of ^7"..count.."^9.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dlistaliases: ^9aliases for ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9were printed to the console.\";") return true diff --git a/luascripts/commands/admin/listlevels.lua b/luascripts/commands/admin/listlevels.lua index 1974f22..2e668fc 100644 --- a/luascripts/commands/admin/listlevels.lua +++ b/luascripts/commands/admin/listlevels.lua @@ -87,7 +87,7 @@ function commandListLevels(clientId, cmdArguments) et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%4s", level["id"]).." ^7"..string.format("%-20s", util.removeColors(db.getlastalias(level["admin_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", level["datetime"]).." ^7"..level["level"].."\";") end - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..limit.." ^9of ^7"..count.."^9.\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..(offset + limit).." ^9of ^7"..count.."^9.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dlistlevels: ^9recorded levels for ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9were printed to the console.\";") end diff --git a/luascripts/commands/admin/showwarns.lua b/luascripts/commands/admin/showwarns.lua index 26bca94..8b06cc2 100644 --- a/luascripts/commands/admin/showwarns.lua +++ b/luascripts/commands/admin/showwarns.lua @@ -60,7 +60,7 @@ function commandShowWarns(clientId, cmdArguments) et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%4s", warn["id"]).." ^7"..string.format("%-20s", util.removeColors(db.getlastalias(warn["admin_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", warn["datetime"]).." ^7"..warn["reason"].."\";") end - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..limit.." ^9of ^7"..count.."^9.\";") + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..(offset + limit).." ^9of ^7"..count.."^9.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dshowwarns: ^9warnings for ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9were printed to the console.\";") end diff --git a/luascripts/util/pagination.lua b/luascripts/util/pagination.lua index 03eef5d..6b981a8 100644 --- a/luascripts/util/pagination.lua +++ b/luascripts/util/pagination.lua @@ -25,13 +25,11 @@ function pagination.calculate(count, limit, offset) offset = count + offset end - limit = limit + offset - - if limit > count then - limit = count + if limit + offset > count then + limit = count % limit end return limit, offset end -return pagination \ No newline at end of file +return pagination From 7484421845ed8d377dd8868ebe38ad3ccc8ace23 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Sat, 4 Feb 2017 14:20:18 +0100 Subject: [PATCH 02/10] Also fixed pagination for negative offsets (refs #54) --- luascripts/util/pagination.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/luascripts/util/pagination.lua b/luascripts/util/pagination.lua index 6b981a8..1030f95 100644 --- a/luascripts/util/pagination.lua +++ b/luascripts/util/pagination.lua @@ -22,10 +22,14 @@ function pagination.calculate(count, limit, offset) offset = offset or 0 if offset < 0 then - offset = count + offset - end - - if limit + offset > count then + if count < math.abs(offset) then + limit = count + offset = 0 + else + limit = math.min(math.abs(offset), 30) + offset = count + offset + end + elseif limit + offset > count then limit = count % limit end From 218dce31b824cb79863127b3eca3e248c87ffe32 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Sat, 4 Feb 2017 19:02:08 +0100 Subject: [PATCH 03/10] Added possibility to disable database system --- luascripts/db/db.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/luascripts/db/db.lua b/luascripts/db/db.lua index 60729df..90c67a5 100644 --- a/luascripts/db/db.lua +++ b/luascripts/db/db.lua @@ -23,21 +23,27 @@ local db = {} local con +function db.isconnected() + return (con ~= nil) +end + -- as this module serves as a wrapper/super class, we load the selected database -- system in this function. might have to think of a better way to implement -- this, but it will suffice. function db.oninit() - if settings.get("db_type") == "mysql" then - con = require "luascripts.wolfadmin.db.mysql" - elseif settings.get("db_type") == "sqlite3" then - con = require "luascripts.wolfadmin.db.sqlite3" - else - error("invalid database system (choose mysql, sqlite3)") + if settings.get("db_type") ~= "none" then + if settings.get("db_type") == "mysql" then + con = require "luascripts.wolfadmin.db.mysql" + elseif settings.get("db_type") == "sqlite3" then + con = require "luascripts.wolfadmin.db.sqlite3" + else + error("invalid database system (choose mysql, sqlite3)") + end + + setmetatable(db, {__index = con}) + + db.start() end - - setmetatable(db, {__index = con}) - - db.start() end events.handle("onGameInit", db.oninit) From 4149d3163b2759ca736391b98c60a4968c6bc837 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Sat, 4 Feb 2017 19:03:52 +0100 Subject: [PATCH 04/10] Bumped version to 1.1.1-dev --- luascripts/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luascripts/main.lua b/luascripts/main.lua index 4466fdd..b59eea2 100644 --- a/luascripts/main.lua +++ b/luascripts/main.lua @@ -41,7 +41,7 @@ local voting = require "luascripts.wolfadmin.game.voting" local stats = require "luascripts.wolfadmin.players.stats" local greetings = require "luascripts.wolfadmin.players.greetings" -local version = "1.1.0" +local version = "1.1.1-dev" local release = "30 January 2017" local basepath = nil From 4253955dbbaca22f9af510100c60ea579966d615 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Sun, 5 Feb 2017 14:46:26 +0100 Subject: [PATCH 05/10] Performance improvement for SQLite3 databases --- luascripts/db/sqlite3.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/luascripts/db/sqlite3.lua b/luascripts/db/sqlite3.lua index 7a03a9f..2048c09 100644 --- a/luascripts/db/sqlite3.lua +++ b/luascripts/db/sqlite3.lua @@ -307,6 +307,7 @@ function sqlite3.start() -- enable foreign key enforcement cur = assert(con:execute("PRAGMA foreign_keys=1")) + cur = assert(con:execute("PRAGMA synchronous=0")) end function sqlite3.close(doSave) From c73a41f7e789a80d823c345e586d9d10ae13e6c7 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Wed, 8 Mar 2017 12:31:19 +0100 Subject: [PATCH 06/10] Fixed listings returning 'duplicate' rows (caused by references) --- luascripts/db/mysql.lua | 7 ++++--- luascripts/db/sqlite3.lua | 7 ++++--- luascripts/util/tables.lua | 10 ++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/luascripts/db/mysql.lua b/luascripts/db/mysql.lua index 6fa1a4b..15bc513 100644 --- a/luascripts/db/mysql.lua +++ b/luascripts/db/mysql.lua @@ -18,6 +18,7 @@ local constants = require "luascripts.wolfadmin.util.constants" local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" +local tables = require "luascripts.wolfadmin.util.tables" local stats = require "luascripts.wolfadmin.players.stats" @@ -83,7 +84,7 @@ function mysql.getaliases(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(aliases, row) + table.insert(aliases, tables.copy(row)) row = cur:fetch(row, "a") end @@ -143,7 +144,7 @@ function mysql.getlevels(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(levels, row) + table.insert(levels, tables.copy(row)) row = cur:fetch(row, "a") end @@ -180,7 +181,7 @@ function mysql.getwarns(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(warns, row) + table.insert(warns, tables.copy(row)) row = cur:fetch(row, "a") end diff --git a/luascripts/db/sqlite3.lua b/luascripts/db/sqlite3.lua index 2048c09..f2a4a6f 100644 --- a/luascripts/db/sqlite3.lua +++ b/luascripts/db/sqlite3.lua @@ -18,6 +18,7 @@ local constants = require "luascripts.wolfadmin.util.constants" local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" +local tables = require "luascripts.wolfadmin.util.tables" local stats = require "luascripts.wolfadmin.players.stats" @@ -83,7 +84,7 @@ function sqlite3.getaliases(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(aliases, row) + table.insert(aliases, tables.copy(row)) row = cur:fetch(row, "a") end @@ -143,7 +144,7 @@ function sqlite3.getlevels(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(levels, row) + table.insert(levels, tables.copy(row)) row = cur:fetch(row, "a") end @@ -180,7 +181,7 @@ function sqlite3.getwarns(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(warns, row) + table.insert(warns, tables.copy(row)) row = cur:fetch(row, "a") end diff --git a/luascripts/util/tables.lua b/luascripts/util/tables.lua index 5731218..4bd87de 100644 --- a/luascripts/util/tables.lua +++ b/luascripts/util/tables.lua @@ -17,6 +17,16 @@ local tables = {} +function tables.copy(table) + local copy = {} + + for key, value in pairs(table) do + copy[key] = value + end + + return copy +end + function tables.contains(table, needle) for key, value in pairs(table) do if value == needle then From c47c6572daaf896b968f5e76b9487f0c400be9fd Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Wed, 8 Mar 2017 13:16:29 +0100 Subject: [PATCH 07/10] Fixed connected players not being added to database on mod init --- luascripts/admin/admin.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/luascripts/admin/admin.lua b/luascripts/admin/admin.lua index 0d47d02..55d3374 100644 --- a/luascripts/admin/admin.lua +++ b/luascripts/admin/admin.lua @@ -74,34 +74,34 @@ function admin.unlockPlayer(clientId) stats.set(clientId, "teamLock", false) end -function admin.updatePlayer(clientId) +function admin.updatePlayer(clientId, firstTime) local player = db.getplayer(stats.get(clientId, "playerGUID")) - if player then + if player and firstTime then local guid = stats.get(clientId, "playerGUID") local ip = stats.get(clientId, "playerIP") db.updateplayer(guid, ip) - else + elseif not player then local guid = stats.get(clientId, "playerGUID") local ip = stats.get(clientId, "playerIP") db.addplayer(guid, ip) - admin.setPlayerLevel(clientId, et.G_shrubbot_level(clientId), 1) + admin.setPlayerLevel(clientId, et.G_shrubbot_level(clientId), clientId) end end -function admin.updateAlias(clientId) +function admin.updateAlias(clientId, firstTime) local playerid = db.getplayer(stats.get(clientId, "playerGUID"))["id"] local name = stats.get(clientId, "playerName") local alias = db.getaliasbyname(playerid, name) - if alias then + if alias and firstTime then db.updatealias(alias["id"], os.time()) if alias["cleanalias"] == "" then db.updatecleanalias(alias["id"], name) end - else + elseif not alias then db.addalias(playerid, name, os.time()) end end @@ -123,11 +123,11 @@ function admin.onconnect(clientId, firstTime, isBot) if stats.get(clientId, "playerGUID") == "NO_GUID" or stats.get(clientId, "playerGUID") == "unknown" then 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 db.isconnected() then - admin.updatePlayer(clientId) - admin.updateAlias(clientId) - end + end + + if db.isconnected() then + admin.updatePlayer(clientId, firstTime) + admin.updateAlias(clientId, firstTime) end end events.handle("onClientConnect", admin.onconnect) From 034a926bc92144b9e41d6a06aa8e340497a18816 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Sun, 12 Feb 2017 13:29:45 +0100 Subject: [PATCH 08/10] Fixed a file descriptor leak --- luascripts/util/files.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/luascripts/util/files.lua b/luascripts/util/files.lua index df40405..c6948f7 100644 --- a/luascripts/util/files.lua +++ b/luascripts/util/files.lua @@ -71,7 +71,10 @@ end function files.loadCFG(fileName, idExpr, fileCreate) local functionStart = et.trap_Milliseconds() - local fileString = files.open(fileName, et.FS_READ, fileCreate) + local fileString = files.open(fileName, et.FS_READ, fileCreate).."\n\n" + + et.trap_FS_FCloseFile(fileDescriptor) + local arrayCount = 0 local array = {} From f9609a3260bca6b5420bc0e089be0b5c99ea08ed Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Tue, 14 Mar 2017 17:32:50 +0100 Subject: [PATCH 09/10] Added extra condition for empty GUIDs --- luascripts/admin/admin.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luascripts/admin/admin.lua b/luascripts/admin/admin.lua index 55d3374..fe028b5 100644 --- a/luascripts/admin/admin.lua +++ b/luascripts/admin/admin.lua @@ -120,7 +120,7 @@ function admin.onconnect(clientId, firstTime, isBot) stats.set(clientId, "namechangePts", 0) if firstTime then - if stats.get(clientId, "playerGUID") == "NO_GUID" or stats.get(clientId, "playerGUID") == "unknown" then + if stats.get(clientId, "playerGUID") == "" or stats.get(clientId, "playerGUID") == "NO_GUID" or stats.get(clientId, "playerGUID") == "unknown" then 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 From 65a8ca18549c791295db45056b8d07d1ce57043b Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Wed, 15 Mar 2017 14:16:40 +0100 Subject: [PATCH 10/10] Fixed GPL link in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 156724e..4cf8554 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ WolfAdmin is a Lua module for Wolfenstein: Enemy Territory servers. LICENSE ============ -[http://www.gnu.org/licenses/gpl-3.0.html](GNU General Public License 3) +[GNU General Public License 3](http://www.gnu.org/licenses/gpl-3.0.html)