-
Notifications
You must be signed in to change notification settings - Fork 6
/
nic.lua
88 lines (88 loc) · 2.53 KB
/
nic.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
local http = ...
minetest.register_node("digistuff:nic", {
description = "Digilines NIC",
groups = {cracky=3},
is_ground_content = false,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec","field[channel;Channel;${channel}")
end,
tiles = {
"digistuff_nic_top.png",
"jeija_microcontroller_bottom.png",
"jeija_microcontroller_sides.png",
"jeija_microcontroller_sides.png",
"jeija_microcontroller_sides.png",
"jeija_microcontroller_sides.png"
},
inventory_image = "digistuff_nic_top.png",
drawtype = "nodebox",
selection_box = {
--From luacontroller
type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, -5/16, 8/16 },
},
_digistuff_channelcopier_fieldname = "channel",
node_box = {
--From Luacontroller
type = "fixed",
fixed = {
{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}, -- Bottom slab
{-5/16, -7/16, -5/16, 5/16, -6/16, 5/16}, -- Circuit board
{-3/16, -6/16, -3/16, 3/16, -5/16, 3/16}, -- IC
}
},
paramtype = "light",
sunlight_propagates = true,
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
local url
local parse_json = false
-- parse message
if type(msg) == "string" then
-- simple string data
url = msg
elseif type(msg) == "table" and type(msg.url) == "string" then
-- config object
url = msg.url
parse_json = msg.parse_json
else
-- not supported
return
end
http.fetch({
url = url,
timeout = 5,
user_agent = "Minetest Digilines Modem"
},
function(res)
if type(res.data) == "string" and parse_json then
-- parse json data and replace payload
res.data = minetest.parse_json(res.data)
end
digilines.receptor_send(pos, digilines.rules.default, channel, res)
end)
end
},
},
})
minetest.register_craft({
output = "digistuff:nic",
recipe = {
{"","","mesecons:wire_00000000_off"},
{"digilines:wire_std_00000000","mesecons_luacontroller:luacontroller0000","mesecons:wire_00000000_off"}
}
})