mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-03 22:52:13 +02:00
Fix banned player's inventory dump. (#1272)
This commit is contained in:
parent
b0a71d74b5
commit
5e57cac9aa
@ -29,6 +29,9 @@ require 'features.player_create'
|
||||
require 'features.rank_system'
|
||||
require 'features.redmew_settings_sync'
|
||||
|
||||
-- Always required so dumping banned player's inventories works.
|
||||
require 'features.dump_offline_inventories'
|
||||
|
||||
if config.player_colors.enabled then
|
||||
require 'features.player_colors'
|
||||
end
|
||||
@ -53,9 +56,7 @@ end
|
||||
if config.death_corpse_tags.enabled then
|
||||
require 'features.death_corpse_tags'
|
||||
end
|
||||
if config.dump_offline_inventories.enabled then
|
||||
require 'features.dump_offline_inventories'
|
||||
end
|
||||
|
||||
if config.admin_commands.enabled then
|
||||
require 'features.admin_commands'
|
||||
end
|
||||
|
@ -6,34 +6,23 @@ local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local Global = require 'utils.global'
|
||||
local CorpseUtil = require 'features.corpse_util'
|
||||
local Config = require 'config'
|
||||
|
||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||
local config = global.config.dump_offline_inventories
|
||||
local offline_timout_mins = config.offline_timout_mins
|
||||
local config = Config.dump_offline_inventories
|
||||
|
||||
local offline_player_queue = {}
|
||||
local banned_players = {}
|
||||
|
||||
Global.register({offline_player_queue = offline_player_queue, banned_players = banned_players}, function(tbl)
|
||||
Global.register({offline_player_queue = offline_player_queue}, function(tbl)
|
||||
offline_player_queue = tbl.offline_player_queue
|
||||
banned_players = tbl.banned_players
|
||||
config = Config.dump_offline_inventories
|
||||
end)
|
||||
|
||||
local spawn_player_corpse = Token.register(function(data)
|
||||
local player = data.player
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local function spawn_player_corpse(player, banned, timeout_minutes)
|
||||
local player_index = player.index
|
||||
local queue_data = offline_player_queue[player_index]
|
||||
if queue_data ~= data.tick then
|
||||
return
|
||||
end
|
||||
|
||||
offline_player_queue[player_index] = nil
|
||||
|
||||
if player.connected then
|
||||
if not banned and player.connected then
|
||||
return
|
||||
end
|
||||
|
||||
@ -77,58 +66,74 @@ local spawn_player_corpse = Token.register(function(data)
|
||||
text = text
|
||||
})
|
||||
|
||||
local message = {
|
||||
'dump_offline_inventories.inventory_location',
|
||||
player.name,
|
||||
offline_timout_mins,
|
||||
string.format('%.1f', position.x),
|
||||
string.format('%.1f', position.y),
|
||||
player.surface.name
|
||||
}
|
||||
local message
|
||||
if banned then
|
||||
message = {
|
||||
'dump_offline_inventories.banned_inventory_location',
|
||||
player.name,
|
||||
string.format('%.1f', position.x),
|
||||
string.format('%.1f', position.y),
|
||||
player.surface.name
|
||||
}
|
||||
else
|
||||
message = {
|
||||
'dump_offline_inventories.inventory_location',
|
||||
player.name,
|
||||
timeout_minutes,
|
||||
string.format('%.1f', position.x),
|
||||
string.format('%.1f', position.y),
|
||||
player.surface.name
|
||||
}
|
||||
end
|
||||
|
||||
game.print(message)
|
||||
|
||||
if tag then
|
||||
CorpseUtil.add_tag(tag, player_index, game.tick, false)
|
||||
end
|
||||
end
|
||||
|
||||
local spawn_player_corpse_token = Token.register(function(data)
|
||||
local player = data.player
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local queue_data = offline_player_queue[player.index]
|
||||
if queue_data ~= data.tick then
|
||||
return
|
||||
end
|
||||
|
||||
spawn_player_corpse(player, false, data.timeout_minutes)
|
||||
end)
|
||||
|
||||
local function start_timer(event, timeout)
|
||||
local function start_timer(event, timeout_minutes)
|
||||
local player_index = event.player_index
|
||||
local player = game.get_player(player_index)
|
||||
|
||||
if player and player.valid and player.character then -- if player leaves before respawning they wont have a character and we don't need to add them to the list
|
||||
if player and player.valid and player.character then -- if player leaves before respawning they wont have a character and we don't need to add them to the list.
|
||||
local tick = game.tick
|
||||
local timeout = timeout_minutes * 60 * 60
|
||||
|
||||
offline_player_queue[player_index] = tick -- tick is used to check that the callback happens after X minutes as multiple callbacks may be active if the player logs off and on multiple times
|
||||
set_timeout_in_ticks(timeout, spawn_player_corpse, {player = player, tick = tick})
|
||||
set_timeout_in_ticks(timeout, spawn_player_corpse_token,
|
||||
{player = player, tick = tick, timeout_minutes = timeout_minutes})
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_pre_player_left_game, function(event)
|
||||
-- If the player is banned we don't want to start a new timer as it will overwrite the previous short timer set when banning.
|
||||
local player_index = event.player_index
|
||||
if not player_index or banned_players[player_index] then
|
||||
if not config.enabled then
|
||||
return
|
||||
end
|
||||
|
||||
local timeout = offline_timout_mins * 60 * 60
|
||||
start_timer(event, timeout)
|
||||
start_timer(event, config.offline_timout_mins)
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_banned, function(event)
|
||||
local player_index = event.player_index
|
||||
if not player_index then
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
banned_players[player_index] = true
|
||||
start_timer(event, 60)
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_unbanned, function(event)
|
||||
local player_index = event.player_index
|
||||
if not player_index then
|
||||
return
|
||||
end
|
||||
|
||||
banned_players[player_index] = nil
|
||||
spawn_player_corpse(player, true, 0)
|
||||
end)
|
||||
|
@ -186,6 +186,7 @@ empty_corpse=[color=red][Corpse][/color]Your corpse was empty and has been remov
|
||||
|
||||
[dump_offline_inventories]
|
||||
inventory_location=[color=blue][Corpse][/color] __1__ has been offline __2__ minutes. Their inventory is now available at [gps=__3__,__4__,__5__]
|
||||
banned_inventory_location=[color=blue][Corpse][/color] __1__ has been banned. Their inventory is now available at [gps=__2__,__3__,__4__]
|
||||
|
||||
[landfill_remover]
|
||||
rank_too_low=You must be auto trusted or above to use the deconstruction planner on landfill.
|
||||
|
Loading…
Reference in New Issue
Block a user