Dusk-The-Dutchie

(CC) FSServer

Jan 19th, 2021
782
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --A simple FileSharing Server
  2. --For CC In-Game
  3. --(c) 2021 by Christopher Yarch
  4. --a.k.a. Dusk the Dragon
  5. math.randomseed(os.time())
  6.  
  7. modem = "top"
  8. rednet.open("top")
  9.  
  10. domain = "fileserver"
  11. progList = {}
  12.  
  13. function rednetHandler()
  14.     id, msg = rednet.receive(domain)
  15.     print("Incoming Message")
  16.     --Check to see if we have a table
  17.     if #msg > 1 then
  18.         --Process the request.
  19.         if msg[1] == "put" then
  20.             print("Sharing File")
  21.             print("Content: "..msg[2])
  22.             local FSID = math.random(11111,99999)
  23.             progList[FSID] = msg[2]
  24.             print(progList[FSID])
  25.             rednet.broadcast(FSID,domain)
  26.             print("File Shared")
  27.         elseif msg[1] == "get" then
  28.             ID = tonumber(msg[2])
  29.             print(ID)
  30.             local prog = progList[ID]
  31.             print(prog)
  32.             if not prog then
  33.                 rednet.broadcast("Err404",domain)
  34.             else
  35.                 rednet.broadcast(prog,domain)
  36.             end
  37.         else
  38.             rednet.broadcast("Err400")
  39.         end
  40.     end
  41. end
  42.  
  43. while true do
  44.     rednetHandler()
  45.     sleep(0.1)
  46. end
RAW Paste Data