Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input = peripheral.wrap("bottom")
- out = peripheral.wrap("top")
- input.setListening(1, true)
- input.setDefaultChannel(1)
- out.open(1)
- local split = function(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- sep = tostring(sep)
- local t={}
- local i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]*)"..sep.."?") do
- t[i] = str
- i = i+1
- end
- return t
- end
- if fs.exists("conf.cfg") then
- conf = fs.open("conf.cfg", "r")
- MyIP = conf.readAll()
- conf.close()
- else
- input.send("REG_IP")
- print("Waiting for registration...")
- local _, _, _, _, msg = os.pullEvent("lan_message")
- MyIP = msg
- conf = fs.open("conf.cfg", "w")
- conf.writeLine(msg)
- conf.close()
- end
- term.clear()
- print("DLSAM by O2 (0.1) / IP: " .. MyIP)
- print("--------------------------------------")
- while true do
- local income = {os.pullEvent()}
- if income[1] == "lan_message" then
- from = income[3]
- msg = income[5]
- cut = split(msg, ";")
- if cut[1] == MyIP then
- out.transmit(1, 1, cut[2])
- print("OUT > IN")
- end
- elseif income[1] == "modem_message" then
- from = income[3]
- msg = income[5]
- if msg == "REG_IP" then
- repeat
- lc = math.random(2,255)
- tip = "10.0.0." .. lc
- if fs.exists("LOCAL_ADRESS/" .. tip) then
- r = 0
- else
- r = 1
- end
- until r == 1
- nc = fs.open("LOCAL_ADRESS/" .. tip, "w")
- nc.writeLine(from)
- nc.close()
- out.transmit(from .. "/" .. tip)
- print("Registered PC " .. from .. " to " .. tip)
- else
- cut = split(msg, "*")
- if cut[1] == "10.0.0.1" then
- input.send(msg)
- print("IN > OUT")
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement