diff --git a/luamods/wolfadmin/commands/client/pm.lua b/luamods/wolfadmin/commands/client/pm.lua index cc1b7db..853bb3f 100644 --- a/luamods/wolfadmin/commands/client/pm.lua +++ b/luamods/wolfadmin/commands/client/pm.lua @@ -15,12 +15,11 @@ -- 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 players = require (wolfa_getLuaPath()..".players.players") +local logs = require (wolfa_getLuaPath()..".util.logs") local settings = require (wolfa_getLuaPath()..".util.settings") function commandPersonalMessage(clientId, command, recipient, ...) @@ -84,6 +83,8 @@ function commandPersonalMessage(clientId, command, recipient, ...) et.trap_SendConsoleCommand(et.EXEC_APPEND, "ccp "..cmdClient.." \"^3private message from "..et.gentity_get(clientId, "pers.netname").."\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..cmdClient.." \"^9reply: ^7r [^2message^7]\";") end + + logs.writeChat(clientId, "priv", cmdClient, ...) end commands.addclient("pm", commandPersonalMessage, "", "", true, (settings.get("fs_game") == "legacy")) commands.addclient("m", commandPersonalMessage, "", "", true, (settings.get("fs_game") == "legacy")) diff --git a/luamods/wolfadmin/commands/client/r.lua b/luamods/wolfadmin/commands/client/r.lua index daf3208..12930ff 100644 --- a/luamods/wolfadmin/commands/client/r.lua +++ b/luamods/wolfadmin/commands/client/r.lua @@ -15,10 +15,9 @@ -- 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 logs = require (wolfa_getLuaPath()..".util.logs") local players = require (wolfa_getLuaPath()..".players.players") function commandR(clientId, command, ...) @@ -51,6 +50,8 @@ function commandR(clientId, command, ...) et.trap_SendConsoleCommand(et.EXEC_APPEND, "ccp "..recipient.." \"^3private message from "..et.gentity_get(clientId, "pers.netname").."\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..recipient.." \"^9reply: ^7r [^2message^7]\";") + logs.writeChat(clientId, "priv", recipient, ...) + return true end commands.addclient("r", commandR, "", "[^2message^7]", true) diff --git a/luamods/wolfadmin/commands/client/say.lua b/luamods/wolfadmin/commands/client/say.lua index f1609c9..49694bb 100644 --- a/luamods/wolfadmin/commands/client/say.lua +++ b/luamods/wolfadmin/commands/client/say.lua @@ -19,26 +19,44 @@ local commands = require (wolfa_getLuaPath()..".commands.commands") local players = require (wolfa_getLuaPath()..".players.players") +local logs = require (wolfa_getLuaPath()..".util.logs") local settings = require (wolfa_getLuaPath()..".util.settings") -function commandSay(clientId, command) +local types = { + ["say"] = "chat", + ["say_team"] = "team", + ["say_teamnl"] = "spec", + ["say_buddy"] = "fire", + ["vsay"] = "chat", + ["vsay_team"] = "team", + ["vsay_buddy"] = "fire" +} + +function commandSay(clientId, command, ...) if players.isMuted(clientId, players.MUTE_CHAT) then et.trap_SendServerCommand(clientId, "cp \"^1You are muted\"") return true end + + logs.writeChat(clientId, types[command], ...) end commands.addclient("say", commandSay, "", "", false, (settings.get("g_standalone") == 0)) commands.addclient("say_team", commandSay, "", "", false, (settings.get("g_standalone") == 0)) commands.addclient("say_teamnl", commandSay, "", "", false, (settings.get("g_standalone") == 0)) commands.addclient("say_buddy", commandSay, "", "", false, (settings.get("g_standalone") == 0)) -function commandVoiceSay(clientId, cmdArguments) +function commandVoiceSay(clientId, command, ...) if players.isMuted(clientId, players.MUTE_VOICE) then et.trap_SendServerCommand(clientId, "cp \"^1You are voicemuted\"") return true end + + if settings.get("g_standalone") == 1 then + logs.writeChat(clientId, types[command], ...) + end end commands.addclient("vsay", commandVoiceSay, "", "", false) commands.addclient("vsay_team", commandVoiceSay, "", "", false) +commands.addclient("vsay_buddy", commandVoiceSay, "", "", false) diff --git a/luamods/wolfadmin/commands/commands.lua b/luamods/wolfadmin/commands/commands.lua index 9f6a6aa..34687c8 100644 --- a/luamods/wolfadmin/commands/commands.lua +++ b/luamods/wolfadmin/commands/commands.lua @@ -15,16 +15,12 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -require (wolfa_getLuaPath()..".util.debug") - local auth = require (wolfa_getLuaPath()..".auth.auth") -local players = require (wolfa_getLuaPath()..".players.players") - local util = require (wolfa_getLuaPath()..".util.util") local events = require (wolfa_getLuaPath()..".util.events") local files = require (wolfa_getLuaPath()..".util.files") -local settings = require (wolfa_getLuaPath()..".util.settings") +local logs = require (wolfa_getLuaPath()..".util.logs") local tables = require (wolfa_getLuaPath()..".util.tables") local commands = {} @@ -123,19 +119,19 @@ function commands.load() return totalAmount end -function commands.log(clientId, command, cmdArguments) +function commands.log(clientId, command, victim, ...) local victimId -- funny, NoQuarter actually checks EACH command for a victim (so even -- !help [playername] will log a victimname). so why not do the same :D -- todo: do this more nicely, maybe change .register() function - if cmdArguments[1] then + if victim then local cmdClient - - if tonumber(cmdArguments[1]) == nil or tonumber(cmdArguments[1]) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then - cmdClient = et.ClientNumberFromString(cmdArguments[1]) + + if tonumber(victim) == nil or tonumber(victim) > tonumber(et.trap_Cvar_Get("sv_maxclients")) then + cmdClient = et.ClientNumberFromString(victim) else - cmdClient = tonumber(cmdArguments[1]) + cmdClient = tonumber(victim) end if cmdClient ~= -1 and cmdClient ~= nil and et.gentity_get(cmdClient, "pers.netname") then @@ -143,35 +139,7 @@ function commands.log(clientId, command, cmdArguments) end end - local fileDescriptor = files.open(settings.get("g_logAdmin"), et.FS_APPEND) - - local logLine - - local clientGUID = clientId and players.getGUID(clientId) or "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - local clientName = clientId and players.getName(clientId) or "console" - local clientFlags = "" - - if settings.get("g_standalone") == 1 then - if victimId then - local victimName = players.getName(victimId) - logLine = string.format("[%s] %s: %s: %s: %s: \"%s\"\n", os.date("%Y-%m-%d %H:%M:%S"), clientGUID, clientName, command, victimName, table.concat(cmdArguments, " ", 2)) - else - logLine = string.format("[%s] %s: %s: %s: \"%s\"\n", os.date("%Y-%m-%d %H:%M:%S"), clientGUID, clientName, command, table.concat(cmdArguments, " ")) - end - else - local levelTime = et.trap_Milliseconds() / 1000 - - if victimId then - local victimName = players.getName(victimId) - logLine = string.format("%3i:%02f: %i: %s: %s: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, victimId, victimName, table.concat(cmdArguments, " ", 2)) - else - logLine = string.format("%3i:%02f: %i: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, table.concat(cmdArguments, " ")) - end - end - - et.trap_FS_Write(logLine, string.len(logLine), fileDescriptor) - - et.trap_FS_FCloseFile(fileDescriptor) + logs.writeAdmin(clientId, command, victimId, ...) end function commands.onGameInit() @@ -179,51 +147,51 @@ function commands.onGameInit() end events.handle("onGameInit", commands.onGameInit) -function commands.onServerCommand(cmdText) - local wolfCmd = string.lower(cmdText) - local cmdArguments = {} - +function commands.onServerCommand(command) + local wolfCmd = string.lower(command) + local args = {} + if servercmds[wolfCmd] and servercmds[wolfCmd]["function"] then for i = 1, et.trap_Argc() - 1 do - table.insert(cmdArguments, et.trap_Argv(i)) + table.insert(args, et.trap_Argv(i)) end - return servercmds[wolfCmd]["function"](wolfCmd, tables.unpack(cmdArguments)) and 1 or 0 + return servercmds[wolfCmd]["function"](wolfCmd, tables.unpack(args)) and 1 or 0 end - local shrubCmd = cmdText - - if string.find(cmdText, "!") == 1 then - shrubCmd = string.lower(string.sub(cmdText, 2, string.len(cmdText))) + local shrubCmd = command + + if string.find(command, "!") == 1 then + shrubCmd = string.lower(string.sub(command, 2, string.len(command))) end if admincmds[shrubCmd] and admincmds[shrubCmd]["function"] and admincmds[shrubCmd]["flag"] then for i = 1, et.trap_Argc() - 1 do - table.insert(cmdArguments, et.trap_Argv(i)) + table.insert(args, et.trap_Argv(i)) end if not admincmds[shrubCmd]["hidden"] then - commands.log(-1337, shrubCmd, cmdArguments) + commands.log(-1337, shrubCmd, tables.unpack(args)) end - return admincmds[shrubCmd]["function"](-1337, shrubCmd, tables.unpack(cmdArguments)) and 1 or 0 + return admincmds[shrubCmd]["function"](-1337, shrubCmd, tables.unpack(args)) and 1 or 0 end end events.handle("onServerCommand", commands.onServerCommand) -function commands.onClientCommand(clientId, cmdText) - local wolfCmd = string.lower(cmdText) - local cmdArguments = {} +function commands.onClientCommand(clientId, command) + local wolfCmd = string.lower(command) + local args = {} -- mod-specific or custom commands loading -- syntax: command arg1 arg2 ... argN if clientcmds[wolfCmd] and clientcmds[wolfCmd]["function"] and clientcmds[wolfCmd]["flag"] then if clientcmds[wolfCmd]["flag"] == "" or auth.isPlayerAllowed(clientId, clientcmds[wolfCmd]["flag"]) then for i = 1, et.trap_Argc() - 1 do - table.insert(cmdArguments, et.trap_Argv(i)) + table.insert(args, et.trap_Argv(i)) end - local isFinished = clientcmds[wolfCmd]["function"](clientId, wolfCmd, tables.unpack(cmdArguments)) + local isFinished = clientcmds[wolfCmd]["function"](clientId, wolfCmd, tables.unpack(args)) if isFinished ~= nil then return isFinished and 1 or 0 @@ -236,20 +204,20 @@ function commands.onClientCommand(clientId, cmdText) local clientCmd = nil if (wolfCmd == "say" or wolfCmd == "say_team" or wolfCmd == "say_buddy") and string.find(et.trap_Argv(1), "/") == 1 then - cmdArguments = util.split(et.trap_Argv(1), " ") - + args = util.split(et.trap_Argv(1), " ") + -- say "/command arg1 arg2 argN" - if #cmdArguments > 1 then - clientCmd = string.sub(cmdArguments[1], 2, string.len(cmdArguments[1])) - table.remove(cmdArguments, 1) + if #args > 1 then + clientCmd = string.sub(args[1], 2, string.len(args[1])) + table.remove(args, 1) -- say /command arg1 arg2 argN else clientCmd = string.sub(et.trap_Argv(1), 2, string.len(et.trap_Argv(1))) - + for i = 2, et.trap_Argc() - 1 do - table.insert(cmdArguments, et.trap_Argv(i)) + table.insert(args, et.trap_Argv(i)) end - if cmdArguments[1] == et.trap_Argv(1) then table.remove(cmdArguments, 1) end + if args[1] == et.trap_Argv(1) then table.remove(args, 1) end end end @@ -259,7 +227,7 @@ function commands.onClientCommand(clientId, cmdText) if clientcmds[clientCmd] and clientcmds[clientCmd]["function"] and clientcmds[clientCmd]["chat"] then if clientcmds[clientCmd]["flag"] == "" or auth.isPlayerAllowed(clientId, clientcmds[clientCmd]["flag"]) then - return clientcmds[clientCmd]["function"](clientId, clientCmd, tables.unpack(cmdArguments)) and 1 or 0 + return clientcmds[clientCmd]["function"](clientId, clientCmd, tables.unpack(args)) and 1 or 0 end end end @@ -269,28 +237,28 @@ function commands.onClientCommand(clientId, cmdText) -- syntax: say or say_* if (wolfCmd == "say" or wolfCmd == "say_team" or wolfCmd == "say_buddy") and string.find(et.trap_Argv(1), "!") == 1 then - cmdArguments = util.split(et.trap_Argv(1), " ") - - -- syntax: say "!command arg1 arg2 ... argN" - if #cmdArguments > 1 then - shrubCmd = string.sub(cmdArguments[1], 2, string.len(cmdArguments[1])) + args = util.split(et.trap_Argv(1), " ") - table.remove(cmdArguments, 1) + -- syntax: say "!command arg1 arg2 ... argN" + if #args > 1 then + shrubCmd = string.sub(args[1], 2, string.len(args[1])) + + table.remove(args, 1) -- syntax: say !command arg1 arg2 ... argN else shrubCmd = string.sub(et.trap_Argv(1), 2, string.len(et.trap_Argv(1))) for i = 2, et.trap_Argc() - 1 do - table.insert(cmdArguments, et.trap_Argv(i)) + table.insert(args, et.trap_Argv(i)) end - if cmdArguments[1] == et.trap_Argv(1) then table.remove(cmdArguments, 1) end + if args[1] == et.trap_Argv(1) then table.remove(args, 1) end end -- syntax: !command arg1 arg2 ... argN elseif string.find(wolfCmd, "!") == 1 then shrubCmd = string.sub(wolfCmd, 2, string.len(wolfCmd)) for i = 1, et.trap_Argc() - 1 do - table.insert(cmdArguments, et.trap_Argv(i)) + table.insert(args, et.trap_Argv(i)) end end @@ -301,10 +269,10 @@ function commands.onClientCommand(clientId, cmdText) if admincmds[shrubCmd] and admincmds[shrubCmd]["function"] and admincmds[shrubCmd]["flag"] then if wolfCmd == "say" or (((wolfCmd == "say_team" and et.gentity_get(cmdClient, "sess.sessionTeam") ~= et.TEAM_SPECTATORS) or wolfCmd == "say_buddy") and auth.isPlayerAllowed(clientId, auth.PERM_TEAMCMDS)) or (wolfCmd == "!"..shrubCmd and auth.isPlayerAllowed(clientId, auth.PERM_SILENTCMDS)) then if admincmds[shrubCmd]["flag"] ~= "" and auth.isPlayerAllowed(clientId, admincmds[shrubCmd]["flag"]) then - local isFinished = admincmds[shrubCmd]["function"](clientId, shrubCmd, tables.unpack(cmdArguments)) + local isFinished = admincmds[shrubCmd]["function"](clientId, shrubCmd, tables.unpack(args)) if not admincmds[shrubCmd]["hidden"] then - commands.log(clientId, shrubCmd, cmdArguments) + commands.log(clientId, shrubCmd, tables.unpack(args)) end if isFinished and "!"..shrubCmd == wolfCmd then -- silent command via console, removes "unknown command" message diff --git a/luamods/wolfadmin/util/logs.lua b/luamods/wolfadmin/util/logs.lua new file mode 100644 index 0000000..149de05 --- /dev/null +++ b/luamods/wolfadmin/util/logs.lua @@ -0,0 +1,90 @@ + +-- 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 players = require (wolfa_getLuaPath()..".players.players") + +local files = require (wolfa_getLuaPath()..".util.files") +local settings = require (wolfa_getLuaPath()..".util.settings") + +local logs = {} + +function logs.writeServer(...) + local fileDescriptor = files.open(settings.get("g_logServer"), et.FS_APPEND) + + local logLine = string.format("[%s] %s\n", os.date("%Y-%m-%d %H:%M:%S"), table.concat({...}, " ")) + + et.trap_FS_Write(logLine, string.len(logLine), fileDescriptor) + + et.trap_FS_FCloseFile(fileDescriptor) +end + +function logs.writeChat(clientId, type, ...) + local fileDescriptor = files.open(settings.get("g_logChat"), et.FS_APPEND) + + local logLine + + local clientGUID = clientId and players.getGUID(clientId) or "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + local clientName = clientId and players.getName(clientId) or "console" + + if type == "priv" then + local args = {...} + local recipientName = players.getName(args[1]) + + logLine = string.format("[%s] %s: %s: %s: %s: \"%s\"\n", os.date("%Y-%m-%d %H:%M:%S"), clientGUID, string.upper(type), clientName, recipientName, table.concat({...}, " ", 2)) + else + logLine = string.format("[%s] %s: %s: %s: \"%s\"\n", os.date("%Y-%m-%d %H:%M:%S"), clientGUID, string.upper(type), clientName, table.concat({...}, " ")) + end + + et.trap_FS_Write(logLine, string.len(logLine), fileDescriptor) + + et.trap_FS_FCloseFile(fileDescriptor) +end + +function logs.writeAdmin(clientId, command, victimId, ...) + local fileDescriptor = files.open(settings.get("g_logAdmin"), et.FS_APPEND) + + local logLine + + local clientGUID = clientId and players.getGUID(clientId) or "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + local clientName = clientId and players.getName(clientId) or "console" + local clientFlags = "" + local args = table.concat({...}, " ") + + if settings.get("g_standalone") == 1 then + if victimId then + local victimName = players.getName(victimId) + logLine = string.format("[%s] %s: %s: %s: %s: \"%s\"\n", os.date("%Y-%m-%d %H:%M:%S"), clientGUID, clientName, command, victimName, args) + else + logLine = string.format("[%s] %s: %s: %s: \"%s\"\n", os.date("%Y-%m-%d %H:%M:%S"), clientGUID, clientName, command, args) + end + else + local levelTime = et.trap_Milliseconds() / 1000 + + if victimId then + local victimName = players.getName(victimId) + logLine = string.format("%3i:%02f: %i: %s: %s: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, victimId, victimName, args) + else + logLine = string.format("%3i:%02f: %i: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, args) + end + end + + et.trap_FS_Write(logLine, string.len(logLine), fileDescriptor) + + et.trap_FS_FCloseFile(fileDescriptor) +end + +return logs diff --git a/luamods/wolfadmin/util/settings.lua b/luamods/wolfadmin/util/settings.lua index 290d789..2083a50 100644 --- a/luamods/wolfadmin/util/settings.lua +++ b/luamods/wolfadmin/util/settings.lua @@ -21,6 +21,8 @@ local events = require (wolfa_getLuaPath()..".util.events") local settings = {} local data = { + ["g_logServer"] = "server.log", + ["g_logChat"] = "chat.log", ["g_logAdmin"] = "admin.log", ["g_fileGreetings"] = "greetings.cfg", ["g_fileRules"] = "rules.cfg",