Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This code is developed by me (onix331) and is available under the GNU General Public License (Version 3)
- --For all CC-Versions Universal
- --See http://opensource.org/licenses/GPL-3.0
- --Have fun
- ver = "0.1 Alpha"--For updates
- status = "---"--You can modify the init-status that will be transferred to the host at the beginning
- --It is usually not necessary to modify the next variables
- requiredvers = "0.1"
- isvers = "0.1"
- function clear()--To clear the screen
- term.clear()
- term.setCursorPos(1,1)
- end
- function main()
- clear()
- print ("Initialising...")
- clientid = tostring(os.getComputerID())
- clear()
- print("Please enter your password!")
- passwd = read()
- hostid = rednet.lookup("TCiP")
- if hostid then
- print("Server found! continuining!")
- else
- print("Server not found! Might be down right now, please try again later!")
- error()
- end
- function pair()
- clear()
- print ("Trying to pair with host")
- hostid = rednet.lookup("TCiP")
- rednet.send(hostid, "pair", "TCiP")
- hostid, message, protocol = rednet.receive(0.5)
- if message=="succesfull" then
- print("Succesfully paired, continuing...")
- else
- print("Pairing not successfull, trying again...")
- pair()
- end
- end
- function getinfo()
- rednet.send(hostid, isvers, "version")
- hostid, message, version = rednet.receive(0.5)
- if message==nil then
- print("Error, host did not respond in time!")
- error()
- elseif message=="ok" then
- print ("Versioncheck ok")
- getmessage()
- else
- print ("Versioncheck not ok, please get the latest version!")
- error()
- end
- end
- function getmessage()
- hostid, message, TCiP = rednet.receive(1)
- if message==nil then
- print("Error, host did not respond in time!")
- error()
- else
- print (message)
- orderinput()
- end
- end
- function sendinitial()--Send the initial data
- rednet.send(hostid, clientid)
- hostid, message, TCiP = rednet.receive(0.5)
- if message=="ok" then
- clear()
- rednet.send(hostid, passwd, "pass")
- hostid, response, TCiP = rednet.receive(0.5)
- if response=="ok" then
- getinfo()
- else
- print ("An error occured. Please reconnect!")
- error()
- end
- else
- print ("Error! Your Computer is not registered!")
- error()
- end
- end
- function orderinput()
- print ("Wie viele Items sollen bestellt werden?")
- number = read()
- if fs.exists("temporaer") then
- shell.run ("rm temporaer")
- end
- order = fs.open("temporaer", "a")
- for i = 1, number do
- orderitems = read()
- order.writeLine(orderitems)
- end
- order.close()
- order = fs.open("temporaer", "r")
- rednet.send(hostid, order.readAll(), "order")
- order.close()
- hostid, orderok = rednet.receive(0.5)
- if orderok=="ok"
- then
- print ("Bestellung erfolgreich angenommen!")
- else
- print ("Fehler bei der Bestellung, bitte spaeter erneut Versuchen!")
- end
- end
- --Print header
- clear()
- print ("Irgendwas by onix331")
- print ("Version ", ver)
- os.sleep(2)
- --Fire up the main program
- pair()
- sendinitial()
- end
- local function openRednet()
- for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do
- if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
- rednet.open(side)
- return side
- end
- end
- print("no wifi present")
- end
- modemSide = openRednet()
- if modemSide == nil then
- print("No modem connected")
- else
- print("Opened modem on "..modemSide)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment