SHOW:
|
|
- or go back to the newest paste.
1 | local authorized = {} | |
2 | local authorizing | |
3 | local close | |
4 | ||
5 | local handle = io.open(".auth", "r") | |
6 | if handle then | |
7 | for user in handle:lines() do | |
8 | authorized[user] = true | |
9 | end | |
10 | handle:close() | |
11 | end | |
12 | ||
13 | while true do | |
14 | event = {os.pullEvent()} | |
15 | if event[1] == "biolock" then | |
16 | if authorized[event[2]] then | |
17 | if rs.getOutput("right") then | |
18 | --accept new authorized entry | |
19 | authorizing = true | |
20 | else | |
21 | rs.setOutput("right", true) | |
22 | close = os.startTimer(20) | |
23 | end | |
24 | elseif authorizing then | |
25 | authorized[event[2]] = true | |
26 | authorizing = false | |
27 | local handle = io.open(".auth", "w") | |
28 | if handle then | |
29 | for k, v in pairs(authorized) do | |
30 | handle:write(k.."\n") | |
31 | end | |
32 | handle:close() | |
33 | end | |
34 | end | |
35 | elseif event[1] == "redstone" then | |
36 | if rs.getInput("bottom") then | |
37 | authorizing = false | |
38 | rs.setOutput("right", false) | |
39 | end | |
40 | elseif event[1] == "timer" and event[2] == close then | |
41 | authorizing = false | |
42 | rs.setOutput("right", false) | |
43 | end | |
44 | end |