Advertisement
Cobra_Tomtrein-temp-

Untitled

Jul 23rd, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. local vfs_index = {}
  2. local server = "test-server"
  3. local server_channel = 9996
  4. local r_channel = 9997
  5.  
  6. dofile("huffman.lua")
  7.  
  8. local command = {
  9. update = "update"
  10. }
  11.  
  12.  
  13.  
  14. local modem = peripheral.find("modem")
  15. modem.open(r_channel)
  16.  
  17.  
  18. function getMessage(msg)
  19. modem.transmit(server_channel,r_channel,server..string.char(175,175,175)..msg)
  20. while true do
  21. local ev,side,c1,c2,msg = os.pullEvent("modem_message")
  22. if c1 == r_channel and c2 == server_channel then
  23. if msg:sub(1,#server) == server then
  24. msg = msg:sub(#server+1)
  25. if msg:sub(1,3) == string.char(175,175,175) then
  26. msg = msg:sub(4)
  27. return msg
  28. end
  29. end
  30. end
  31. end
  32. end
  33.  
  34.  
  35.  
  36.  
  37. function update()
  38. local ret = getMessage(command.update)
  39. local txt = huffman.decode(nil,ret,true)
  40. vfs_index = textutils.unserialize(txt)
  41. end
  42.  
  43. function getFile(path)
  44. local ret = getMessage(command.getFile..path)
  45. local txt = huffman.decode(nil,ret,true)
  46. return txt
  47. end
  48.  
  49. update()
  50. return vfs_index
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement