PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/script/command/admin.lua

http://hopmod.googlecode.com/
Lua | 37 lines | 23 code | 11 blank | 3 comment | 6 complexity | 745a6efdb7477e709fdf81dde02d2a7d MD5 | raw file
 1--[[
 2    A player command to raise privilege to admin
 3]]
 4
 5local domains = {}
 6
 7local function init() 
 8    domains = table_unique(server.parse_list(server["admin_domains"]))
 9end
10
11local function unload() end
12
13local function run(cn)
14
15    if not domains or #domains == 0 then
16        server.player_msg(cn, red("Cannot execute admin command: no domains set"))
17        return
18    end
19    local sid = server.player_sessionid(cn)
20
21    for _, domain in pairs(domains) do
22        auth.send_request(cn, domain, function(cn, user_id, domain, status)
23
24            if not (sid == server.player_sessionid(cn)) or not (status == auth.request_status.SUCCESS) then
25                return
26            end
27            
28            server.setadmin(cn)
29            
30            server.msg(server.player_displayname(cn) .. " claimed admin as '" .. magenta(user_id) .. "'")
31            server.log(string.format("%s playing as %s(%i) used auth to claim admin.", user_id, server.player_name(cn), cn))
32        end)
33    end
34end
35
36return {init = init, run = run, unload = unload}
37