Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI(".server/api")
- os.loadAPI(".server/encrypt")
- api.open("right")
- function main()
- while true do
- local event, id, msg, dist = api.evt("rednet_message")
- if string.find(msg, "update") then
- msg = string.sub(msg, string.len("update")+2)
- ids = textutils.unserialize(msg)
- if api.isID(id) then
- mesg = textutils.unserialize(msg)
- end
- elseif string.find(msg, "apply") then
- if api.isID(id) then
- msg = string.sub(msg, string.len("apply")+2)
- local _, _, user, pass = string.find(msg, "(%w+)&pwd=(%w+)")
- term.scroll(1)
- term.setTextColor(colors.yellow)
- print("Authentificating...")
- if api.isPermitted(user, pass) then
- term.scroll(1)
- term.setTextColor(colors.lime)
- print("Authentificated!")
- api.send(id, encrypt.hash("OK"))
- else
- term.scroll(1)
- term.setTextColor(colors.red)
- print("Not authentificated!")
- api.send(id, encrypt.hash("FAIL"))
- end
- sleep(2)
- end
- elseif string.find(msg, "applicate") then
- if api.isID(id) then
- msg = string.sub(msg, string.len("applicate")+2)
- local _, _, user, pass = string.find(msg, "(%w+)&pwd=(%w+)")
- if not api.isPermitted(user, pass) then
- api.setPermitted(user, pass)
- api.send(id, encrypt.hash("DONE"))
- else
- api.send(id, encrypt.hash("EXISTS"))
- end
- end
- elseif string.find(msg, "balance") then
- if api.isID(id) then
- msg = string.sub(msg, string.len("balance")+2)
- local _, _, user, pass = string.find(msg, "(%w+)&pwd=(%w+)")
- term.scroll(1)
- term.setTextColor(colors.orange)
- print("The Cash database has been read!")
- local balance = api.getBalance(user, pass)
- if not balance then
- error("BALANCE cant be read!", 2)
- end
- api.send(id, balance)
- end
- elseif string.find(msg, "error") then
- term.setTextColor(colors.red)
- print(msg)
- elseif msg == "ping" then
- term.scroll(1)
- term.setTextColor(colors.yellow)
- print("Got \"ping\" from "..id)
- if not api.isID(id) then
- api.saveID(id)
- term.scroll(1)
- term.setTextColor(colors.lime)
- print("Saved ID of client")
- end
- api.send(id, "pong")
- term.scroll(1)
- term.setTextColor(colors.lime)
- print("Successfully sended \"pong\"")
- end
- end
- end
- --while true do
- main()
- --parallel.waitForAny(main, pong)
- --sleep(1)
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement