1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-30 23:17:53 +02:00
ComfyFactorio/utils/command_handler.lua
2021-12-05 22:15:49 +01:00

61 lines
1.5 KiB
Lua

local Event = require 'utils.event'
local Server = require 'utils.server'
local Timestamp = require 'utils.timestamp'
local format = string.format
local function on_console_command(event)
local cmd = event.command
if not event.player_index then
return
end
local player = game.players[event.player_index]
local param = event.parameters
if not player.admin then
return
end
local server_time = Server.get_current_time()
if server_time then
server_time = format(' (Server time: %s)', Timestamp.to_string(server_time))
else
server_time = ' at tick: ' .. game.tick
end
if string.len(param) <= 0 then
param = nil
end
local commands = {
['editor'] = true,
['command'] = true,
['silent-command'] = true,
['sc'] = true,
['debug'] = true
}
if not commands[cmd] then
return
end
if player then
if param then
print('[COMMAND HANDLER] ' .. player.name .. ' ran: ' .. cmd .. ' "' .. param .. '" ' .. server_time)
return
else
print('[COMMAND HANDLER] ' .. player.name .. ' ran: ' .. cmd .. server_time)
return
end
else
if param then
print('[COMMAND HANDLER] ran: ' .. cmd .. ' "' .. param .. '" ' .. server_time)
return
else
print('[COMMAND HANDLER] ran: ' .. cmd .. server_time)
return
end
end
end
Event.add(defines.events.on_console_command, on_console_command)