Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is only a non-tested version, so easy-to-fix bugs may occurs
- function createConfig()
- if fs.exists("/serverFolder/server.config") then
- return "nothing"
- else
- print("Thanks you for download this rednet protocol")
- os.sleep(2)
- shell.run("clear")
- print("Enter the side of your modem")
- local modemSide = io.read()
- shell.run("clear")
- print("Enter the id of this computer")
- local idServ = io.read()
- shell.run("clear")
- print("You have finished the configuration of your program")
- fs.makeDir("serverFolder")
- fs.makeDir("usermade")
- local conf = io.open("/serverFolder/server.config", "w")
- local data = {side = modemSide, id = idServ}
- local dataS = textutils.serialize(data)
- local writeIsFail = conf:write(dataS)
- conf:close()
- print("Config succesfully written")
- end
- end
- function loadConfig()
- shell.run("clear")
- if fs.exists("/serverFolder/server.config") then
- local conf = fs.open("/serverFolder/server.config", "r")
- local dataS = conf.readAll()
- conf.close()
- local data = textutils.unserialize(dataS)
- local side = data.side
- local id = data.id
- rednet.open(side)
- return id
- else
- print("Cannot find the config file, please restart this program")
- os.sleep(3)
- return
- end
- end
- function server()
- while exit == 0 do
- id, idToSend = rednet.receive()
- print("Id of the addressee received")
- print("The id is :")
- write(idToSend)
- print(" ")
- msgVerification = 0
- idToSend1 = tonumber(idToSend)
- if idToSend1 == id then
- print("Message for the server received")
- id, msg = rednet.receive()
- if msg == "p" then
- id, msg1 = rednet.receive()
- id, msg2 = rednet.receive()
- shell.run(msg1, msg2)
- elseif msg == "f" then
- id, msgDo = rednet.receive()
- id, msg1 = rednet.receive()
- if msgDo == "e" then
- loadstring(msg1) ()
- elseif msgDo == "s" then
- msgName = rednet.receive()
- newFile = io.open("/usermade/"..msgName, "w")
- newFile:write(msg1)
- newFile:close()
- end
- elseif msg == "exit" then
- shell.run("clear")
- rednet.close("right")
- return
- end
- else
- id, msgType = rednet.receive()
- id, msgCommande = rednet.receive()
- print("Message received")
- while msgVerification == 0 do
- rednet.send(idToSend1, msgType)
- rednet.send(idToSend1, msgCommande)
- if msgType == "p" then
- id, msgArg = rednet.receive()
- rednet.send(idToSend1, msgArg)
- end
- id, msgVerification = rednet.receive(5)
- end
- print("Message send succesfully")
- end
- end
- end
- msgVerification = 0
- exit = 0
- shell.run("clear")
- shell.run("id")
- createConfig()
- id = tonumber(loadConfig())
- server()
Advertisement
Add Comment
Please, Sign In to add comment