-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlrnd
54 lines (51 loc) · 1.85 KB
/
lrnd
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
local unpack = unpack or table.unpack
local RN_BROADCAST = 65535
local lyqydnet = false
local rnReceivedMessages = {}
local rnReceivedTimeouts = {}
process.addHook({"modem_message"})
while true do
local event = {os.pullEventRaw()}
if not lyqydnet then lyqydnet = process.getFromName("lyqydnet") end
if event[1] == "modem_message" then
if lyqydnet then
lyqydnet:queue(unpack(event))
else
local rm = event[3] == os.getComputerID() or event[3] == RN_BROADCAST
for pID, proc in pairs(process.list) do
if proc and proc.name ~= "lrnd" and proc.name ~= "lyqydnet" and proc.modem and proc.modem[event[2]] and proc.modem[event[2]][event[3]] then
proc:queue(unpack(event))
end
if rm and proc and proc.rednet and proc.rednet[event[2]] then
if term.current then
if not rnReceivedMessages[event[5].nMessageID] then
proc:queue("rednet_message", event[4], event[5].message, event[5].sProtocol)
end
else
proc:queue("rednet_message", event[4], event[5], event[6])
end
end
end
if rm and term.current then
if not rnReceivedMessages[event[5].nMessageID] then
rnReceivedMessages[event[5].nMessageID] = true
rnReceivedTimeouts[os.startTimer(30)] = event[5].nMessageID
end
if event[5].sProtocol == "dns" and event[5].message.sType == "lookup" then
for pID, proc in ipairs(process.list) do
if proc and proc.rednet and proc.rednet.hosting then
local hostname = proc.rednet.hosting[event[5].message.sProtocol]
if hostname then
rednet.send(event[4], {sType = "lookup response", sHostname = hostname, sProtocol = event[5].message.sProtocol}, "dns")
break
end
end
end
end
end
end
elseif event[1] == "timer" and rnReceivedTimeouts[event[2]] then
rnReceivedMessages[rnReceivedTimeouts[event[2]]] = nil
rnReceivedTimeouts[event[2]] = nil
end
end