Fixed serverlist to ignore invalid settings when loading
This commit is contained in:
parent
0ecf2229e6
commit
b822e92c0e
|
@ -19,7 +19,7 @@ function AddServer.add()
|
|||
|
||||
local added, error = ServerList.add(host, port, protocol)
|
||||
if not added then
|
||||
displayErrorBox(tr('Add Error'), tr(error))
|
||||
displayErrorBox(tr('Error'), tr(error))
|
||||
else
|
||||
AddServer.hide()
|
||||
end
|
||||
|
|
|
@ -11,8 +11,10 @@ function ServerList.init()
|
|||
serverListWindow = g_ui.displayUI('serverlist')
|
||||
serverTextList = serverListWindow:getChildById('serverList')
|
||||
|
||||
servers = g_settings.getNode('ServerList') or {}
|
||||
ServerList.load()
|
||||
local serverSettings = g_settings.getNode('ServerList')
|
||||
if serverSettings then
|
||||
ServerList.load(serverSettings)
|
||||
end
|
||||
end
|
||||
|
||||
function ServerList.terminate()
|
||||
|
@ -23,9 +25,9 @@ function ServerList.terminate()
|
|||
ServerList = nil
|
||||
end
|
||||
|
||||
function ServerList.load()
|
||||
for k,server in pairs(servers) do
|
||||
ServerList.add(k, server.port, server.protocol, true)
|
||||
function ServerList.load(serverSettings)
|
||||
for host, server in pairs(serverSettings) do
|
||||
ServerList.add(host, server.port, server.protocol, true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,7 +45,9 @@ function ServerList.select()
|
|||
end
|
||||
|
||||
function ServerList.add(host, port, protocol, load)
|
||||
if not load and servers[host] then
|
||||
if not host or not port or not protocol then
|
||||
return false, 'Failed to load settings'
|
||||
elseif not load and servers[host] then
|
||||
return false, 'Server already exists'
|
||||
elseif host == '' or port == '' then
|
||||
return false, 'Required fields are missing'
|
||||
|
|
Loading…
Reference in New Issue