Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("redstone")
- local mon = peripheral.wrap("monitor_2")
- if not mon then
- mon = term
- end
- pri = peripheral.wrap("printer_0")
- if not pri then
- insult = nil
- end
- local tArgs = { ... }
- local opt = getOpt(tArgs)
- if #tArgs == 0 then
- opt.b = true
- opt.w = false
- opt.l = true
- end
- local function printUsage()
- print( "Usage:" )
- end
- function timestamp()
- file=http.get("http://wyvern67.free.fr/Minecraft/scripts/time.php")
- if not file then print("Url invalide") return false end
- sTime = file.readLine(1)
- file.close()
- return sTime
- end
- function getOpt(tArgs)
- local function isOption(text)
- --if text starts with a dash like "-something" consider it an option
- if (text == nil) or (string.sub(text, 0, 1) == "-") then
- return true
- else
- return false
- end
- end
- local opt = {}
- local i = 1
- while i <= #tArgs do
- if isOption(tArgs[i]) then
- if isOption(tArgs[i+1]) then
- --if no argument (no next arg or it's an option too)
- --interpret like options.something = true
- opt[string.sub(tArgs[i], 2)] = true
- else
- --interpret like options.something = value
- opt[string.sub(tArgs[i], 2)] = tArgs[i+1]
- i = i+1 --skip the next arg, it was the argument for -something
- end
- else
- --if not an option
- --aka a random arg, do options[number] = argument
- table.insert(opt, tArgs[i])
- end
- i = i+1
- end
- return opt
- end
- function table.search(t, value)
- for i,v in pairs(t) do
- if v == value then
- return i
- end
- end
- return false
- end
- local whitelist = {
- "Wyvern67",
- "uncle_pete",
- "herbzah",
- "Mrairs",
- "StoneHammers",
- "SystemProcess",
- "wifeisaggro",
- "Sh4dow_G4ming",
- "moneyslow"
- }
- local function isWhitelisted(name)
- return table.search(whitelist, name)
- end
- local blacklist = {
- "posterierman",
- }
- local function isBlacklisted(name)
- return table.search(blacklist, name)
- end
- local function allowEntry()
- rs.setOutput("back", false)
- rs.setOutput("front", true)
- end
- local function denyEntry()
- rs.setOutput("front", false)
- rs.setOutput("back", true)
- end
- local function pressurePlates()
- if rs.getInput("right") then
- print("Pressure plates")
- end
- return rs.getInput("right")
- end
- local db = [[___________ __
- \_ _____/____ _/ |_
- | __)_\__ \\ __\
- | \/ __ \| |
- /_______ (____ /__|
- \/ \/
- _________.__ .__ __
- / _____/| |__ |__|/ |_
- \_____ \ | | \| \ __\
- / \| Y \ || |
- /_______ /|___| /__||__|
- \/ \/
- ]]
- function dickbutt(text)
- pri.newPage()
- pri.setPageTitle("Message from Wyvern67")
- text = text .. "\n"
- local i = 1
- for line in string.gmatch(text, "(.-)\n") do
- pri.setCursorPos(1,i)
- pri.write(line)
- i = i+1
- end
- pri.endPage()
- end
- function insult(text)
- pri.newPage()
- pri.setPageTitle("Message from Wyvern67")
- if pri.getPaperLevel == 0 then
- text = [[You got this printer out
- of paper. Are you
- happy about yourself?]]
- end
- if pri.getInkLevel == 0 then
- text = [[You got this printer out
- of paper. Are you
- happy about yourself?]]
- end
- text = text .. "\n"
- local i = 3
- for line in string.gmatch(text, "(.-)\n") do
- pri.setCursorPos(1,i)
- pri.write(line)
- i = i+1
- end
- pri.endPage()
- end
- local function print_monitor(text)
- print(text)
- if mon and mon.getCursorPos and mon.write and mon.setCursorPos then
- local x,y = mon.getCursorPos()
- mon.write(text)
- mon.setCursorPos(10,y+1)
- end
- end
- print_monitor("")
- s = peripheral.wrap("top")
- local lastInsulted = ""
- while true do
- mon.clear()
- mon.setCursorPos(10, 3)
- local players = s.getPlayers()
- local nPlayers = #players
- if nPlayers > 0 then
- local player
- local entry = true
- local welcome = {}
- local knowEverybody = true
- --Parsing players
- for i,v in pairs(players) do
- player = v.name
- if opt.b then
- if isBlacklisted(player) then
- entry = false
- welcome = {player}
- break
- end
- end
- if opt.w then
- entry = entry and isWhitelisted(player)
- end
- if i>1 and opt.l then
- local h = fs.open("logs", "a")
- local txt = timestamp() .. ": " .. player
- h.writeLine(txt)
- print(txt)
- h.close()
- end
- if isWhitelisted(player) then
- welcome[#welcome+1] = "bro #"..table.search(whitelist, player)
- else
- welcome[#welcome+1] = player
- knowEverybody = false
- end
- end
- --Allow or deny entry based on players inside the gates
- if entry then
- --Prepare entry message according to the players
- local message = "Welcome, " .. welcome[1]
- for i=2, #welcome-1 do
- message = message .. ", " .. welcome[i]
- end
- if #welcome > 1 then
- message = message .. " and " .. welcome[#welcome]
- end
- message = message .. "."
- --Actual entry script
- allowEntry()
- print_monitor(message)
- if knowEverybody == false then
- print_monitor("Although I do not know")
- print_monitor("everybody, you are still")
- print_monitor("welcome :).")
- end
- while #s.getPlayers() == nPlayers do
- if pressurePlates() then
- rs.setOutput("back", true)
- else
- rs.setOutput("back", false)
- end
- sleep()
- end
- else
- denyEntry()
- print_monitor("Sorry. " .. welcome[1] .. ", you aren't")
- print_monitor("allowed here.")
- print_monitor("You need to leave. :/")
- if insult and lastInsulted ~= welcome[1] then
- print_monitor("The owner left you a personnal")
- print_monitor("message.")
- print_monitor("Please, take it.")
- insult("fuck off " .. welcome[1])
- lastInsulted = welcome[1]
- end
- while #s.getPlayers() == nPlayers do
- sleep()
- end
- end
- rs.setOutput("back", true)
- rs.setOutput("front", false)
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement