summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2016-12-24 01:56:06 -0600
committercheapie <no-email-for-you@example.com>2016-12-24 01:56:06 -0600
commit99eab9dd58223664a6e78da4def93f69f38d1990 (patch)
treeae2be68ea08075ad855e61e60179c30d41d41c2c /init.lua
parent6273c27d944151404ce046aab5a03043be7a17e8 (diff)
downloaddigistuff-99eab9dd58223664a6e78da4def93f69f38d1990.tar
digistuff-99eab9dd58223664a6e78da4def93f69f38d1990.tar.gz
digistuff-99eab9dd58223664a6e78da4def93f69f38d1990.tar.bz2
digistuff-99eab9dd58223664a6e78da4def93f69f38d1990.tar.xz
digistuff-99eab9dd58223664a6e78da4def93f69f38d1990.zip
Add modem
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua49
1 files changed, 49 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index e9b1cf7..1eb13b4 100644
--- a/init.lua
+++ b/init.lua
@@ -756,3 +756,52 @@ minetest.register_node("digistuff:piezo", {
},
},
})
+
+local http = minetest.request_http_api()
+
+if http then
+ minetest.register_node("digistuff:modem", {
+ description = "Digilines Modem",
+ groups = {cracky=3},
+ on_construct = function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("formspec","field[channel;Channel;${channel}")
+ end,
+ tiles = {
+ "digistuff_piezo_top.png",
+ "digistuff_piezo_sides.png",
+ "digistuff_piezo_sides.png",
+ "digistuff_piezo_sides.png",
+ "digistuff_piezo_sides.png",
+ "digistuff_piezo_sides.png"
+ },
+ on_receive_fields = function(pos, formname, fields, sender)
+ local name = sender:get_player_name()
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.record_protection_violation(pos,name)
+ return
+ end
+ local meta = minetest.get_meta(pos)
+ if fields.channel then meta:set_string("channel",fields.channel) end
+ end,
+ digiline =
+ {
+ receptor = {},
+ effector = {
+ action = function(pos,node,channel,msg)
+ local meta = minetest.get_meta(pos)
+ if meta:get_string("channel") ~= channel then return end
+ if type(msg) ~= "string" then return end
+ http.fetch({
+ url = msg,
+ timeout = 5,
+ user_agent = "Minetest Digilines Modem",
+ },
+ function(res)
+ digiline:receptor_send(pos, digiline.rules.default, channel, res)
+ end)
+ end
+ },
+ },
+ })
+end