From aadbe02df42515dc3ba69b24dcb1612d400b1eab Mon Sep 17 00:00:00 2001 From: ZioPao Date: Sun, 5 May 2024 00:14:37 +0200 Subject: [PATCH] Fixed sync with server after setup to prevent issues with medical check --- .../client/TOC/Controllers/DataController.lua | 18 ++++++++++++++---- media/lua/server/TOC/ServerDataHandler.lua | 8 +++++++- media/lua/shared/TOC/StaticData.lua | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/media/lua/client/TOC/Controllers/DataController.lua b/media/lua/client/TOC/Controllers/DataController.lua index 9157b43..eaaa512 100644 --- a/media/lua/client/TOC/Controllers/DataController.lua +++ b/media/lua/client/TOC/Controllers/DataController.lua @@ -57,6 +57,7 @@ function DataController:setup(key) ---@type tocModDataType self.tocData = { -- Generic stuff that does not belong anywhere else + isInitializing = true, isIgnoredPartInfected = false, isAnyLimbCut = false, limbs = {}, @@ -86,9 +87,16 @@ function DataController:setup(key) } end - -- Add it to global mod data + -- Add it to client global mod data ModData.add(key, self.tocData) + -- Sync with the server + self:apply() + + -- -- Disable lock + -- self.tocData.isInitializing = false + -- ModData.add(key, self.tocData) + end ---In case of desync between the table on ModData and the table here @@ -100,7 +108,7 @@ function DataController:applyOnlineData(tocData) end ---@param key string -function DataController:loadLocalData(key) +function DataController:tryLoadLocalData(key) self.tocData = ModData.get(key) --TOC_DEBUG.printTable(self.tocData) @@ -389,6 +397,7 @@ function DataController.ReceiveData(key, data) -- TODO Add update from server scenario if handler.isResetForced then + TOC_DEBUG.print("Forced reset") handler:setup(key) elseif data then if data.isUpdateFromServer then @@ -396,7 +405,8 @@ function DataController.ReceiveData(key, data) end handler:applyOnlineData(data) elseif username == getPlayer():getUsername() then - handler:loadLocalData(key) + TOC_DEBUG.print("loading local data") + handler:tryLoadLocalData(key) end @@ -436,7 +446,7 @@ Events.OnReceiveGlobalModData.Add(DataController.ReceiveData) --- SP Only initialization ---@param key string function DataController:initSinglePlayer(key) - self:loadLocalData(key) + self:tryLoadLocalData(key) if self.tocData == nil or self.isResetForced then self:setup(key) end diff --git a/media/lua/server/TOC/ServerDataHandler.lua b/media/lua/server/TOC/ServerDataHandler.lua index 253ff67..e302f46 100644 --- a/media/lua/server/TOC/ServerDataHandler.lua +++ b/media/lua/server/TOC/ServerDataHandler.lua @@ -29,12 +29,18 @@ function ServerDataHandler.AddTable(key, table) --TOC_DEBUG.printTable(table) -- Set that the data has been modified and it's updated on the server - table.isUpdateFromServer = true + table.isUpdateFromServer = true -- FIX this is useless ModData.add(key, table) -- Add it to the server mod data ServerDataHandler.modData[key] = table + -- if table.isInitializing == true then + -- TOC_DEBUG.print("Applied data after setup") + -- table.isInitializing = false + -- end + + -- Since this could be triggered by a different client than the one referenced in the key, we're gonna -- apply the changes back to the key client again to be sure that everything is in sync local username = CommandsData.GetUsername(key) diff --git a/media/lua/shared/TOC/StaticData.lua b/media/lua/shared/TOC/StaticData.lua index 7d8d168..2d3c47f 100644 --- a/media/lua/shared/TOC/StaticData.lua +++ b/media/lua/shared/TOC/StaticData.lua @@ -2,7 +2,7 @@ ---@alias limbsTable {Hand_L : partDataType, ForeArm_L : partDataType, UpperArm_L : partDataType, Hand_R : partDataType, ForeArm_R : partDataType, UpperArm_R : partDataType } ---@alias prosthesisData {isProstEquipped : boolean, prostFactor : number } ---@alias prosthesesTable {Top_L : prosthesisData, Top_R : prosthesisData } -- TODO add Bottom_L and Bottom_R ----@alias tocModDataType { limbs : limbsTable, prostheses : prosthesesTable, isIgnoredPartInfected : boolean, isAnyLimbCut : boolean, isUpdateFromServer : boolean } +---@alias tocModDataType { limbs : limbsTable, prostheses : prosthesesTable, isIgnoredPartInfected : boolean, isAnyLimbCut : boolean, isUpdateFromServer : boolean, isInitializing : boolean} ---------------------------