Advertisement
Guest User

repnetAPI

a guest
Aug 23rd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. local repoID = 0
  2.  
  3. function init(side, repo)
  4.     rednet.open(side)
  5.     repoID = repo
  6. end
  7.  
  8. function fileToString(path)
  9.  local file = fs.open(path, "r")
  10.  local content = file.readAll()
  11.  local str = textutils.serialize(content)
  12.  return str
  13. end
  14.  
  15. function sendFile(path)
  16.     local code = fileToString(path)
  17.     local to = repoID
  18.  rednet.send(to, "cfile "..path)
  19.     rednet.send(to, code)
  20. end
  21.  
  22. function sendFileRequest(path)
  23.     rednet.send(repoID, "request "..path)
  24. end
  25.  
  26. function getFile(path)
  27.     sendFileRequest(path)
  28.     local id, msg, distance = rednet.receive()
  29.     local handle = fs.open(path, "w")
  30.  local strx = string.gmatch(msg, "ass!s!123_ADADkpc8[(1O")
  31.  if strx == nil then
  32.  print("Received file "..path.." successfully!")
  33.  else
  34.  print("You do not have permissions to access this file!")
  35.  end
  36.     handle.write(textutils.unserialize(msg))
  37.  handle.close()
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement