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) local added, error = ServerList.add(host, port, protocol)
if not added then if not added then
displayErrorBox(tr('Add Error'), tr(error)) displayErrorBox(tr('Error'), tr(error))
else else
AddServer.hide() AddServer.hide()
end end

View File

@ -11,8 +11,10 @@ function ServerList.init()
serverListWindow = g_ui.displayUI('serverlist') serverListWindow = g_ui.displayUI('serverlist')
serverTextList = serverListWindow:getChildById('serverList') serverTextList = serverListWindow:getChildById('serverList')
servers = g_settings.getNode('ServerList') or {} local serverSettings = g_settings.getNode('ServerList')
ServerList.load() if serverSettings then
ServerList.load(serverSettings)
end
end end
function ServerList.terminate() function ServerList.terminate()
@ -23,9 +25,9 @@ function ServerList.terminate()
ServerList = nil ServerList = nil
end end
function ServerList.load() function ServerList.load(serverSettings)
for k,server in pairs(servers) do for host, server in pairs(serverSettings) do
ServerList.add(k, server.port, server.protocol, true) ServerList.add(host, server.port, server.protocol, true)
end end
end end
@ -43,7 +45,9 @@ function ServerList.select()
end end
function ServerList.add(host, port, protocol, load) 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' return false, 'Server already exists'
elseif host == '' or port == '' then elseif host == '' or port == '' then
return false, 'Required fields are missing' return false, 'Required fields are missing'