summaryrefslogtreecommitdiff
path: root/indra/newview/scripts/lua/require/login.lua
blob: 50fc9e379333d2b9c707b1b507f6b81a807b3e61 (plain)
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
local leap = require 'leap'
local startup = require 'startup'
local mapargs = require 'mapargs'

local login = {}

local function ensure_login_state(op)
    -- no point trying to login until the viewer is ready
    startup.wait('STATE_LOGIN_WAIT')
    -- Once we've actually started login, LLPanelLogin is destroyed, and so is
    -- its "LLPanelLogin" listener. At that point,
    -- leap.request("LLPanelLogin", ...) will hang indefinitely because no one
    -- is listening on that LLEventPump any more. Intercept that case and
    -- produce a sensible error.
    local state = startup.state()
    if startup.before('STATE_LOGIN_WAIT', state) then
        error(`Can't engage login operation {op} once we've reached state {state}`, 2)
    end
end

function login.login(...)
    ensure_login_state('login')
    local args = mapargs('username,grid,slurl', ...)
    args.op = 'login'
    return leap.request('LLPanelLogin', args)
end

function login.savedLogins(grid)
    ensure_login_state('savedLogins')
    return leap.request('LLPanelLogin', {op='savedLogins'})['logins']
end

return login