mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-30 19:22:14 +00:00
implement per-server login management
This commit is contained in:
parent
27963775ed
commit
113dee80a4
2 changed files with 24 additions and 18 deletions
|
@ -81,8 +81,11 @@ local function register_buttonhandler(this, fields)
|
||||||
core.settings:set("name", fields.name)
|
core.settings:set("name", fields.name)
|
||||||
core.settings:set("address", gamedata.address)
|
core.settings:set("address", gamedata.address)
|
||||||
core.settings:set("remote_port", gamedata.port)
|
core.settings:set("remote_port", gamedata.port)
|
||||||
if core.settings:get_bool("remember_password") then
|
if core.settings:get_bool("remember_login") then
|
||||||
core.settings:set("password", fields.password)
|
keyringmgr.set_login({
|
||||||
|
address = gamedata.address,
|
||||||
|
port = gamedata.port,
|
||||||
|
}, fields.name, fields.password)
|
||||||
end
|
end
|
||||||
|
|
||||||
core.start()
|
core.start()
|
||||||
|
|
|
@ -56,6 +56,8 @@ end
|
||||||
|
|
||||||
-- Persists the selected server in the "address" and "remote_port" settings
|
-- Persists the selected server in the "address" and "remote_port" settings
|
||||||
|
|
||||||
|
local input_playername = keyringmgr.get_last_playername() or core.settings:get("name")
|
||||||
|
local input_password = keyringmgr.get_last_password() or ""
|
||||||
local function set_selected_server(server)
|
local function set_selected_server(server)
|
||||||
if server == nil then -- reset selection
|
if server == nil then -- reset selection
|
||||||
core.settings:remove("address")
|
core.settings:remove("address")
|
||||||
|
@ -69,6 +71,18 @@ local function set_selected_server(server)
|
||||||
if address and port then
|
if address and port then
|
||||||
core.settings:set("address", address)
|
core.settings:set("address", address)
|
||||||
core.settings:set("remote_port", port)
|
core.settings:set("remote_port", port)
|
||||||
|
|
||||||
|
-- Pull info from last login (if exists)
|
||||||
|
-- This will always fail if remember_login is false
|
||||||
|
-- because nothing has been stored, nor will it ever be
|
||||||
|
local login = keyringmgr.get_last_login(server)
|
||||||
|
if login then
|
||||||
|
input_playername = login.playername
|
||||||
|
input_password = login.password
|
||||||
|
else
|
||||||
|
input_playername = core.settings:get("name")
|
||||||
|
input_password = ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -96,11 +110,6 @@ local function get_formspec(tabview, name, tabdata)
|
||||||
tabdata.search_for = ""
|
tabdata.search_for = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local password = ""
|
|
||||||
if core.settings:get_bool("remember_password") then
|
|
||||||
password = core.settings:get("password")
|
|
||||||
end
|
|
||||||
|
|
||||||
local retval =
|
local retval =
|
||||||
-- Search
|
-- Search
|
||||||
"field[0.25,0.25;7,0.75;te_search;;" .. core.formspec_escape(tabdata.search_for) .. "]" ..
|
"field[0.25,0.25;7,0.75;te_search;;" .. core.formspec_escape(tabdata.search_for) .. "]" ..
|
||||||
|
@ -134,8 +143,8 @@ local function get_formspec(tabview, name, tabdata)
|
||||||
"container[0,4.8]" ..
|
"container[0,4.8]" ..
|
||||||
"label[0.25,0;" .. fgettext("Name") .. "]" ..
|
"label[0.25,0;" .. fgettext("Name") .. "]" ..
|
||||||
"label[2.875,0;" .. fgettext("Password") .. "]" ..
|
"label[2.875,0;" .. fgettext("Password") .. "]" ..
|
||||||
"field[0.25,0.2;2.625,0.75;te_name;;" .. core.formspec_escape(core.settings:get("name")) .. "]" ..
|
"field[0.25,0.2;2.625,0.75;te_name;;" .. core.formspec_escape(input_playername) .. "]" ..
|
||||||
"pwdfield[2.875,0.2;2.625,0.75;te_pwd;;" .. core.formspec_escape(password) .. "]" ..
|
"pwdfield[2.875,0.2;2.625,0.75;te_pwd;;" .. core.formspec_escape(input_password) .. "]" ..
|
||||||
"container_end[]" ..
|
"container_end[]" ..
|
||||||
|
|
||||||
-- Connect
|
-- Connect
|
||||||
|
@ -445,15 +454,6 @@ end
|
||||||
local function main_button_handler(tabview, fields, name, tabdata)
|
local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
if fields.te_name then
|
if fields.te_name then
|
||||||
gamedata.playername = fields.te_name
|
gamedata.playername = fields.te_name
|
||||||
core.settings:set("name", fields.te_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
if core.settings:get_bool("remember_password") then
|
|
||||||
if fields.te_pwd then
|
|
||||||
core.settings:set("password", fields.te_pwd)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
core.settings:set("password", "")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.servers then
|
if fields.servers then
|
||||||
|
@ -568,6 +568,9 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
if server and server.address == gamedata.address and
|
if server and server.address == gamedata.address and
|
||||||
server.port == gamedata.port then
|
server.port == gamedata.port then
|
||||||
|
|
||||||
|
if core.settings:get_bool("remember_login") then
|
||||||
|
keyringmgr.set_login(server, gamedata.playername, gamedata.password)
|
||||||
|
end
|
||||||
serverlistmgr.add_favorite(server)
|
serverlistmgr.add_favorite(server)
|
||||||
|
|
||||||
gamedata.servername = server.name
|
gamedata.servername = server.name
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue