mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Add general event logging (#313)
* Update _file_loader.lua * Create logging.lua * Create logging.lua * Update logging.lua * Update logging.lua * Update logging.lua * Update logging.lua * Update logging.lua
This commit is contained in:
@@ -67,6 +67,7 @@ return {
|
||||
'modules.addons.nukeprotect',
|
||||
'modules.addons.inserter',
|
||||
'modules.addons.miner',
|
||||
'modules.addons.logging',
|
||||
|
||||
-- Control
|
||||
'modules.control.vlayer',
|
||||
|
||||
43
config/logging.lua
Normal file
43
config/logging.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
--- Settings for logging
|
||||
-- @config logging
|
||||
|
||||
return {
|
||||
file_name = 'log/logging.log',
|
||||
rocket_launch_display = {
|
||||
[1] = true,
|
||||
[2] = true,
|
||||
[5] = true,
|
||||
[10] = true,
|
||||
[20] = true,
|
||||
[50] = true,
|
||||
[100] = true,
|
||||
[200] = true,
|
||||
[500] = true,
|
||||
[1000] = true,
|
||||
[2000] = true,
|
||||
[5000] = true,
|
||||
[10000] = true,
|
||||
[20000] = true,
|
||||
[50000] = true,
|
||||
[100000] = true,
|
||||
[200000] = true,
|
||||
[500000] = true,
|
||||
[1000000] = true,
|
||||
[2000000] = true,
|
||||
[5000000] = true,
|
||||
[10000000] = true
|
||||
},
|
||||
disconnect_reason = {
|
||||
[defines.disconnect_reason.quit] = ' left the game',
|
||||
[defines.disconnect_reason.dropped] = ' was dropped from the game',
|
||||
[defines.disconnect_reason.reconnect] = ' is reconnecting',
|
||||
[defines.disconnect_reason.wrong_input] = ' was having a wrong input',
|
||||
[defines.disconnect_reason.desync_limit_reached] = ' had desync limit reached',
|
||||
[defines.disconnect_reason.cannot_keep_up] = ' cannot keep up',
|
||||
[defines.disconnect_reason.afk] = ' was afk',
|
||||
[defines.disconnect_reason.kicked] = ' was kicked',
|
||||
[defines.disconnect_reason.kicked_and_deleted] = ' was kicked and deleted',
|
||||
[defines.disconnect_reason.banned] = ' was banned',
|
||||
[defines.disconnect_reason.switching_servers] = ' is switching servers'
|
||||
}
|
||||
}
|
||||
71
modules/addons/logging.lua
Normal file
71
modules/addons/logging.lua
Normal file
@@ -0,0 +1,71 @@
|
||||
--[[-- Addon Logging
|
||||
@addon Logging
|
||||
]]
|
||||
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local config = require 'config.logging' --- @dep config.logging
|
||||
local config_res = require 'config.research' --- @dep config.research
|
||||
|
||||
local function add_log(data)
|
||||
game.write_file(config.file_name, data .. '\n', true, 0)
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_rocket_launched, function(event)
|
||||
if event and event.rocket and event.rocket.force and event.rocket.force.rockets_launched then
|
||||
if config.rocket_launch_display[event.rocket.force.rockets_launched] then
|
||||
add_log('[ROCKET] ' .. event.rocket.force.rockets_launched .. ' rockets launched')
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_pre_player_died, function(event)
|
||||
if event and event.player_index then
|
||||
if event.cause then
|
||||
if event.cause.type and event.cause.type == 'character' and event.cause.player and event.cause.player.index then
|
||||
add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of ' .. (game.players[event.cause.player.index].name or ' unknown reason'))
|
||||
|
||||
else
|
||||
add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of ' .. (event.cause.name or ' unknown reason'))
|
||||
end
|
||||
|
||||
else
|
||||
add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of unknown reason')
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_research_finished, function(event)
|
||||
if event and event.research then
|
||||
if event.by_script then
|
||||
return
|
||||
end
|
||||
|
||||
if event.research.level and event.research.level > 1 then
|
||||
if config_res.inf_res[event.research.name] and (event.research.level >= config_res.inf_res[event.research.name]) then
|
||||
add_log('[RES] ' .. string.match(event.research.name, '^(.-)%-%d+$'):gsub('-', ' ') .. ' at level ' .. (event.research.level - 1) .. ' has been researched')
|
||||
else
|
||||
add_log('[RES] ' .. string.match(event.research.name, '^(.-)%-%d+$'):gsub('-', ' ') .. ' at level ' .. event.research.level .. ' has been researched')
|
||||
end
|
||||
|
||||
else
|
||||
add_log('[RES] ' .. string.match(event.research.name, '^(.-)%-%d+$'):gsub('-', ' ') .. ' has been researched')
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_joined_game, function(event)
|
||||
if event and event.player_index then
|
||||
add_log('[JOIN] ' .. game.players[event.player_index].name .. ' joined the game')
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_left_game, function(event)
|
||||
if event and event.player_index then
|
||||
if event.reason then
|
||||
add_log('[LEAVE] ' .. game.players[event.player_index].name .. config.disconnect_reason[event.reason])
|
||||
|
||||
else
|
||||
add_log('[LEAVE] ' .. game.players[event.player_index].name .. config.disconnect_reason[defines.disconnect_reason.quit])
|
||||
end
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user