Cavious

shield_server

Jun 25th, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. rednet.open("back")
  2. side = "bottom"
  3. password = "269723"
  4.  
  5. decline = "Access Denied"
  6. approved_on = "Access Granted! Shield Online."
  7. approved_off = "Access Granted! Shield Offline."
  8. error_msg = "invalid entry"
  9.  
  10. function run()
  11.    
  12.     term.setBackgroundColor(colors.gray)
  13.     term.clear()
  14.     term.setTextColor(colors.yellow)
  15.     term.setCursorPos(1,1)
  16.     term.write("Shield Server v1.0")
  17.     term.setCursorPos(25,1)
  18.     term.write("Shield Status: ")
  19.     term.setCursorPos(1,2)
  20.     term.write("==================")
  21.     term.setCursorPos(1,4)
  22.     term.write("Now Accepting Connection From:")
  23.    
  24.     while(true) do
  25.    
  26.         local id, message, protocol = rednet.receive()
  27.        
  28.         term.setTextColor(colors.red)
  29.         term.write(id)
  30.        
  31.         local start_point = string.find(message, "<p>") + 3
  32.         local end_point = string.find(message, "</p>") - 1
  33.         local user_password = string.sub(message, start_point, end_point)
  34.        
  35.         local start_point = string.find(message, "<r>") + 3
  36.         local end_point = string.find(message, "</r>") - 1
  37.         local request = string.sub(message, start_point, end_point)
  38.        
  39.         if(user_password == password) then
  40.             if(request == "on") then
  41.                 redstone.setOutput(side, true)
  42.                 rednet.send(id, approved_on)
  43.                 term.setCursorPos(40,1)
  44.                 term.setTextColor(colors.lime)
  45.                 term.write("ONLINE ")
  46.             elseif(request == "off") then
  47.                 redstone.setOutput(side, false)
  48.                 rednet.send(id, approved_off)
  49.                 term.setCursorPos(40,1)
  50.                 term.setTextColor(colors.red)
  51.                 term.write("OFFLINE")
  52.             else
  53.                 rednet.send(id, error_msg)
  54.             end
  55.         else
  56.             rednet.send(id, decline)
  57.         end
  58.        
  59.         term.clearLine()
  60.         term.setCursorPos(1,5)
  61.        
  62.    
  63.     end
  64.    
  65. end
  66.  
  67.  
  68. run()
Advertisement
Add Comment
Please, Sign In to add comment