Skip to content

Commit

Permalink
Make cannon 'fire' response optional, defaulting to off.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisjenkins75 authored and BuckarooBanzay committed Mar 8, 2021
1 parent 8450e4a commit e7f3f1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions digiline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spacecannon.digiline_handler_get = function(pos, node, channel)
digilines.receptor_send(pos, spacecannon.digiline_rules, channel, resp)
end

spacecannon.digiline_handler_fire = function(pos, node, channel)
spacecannon.digiline_handler_fire = function(pos, node, channel, msg)
local meta = minetest.get_meta(pos)

-- TODO: Add ability to set "target node" in the msg, and if its within
Expand Down Expand Up @@ -60,7 +60,14 @@ spacecannon.digiline_handler_fire = function(pos, node, channel)
pos = pos
}

digilines.receptor_send(pos, spacecannon.digiline_rules, channel, resp)
-- Only send response if the fire request specifically asked for it.
-- Consider a large (N) bank of cannons on the same digiline. Firing all N
-- at the same time would generate N responses, which would be seen by the LUAC
-- and the (N-1) other cannons, resulting in N^2 message processing. If N>20,
-- the LUAC will get fried.
if msg.verbose then
digilines.receptor_send(pos, spacecannon.digiline_rules, channel, resp)
end
end

spacecannon.digiline_effector = function(pos, node, channel, msg)
Expand Down
11 changes: 9 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ An "on" signal triggers a fire-action.
Fire a cannon:
```lua
if event.type == "program" then
digiline_send("cannon", { command="fire" })
digiline_send("cannon", { command="fire", verbose=false })
end
```

Expand Down Expand Up @@ -66,7 +66,14 @@ Example response from a "get" request:
}
```

Example response from a "fire" request:
The "fire" request can specify an optional "verbose" flag. If this flag
evaluates to true, then the following example response will be sent back.
Note that if you have a large number of cannons that you will likely want
to disable responses. N cannons firing and generating responses will
cause N^2 messages to be processed, as each cannon receives the fire response
from all of its peers. If N>20, your LUAC will overheat. N>900, and your
server admin will want to have a chat with you.

```lua
{
type = "digiline",
Expand Down

0 comments on commit e7f3f1e

Please sign in to comment.