Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- print("Running Ballot Server.")
- while true do
- rednet.open("top")
- id,command = rednet.receive()
- if command == "list" then
- local list = fs.list("disk")
- rednet.send(id,textutils.serialize(list))
- end
- if command == "info" then
- local id,ballot = rednet.receive(10)
- hBallot = fs.open("disk/"..ballot,"r")
- rednet.send(id,hBallot.readLine())
- hBallot.close()
- end
- if command == "vote" then
- local id,ballot = rednet.receive()
- local id,Uid = rednet.receive()
- if not fs.exists("disk/idlists/"..ballot) then
- T = fs.open("disk/idlists/"..ballot,"w")
- T.close()
- end
- local hList = fs.open("disk/idlists/"..ballot,"r")
- for i=1,1000 do
- duplicate = hList.readLine()
- if duplicate == nil then
- hList.close()
- hList = fs.open("disk/idlists/"..ballot,"a")
- hList.writeLine(Uid)
- rednet.send(id,"accepted")
- hList.close()
- break
- end
- if duplicate == Uid then
- rednet.send(id,"denied")
- end
- end
- FileDir = "disk/"..ballot
- hMsg = fs.open(FileDir,"r")
- info = hMsg.readLine()
- rednet.send(id,info)
- hMsg.close()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment