goreae

CC VOTE/RESULTSSERVER

Jan 3rd, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. --term.clear()
  2. --term.setCursorPos(1,1)
  3. print("Running Results Server.")
  4. rednet.open("top")
  5. while true do
  6.   id,command = rednet.receive()
  7.   if command == "vote" then
  8.     local id,ballot = rednet.receive(10)
  9.     local id,result = rednet.receive(10)
  10.     print(ballot)
  11.     print(result)
  12.     hrResult = fs.open("disk/results/"..ballot,"r")
  13.     cResults = textutils.unserialize(hrResult.readLine())
  14.     hrResult.close()
  15.     if result == "yes" then
  16.       slot = 1
  17.     end
  18.     if result == "no" then
  19.       slot = 2
  20.     end
  21.     cResults[slot] = cResults[slot]+1
  22.     hwResult = fs.open("disk/results/"..ballot,"w")
  23.     hwResult.writeLine(textutils.serialize(cResults))
  24.     hwResult.close()
  25.   end
  26.   if command == "access" then
  27.     local id,ballot = rednet.receive()
  28.     local rPath = "disk/results/"..ballot
  29.     hrResult = fs.open(rPath,"r")
  30.     rednet.send(id,hrResult.readLine())
  31.     hrResult.close()
  32.   end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment