mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 15:24:52 +09:00
Merge pull request #1012 from bbassie/feature/inventory-sync-tools
Add inspect and modify tools for inventory sync
This commit is contained in:
17 files changed
+1861
-65
No files matched your search
@@ -112,6 +112,8 @@ function player_sync.serialize_player(player, player_record)
|
||||
local failed_deserialization = get_script_data().failed_deserialization[player.name] or {}
|
||||
local serialized_player = serialize.serialize_player(player, failed_deserialization, player_record.components)
|
||||
serialized_player.generation = player_record.generation
|
||||
-- Always sent so the controller can tell this instance supports epochs
|
||||
serialized_player.epoch = player_record.epoch or 0
|
||||
|
||||
-- Leaving on the tick of a download the temporary bonus is still there and must not be uploaded. Removing it
|
||||
-- from the character here would shrink the main inventory before the armor's bonus applies and spill items.
|
||||
@@ -299,9 +301,15 @@ function player_sync.sync_player(acquire_response)
|
||||
end
|
||||
|
||||
local script_data = get_script_data()
|
||||
-- Epoch is bumped when an admin replaces or deletes the stored data
|
||||
local epoch = acquire_response.epoch or 0
|
||||
local finished_record = script_data.finished_downloads[acquire_response.player_name]
|
||||
if finished_record then
|
||||
if acquire_response.status == "acquired" and finished_record.generation == acquire_response.generation then
|
||||
if
|
||||
acquire_response.status == "acquired"
|
||||
and finished_record.generation == acquire_response.generation
|
||||
and (finished_record.epoch or 0) == epoch
|
||||
then
|
||||
player_sync.finish_download(player, finished_record)
|
||||
return
|
||||
end
|
||||
@@ -314,7 +322,11 @@ function player_sync.sync_player(acquire_response)
|
||||
local download_record = script_data.active_downloads[acquire_response.player_name]
|
||||
if download_record then
|
||||
-- Ignore the response if it affirms the current active download
|
||||
if acquire_response.status == "acquired" and download_record.generation == acquire_response.generation then
|
||||
if
|
||||
acquire_response.status == "acquired"
|
||||
and download_record.generation == acquire_response.generation
|
||||
and (download_record.epoch or 0) == epoch
|
||||
then
|
||||
game.print("Continuing active download")
|
||||
return
|
||||
end
|
||||
@@ -335,6 +347,8 @@ function player_sync.sync_player(acquire_response)
|
||||
-- download was started. Restart it.
|
||||
game.print("Restarting download")
|
||||
download_record.restart = true
|
||||
download_record.generation = acquire_response.generation
|
||||
download_record.epoch = epoch
|
||||
return
|
||||
end
|
||||
|
||||
@@ -363,15 +377,17 @@ function player_sync.sync_player(acquire_response)
|
||||
return
|
||||
end
|
||||
|
||||
local stale = (player_record.epoch or 0) ~= epoch
|
||||
if
|
||||
acquire_response.has_data
|
||||
and (
|
||||
not player_record.sync
|
||||
or stale
|
||||
or acquire_response.generation > player_record.generation
|
||||
or serialize.newly_synced(player_record.components, script_data.components)
|
||||
)
|
||||
then
|
||||
player_sync.initiate_inventory_download(player, player_record, acquire_response.generation)
|
||||
player_sync.initiate_inventory_download(player, player_record, acquire_response.generation, epoch)
|
||||
|
||||
else
|
||||
if acquire_response.generation == 0 then
|
||||
@@ -385,6 +401,14 @@ function player_sync.sync_player(acquire_response)
|
||||
start_sync(player_record, script_data.components)
|
||||
player_record.dirty = true
|
||||
player_record.sync_in_progress = false
|
||||
-- Deleted data keeps its generation and epoch so the next upload is accepted as the new baseline
|
||||
player_record.epoch = epoch
|
||||
-- A copy from another epoch has nothing to do with the stored generation
|
||||
if stale then
|
||||
player_record.generation = acquire_response.generation
|
||||
else
|
||||
player_record.generation = math.max(player_record.generation, acquire_response.generation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -408,6 +432,7 @@ function player_sync.finish_download(player, finished_record)
|
||||
player_record.sync_in_progress = false
|
||||
start_sync(player_record, finished_record.components)
|
||||
player_record.generation = finished_record.generation
|
||||
player_record.epoch = finished_record.epoch
|
||||
end
|
||||
|
||||
-- Download inventory from controller
|
||||
@@ -514,12 +539,13 @@ function player_sync.confirm_upload(player_name, generation)
|
||||
player_record.dirty = false
|
||||
end
|
||||
|
||||
function player_sync.initiate_inventory_download(player, player_record, generation)
|
||||
function player_sync.initiate_inventory_download(player, player_record, generation, epoch)
|
||||
player.print("Initiating inventory download...")
|
||||
local record = {
|
||||
started = game.ticks_played,
|
||||
last_active = game.ticks_played,
|
||||
generation = generation,
|
||||
epoch = epoch,
|
||||
data = "",
|
||||
}
|
||||
local script_data = get_script_data()
|
||||
|
||||
Reference in new issue
Block a user