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"
- hechtid = 2
- function clear()--To clear the screen
- term.clear()
- term.setCursorPos(1,1)
- end
- function main()
- print("Initialising...")
- rednet.host("TCiP", "authost")
- idok = "0"
- pwok = "0"
- ids = {}
- pws = {}
- file = fs.open("listedids", "r")
- if file then
- local line = file.readLine()
- while line do
- table.insert(ids, line)
- line = file.readLine()
- end
- file.close()
- end
- file1 = fs.open("passwds", "r")
- if file1 then
- local line = file1.readLine()
- while line do
- table.insert(pws, line)
- line = file1.readLine()
- end
- file1.close()
- end
- function getclientver()
- clientid, clientvers, protocol = rednet.receive(2)
- if clientvers==nil then
- print ("Version check failed")
- receive()
- elseif clientvers==requiredvers then
- print ("Version check ok")
- rednet.send(tonumber(clientid), "ok")
- sendmessage()
- end
- end
- function sendmessage()
- message = fs.open("message", "r")
- if message then
- rednet.send(tonumber(clientid), message.readAll())
- print (message)
- message.close()
- end
- receive()
- end
- function idcheck()
- senderid, clientid, protocol = rednet.receive(20)
- for i=1,#ids do
- if clientid==ids[i] then
- rednet.send(tonumber(clientid), "ok")
- print("Idcheck ok (", clientid, ")")
- idok = "1"
- end
- end
- if idok=="1" then
- idok = "0"
- passwordcheck()
- else
- rednet.send(tonumber(clientid), "notexist")
- print("Idcheck not ok (", clientid, ")")
- receive()
- end
- end
- function passwordcheck()
- clientid, passwd, protocol = rednet.receive(10)
- if passwd==nil then
- print ("Client waited too long, continuining...")
- receive()
- end
- for i=1,#pws do
- if passwd==pws[i] then
- rednet.send(tonumber(clientid), "ok")
- pwok = "1"
- print("Passwordcheck ok (", passwd, ")")
- passwd = ""
- end
- end
- if pwok=="1" then
- pwok = "0"
- getclientver()
- else
- rednet.send(tonumber(clientid), "wrong")
- print("Passwordcheck not ok (", passwd, ")")
- receive()
- end
- end
- function receive()
- while true do
- clientid, message, protocol = rednet.receive(2)
- if protocol=="TCiP" then--To pair to the client
- rednet.send(clientid, "succesfull")
- print ("Succesfull paired, continuing...")
- idcheck()
- end
- if protocol=="order" then--To receive orders
- print ("Client ", clientid, " has ordered something!")
- file = fs.open("orders", "a")
- file.writeLine(clientid)
- file.writeLine(message)
- file.writeLine(" ")
- file.close()
- print ("Got order!")
- rednet.send(clientid, "ok")
- end
- end
- end
- clear()
- print ("Irgendwas by onix331")
- print ("Version ", ver)
- print ("Waiting for pair request")
- receive()
- 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