Fixed serverlist to ignore invalid settings when loading

This commit is contained in:
TheSumm 2015-07-17 11:22:31 +02:00
parent 0ecf2229e6
commit b822e92c0e
2 changed files with 11 additions and 7 deletions

View File

@ -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

View File

@ -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'