Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDAuthen = 22
- IDBallot = 49
- IDResult = 26
- password = "Admin"
- rednet.open("top")
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- while true do
- clearScreen()
- print("Please insert ID.")
- os.pullEvent("disk","bottom")
- rednet.send(IDAuthen,disk.getLabel("bottom"))
- sleep(1)
- hUid = fs.open("disk/"..disk.getLabel("bottom"),"r")
- Uid = hUid.readLine()
- hUid.close()
- rednet.send(IDAuthen,Uid)
- id,response = rednet.receive()
- if response == "denied" then
- print("Uid and IGN do not match. please see an admin for assistance.")
- error()
- end
- if response == "accepted" then
- clearScreen()
- while true do
- clearScreen()
- print("welcome to the voting booth!")
- print("type 'list' to list current ballots.")
- print("type 'info' for more info on a ballot.")
- print("type 'vote' to vote on a ballot.")
- print("type 'logout' to exit the booth.")
- local choice = read()
- if choice == password then error() end
- rednet.send(IDBallot,choice)
- if choice == "list" then
- clearScreen()
- id,msg = rednet.receive()
- local list = textutils.unserialize(msg)
- print("The availiable ballots are:")
- for i=1,1000 do
- if list[i] == nil then break end
- if list[i] ~= "idlists" then
- if list[i] ~= "results" then
- print(list[i])
- end
- end
- end
- print("Press any key to continue.")
- os.pullEvent("key")
- end
- if choice == "info" then
- clearScreen()
- print("what ballot would you like information on?")
- ballot = read()
- rednet.send(IDBallot,ballot)
- id,info = rednet.receive()
- clearScreen()
- print("info on "..ballot..":")
- print(nil)
- print(info)
- print(nil)
- print("Press any key to continue.")
- os.pullEvent("key")
- end
- if choice == "vote" then
- clearScreen()
- print("What ballot would you like to vote on?")
- ballot = read()
- rednet.send(IDBallot,ballot)
- rednet.send(IDBallot,Uid)
- id,access = rednet.receive()
- id,info = rednet.receive()
- if access == "denied" then
- clearScreen()
- print("You've already voted on this ballot, please try another.")
- print("Press any key to continue")
- os.pullEvent("key")
- end
- if access == "accepted" then
- while true do
- valid = 0
- clearScreen()
- print("Information on "..ballot..":")
- print(info)
- print(nil)
- print("enter your choice 'yes' or 'no' below.")
- vote = read()
- if vote == "yes" then
- valid = 1
- end
- if vote == "no" then
- valid = 1
- end
- if valid == 1 then
- rednet.send(IDResult,"vote")
- sleep(.5)
- rednet.send(IDResult,ballot)
- sleep(.5)
- rednet.send(IDResult,vote)
- break
- else
- print("'"..vote.."' is not a valid entry. Please enter 'yes' or 'no'.")
- end
- end
- end
- end
- if choice == "logout" then
- disk.eject("bottom")
- print("Thanks for voting!")
- sleep(2)
- rednet.close("top")
- clearScreen()
- os.reboot()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment