1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Shift command logging to free_item_logging, fix cases of server as actor (#427)

Shift command logging to free_item_logging, fix cases of server as actor
This commit is contained in:
Matthew 2018-11-23 12:07:44 -05:00 committed by Valansch
parent 3469225eaa
commit b9e360ce3a
4 changed files with 22 additions and 35 deletions

View File

@ -22,7 +22,6 @@ local function invoke(cmd)
local pos = game.player.surface.find_non_colliding_position('player', game.player.position, 0, 1)
game.players[target].teleport({pos.x, pos.y}, game.player.surface)
game.print(target .. ', get your ass over here!')
Utils.log_command(game.player.name, cmd.name, cmd.parameter)
end
--- Takes a target and teleports player to target. (admin only)
@ -41,7 +40,6 @@ local function teleport_player(cmd)
game.player.teleport(pos, surface)
game.print(target .. "! watcha doin'?!")
game.player.print('You have teleported to ' .. game.players[target].name)
Utils.log_command(game.player.name, cmd.name, cmd.parameter)
end
--- Takes a selected entity and teleports player to entity. (admin only)
@ -56,7 +54,6 @@ local function teleport_location(cmd)
end
local pos = game.player.surface.find_non_colliding_position('player', game.player.selected.position, 0, 1)
game.player.teleport(pos)
Utils.log_command(game.player.name, cmd.name, false)
end
--- Kill a player with fish as the cause of death.
@ -91,8 +88,8 @@ local function kill(cmd)
end
if global.walking then
if global.walking[player.index] == true or global.walking[target.index] == true then
player.print("A player on walkabout cannot be killed by a mere fish, don't waste your efforts.")
if (player and global.walking[player.index]) or global.walking[target.index] then
Game.player_print("A player on walkabout cannot be killed by a mere fish, don't waste your efforts.")
return
end
end
@ -110,7 +107,6 @@ local function kill(cmd)
if not do_fish_kill(target) then
Game.player_print(table.concat {"'Sorry, '", target.name, "' doesn't have a character to kill."})
end
Utils.log_command(game.player.name, cmd.name, param)
else
Game.player_print("Sorry you don't have permission to use the kill command on other players.")
end
@ -146,10 +142,8 @@ local function regular(cmd)
return
elseif (params[1] == 'promote') then
UserGroups.add_regular(params[2])
Utils.log_command(game.player.name, cmd.name, cmd.parameter)
elseif (params[1] == 'demote') then
UserGroups.remove_regular(params[2])
Utils.log_command(game.player.name, cmd.name, cmd.parameter)
else
Game.player_print('Command failed. Usage: /regular <promote, demote>, <player>')
end
@ -231,11 +225,9 @@ local function toggle_tp_mode(cmd)
if toggled then
global.tp_players[index] = nil
Game.player_print('tp mode is now off')
Utils.log_command(game.player.name, cmd.name, 'off')
else
global.tp_players[index] = true
Game.player_print('tp mode is now on - place a ghost entity to teleport there.')
Utils.log_command(game.player.name, cmd.name, 'on')
end
end
@ -290,7 +282,6 @@ local function tempban(cmd)
local group = get_group()
game.print(Utils.get_actor() .. ' put ' .. params[1] .. ' in timeout for ' .. params[2] .. ' minutes.')
Utils.log_command(game.player.name, cmd.name, cmd.parameter)
if group then
group.add_player(params[1])
if not tonumber(cmd.parameter) then
@ -336,7 +327,6 @@ local function pool(cmd)
end
game.player.surface.set_tiles(t)
game.player.surface.create_entity {name = 'fish', position = {p.x + 0.5, p.y + 5}}
Utils.log_command(game.player.name, cmd.name, false)
end
end
@ -488,7 +478,6 @@ commands.add_command(
function()
if game.player and game.player.admin then
game.player.cheat_mode = not game.player.cheat_mode
Utils.log_command(game.player, 'hax', false)
end
end
)

View File

@ -86,9 +86,8 @@ local function popup(cmd)
show_popup(p, message)
end
player.print('Popup sent')
Utils.print_admins(player.name .. ' sent a popup to all players', false)
Utils.log_command(game.player.name, cmd.name, cmd.parameter)
Game.player_print('Popup sent')
Utils.print_admins(Utils.get_actor() .. ' sent a popup to all players', false)
end
-- Creates a popup dialog for all players, specifically for the server upgrading factorio versions
@ -105,9 +104,8 @@ local function popup_update(cmd)
show_popup(p, message)
end
player.print('Popup sent')
Utils.print_admins(player.name .. ' sent a popup to all players', false)
Utils.log_command(game.player.name, cmd.name, message)
Game.player_print('Popup sent')
Utils.print_admins(Utils.get_actor() .. ' sent a popup to all players', false)
end
-- Creates a popup dialog for the specifically targetted player
@ -141,8 +139,7 @@ local function popup_player(cmd)
show_popup(target, message)
player.print('Popup sent')
Utils.log_command(game.player.name, cmd.name, cmd.parameter)
Game.player_print('Popup sent')
end
commands.add_command('popup', '<message> - Shows a popup to all connected players (Admins only)', popup)

View File

@ -207,7 +207,7 @@ function Module.jail(target_player, player)
target_player.print('Please respond to inquiries from the admins.', {r = 1, g = 1, b = 0, a = 1})
target_player.print(prefix_e)
Utils.print_admins(target_player.name .. ' has been jailed by ' .. player.name)
Utils.log_command(player, 'jail', target_player.name)
Utils.log_command(Utils.get_actor(), 'jail', target_player.name)
else
-- Let admin know it didn't work.
print('Something went wrong in the jailing of ' .. target_player.name .. '. You can still change their group via /permissions.')
@ -264,7 +264,7 @@ function Module.unjail_player(cmd)
target_player.print('Your ability to perform actions has been restored', {r = 0, g = 1, b = 0, a = 1})
target_player.print(prefix_e)
Utils.print_admins(target_player.name .. ' has been released from jail by ' .. player.name)
Utils.log_command(player, 'unjail', target_player.name)
Utils.log_command(Utils.get_actor(), 'unjail', target_player.name)
else
-- Let admin know it didn't work.
Game.player_print('Something went wrong in the unjailing of ' .. target .. '. You can still change their group via /permissions and inform them.')

View File

@ -16,7 +16,9 @@ Module.print_except = function(msg, player)
end
end
-- Takes a LuaPlayer or string as source
--- Prints a message to all online admins
--@param1 The message to print, as a string
--@param2 The source of the message, as a string, LuaPlayer, or nil.
Module.print_admins = function(msg, source)
local source_name
local chat_color
@ -41,6 +43,7 @@ Module.print_admins = function(msg, source)
end
end
--- Returns a valid string with the name of the actor of a command.
Module.get_actor = function()
if game.player then
return game.player.name
@ -119,22 +122,20 @@ Module.format_time = function(ticks)
return table.concat(result, ' ')
end
--- Prints a message letting the player know they cannot run a command
-- @param1 name of the command
Module.cant_run = function(name)
Game.player_print("Can't run command (" .. name .. ') - insufficient permission.')
end
Module.log_command = function(user, command, parameters)
local name
-- We can use a LuaPlayer or a string (ex. "Server").
if type(user) == 'string' then
name = user
else
name = user.name
end
local action = table.concat {'[Admin-Command] ', name, ' used: ', command}
--- Logs the use of a command and its user
-- @param1 takes a string with the actor's name (usually acquired by calling get_actor)
-- @param2 the command's name as table element
-- @param3 the command's parameters as a table element (optional)
Module.log_command = function(actor, command, parameters)
local action = table.concat {'[Admin-Command] ', actor, ' used: ', command}
if parameters then
action = table.concat {'[Admin-Command] ', name, ' used: ', command, ' ', parameters}
action = table.concat {action, ' ', parameters}
end
log(action)
end