Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local f = require("filesystem")
- local event = require("event")
- local m = component.modem
- local t = component.tunnel
- local arch
- arch = "relay"
- for x in f.list("/mnt/") do
- for y in f.list("/mnt/"..x) do
- if y == arch then
- externaldisk = x
- end
- end
- end
- print(externaldisk .. " ready!")
- function loadfile(file)
- for i in f.list("/mnt/" .. externaldisk) do
- if i == file then
- local result = "/mnt/" .. externaldisk .. i
- print(result)
- return tostring(result)
- end
- end
- end
- function readfile(file)
- for line in io.lines(file) do
- print(line)
- return line
- end
- end
- function split(string)
- local result = {}
- local one, two = string.match(string,"(.-);(.+)")
- table.insert(result,one)
- table.insert(result,two)
- return result
- end
- local cmd
- local msg
- m.setStrength(255)
- local localport = tonumber(readfile(loadfile("port")))
- m.open(localport)
- print("begin code!")
- while true do
- print(arch)
- print(localport)
- print(externaldisk)
- print("ready")
- local eventName, myAddress, itsAddress, port, distance, message = event.pull("modem_message")
- cmd = split(message)
- print(cmd[1])
- print(cmd[2])
- if cmd[1]=="msg" then
- msg = split(cmd[2])
- if msg[1]=="hard" then
- t.send(msg[2])
- else
- m.broadcast(msg[1],msg[2])
- end
- else
- os.execute(cmd[2])
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement