Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lua/SimCallbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,34 @@ Callbacks.UpdateMarker = SimPing.UpdateMarker

Callbacks.FactionSelection = ScenarioFramework.OnFactionSelect

Callbacks.ToggleSelfDestruct = import("/lua/selfdestruct.lua").ToggleSelfDestruct
---@param data ToggleSelfDestructData
---@param units Unit[]
Callbacks.ToggleSelfDestruct = function(data, units)
-- prevent malformed input
if (not units) or (table.getn(units) == 0) then
return
end

-- prevent abuse
if (not data.owner) or (not OkayToMessWithArmy(data.owner)) then
return
end

-- moderation rule: if you self destruct with one or more ACUs in the selection when playing full
-- share, then you only self destruct the ACUs. This does not make it impossible to abuse, but it
-- does introduce a simple guardrail.
if ScenarioInfo.Options.Share == "FullShare" then
local commandUnits = EntityCategoryFilterDown(categories.COMMAND, SecureUnits(units))
if table.getn(commandUnits) > 0 then
import("/lua/selfdestruct.lua").ToggleSelfDestruct(data, commandUnits)
return
end
end
Comment on lines +195 to +204

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is trivial to bypass with UI mods splitting the user's order into two callback calls, so why not implement it in the UI layer? Then it's easy to have a handler with proper user feedback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also trivial to identify that this happened when parsing the replay. Malicious intent is then confirmed, easier to ban in my point of view.

You're free to also implement something in the UI layer, by all means.


-- otherwise just pass it through as usual
import("/lua/selfdestruct.lua").ToggleSelfDestruct(data, units)
Comment thread
Garanas marked this conversation as resolved.
end


Callbacks.MarkerOnScreen = import("/lua/simcameramarkers.lua").MarkerOnScreen

Expand Down
6 changes: 5 additions & 1 deletion lua/selfdestruct.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ local CancelCountdown = CancelCountdown
local ForkThread = ForkThread
local KillThread = KillThread

---@class ToggleSelfDestructData
---@field owner number
---@field noDelay boolean

-- prevent magic numbers
local countdownDuration = 5

Expand All @@ -20,7 +24,7 @@ local function SelfDestructThread(unit)
end

--- Toggles the destruction of the units
---@param data { owner: number, noDelay: boolean }
---@param data ToggleSelfDestructData
---@param units? Unit[]
function ToggleSelfDestruct(data, units)

Expand Down
Loading