Guest User

Detector

a guest
Jan 3rd, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. local P = peripheral.find("modem")
  2. if P == nil then
  3.   error("There is no router on this PC!")
  4. end
  5. print("Got the modem!")
  6. P.open(15)
  7. Whitelist = {"Famous5000"}
  8. if fs.exists("Whitelist") then
  9.   Whitelist = io.open("Whitelist","r")
  10.   Whitelist = Whitelist:read()
  11.   local W = {}
  12.   for I = 1,#Whitelist do
  13.     W = Whitelist[I]
  14.   end
  15.   Whitelist = W
  16. end
  17. while true do
  18.   local _,_,Channel,_,Message = os.pullEvent("modem_message")
  19.   if type(Message) == "table" then
  20.     sleep(0.1)
  21.     local Plr = Message[1]
  22.     INVALID = false
  23.     if Plr ~= "Famous5000" then
  24.       INVALID = true
  25.       for I = 1,#Whitelist do
  26.         if Plr == Whitelist[I] then
  27.           INVALID = false
  28.         end
  29.       end
  30.       if INVALID == true then
  31.         term.setTextColor(colors.red)
  32.         print("A blocked attempt to access this system from "..Plr)
  33.         term.setTextColor(colors.white)
  34.       end
  35.     end
  36.     local Msg = Message[2]
  37.     if INVALID == false then
  38.       if Msg:lower() == "open" then
  39.         redstone.setAnalogOutput("top",15)
  40.         sleep(2)
  41.         redstone.setAnalogOutput("top",0)
  42.       end
  43.       if Msg:lower() == "shutdown" then
  44.         break
  45.       end
  46.       if Msg:lower():sub(0,3) == "add" then
  47.         local P = Msg:sub(5)
  48.         local C = 0
  49.         for I = 1,#Whitelist do
  50.           C = I + 1
  51.         end
  52.         C = tonumber(C)
  53.         Whitelist[1] = P
  54.       end
  55.       if Msg:lower():sub(0,3) == "rem" then      
  56.         local P = Msg:sub(5)
  57.         if P == "clr" then
  58.           Whitelist = {"Famous5000"}
  59.         else
  60.           for I = 1,#Whitelist do
  61.             if Whitelist[I]:lower():match(P:lower()) then
  62.               table.remove(Whitelist,I)
  63.             end
  64.           end
  65.         end
  66.       end
  67.       print("Recieved message from "..Plr)
  68.     end
  69.   end
  70. end
  71. local W = fs.open("Whitelist","w")
  72. print("I have been told to shut down. Rebooting...")
  73. sleep(3)
  74. if W then
  75.   for n,T in ipairs(Whitelist) do
  76.     W.write(T.."\n")
  77.   end
  78.   W.close()
  79. else
  80.   print("Access denied. Please fix this")
  81. end
  82. sleep(10)
  83. if not fs.exists("startup") then
  84.   local R = fs.open("startup","w")
  85.   Lines = {"shell.run(\"Detector\")",
  86.   "os.reboot()"}
  87.   if R then
  88.     for n,T in ipairs(Lines) do
  89.       R.write(T.."\n")
  90.     end
  91.   end
  92.   R.close()
  93.   os.reboot()
  94. end
Advertisement
Add Comment
Please, Sign In to add comment