mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 23:04:52 +09:00
Remove extra whitespace in inventory_sync plugin
This commit is contained in:
1 parent
4a29c13acb
commit
cbfc0adf3d
7 files changed
+13
-13
No files matched your search
@@ -45,6 +45,6 @@ This plugin does event based synchronization of inventories. The data flow is as
|
||||
|
||||
12. Once the entire command is transfered, the scenario script clears the old inventory, applies the new inventory from the scenario script and sets the player to survival mode.
|
||||
|
||||
Communication between the server and instance goes over stdout or rcon, depending on the size of the data.
|
||||
Communication between the server and instance goes over stdout or rcon, depending on the size of the data.
|
||||
Communication between the instance and the master server goes over websockets.
|
||||
Overall, we are able to achieve a latency between 3 and infinite ticks from server join, depending on the size of the inventory. The major limiter is rcon transfer speeds with larger inventories, especially if they contain blueprints.
|
||||
@@ -1,5 +1,5 @@
|
||||
local inventories = {
|
||||
defines.inventory.character_main,
|
||||
defines.inventory.character_main,
|
||||
defines.inventory.character_guns,
|
||||
defines.inventory.character_ammo,
|
||||
defines.inventory.character_armor,
|
||||
|
||||
@@ -77,7 +77,7 @@ function download_inventory(player_name, data, number, total)
|
||||
end
|
||||
|
||||
-- Load crafting queue
|
||||
load_crafting_queue(serialized_player.crafting_queue, player)
|
||||
load_crafting_queue(serialized_player.crafting_queue, player)
|
||||
|
||||
-- Misc
|
||||
player.cheat_mode = serialized_player.cheat_mode
|
||||
|
||||
@@ -15,7 +15,7 @@ local handle_gui_events = function(event)
|
||||
-- Handle inventory dirtying
|
||||
if not global.inventory_sync.players[player.name].dirty_inventory then
|
||||
global.inventory_sync.players[player.name].dirty_inventory = true
|
||||
|
||||
|
||||
-- Restore player character
|
||||
ensure_character(player)
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
When a player leaves the game, serialize their inventory and upload it to the master.
|
||||
|
||||
When a player joins the game, wait until they have a character, then send a request to
|
||||
When a player joins the game, wait until they have a character, then send a request to
|
||||
the master server for the players inventory.
|
||||
|
||||
When the master sends an inventory, parse it and give it to the player.
|
||||
@@ -105,7 +105,7 @@ end
|
||||
-- Upload inventory when a player leaves the game. Triggers on restart after crash if player was online during crash.
|
||||
inventory_sync.events[defines.events.on_pre_player_left_game] = function(event)
|
||||
-- for some reason, on_pre_player_left_game gets called before on_server_startup so global isn't ready yet
|
||||
if not global.inventory_sync then
|
||||
if not global.inventory_sync then
|
||||
log("ERROR: Global inventory sync not defined")
|
||||
return
|
||||
end
|
||||
@@ -156,7 +156,7 @@ function inventory_sync.initiate_inventory_download(player)
|
||||
global.inventory_sync.players[player.name].sync_start_tick = game.tick
|
||||
end
|
||||
function inventory_sync.check_inventory_download_failed()
|
||||
-- Used for letting the master report the inventory download failing, like when the master is offline or an
|
||||
-- Used for letting the master report the inventory download failing, like when the master is offline or an
|
||||
-- error occurs somewhere in the server code. The player will be returned to a playable state.
|
||||
for name, data in pairs(global.inventory_sync.players) do
|
||||
if data.sync_start_tick ~= 0 and data.sync_start_tick <= game.tick - 600 then
|
||||
|
||||
@@ -20,7 +20,7 @@ function save_crafts(event)
|
||||
while player.crafting_queue_size > 0 do
|
||||
local old_queue = player.crafting_queue
|
||||
local queueItem = player.crafting_queue[1]
|
||||
|
||||
|
||||
-- Cancel craft
|
||||
player.cancel_crafting {
|
||||
index = 1,
|
||||
@@ -29,10 +29,10 @@ function save_crafts(event)
|
||||
|
||||
local rightmost_right_index = 0 -- 0 indexed since it is subtractive in a 1 indexed language
|
||||
local new_queue = player.crafting_queue
|
||||
while
|
||||
while
|
||||
new_queue ~= nil and
|
||||
new_queue[#new_queue - rightmost_right_index] ~= nil and
|
||||
new_queue[#new_queue - rightmost_right_index].count >= old_queue[#old_queue - rightmost_right_index].count
|
||||
new_queue[#new_queue - rightmost_right_index].count >= old_queue[#old_queue - rightmost_right_index].count
|
||||
do
|
||||
rightmost_right_index = rightmost_right_index + 1
|
||||
end
|
||||
@@ -48,7 +48,7 @@ function save_crafts(event)
|
||||
added = oldItem.count - newItem.count
|
||||
if oldItem.recipe ~= newItem.recipe then
|
||||
log("ERROR: Old item "..oldItem.recipe.." is not equal "..newItem.recipe)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- If the last item we added was of the same type, merge them in the queue
|
||||
@@ -63,7 +63,7 @@ function save_crafts(event)
|
||||
end
|
||||
-- game.print("Saved craft "..oldItem.recipe)
|
||||
end
|
||||
|
||||
|
||||
-- Find amount of items added and remove from inventory
|
||||
local new_items = inventory.get_contents()
|
||||
local difference = {}
|
||||
|
||||
@@ -73,7 +73,7 @@ function upload_inventory(playerIndex)
|
||||
end
|
||||
|
||||
clusterio_api.send_json("inventory_sync_upload", serialized_player)
|
||||
|
||||
|
||||
-- Clear saved crafting queue
|
||||
global.inventory_sync.saved_crafting_queue[player.name] = nil
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user