Too much stuff to fix.

This commit is contained in:
ZioPao
2024-03-29 18:46:44 +01:00
parent 883a84412b
commit d73b1a3f43
13 changed files with 120 additions and 28 deletions

View File

@@ -1,7 +1,12 @@
if isClient() then return end -- The event makes this necessary to prevent clients from running this file
local StaticData = require("TOC/StaticData")
local CommandsData = require("TOC/CommandsData")
------------------------
local ServerDataHandler = {}
ServerDataHandler.modData = {}
@@ -21,10 +26,36 @@ function ServerDataHandler.AddTable(key, table)
if not luautils.stringStarts(key, StaticData.MOD_NAME .. "_") then return end
TOC_DEBUG.print("Received TOC ModData: " .. tostring(key))
TOC_DEBUG.printTable(table)
--TOC_DEBUG.printTable(table)
-- Set that the data has been modified and it's updated on the server
table.isUpdateFromServer = true
ModData.add(key, table) -- Add it to the server mod data
ServerDataHandler.modData[key] = table
-- 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)
TOC_DEBUG.print("Reapplying to " .. username)
-- Since getPlayerFromUsername doesn't work in mp, we're gonna do this workaround. ew
local onlinePlayers = getOnlinePlayers()
local selectedPlayer
for i=0, onlinePlayers:size() - 1 do
---@type IsoPlayer
local player = onlinePlayers:get(i)
if player:getUsername() == username then
selectedPlayer = player
break
end
end
TOC_DEBUG.print("Player username from IsoPlayer: " .. selectedPlayer:getUsername())
sendServerCommand(selectedPlayer, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveApplyFromServer, {})
end
Events.OnReceiveGlobalModData.Add(ServerDataHandler.AddTable)

View File

@@ -28,7 +28,6 @@ function ServerRelayCommands.RelayExecuteAmputationAction(surgeonPl, args)
sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveExecuteAmputationAction, params)
end
--* ADMIN ONLY *--
---Relay a local init from another client
---@param adminObj IsoPlayer