Advertisement
Firestorm002

Voting Booth Program v1.0

Aug 10th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. w,h = term.getSize()
  2. modemside = "top"
  3.  
  4. function clear()
  5.   term.clear()
  6. end
  7.  
  8. function write(str,xpos,ypos)
  9.   term.setCursorPos(xpos,ypos)
  10.   term.write(str)
  11. end
  12.  
  13. function printCenter(str,ypos)
  14.   term.setCursorPos(w/2 - #str/2,ypos)
  15.   term.write(str)
  16. end
  17.  
  18. function header(str)
  19.   printCenter(string.rep("-",w),1)
  20.   printCenter(str,3)
  21.   printCenter(string.rep("-",w),5)
  22. end
  23.  
  24. function connect()
  25.   while true do
  26.     clear()
  27.     term.setTextColor(colors.lime)
  28.     header("<VOTING BOOTH>")
  29.     term.setTextColor(colors.yellow)
  30.     printCenter("<Please login with M.C. username, and password.>",7)
  31.     term.setTextColor(colors.orange)
  32.     write("Minecraft Username: ",2,10)
  33.     user = read()
  34.     sleep(2)
  35.     write("Minecraft Password: ",2,12)
  36.     pass = read("*")
  37.     if pass == "nil" then
  38.       clear()
  39.     else
  40.       http.request("http://login.minecraft.net/?user=" ..user.. "&password=" ..pass.. "&version=12")
  41.       local event, url, response = os.pullEvent()
  42.       if event == "http_success" then
  43.         _sResponse = { response.readAll() }
  44.         if string.find(tostring(_sResponse[1]), "deprecated") then
  45.           sleep(1)
  46.           term.setCursorPos(1,1)
  47.           break
  48.         end
  49.       end
  50.     response.close()
  51.     end
  52.     sleep(2)
  53.     end
  54.   end
  55.  
  56. while true do
  57.   rednet.open(modemside)
  58.   connect()
  59.   clear()
  60.   rednet.broadcast("needvoter")
  61.   sleep(.1)
  62.   rednet.broadcast(user)
  63.   ev,p1,p2,p3 = os.pullEvent("rednet_message")
  64.   if p2 == "yes" then
  65.     term.setTextColor(colors.red)
  66.     header("<YOU CAN NOT VOTE>")
  67.     term.setTextColor(colors.orange)
  68.     printCenter("You have already voted "..user..".",10)
  69.     sleep(3)
  70.   elseif p2 == "no" then
  71.     term.setTextColor(colors.lime)
  72.     header("<PLACE YOUR VOTE>")
  73.     term.setTextColor(colors.yellow)
  74.     printCenter("Press 'a' to vote for the left option, and",10)
  75.     printCenter("press 'b' to vote for the right option.",11)
  76.     ev,p1,p2,p3 = os.pullEvent("char")
  77.     if p1 == "a" then
  78.       rednet.broadcast("vote1")
  79.     elseif p1 == "b" then
  80.       rednet.broadcast("vote2")
  81.     end
  82.     rednet.broadcast("newvoter")
  83.     sleep(.1)
  84.     rednet.broadcast(user)
  85.     clear()
  86.     term.setTextColor(colors.lime)
  87.     header("<VOTE SENT>")
  88.     term.setTextColor(colors.yellow)
  89.     printCenter("Thanks for voting!",8)
  90.     sleep(3)
  91.   end
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement