From ab5403da14f2010fecf464b89a52a72bc6c81554 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Fri, 17 Mar 2017 14:05:43 +0100 Subject: [PATCH] Removed !listlevels and moved functionality into !showhistory --- database/new/mysql.sql | 1 - database/new/sqlite.sql | 1 - database/upgrade/1.1.0/mysql.sql | 1 - database/upgrade/1.1.0/sqlite.sql | 1 - luamods/wolfadmin/admin/admin.lua | 4 +- luamods/wolfadmin/auth/auth.lua | 1 - luamods/wolfadmin/auth/shrubbot.lua | 1 - .../wolfadmin/commands/admin/listlevels.lua | 108 ------------------ luamods/wolfadmin/commands/admin/setlevel.lua | 4 +- luamods/wolfadmin/db/mysql.lua | 33 ------ luamods/wolfadmin/db/sqlite3.lua | 33 ------ 11 files changed, 4 insertions(+), 184 deletions(-) delete mode 100644 luamods/wolfadmin/commands/admin/listlevels.lua diff --git a/database/new/mysql.sql b/database/new/mysql.sql index 6d3b6c9..8cd93a2 100644 --- a/database/new/mysql.sql +++ b/database/new/mysql.sql @@ -278,7 +278,6 @@ INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listhistory'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listwarns'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listbans'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listaliases'); -INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listlevels'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'liststats'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'finger'); diff --git a/database/new/sqlite.sql b/database/new/sqlite.sql index 2f19393..cc4b51c 100644 --- a/database/new/sqlite.sql +++ b/database/new/sqlite.sql @@ -286,7 +286,6 @@ INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listhistory'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listwarns'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listbans'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listaliases'); -INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listlevels'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'liststats'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'finger'); diff --git a/database/upgrade/1.1.0/mysql.sql b/database/upgrade/1.1.0/mysql.sql index fd83ef9..2386b80 100644 --- a/database/upgrade/1.1.0/mysql.sql +++ b/database/upgrade/1.1.0/mysql.sql @@ -205,7 +205,6 @@ INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listhistory'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listwarns'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listbans'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listaliases'); -INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listlevels'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'liststats'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'finger'); diff --git a/database/upgrade/1.1.0/sqlite.sql b/database/upgrade/1.1.0/sqlite.sql index a1c63b6..8a3c545 100644 --- a/database/upgrade/1.1.0/sqlite.sql +++ b/database/upgrade/1.1.0/sqlite.sql @@ -208,7 +208,6 @@ INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listhistory'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listwarns'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listbans'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listaliases'); -INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'listlevels'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'liststats'); INSERT INTO `level_role`(`level_id`, `role`) VALUES (5, 'finger'); diff --git a/luamods/wolfadmin/admin/admin.lua b/luamods/wolfadmin/admin/admin.lua index 3505a92..c9db6a5 100644 --- a/luamods/wolfadmin/admin/admin.lua +++ b/luamods/wolfadmin/admin/admin.lua @@ -35,12 +35,10 @@ function admin.kickPlayer(victimId, invokerId, reason) et.trap_DropClient(victimId, "You have been kicked, Reason: "..(reason and reason or "kicked by admin"), 0) end -function admin.setPlayerLevel(clientId, level, invokerId) +function admin.setPlayerLevel(clientId, level) local playerId = db.getPlayer(players.getGUID(clientId))["id"] - local invokerPlayerId = db.getPlayer(players.getGUID(invokerId))["id"] db.updatePlayerLevel(playerId, level) - db.addSetLevel(playerId, level, invokerPlayerId, os.time()) end function admin.onClientConnectAttempt(clientId, firstTime, isBot) diff --git a/luamods/wolfadmin/auth/auth.lua b/luamods/wolfadmin/auth/auth.lua index 1564db4..1b237fb 100644 --- a/luamods/wolfadmin/auth/auth.lua +++ b/luamods/wolfadmin/auth/auth.lua @@ -35,7 +35,6 @@ auth.PERM_LISTRULES = "listrules" auth.PERM_LISTHISTORY = "listhistory" auth.PERM_LISTBANS = "listbans" auth.PERM_LISTALIASES = "listaliases" -auth.PERM_LISTLEVELS = "listlevels" auth.PERM_LISTSTATS = "liststats" auth.PERM_FINGER = "finger" diff --git a/luamods/wolfadmin/auth/shrubbot.lua b/luamods/wolfadmin/auth/shrubbot.lua index d1c4b23..9bd898c 100644 --- a/luamods/wolfadmin/auth/shrubbot.lua +++ b/luamods/wolfadmin/auth/shrubbot.lua @@ -34,7 +34,6 @@ local flags = { [auth.PERM_LISTHISTORY] = "f", [auth.PERM_LISTBANS] = "B", [auth.PERM_LISTALIASES] = "f", - [auth.PERM_LISTLEVELS] = "s", [auth.PERM_LISTSTATS] = "I", [auth.PERM_FINGER] = "f", diff --git a/luamods/wolfadmin/commands/admin/listlevels.lua b/luamods/wolfadmin/commands/admin/listlevels.lua deleted file mode 100644 index b2a6ec8..0000000 --- a/luamods/wolfadmin/commands/admin/listlevels.lua +++ /dev/null @@ -1,108 +0,0 @@ - --- WolfAdmin module for Wolfenstein: Enemy Territory servers. --- Copyright (C) 2015-2017 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 . - -local auth = require (wolfa_getLuaPath()..".auth.auth") - -local commands = require (wolfa_getLuaPath()..".commands.commands") - -local db = require (wolfa_getLuaPath()..".db.db") - -local players = require (wolfa_getLuaPath()..".players.players") - -local pagination = require (wolfa_getLuaPath()..".util.pagination") -local settings = require (wolfa_getLuaPath()..".util.settings") -local util = require (wolfa_getLuaPath()..".util.util") - -function commandListLevels(clientId, command, victim, offset) - local cmdClient - - if victim == nil then - if settings.get("g_standalone") ~= 0 then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels usage: "..commands.getadmin("listlevels")["syntax"].."\";") - - return true - else - local fileName = et.trap_Cvar_Get("g_shrubbot") - local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ) - local levelsCount = 0 - - if fileLength == -1 then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9an error happened (shrubbot file could not be opened)\";") - - error("failed to open "..fileName.."\n") - end - - local fileString = et.trap_FS_Read(fileDescriptor, fileLength) - - et.trap_FS_FCloseFile(fileDescriptor) - - for _, levelNr, levelName, levelFlags in string.gmatch(fileString, "(%[level%]\nlevel%s+=%s+(-?[0-9]+)\nname%s+=%s+([%a%d%p ]+)\nflags%s+=%s+([%a%d%p]*)\n\n)") do - -- et.G_Print(string.format("%d %s %s\n", levelNr, levelName, levelFlags)) - - local numberOfSpaces = 24 - string.len(util.removeColors(levelName)) - local spaces = string.rep(" ", numberOfSpaces) - - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^7"..string.format("%5s", levelNr).." ^7"..spaces..levelName.." ^7"..levelFlags.."\";") - - levelsCount = levelsCount + 1 - end - - et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dlistlevels: ^9"..levelsCount.." available levels (open console for the full list)\";") - - return true - end - elseif not db.isConnected() then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9level history is disabled.\";") - - return true - elseif tonumber(victim) == nil or tonumber(victim) < 0 or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then - cmdClient = et.ClientNumberFromString(victim) - else - cmdClient = tonumber(victim) - end - - if cmdClient == -1 or cmdClient == nil then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9no or multiple matches for '^7"..victim.."^9'.\";") - - return true - elseif not et.gentity_get(cmdClient, "pers.netname") then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9no connected player by that name or slot #\";") - - return true - end - - local player = db.getPlayer(players.getGUID(cmdClient))["id"] - - local count = db.getLevelsCount(player) - local limit, offset = pagination.calculate(count, 30, tonumber(offset)) - local levels = db.getLevels(player, limit, offset) - - if not (levels and #levels > 0) then - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9there are no recorded levels for player ^7"..et.gentity_get(cmdClient, "pers.netname").."^9.\";") - else - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dLevels for ^7"..et.gentity_get(cmdClient, "pers.netname").."^d:\";") - for _, level in pairs(levels) do - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%4s", level["id"]).." ^7"..string.format("%-20s", util.removeColors(db.getLastAlias(level["invoker_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", level["datetime"]).." ^7"..level["level_id"].."\";") - end - - 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 - - return true -end -commands.addadmin("listlevels", commandListLevels, auth.PERM_LISTLEVELS, "display all levels on the server", (not db.isConnected() and nil or "^9(^3name|slot#^9) ^9(^hoffset^9)")) diff --git a/luamods/wolfadmin/commands/admin/setlevel.lua b/luamods/wolfadmin/commands/admin/setlevel.lua index c6cbb37..da33f9f 100644 --- a/luamods/wolfadmin/commands/admin/setlevel.lua +++ b/luamods/wolfadmin/commands/admin/setlevel.lua @@ -16,6 +16,7 @@ -- along with this program. If not, see . local admin = require (wolfa_getLuaPath()..".admin.admin") +local history = require (wolfa_getLuaPath()..".admin.history") local auth = require (wolfa_getLuaPath()..".auth.auth") @@ -50,7 +51,7 @@ function commandSetLevel(clientId, command, victim, level) return false end - admin.setPlayerLevel(cmdClient, level, clientId) + history.add(cmdClient, clientId, "level", level) return false end @@ -96,6 +97,7 @@ function commandSetLevel(clientId, command, victim, level) end admin.setPlayerLevel(cmdClient, tonumber(level), clientId) + history.add(cmdClient, clientId, "level", level) et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsetlevel: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is now a level ^7"..level.." ^9player.\";") diff --git a/luamods/wolfadmin/db/mysql.lua b/luamods/wolfadmin/db/mysql.lua index bfd482f..26c92a5 100644 --- a/luamods/wolfadmin/db/mysql.lua +++ b/luamods/wolfadmin/db/mysql.lua @@ -239,39 +239,6 @@ function mysql.getLastAlias(playerid) return alias end --- level history -function mysql.addSetLevel(playerid, level, invokerid, datetime) - cur = assert(con:execute("INSERT INTO `player_level` (`player_id`, `level_id`, `invoker_id`, `datetime`) VALUES ("..tonumber(playerid)..", "..tonumber(level)..", "..tonumber(invokerid)..", "..tonumber(datetime)..")")) -end - -function mysql.getLevelsCount(playerid) - cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `player_level` WHERE `player_id`="..tonumber(playerid).."")) - - local count = tonumber(cur:fetch({}, "a")["count"]) - cur:close() - - return count -end - -function mysql.getLevels(playerid, limit, offset) - limit = limit or 30 - offset = offset or 0 - - cur = assert(con:execute("SELECT * FROM `player_level` WHERE `player_id`="..tonumber(playerid).." LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset))) - - local levels = {} - local row = cur:fetch({}, "a") - - while row do - table.insert(levels, tables.copy(row)) - row = cur:fetch(row, "a") - end - - cur:close() - - return levels -end - -- history function mysql.addHistory(victimId, invokerId, type, datetime, reason) cur = assert(con:execute("INSERT INTO `history` (`victim_id`, `invoker_id`, `type`, `datetime`, `reason`) VALUES ("..tonumber(victimId)..", "..tonumber(invokerId)..", '"..util.escape(type).."', "..tonumber(datetime)..", '"..util.escape(reason).."')")) diff --git a/luamods/wolfadmin/db/sqlite3.lua b/luamods/wolfadmin/db/sqlite3.lua index b2ec91b..0cef428 100644 --- a/luamods/wolfadmin/db/sqlite3.lua +++ b/luamods/wolfadmin/db/sqlite3.lua @@ -239,39 +239,6 @@ function sqlite3.getLastAlias(playerid) return alias end --- level history -function sqlite3.addSetLevel(playerid, level, invokerid, datetime) - cur = assert(con:execute("INSERT INTO `player_level` (`player_id`, `level_id`, `invoker_id`, `datetime`) VALUES ("..tonumber(playerid)..", "..tonumber(level)..", "..tonumber(invokerid)..", "..tonumber(datetime)..")")) -end - -function sqlite3.getLevelsCount(playerid) - cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `player_level` WHERE `player_id`="..tonumber(playerid).."")) - - local count = tonumber(cur:fetch({}, "a")["count"]) - cur:close() - - return count -end - -function sqlite3.getLevels(playerid, limit, offset) - limit = limit or 30 - offset = offset or 0 - - cur = assert(con:execute("SELECT * FROM `player_level` WHERE `player_id`="..tonumber(playerid).." LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset))) - - local levels = {} - local row = cur:fetch({}, "a") - - while row do - table.insert(levels, tables.copy(row)) - row = cur:fetch(row, "a") - end - - cur:close() - - return levels -end - -- history function sqlite3.addHistory(victimId, invokerId, type, datetime, reason) cur = assert(con:execute("INSERT INTO `history` (`victim_id`, `invoker_id`, `type`, `datetime`, `reason`) VALUES ("..tonumber(victimId)..", "..tonumber(invokerId)..", '"..util.escape(type).."', "..tonumber(datetime)..", '"..util.escape(reason).."')"))