Advertisement
BlueMond

CloudS

Sep 8th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 KB | None | 0 0
  1. local version = 1.0
  2. local filename = "server"
  3. local paste = "aHyjJDrb"
  4.  
  5. local function update()
  6.         local url = "http://pastebin.com/raw.php?i="..paste
  7.         local temp = http.get(url)
  8.         local ver = temp.readLine()
  9.         if tonumber(string.sub(ver, 17)) ~= version then
  10.                 fs.delete(filename)
  11.                 shell.run("pastebin get "..paste.." "..filename)
  12.                 shell.run(filename)
  13.                 return true
  14.         end
  15.         return false
  16. end
  17.  
  18. local test = update()
  19. if test == true then
  20.         error()
  21. end
  22.  
  23. rednet.open("top")
  24.      
  25.     local cName = "bluemond" --put the cloud's name here (also used to connect)
  26.     cName = cName:lower()
  27.     local takePass = true
  28.     local pass = "1234" --put the password here
  29.     local request = "$CONNECT$?:"..cName
  30.     local file = "Cloud_Dir" --put the cloud directory here
  31.     shell.run("clear")
  32.     print("Hosting Server: "..cName)
  33.      
  34.     local function sendFiles(pl)
  35.         local files = fs.list(file)
  36.         local out = "$FILES$"
  37.            
  38.         if #files == 0 then
  39.             rednet.send(pl,"$FILES$:$NONE$")
  40.         else
  41.             for x=1,#files do
  42.                 out = out..":"..files[x]
  43.             end
  44.             rednet.send(pl,out)
  45.         end
  46.     end
  47.      
  48.     local function start()
  49.         while true do
  50.                         id,msg = rednet.receive()
  51.                    
  52.             --connection handshake
  53.             if msg == request then
  54.                 if takePass then
  55.                     rednet.send(id,"$CONNECT$Y:"..cName)
  56.                 else
  57.                     rednet.send(id,"$CONNECT$N:"..cName)
  58.                 end
  59.             end
  60.                    
  61.             --password check
  62.             if string.sub(msg,1,11) == "$PASSCHECK$" then
  63.                 if string.sub(msg,13,#msg) == pass then
  64.                     rednet.send(id,"$PASSCHECK$:TRUE")
  65.                 else
  66.                     rednet.send(id,"$PASSCHECK$:FALSE")
  67.                 end
  68.             end
  69.                    
  70.             --file request
  71.             if string.sub(msg,1,7) == "$FILES$" then
  72.                 if string.sub(msg,9,#msg) == pass then
  73.                     sendFiles(id)
  74.                 elseif takePass == false then
  75.                                         sendFiles(id)
  76.                                 end
  77.             end
  78.                    
  79.             end
  80.     end
  81.      
  82.     if not fs.exists(file) then
  83.             fs.makeDir(file)
  84.             shell.run("clear")
  85.             print("~Cloud Directory Created~")
  86.                         print("Please re-run the server.")
  87.     else
  88.             start()
  89.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement