Advertisement
Dusk-The-Dutchie

(CC) FSClient

Jan 19th, 2021
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. --A simple FileSharing Client
  2. --For CC In-Game
  3. --(c) 2021 by Christopher Yarch
  4. --a.k.a Dusk The Dragon
  5.  
  6. args = {...}
  7.  
  8. modem = "back"
  9. rednet.open(modem)
  10.  
  11. domain = "fileserver"
  12.  
  13. if args[1] == "get" then
  14.     local packet = {}
  15.     table.insert(packet,"get")
  16.     table.insert(packet,args[2])
  17.     rednet.broadcast(packet,domain)
  18.     id, msg = rednet.receive(domain,5)
  19.     if not msg then
  20.         print("Timed Out on Get")
  21.     else
  22.         if msg == "Err400" then
  23.             print("Bad Request")
  24.         elseif msg == "Err404" then
  25.             print("Invalid ID")
  26.         else
  27.             f = fs.open(args[3],"w")
  28.             f.write(msg)
  29.             f.close()
  30.             print("File received and written")
  31.         end
  32.     end
  33. elseif args[1] == "put" then
  34.     if fs.exists(args[2]) then
  35.         f = fs.open(args[2],"r")
  36.         data = f.readAll()
  37.         f.close()
  38.         local packet = {}
  39.         table.insert(packet,"put")
  40.         table.insert(packet,data)
  41.         rednet.broadcast(packet,domain)
  42.         id,msg = rednet.receive(domain,5)
  43.         if not msg then
  44.             print("Time Out on Put")
  45.         else
  46.             if msg == "Err400" then
  47.                 print("Bad Request")
  48.             else
  49.                 print("File Shared: "..msg)
  50.             end
  51.         end
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement