Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This is a non-tested version so report any bugs you find please
- function login(password)
- print("Please enter your password :")
- local pass = io.read("*")
- shell.run("clear")
- if pass == password then
- print("Access granted")
- return "true"
- else
- print("Wrong password")
- os.sleep(2)
- return
- end
- end
- function createConfig()
- if fs.exists("/clientFolder/client.config") then
- return "nothing"
- else
- print("Thanks you for download this rednet protocol")
- print("You are going to configure this program, follow this step-by-step configuration")
- os.sleep(3)
- shell.run("clear")
- print("First enter the side of your modem")
- local modemSide = io.read()
- shell.run("clear")
- print("Type your server ip")
- local ipServ = io.read()
- shell.run("clear")
- print("You have finished the configuration of your program")
- fs.makeDir("clientFolder")
- fs.makeDir("usermade")
- local conf = io.open("/clientFolder/client.config", "w")
- local data = {side = modemSide, id = ipServ}
- local dataS = textutils.serialize(data)
- local writeIsFail = conf:write(dataS)
- conf:close()
- if writeIsFail then
- print("Config succesfully writed")
- else
- print("Cannot write in the config file")
- end
- end
- end
- function loadConfig()
- shell.run("clear")
- if fs.exists("/clientFolder/client.config") then
- local conf = fs.open("/clientFolder/client.config", "r")
- local dataS = conf.readAll()
- local data = textutils.unserialize(dataS)
- os.sleep(2)
- local id = data.id
- local side = data.side
- rednet.open(side)
- return id
- else
- print("Cannot find the config file, please restart this program")
- os.sleep(3)
- return
- end
- end
- function message()
- shell.run("clear")
- shell.run("id")
- print("Do you want to send (s) or receive (r) message ?")
- input = io.read()
- shell.run("clear")
- if input == "s" then
- print("Type the id of the addressee :")
- idToSend = io.read()
- shell.run("clear")
- rednet.send(id, idToSend)
- print("What do you want to do :")
- print("Send a file (f) or a program (p)?")
- print("Cut the communication with the other computer (exit)?")
- print("Exit this program (/quit)?")
- type = io.read()
- rednet.send(id, type)
- shell.run("clear")
- if type == "f" then
- print("Do you want to execute (e) or save the file (s) ?")
- toDo = io.read()
- rednet.send(id, toDo)
- print("What is the name of the file ?")
- fileOpen = io.read()
- local file = fs.open(fileOpen, "r")
- local sFile = file.readAll()
- rednet.send(id, sFile)
- file.close()
- if toDo == "s" then
- print("What is the name on the other computer ?")
- nameFile = io.read()
- rednet.send(id, nameFile)
- end
- print("File sent")
- elseif type == "p" then
- print("What is the name of the program ?")
- programSend = io.read()
- rednet.send(id, programSend)
- print("Type the argument of the program (0 if there is not argument):")
- argument = io.read()
- rednet.send(id, argument)
- print("Program sent")
- elseif type == "exit" then
- print("Communication cut")
- rednet.send(id, type)
- elseif type == "/quit" then
- shell.run("clear")
- rednet.close("right")
- return
- end
- elseif input == "r" then
- shell.run("id")
- textutils.slowPrint("Listening for request...")
- while exit == 0 do
- 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
- rednet.send(id, 1)
- end
- end
- end
- end
- shell.run("clear")
- shell.run("id")
- exit = 0
- createConfig()
- id = tonumber(loadConfig())
- message()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement