Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Client
- local timeout = 0.5
- rednet.open("top")
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function start1()
- local file = fs.open("network/Router","r")
- IP = file.readLine()
- Password = file.readLine()
- file.close()
- rednet.send(tonumber(IP),tonumber(Password))
- local scrap,message = rednet.receive(timeout)
- if message == "connected!" then
- print("connected!")
- programm()
- elseif message == "!" then
- fs.delete("network/Router")
- os.reboot()
- end
- end
- function start()
- write("Router IP: ")
- local IP = tonumber(io.read())
- write("Router Password: ")
- local Password = tonumber(io.read())
- rednet.send(IP,Password)
- local scrap,message = rednet.receive()
- if tonumber(scrap) == IP then
- if message == "Type!" then
- write("Type: ")
- rednet.send(IP,io.read())
- local scrap,message = rednet.receive()
- if message == "connected!" then
- clear()
- print("Connected")
- fs.makeDir("network")
- local file = fs.open("network/Router","w")
- file.writeLine(IP)
- file.writeLine(Password)
- file.close()
- print("Router-settings saved to network/Router !")
- programm()
- end
- else
- print("Message: "..message)
- start()
- end
- else
- print("IP: "..scrap)
- start()
- end
- end
- function getRouter()
- local file = fs.open("network/Router","r")
- if file then
- IP = file.readLine()
- Password = file.readLine()
- file.close()
- end
- return IP,Password
- end
- function getData()
- IP,Passwort = getRouter()
- local scrap,message = rednet.receive()
- if tonumber(scrap) == tonumber(IP) then
- rednet.send(tonumber(IP),"received!")
- return message
- end
- end
- function sendData(id,data)
- IP,Passwort = getRouter()
- rednet.send(tonumber(IP),"SD")
- local scrap,message = rednet.receive()
- if (message) ~= nil then
- if message == "data" then
- rednet.send(tonumber(IP),id)
- rednet.send(tonumber(IP),data)
- local scrap,message = rednet.receive()
- if (message) ~= nil then
- if message == "0" then
- return false
- elseif message == "1" then
- return true
- end
- end
- end
- end
- end
- function programm()
- -- put your programm in here!
- while true do
- print(getData())
- end
- end
- if fs.exists("network/Router") then
- start1()
- else
- start()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement