mew
This commit is contained in:
parent
fe086e3a0c
commit
1ff3cea4d6
29 changed files with 3206 additions and 79 deletions
1
computer/5/complete.lua
Normal file
1
computer/5/complete.lua
Normal file
|
@ -0,0 +1 @@
|
|||
shell.setCompletionFunction("turtlemanager"
|
35
computer/5/customlookup.lua
Normal file
35
computer/5/customlookup.lua
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
|
||||
results = {}
|
||||
rednet.broadcast({
|
||||
sType = "lookup",
|
||||
sProtocol = "tomfoolery",
|
||||
sHostname = "pocket"
|
||||
})
|
||||
local timer = os.startTimer(1)
|
||||
while true do
|
||||
local event,p1,p2,p3 = os.pullEvent()
|
||||
if event == "rednet_message" then
|
||||
local sender, message, message_protocol = p1,p2,p3
|
||||
print(sender, message, message_protocol)
|
||||
if
|
||||
message_protocol == "dns" and
|
||||
type(message) == "table" and
|
||||
message.sType == "lookup response"
|
||||
then
|
||||
if message.sProtocol == "tomfoolery" then
|
||||
if hostname == nil then
|
||||
print(sender)
|
||||
table.insert(results,{sender,message.sHostname})
|
||||
elseif message.sHostname == hostname then
|
||||
os.cancelTimer(timer)
|
||||
print(sender)
|
||||
return sender
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif event == "timer" and p1 == timer then
|
||||
break
|
||||
end
|
||||
end
|
||||
return results
|
61
computer/5/rednetcopy
Normal file
61
computer/5/rednetcopy
Normal file
|
@ -0,0 +1,61 @@
|
|||
require("rom/apis/rednet")
|
||||
function lookup(protocol, hostname)
|
||||
-- expect(1, protocol, "string")
|
||||
-- expect(2, hostname, "string", "nil")
|
||||
-- Build list of host IDs
|
||||
local results = nil
|
||||
if hostname == nil then
|
||||
results = {}
|
||||
end
|
||||
|
||||
-- Check localhost first
|
||||
if hostnames and hostnames[protocol] then
|
||||
if hostname == nil then
|
||||
table.insert(results, {os.getComputerID(),os.getComputerLabel()})
|
||||
elseif hostname == "localhost" or hostname == hostnames[protocol] then
|
||||
return {os.getComputerID(),os.getComputerLabel()}
|
||||
end
|
||||
end
|
||||
if not isOpen() then
|
||||
if results then
|
||||
return results
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
-- Broadcast a lookup packet
|
||||
broadcast({
|
||||
sType = "lookup",
|
||||
sProtocol = protocol,
|
||||
sHostname = hostname,
|
||||
}, "dns")
|
||||
|
||||
-- Start a timer
|
||||
local timer = os.startTimer(0.05)
|
||||
-- Wait for events
|
||||
while true do
|
||||
local event, p1, p2, p3 = os.pullEvent()
|
||||
if event == "rednet_message" then
|
||||
-- Got a rednet message, check if it's the response to our request
|
||||
local sender_id, message, message_protocol = p1, p2, p3
|
||||
if message_protocol == "dns" and type(message) == "table" and message.sType == "lookup response" then
|
||||
if message.sProtocol == protocol then
|
||||
if hostname == nil then
|
||||
table.insert(results, {sender_id,message.sHostname})
|
||||
elseif message.sHostname == hostname then
|
||||
return {sender_id,message.sHostname}
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif event == "timer" and p1 == timer then
|
||||
-- Got a timer event, check it's the end of our timeout
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if results then
|
||||
return results
|
||||
end
|
||||
return {}
|
||||
end
|
||||
return {lookup = lookup}
|
2
computer/5/turtlemanager
Normal file
2
computer/5/turtlemanager
Normal file
|
@ -0,0 +1,2 @@
|
|||
local arg = ...
|
||||
print(arg or 0)
|
9
computer/5/turtlemanagercompletion.lua
Normal file
9
computer/5/turtlemanagercompletion.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
function()
|
||||
return shell.setCompletionFunction(
|
||||
"turtlemanager.lua",
|
||||
function(...)
|
||||
return {"meow"}
|
||||
end
|
||||
)
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue