Guest User

todoserver

a guest
Jan 2nd, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. function addList(txtline)
  2.    fs.makeDir("disk/todo/"..txtline)
  3. end
  4.  
  5. local function checkList(id)
  6.  local msg = {}
  7.   msg[1] = fs.list("disk/todo/")[1]
  8.   msg[2] = fs.list("disk/todo/")[2]
  9.   msg[3] = fs.list("disk/todo/")[3]
  10.   msg[4] = fs.list("disk/todo/")[4]
  11.   msg[5] = fs.list("disk/todo/")[5]
  12.   msg[6] = fs.list("disk/todo/")[6]
  13.   msg[7] = fs.list("disk/todo/")[7]
  14.   msg[8] = fs.list("disk/todo/")[8]
  15.   msg[9] = fs.list("disk/todo/")[9]
  16.   msg[10] = fs.list("disk/todo/")[10]
  17. sleep(2)
  18. local txtr = textutils.serialize(msg)  
  19. rednet.send(id, txtr)
  20. textutils.unserialize(txtr)
  21. end
  22.    
  23. local function delList(item)
  24.   if fs.exists("disk/todo/"..item) then
  25.   fs.delete("disk/todo/"..item)
  26.   return true
  27.  else
  28.   return false
  29. end
  30. end
  31.  
  32. rednet.open("top")
  33.  
  34. while true do
  35.    id, cmd = rednet.receive()
  36.      if cmd == "create" then
  37.        print("Add: "..id)
  38.         sleep(5)
  39.          rednet.send(id, "What would you like to add?")
  40.           sleep(0.5)
  41.           idb, txtb = rednet.receive()
  42.           print(txtb)
  43.         print("------------------------")    
  44.         addList(txtb)
  45.      elseif cmd == "delete" then
  46.         print("Delete: "..id)
  47.         sleep(5)
  48.         rednet.send(idb, "What would you like to delete?")
  49.          ida, txta = rednet.receive()
  50.           print(txta)
  51.           print("----------------------")
  52.         if not delList(txta) then
  53.           print("   Failed: Does not Exist.")
  54.        end
  55.        elseif cmd == "read" then
  56.         print("Read: "..id)
  57.         print("------------------------")
  58.        checkList(ida)
  59.      end
  60.    end
Advertisement
Add Comment
Please, Sign In to add comment