summaryrefslogtreecommitdiff
path: root/indra/newview/scripts/lua/require/login.lua
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-09-25 11:56:44 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-09-25 11:56:44 -0400
commit55df7328c6f8c864ea309c57d73e791e079b3c2c (patch)
treecb4cba5e51d9649ba229c4eefeaafe783b9250e2 /indra/newview/scripts/lua/require/login.lua
parent4b2b94f4864f2e2e7d76f4f17b2d58bb959b3edb (diff)
parent86d2fb93b73d2689104c564ec859be7f83416691 (diff)
Merge branch 'develop' into marchcat/xcode-16
Diffstat (limited to 'indra/newview/scripts/lua/require/login.lua')
-rw-r--r--indra/newview/scripts/lua/require/login.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/indra/newview/scripts/lua/require/login.lua b/indra/newview/scripts/lua/require/login.lua
new file mode 100644
index 0000000000..37c9093a21
--- /dev/null
+++ b/indra/newview/scripts/lua/require/login.lua
@@ -0,0 +1,42 @@
+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
+
+local function fullgrid(grid)
+ if string.find(grid, '.', 1, true) then
+ return grid
+ else
+ return `util.{grid}.secondlife.com`
+ end
+end
+
+function login.login(...)
+ ensure_login_state('login')
+ local args = mapargs('username,grid,slurl', ...)
+ args.op = 'login'
+ args.grid = fullgrid(args.grid)
+ return leap.request('LLPanelLogin', args)
+end
+
+function login.savedLogins(grid)
+ ensure_login_state('savedLogins')
+ return leap.request('LLPanelLogin', {op='savedLogins', grid=fullgrid(grid)})['logins']
+end
+
+return login