-
Notifications
You must be signed in to change notification settings - Fork 6
/
auth.lua
68 lines (53 loc) · 1.26 KB
/
auth.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
mineunit("player")
-- AuthEntry class
local last_unique_id = -1
local function unique_id()
last_unique_id = last_unique_id + 1
return last_unique_id
end
local AuthEntry = {}
mineunit.export_object(AuthEntry, {
name = "AuthEntry",
typename = "table",
constructor = function(self, name)
assert(type(name) == "string" and name ~= "", "Invalid AuthEntry name '"..tostring(name).."'")
local obj = {}
local player = mineunit:get_players()[name]
assert.is_player(player)
obj.id = unique_id()
obj.name = name
obj.privileges = player._privs
obj.password = ""
obj.last_login = 0
setmetatable(obj, AuthEntry)
return obj
end,
})
-- Engine core.auth
local auth = {}
local entries = {}
function auth.read(name)
if not entries[name] then
entries[name] = AuthEntry(name)
end
return entries[name]
end
function auth.save(entry)
local player = mineunit:get_players()[entry.name]
assert.is_Player(player)
player._privs = entry.privileges
end
function auth.create()
mineunit:info("auth.create() called")
end
function auth.delete()
mineunit:info("auth.delete() called")
end
function auth.list_names()
mineunit:info("auth.list_names() called")
end
function auth.reload()
mineunit:info("auth.reload() called")
end
_G.core.auth = auth
mineunit("game/auth")