goreae

CC VOTE/VOTE

Jan 3rd, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.76 KB | None | 0 0
  1. IDAuthen = 22
  2. IDBallot = 49
  3. IDResult = 26
  4. password = "Admin"
  5.  
  6. rednet.open("top")
  7. function clearScreen()
  8.   term.clear()
  9.   term.setCursorPos(1,1)
  10. end
  11. while true do
  12.   clearScreen()
  13.   print("Please insert ID.")
  14.   os.pullEvent("disk","bottom")
  15.   rednet.send(IDAuthen,disk.getLabel("bottom"))
  16.   sleep(1)
  17.   hUid = fs.open("disk/"..disk.getLabel("bottom"),"r")
  18.   Uid = hUid.readLine()
  19.   hUid.close()
  20.   rednet.send(IDAuthen,Uid)
  21.   id,response = rednet.receive()
  22.   if response == "denied" then
  23.     print("Uid and IGN do not match. please see an admin for assistance.")
  24.     error()
  25.   end
  26.   if response == "accepted" then
  27.     clearScreen()
  28.     while true do
  29.       clearScreen()
  30.       print("welcome to the voting booth!")
  31.       print("type 'list' to list current ballots.")
  32.       print("type 'info' for more info on a ballot.")
  33.       print("type 'vote' to vote on a ballot.")
  34.       print("type 'logout' to exit the booth.")
  35.       local choice = read()
  36.       if choice == password then error() end
  37.       rednet.send(IDBallot,choice)
  38.       if choice == "list" then
  39.         clearScreen()
  40.         id,msg = rednet.receive()
  41.         local list = textutils.unserialize(msg)
  42.         print("The availiable ballots are:")
  43.         for i=1,1000 do
  44.           if list[i] == nil then break end
  45.           if list[i] ~= "idlists" then
  46.             if list[i] ~= "results" then
  47.               print(list[i])
  48.             end
  49.           end
  50.         end
  51.         print("Press any key to continue.")
  52.         os.pullEvent("key")
  53.       end
  54.       if choice == "info" then  
  55.         clearScreen()
  56.         print("what ballot would you like information on?")
  57.         ballot = read()
  58.         rednet.send(IDBallot,ballot)
  59.         id,info = rednet.receive()
  60.         clearScreen()
  61.         print("info on "..ballot..":")
  62.         print(nil)
  63.         print(info)
  64.         print(nil)
  65.         print("Press any key to continue.")
  66.         os.pullEvent("key")
  67.       end
  68.       if choice == "vote" then
  69.         clearScreen()
  70.         print("What ballot would you like to vote on?")
  71.         ballot = read()
  72.         rednet.send(IDBallot,ballot)
  73.         rednet.send(IDBallot,Uid)
  74.         id,access = rednet.receive()
  75.         id,info = rednet.receive()
  76.         if access == "denied" then
  77.           clearScreen()
  78.           print("You've already voted on this ballot, please try another.")
  79.           print("Press any key to continue")
  80.           os.pullEvent("key")
  81.         end
  82.         if access == "accepted" then
  83.           while true do
  84.             valid = 0
  85.             clearScreen()
  86.             print("Information on "..ballot..":")
  87.             print(info)
  88.             print(nil)
  89.             print("enter your choice 'yes' or 'no' below.")
  90.             vote = read()
  91.             if vote == "yes" then
  92.               valid = 1
  93.             end
  94.             if vote == "no" then
  95.               valid = 1
  96.             end
  97.             if valid == 1 then
  98.               rednet.send(IDResult,"vote")
  99.               sleep(.5)
  100.               rednet.send(IDResult,ballot)
  101.               sleep(.5)
  102.               rednet.send(IDResult,vote)
  103.               break
  104.             else
  105.               print("'"..vote.."' is not a valid entry. Please enter 'yes' or 'no'.")
  106.             end
  107.           end
  108.         end
  109.       end    
  110.       if choice == "logout" then
  111.         disk.eject("bottom")
  112.         print("Thanks for voting!")
  113.         sleep(2)
  114.         rednet.close("top")
  115.         clearScreen()
  116.         os.reboot()
  117.       end
  118.     end
  119.   end
  120. end
Advertisement
Add Comment
Please, Sign In to add comment