Removed !listlevels and moved functionality into !showhistory

This commit is contained in:
Timo Smit 2017-03-17 14:05:43 +01:00
parent 78213fbc78
commit ab5403da14
11 changed files with 4 additions and 184 deletions

View file

@ -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');

View file

@ -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');

View file

@ -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');

View file

@ -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');

View file

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

View file

@ -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"

View file

@ -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",

View file

@ -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 <http://www.gnu.org/licenses/>.
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)"))

View file

@ -16,6 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
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.\";")

View file

@ -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).."')"))

View file

@ -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).."')"))