Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- local USERS_FILE = "allowed_users"
- local function load_allowed()
- if fs.exists(USERS_FILE) then
- local fh = fs.open(USERS_FILE, "r")
- local content = fh.readAll()
- fh.close()
- local ok, t = pcall(textutils.unserialize, content)
- if ok and type(t) == "table" then
- return t
- end
- else
- print("ERRORE! nessuna lista utenti trovata...")
- return {}
- end
- end
- local function is_allowed(tbl, name)
- if not name then return false end
- for _, v in ipairs(tbl) do
- if v == name then return true end
- end
- return false
- end
- -- Carica lista utenti all'avvio
- local allowed = load_allowed()
- print("Sistema attivo. In attesa...")
- while true do
- local ev, playerName = os.pullEvent(player)
- if is_allowed(allowed, playerName) then
- print("Accesso consentito per: "..playerName)
- redstone.setOutput("left", true)
- redstone.setOutput("right", true)
- sleep(2)
- redstone.setOutput("left", false)
- redstone.setOutput("right", false)
- else
- print("Accesso negato")
- end
- end
Add Comment
Please, Sign In to add comment