Cleaning MP handlers

This commit is contained in:
Pao
2023-02-10 01:30:33 +01:00
parent 65ca3d285e
commit dad01605d0
15 changed files with 320 additions and 241 deletions

View File

@@ -5,7 +5,7 @@
local ServerCommands = {}
ServerCommands["ResponseCanAct"] = function(arg)
ServerCommands.ResponseCanAct = function(arg)
print("TOC: ResponseCanAct")
@@ -21,7 +21,7 @@ end
ServerCommands["CanCutLimb"] = function(arg)
ServerCommands.CanCutLimb = function(arg)
local part_name = arg["toSend"]
arg["To"] = arg["From"]
@@ -31,21 +31,14 @@ ServerCommands["CanCutLimb"] = function(arg)
sendClientCommand("TOC", "SendServer", arg)
end
ServerCommands["CutLimb"] = function(arg)
local arg = arg["toSend"]
--local surgeon_id = arg[5]
-- Disable the sound coming from the surgeon
--getPlayerByOnlineID(surgeon_id):getEmitter():stopSoundByName("Amputation_Sound")
TocCutLimb(arg[1], arg[2], arg[3], arg[4])
ServerCommands.CutLimb = function(arg)
local data = arg["toSend"]
TocCutLimb(data[1], data[2], data[3], data[4])
end
ServerCommands["CanOperateLimb"] = function(arg)
ServerCommands.CanOperateLimb = function(arg)
local part_name = arg["toSend"]
arg["To"] = arg["From"]
@@ -54,13 +47,14 @@ ServerCommands["CanOperateLimb"] = function(arg)
arg["toSend"] = { part_name, "Operate", CheckIfCanBeOperated(part_name) }
sendClientCommand("TOC", "SendServer", arg)
end
ServerCommands["OperateLimb"] = function(arg)
local arg = arg["toSend"]
TocOperateLimb(arg[1], arg[2], arg[3])
ServerCommands.OperateLimb = function(arg)
local data = arg["toSend"]
TocOperateLimb(data[1], data[2], data[3])
end
ServerCommands["CanEquipProsthesis"] = function(arg)
ServerCommands.CanEquipProsthesis = function(arg)
local part_name = arg["toSend"]
--local item = arg["toSend"][2] -- TODO Add item prosth here
@@ -71,19 +65,18 @@ ServerCommands["CanEquipProsthesis"] = function(arg)
sendClientCommand("TOC", "SendServer", arg)
end
ServerCommands["EquipProsthesis"] = function(arg)
ServerCommands.EquipProsthesis = function(arg)
-- part_name = arg[1]
-- prosthesis = arg[2]
local arg = arg["toSend"]
TocEquipProsthesis(arg[1], arg[2])
local data = arg["toSend"]
TocEquipProsthesis(data[1], data[2])
end
ServerCommands["CanUnequipProsthesis"] = function(arg)
ServerCommands.CanUnequipProsthesis = function(arg)
local part_name = arg["toSend"]
arg["To"] = arg["From"]
arg["From"] = getPlayer():getOnlineID()
@@ -91,19 +84,18 @@ ServerCommands["CanUnequipProsthesis"] = function(arg)
arg["toSend"] = { part_name, "Unequip", CheckIfProsthesisCanBeUnequipped(part_name)}
sendClientCommand("TOC", "SendServer", arg)
end
ServerCommands["UnequipProsthesis"] = function(arg)
ServerCommands.UnequipProsthesis = function(arg)
-- part_name = arg[1]
local arg = arg["toSend"]
TheOnlyCure.TocUnequipProsthesis(arg[1], arg[2])
local data = arg["toSend"]
TheOnlyCure.TocUnequipProsthesis(data[1], data[2])
end
ServerCommands["CanResetEverything"] = function(arg)
ServerCommands.CanResetEverything = function(arg)
local part_name = "RightHand" --useless
arg["To"] = arg["From"]
@@ -112,22 +104,20 @@ ServerCommands["CanResetEverything"] = function(arg)
arg["toSend"] = { part_name, "Cut", true }
sendClientCommand("TOC", "SendServer", arg)
end
ServerCommands["ResetEverything"] = function(_)
ServerCommands.ResetEverything = function(_)
TocResetEverything()
end
-- Used when amputating the limb of another player
ServerCommands["AcceptDamageOtherPlayer"] = function(arg)
local patient_id = arg[1]
ServerCommands.AcceptDamageOtherPlayer = function(arg)
local patient = getPlayerByOnlineID(arg[1])
local part_name = arg[2]
TocDamagePlayerDuringAmputation(patient, part_name)
end
-- Used to propagate animation changes after amputating a foot
ServerCommands["SetCrawlAnimation"] = function(args)
ServerCommands.SetCrawlAnimation = function(args)
local player = getPlayerByOnlineID(args.id)
local check = args.check
@@ -137,7 +127,7 @@ ServerCommands["SetCrawlAnimation"] = function(args)
end
-- Used to propagate the stop of the sound of amputation
ServerCommands["StopAmputationSound"] = function(args)
ServerCommands.StopAmputationSound = function(args)
local player = getPlayerByOnlineID(args.surgeon_id)
player:getEmitter():stopSoundByName("Amputation_Sound")

View File

@@ -249,6 +249,7 @@ local function TocUpdateEveryOneMinute()
-- Sends only Limbs since the other stuff is mostly static
if toc_data ~= nil then
-- FIXME Send little packets instead of the whole thing?
-- TODO we shouldn't run this if we're in SP I guess?
sendClientCommand(player, 'TOC', 'ChangePlayerState', { toc_data.Limbs } )
end

View File

@@ -1,21 +1,18 @@
--- A rly big thx to Fenris_Wolf and Chuck to help me with that. Love you guy
---Server side
local TOC_Commands = {}
local ClientCommands = {}
-- TODO rework this
TOC_Commands.SendServer = function(player, arg)
-- Main handler of base functions for TOC, not changed till now 'cause it works
ClientCommands.SendServer = function(player, arg)
local otherPlayer = getPlayerByOnlineID(arg["To"])
sendServerCommand(otherPlayer, "TOC", arg["command"], arg)
end
-- Cut Limb stuff
TOC_Commands["AskDamageOtherPlayer"] = function(_, arg)
-- Cutting Limbs
ClientCommands.AskDamageOtherPlayer = function(_, arg)
local patient = getPlayerByOnlineID(arg[1])
local patient_id = arg[1]
@@ -25,9 +22,16 @@ TOC_Commands["AskDamageOtherPlayer"] = function(_, arg)
end
ClientCommands.AskStopAmputationSound = function(_, args)
-------- ANIMATIONS
TOC_Commands["NotifyNewCrawlAnimation"] = function(player, args)
print("TOC: We're in AskStopAmputationSound")
sendServerCommand("TOC", "StopAmputationSound", {surgeon_id = args.surgeon_id})
end
-- Animations
ClientCommands.NotifyNewCrawlAnimation = function(player, args)
sendServerCommand("TOC", "SetCrawlAnimation", {id = args.id, check = args.check})
@@ -36,22 +40,15 @@ end
-- CHEATING STUFF
TOC_Commands["AskToResetEverything"] = function(_, arg)
-- Cheats
ClientCommands.AskToResetEverything = function(_, arg)
local clicked_player = getPlayerByOnlineID(arg[1])
sendServerCommand(clicked_player, "TOC", "ResetEverything", {})
end
TOC_Commands.AskStopAmputationSound = function(_, args)
print("TOC: We're in AskStopAmputationSound")
sendServerCommand("TOC", "StopAmputationSound", {surgeon_id = args.surgeon_id})
end
TOC_Commands.ChangePlayerState = function(playerObj, args)
-- Global Mod Data data handler
ClientCommands.ChangePlayerState = function(playerObj, args)
ModData.get("TOC_PLAYER_DATA")[playerObj:getUsername()] = args
ModData.transmit("TOC_PLAYER_DATA")
end
@@ -68,17 +65,12 @@ Events.OnInitGlobalModData.Add(TOC_OnInitGlobalModData)
------------------------------------------------------
TOC_Commands.OnClientCommand = function(module, command, playerObj, args)
print("TOC: Running ClientCommand " .. command)
if module == 'TOC' and TOC_Commands[command] then
TOC_Commands[command](playerObj, args)
local function OnClientCommand(module, command, playerObj, args)
if module == 'TOC' and ClientCommands[command] then
ClientCommands[command](playerObj, args)
end
end
Events.OnClientCommand.Add(TOC_Commands.OnClientCommand)
Events.OnClientCommand.Add(OnClientCommand)