Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local P = peripheral.find("modem")
- if P == nil then
- error("There is no router on this PC!")
- end
- print("Got the modem!")
- P.open(15)
- Whitelist = {"Famous5000"}
- if fs.exists("Whitelist") then
- Whitelist = io.open("Whitelist","r")
- Whitelist = Whitelist:read()
- local W = {}
- for I = 1,#Whitelist do
- W = Whitelist[I]
- end
- Whitelist = W
- end
- while true do
- local _,_,Channel,_,Message = os.pullEvent("modem_message")
- if type(Message) == "table" then
- sleep(0.1)
- local Plr = Message[1]
- INVALID = false
- if Plr ~= "Famous5000" then
- INVALID = true
- for I = 1,#Whitelist do
- if Plr == Whitelist[I] then
- INVALID = false
- end
- end
- if INVALID == true then
- term.setTextColor(colors.red)
- print("A blocked attempt to access this system from "..Plr)
- term.setTextColor(colors.white)
- end
- end
- local Msg = Message[2]
- if INVALID == false then
- if Msg:lower() == "open" then
- redstone.setAnalogOutput("top",15)
- sleep(2)
- redstone.setAnalogOutput("top",0)
- end
- if Msg:lower() == "shutdown" then
- break
- end
- if Msg:lower():sub(0,3) == "add" then
- local P = Msg:sub(5)
- local C = 0
- for I = 1,#Whitelist do
- C = I + 1
- end
- C = tonumber(C)
- Whitelist[1] = P
- end
- if Msg:lower():sub(0,3) == "rem" then
- local P = Msg:sub(5)
- if P == "clr" then
- Whitelist = {"Famous5000"}
- else
- for I = 1,#Whitelist do
- if Whitelist[I]:lower():match(P:lower()) then
- table.remove(Whitelist,I)
- end
- end
- end
- end
- print("Recieved message from "..Plr)
- end
- end
- end
- local W = fs.open("Whitelist","w")
- print("I have been told to shut down. Rebooting...")
- sleep(3)
- if W then
- for n,T in ipairs(Whitelist) do
- W.write(T.."\n")
- end
- W.close()
- else
- print("Access denied. Please fix this")
- end
- sleep(10)
- if not fs.exists("startup") then
- local R = fs.open("startup","w")
- Lines = {"shell.run(\"Detector\")",
- "os.reboot()"}
- if R then
- for n,T in ipairs(Lines) do
- R.write(T.."\n")
- end
- end
- R.close()
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment