2014-04-18 15:39:15 +02:00
|
|
|
--Minetest
|
|
|
|
--Copyright (C) 2014 sapier
|
|
|
|
--
|
|
|
|
--This program is free software; you can redistribute it and/or modify
|
|
|
|
--it under the terms of the GNU Lesser General Public License as published by
|
2020-08-06 20:33:21 +02:00
|
|
|
--the Free Software Foundation; either version 3.0 of the License, or
|
2014-04-18 15:39:15 +02:00
|
|
|
--(at your option) any later version.
|
|
|
|
--
|
|
|
|
--This program is distributed in the hope that it will be useful,
|
|
|
|
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
--GNU Lesser General Public License for more details.
|
|
|
|
--
|
|
|
|
--You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
--with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2020-08-06 20:33:21 +02:00
|
|
|
local password_save = core.settings:get_bool("password_save")
|
|
|
|
local password_tmp = ""
|
|
|
|
|
2022-04-23 09:36:46 +03:00
|
|
|
local esc = core.formspec_escape
|
2022-06-14 20:58:04 +12:00
|
|
|
local defaulttexturedir = esc(defaulttexturedir)
|
2022-04-23 09:36:46 +03:00
|
|
|
local lower = utf8.lower
|
|
|
|
local mobile = PLATFORM == "Android" or PLATFORM == "iOS"
|
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
local function get_formspec(tabview, name, tabdata)
|
2016-03-14 10:18:29 +01:00
|
|
|
-- Update the cached supported proto info,
|
|
|
|
-- it may have changed after a change by the settings menu.
|
|
|
|
common_update_cached_supp_proto()
|
2021-01-22 15:08:57 +00:00
|
|
|
local selected
|
2017-01-06 20:29:29 +00:00
|
|
|
if menudata.search_result then
|
2021-01-22 15:08:57 +00:00
|
|
|
selected = menudata.search_result[tabdata.selected]
|
2017-01-06 20:29:29 +00:00
|
|
|
else
|
2021-01-22 15:08:57 +00:00
|
|
|
selected = serverlistmgr.servers[tabdata.selected]
|
2017-01-06 20:29:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if not tabdata.search_for then
|
|
|
|
tabdata.search_for = ""
|
|
|
|
end
|
2016-03-14 10:18:29 +01:00
|
|
|
|
2020-08-06 20:33:21 +02:00
|
|
|
local search_panel
|
2022-04-23 09:36:46 +03:00
|
|
|
if mobile then
|
2020-08-06 20:33:21 +02:00
|
|
|
search_panel =
|
2022-04-23 09:36:46 +03:00
|
|
|
"field[0.2,0.1;5.1,1;Dte_search;;" .. esc(tabdata.search_for) .. "]" ..
|
2022-06-14 20:58:04 +12:00
|
|
|
"image_button[4.87,-0.13;0.83,0.83;" .. defaulttexturedir ..
|
|
|
|
"search.png;btn_mp_search;;true;false]" ..
|
|
|
|
"image_button[5.62,-0.13;0.83,0.83;" .. defaulttexturedir ..
|
|
|
|
"refresh.png;btn_mp_refresh;;true;false]" ..
|
|
|
|
"image_button[6.37,-0.13;0.83,0.83;" .. defaulttexturedir ..
|
|
|
|
(serverlistmgr.mobile_only and "online_mobile" or "online_pc") .. ".png" ..
|
2022-02-27 21:33:33 +01:00
|
|
|
";btn_mp_mobile;;true;false]"
|
2020-08-06 20:33:21 +02:00
|
|
|
else
|
|
|
|
search_panel =
|
2022-04-23 09:36:46 +03:00
|
|
|
"field[0.2,0.1;5.8,1;Dte_search;;" .. esc(tabdata.search_for) .. "]" ..
|
2022-06-14 20:58:04 +12:00
|
|
|
"image_button[5.62,-0.13;0.83,0.83;" .. defaulttexturedir ..
|
|
|
|
"search.png;btn_mp_search;;true;false]" ..
|
|
|
|
"image_button[6.37,-0.13;0.83,0.83;" .. defaulttexturedir ..
|
|
|
|
"refresh.png;btn_mp_refresh;;true;false]"
|
2020-08-06 20:33:21 +02:00
|
|
|
end
|
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
local retval =
|
2017-01-16 15:15:43 +00:00
|
|
|
-- Search
|
2022-02-27 21:33:33 +01:00
|
|
|
search_panel ..
|
2017-01-16 15:15:43 +00:00
|
|
|
|
|
|
|
-- Address / Port
|
2022-02-27 21:33:33 +01:00
|
|
|
"field[7.4,0.6;3.2,0.5;te_address;" .. fgettext("Address") .. ":" .. ";" ..
|
2020-08-06 20:33:21 +02:00
|
|
|
esc(core.settings:get("address")) .. "]" ..
|
2022-02-27 21:33:33 +01:00
|
|
|
"field[10.45,0.6;1.95,0.5;te_port;" .. fgettext("Port") .. ":" .. ";" ..
|
2020-08-06 20:33:21 +02:00
|
|
|
esc(core.settings:get("remote_port")) .. "]" ..
|
|
|
|
|
|
|
|
-- Name
|
2022-02-27 21:33:33 +01:00
|
|
|
"field[7.4,1.75;3.2,0.5;te_name;" .. fgettext("Name") .. ":" .. ";" ..
|
2020-08-06 20:33:21 +02:00
|
|
|
esc(core.settings:get("name")) .. "]" ..
|
2017-01-16 15:15:43 +00:00
|
|
|
|
|
|
|
-- Description Background
|
2022-02-27 21:33:33 +01:00
|
|
|
"box[7.1,2.1;4.8,2.65;#33314B99]" ..
|
2017-01-16 15:15:43 +00:00
|
|
|
|
|
|
|
-- Connect
|
2022-06-14 20:58:04 +12:00
|
|
|
"style[btn_mp_connect;fgimg=" .. defaulttexturedir ..
|
|
|
|
"btn_play.png;fgimg_hovered=" .. defaulttexturedir .. "btn_play_hover.png]" ..
|
2022-02-27 21:33:33 +01:00
|
|
|
"image_button[8.8,4.88;3.3,0.9;;btn_mp_connect;;true;false]" ..
|
2020-08-06 20:33:21 +02:00
|
|
|
"tooltip[btn_mp_connect;".. fgettext("Connect") .. "]"
|
|
|
|
|
2022-02-27 21:33:33 +01:00
|
|
|
local pwd = password_save and core.settings:get("password") or password_tmp
|
2020-08-06 20:33:21 +02:00
|
|
|
-- Password
|
2022-02-27 21:33:33 +01:00
|
|
|
retval = retval .. "pwdfield[10.45,1.8;1.95,0.39;te_pwd;" ..
|
|
|
|
fgettext("Password") .. ":" .. ";" .. esc(pwd) .. "]"
|
2014-04-18 15:39:15 +02:00
|
|
|
|
2021-01-22 15:08:57 +00:00
|
|
|
if tabdata.selected and selected then
|
2016-04-18 18:20:04 +02:00
|
|
|
if gamedata.fav then
|
2022-06-14 20:58:04 +12:00
|
|
|
retval = retval ..
|
|
|
|
"style[btn_delete_favorite;fgimg=" .. defaulttexturedir ..
|
|
|
|
"trash.png;fgimg_hovered=" .. defaulttexturedir .. "trash_hover.png]" ..
|
|
|
|
"image_button[7.1,4.91;0.83,0.83;;btn_delete_favorite;;true;false]"
|
2016-04-18 18:20:04 +02:00
|
|
|
end
|
2021-06-11 18:14:03 +12:00
|
|
|
if selected.description then
|
2020-08-06 20:33:21 +02:00
|
|
|
retval = retval .. "textarea[7.5,2.2;4.8,3;;" ..
|
|
|
|
esc((gamedata.serverdescription or ""), true) .. ";]"
|
2016-04-18 18:20:04 +02:00
|
|
|
end
|
|
|
|
end
|
2014-12-01 00:58:00 +01:00
|
|
|
|
2022-02-27 21:33:33 +01:00
|
|
|
--favorites
|
2020-08-06 20:33:21 +02:00
|
|
|
retval = retval ..
|
2022-02-27 21:33:33 +01:00
|
|
|
"background9[-0.07,0.7;7.19,5.08;" ..
|
2022-06-14 20:58:04 +12:00
|
|
|
defaulttexturedir .. "worldlist_bg.png" .. ";false;40]" ..
|
2022-02-27 21:33:33 +01:00
|
|
|
"tableoptions[background=#0000;border=false]" ..
|
2020-08-06 20:33:21 +02:00
|
|
|
"tablecolumns[" ..
|
|
|
|
image_column(fgettext("Favorite")) .. ",align=center;" ..
|
2022-02-27 21:33:33 +01:00
|
|
|
image_column(fgettext("Lag")) .. ",padding=0.5;" ..
|
2016-04-18 18:20:04 +02:00
|
|
|
"color,span=3;" ..
|
2020-08-06 20:33:21 +02:00
|
|
|
"text,align=right;" .. -- clients
|
|
|
|
"text,align=center,padding=0.25;" .. -- "/"
|
|
|
|
"text,align=right,padding=0.25;" .. -- clients_max
|
|
|
|
image_column(fgettext("Server mode")) .. ",padding=0.5;" ..
|
2016-04-18 18:20:04 +02:00
|
|
|
"color,span=1;" ..
|
2020-08-06 20:33:21 +02:00
|
|
|
"text,padding=0.5]" ..
|
2022-02-27 21:33:33 +01:00
|
|
|
"table[-0.1,0.7;7,4.94;favorites;"
|
2017-01-06 20:29:29 +00:00
|
|
|
|
|
|
|
if menudata.search_result then
|
2021-01-22 15:08:57 +00:00
|
|
|
local favs = serverlistmgr.get_favorites()
|
2017-01-06 20:29:29 +00:00
|
|
|
for i = 1, #menudata.search_result do
|
|
|
|
local server = menudata.search_result[i]
|
|
|
|
for fav_id = 1, #favs do
|
|
|
|
if server.address == favs[fav_id].address and
|
|
|
|
server.port == favs[fav_id].port then
|
|
|
|
server.is_favorite = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if i ~= 1 then
|
|
|
|
retval = retval .. ","
|
|
|
|
end
|
|
|
|
|
2021-06-11 18:14:03 +12:00
|
|
|
retval = retval .. render_serverlist_row(server, server.is_favorite)
|
2017-01-06 20:29:29 +00:00
|
|
|
end
|
2021-01-22 15:08:57 +00:00
|
|
|
elseif #serverlistmgr.servers > 0 then
|
|
|
|
local favs = serverlistmgr.get_favorites()
|
2016-04-18 18:20:04 +02:00
|
|
|
if #favs > 0 then
|
|
|
|
for i = 1, #favs do
|
2021-01-22 15:08:57 +00:00
|
|
|
for j = 1, #serverlistmgr.servers do
|
2022-05-12 19:23:14 +03:00
|
|
|
if serverlistmgr.servers[j] and serverlistmgr.servers[j].address == favs[i].address and
|
2021-01-22 15:08:57 +00:00
|
|
|
serverlistmgr.servers[j].port == favs[i].port then
|
|
|
|
table.insert(serverlistmgr.servers, i, table.remove(serverlistmgr.servers, j))
|
|
|
|
end
|
2016-04-18 18:20:04 +02:00
|
|
|
end
|
2022-02-27 21:33:33 +01:00
|
|
|
if serverlistmgr.servers[i] and favs[i].address ~= serverlistmgr.servers[i].address then
|
2021-01-22 15:08:57 +00:00
|
|
|
table.insert(serverlistmgr.servers, i, favs[i])
|
2016-04-18 18:20:04 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-06-11 18:14:03 +12:00
|
|
|
|
|
|
|
retval = retval .. render_serverlist_row(serverlistmgr.servers[1], (#favs > 0))
|
|
|
|
for i = 2, #serverlistmgr.servers do
|
|
|
|
retval = retval .. "," .. render_serverlist_row(serverlistmgr.servers[i], (i <= #favs))
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-22 15:08:57 +00:00
|
|
|
if tabdata.selected then
|
|
|
|
retval = retval .. ";" .. tabdata.selected .. "]"
|
2014-04-18 15:39:15 +02:00
|
|
|
else
|
|
|
|
retval = retval .. ";0]"
|
|
|
|
end
|
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
2022-06-14 20:58:04 +12:00
|
|
|
local function is_favorite(server)
|
|
|
|
local favs = serverlistmgr.get_favorites()
|
|
|
|
for fav_id = 1, #favs do
|
|
|
|
if server.address == favs[fav_id].address and
|
|
|
|
server.port == favs[fav_id].port then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
local function main_button_handler(tabview, fields, name, tabdata)
|
2021-01-22 15:08:57 +00:00
|
|
|
local serverlist = menudata.search_result or serverlistmgr.servers
|
2017-01-06 20:29:29 +00:00
|
|
|
|
2016-04-18 22:43:12 +02:00
|
|
|
if fields.te_name then
|
|
|
|
gamedata.playername = fields.te_name
|
2014-12-12 14:49:19 -05:00
|
|
|
core.settings:set("name", fields.te_name)
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
|
2020-08-06 20:33:21 +02:00
|
|
|
if fields.te_pwd then
|
|
|
|
if password_save then
|
|
|
|
core.settings:set("password", fields.te_pwd)
|
|
|
|
else
|
|
|
|
password_tmp = fields.te_pwd
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-11 18:14:03 +12:00
|
|
|
if fields.favorites then
|
|
|
|
local event = core.explode_table_event(fields.favorites)
|
2017-01-06 20:29:29 +00:00
|
|
|
local fav = serverlist[event.row]
|
2016-04-18 18:20:04 +02:00
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
if event.type == "DCL" then
|
2017-01-06 20:29:29 +00:00
|
|
|
if event.row <= #serverlist then
|
2021-01-22 15:08:57 +00:00
|
|
|
if not is_server_protocol_compat_or_error(
|
2016-04-15 04:13:53 +02:00
|
|
|
fav.proto_min, fav.proto_max) then
|
2015-02-17 01:37:14 +01:00
|
|
|
return true
|
|
|
|
end
|
2016-04-18 22:43:12 +02:00
|
|
|
|
2016-04-15 04:13:53 +02:00
|
|
|
gamedata.address = fav.address
|
|
|
|
gamedata.port = fav.port
|
2016-04-18 22:43:12 +02:00
|
|
|
gamedata.playername = fields.te_name
|
2014-04-18 15:39:15 +02:00
|
|
|
gamedata.selected_world = 0
|
|
|
|
|
2016-04-18 22:43:12 +02:00
|
|
|
if fields.te_pwd then
|
|
|
|
gamedata.password = fields.te_pwd
|
|
|
|
end
|
|
|
|
|
2016-04-15 04:13:53 +02:00
|
|
|
gamedata.servername = fav.name
|
|
|
|
gamedata.serverdescription = fav.description
|
2014-04-18 15:39:15 +02:00
|
|
|
|
2016-04-18 22:43:12 +02:00
|
|
|
if gamedata.address and gamedata.port then
|
2014-12-12 14:49:19 -05:00
|
|
|
core.settings:set("address", gamedata.address)
|
|
|
|
core.settings:set("remote_port", gamedata.port)
|
2014-04-18 15:39:15 +02:00
|
|
|
core.start()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if event.type == "CHG" then
|
2017-01-06 20:29:29 +00:00
|
|
|
if event.row <= #serverlist then
|
2016-04-18 18:20:04 +02:00
|
|
|
gamedata.fav = false
|
2021-01-22 15:08:57 +00:00
|
|
|
local favs = serverlistmgr.get_favorites()
|
2016-04-18 18:20:04 +02:00
|
|
|
local address = fav.address
|
|
|
|
local port = fav.port
|
|
|
|
gamedata.serverdescription = fav.description
|
|
|
|
|
|
|
|
for i = 1, #favs do
|
|
|
|
if fav.address == favs[i].address and
|
|
|
|
fav.port == favs[i].port then
|
|
|
|
gamedata.fav = true
|
|
|
|
end
|
|
|
|
end
|
2014-04-18 15:39:15 +02:00
|
|
|
|
2016-04-18 22:43:12 +02:00
|
|
|
if address and port then
|
2014-12-12 14:49:19 -05:00
|
|
|
core.settings:set("address", address)
|
|
|
|
core.settings:set("remote_port", port)
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
2021-01-22 15:08:57 +00:00
|
|
|
tabdata.selected = event.row
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-18 22:43:12 +02:00
|
|
|
if fields.key_up or fields.key_down then
|
2021-01-22 15:08:57 +00:00
|
|
|
local fav_idx = core.get_table_index("favorites")
|
2017-01-06 20:29:29 +00:00
|
|
|
local fav = serverlist[fav_idx]
|
2014-04-18 15:39:15 +02:00
|
|
|
|
2016-04-18 22:43:12 +02:00
|
|
|
if fav_idx then
|
|
|
|
if fields.key_up and fav_idx > 1 then
|
|
|
|
fav_idx = fav_idx - 1
|
2021-01-22 15:08:57 +00:00
|
|
|
elseif fields.key_down and fav_idx < #serverlistmgr.servers then
|
2016-04-18 22:43:12 +02:00
|
|
|
fav_idx = fav_idx + 1
|
|
|
|
end
|
2014-04-18 15:39:15 +02:00
|
|
|
else
|
|
|
|
fav_idx = 1
|
|
|
|
end
|
2016-04-18 22:43:12 +02:00
|
|
|
|
2021-01-22 15:08:57 +00:00
|
|
|
if not serverlistmgr.servers or not fav then
|
|
|
|
tabdata.selected = 0
|
2014-06-22 14:00:57 +02:00
|
|
|
return true
|
|
|
|
end
|
2016-04-18 22:43:12 +02:00
|
|
|
|
|
|
|
local address = fav.address
|
|
|
|
local port = fav.port
|
2017-01-06 20:29:29 +00:00
|
|
|
gamedata.serverdescription = fav.description
|
2016-04-18 22:43:12 +02:00
|
|
|
if address and port then
|
2014-12-12 14:49:19 -05:00
|
|
|
core.settings:set("address", address)
|
|
|
|
core.settings:set("remote_port", port)
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
|
2021-01-22 15:08:57 +00:00
|
|
|
tabdata.selected = fav_idx
|
2014-04-18 15:39:15 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2016-04-18 18:20:04 +02:00
|
|
|
if fields.btn_delete_favorite then
|
2021-01-22 15:08:57 +00:00
|
|
|
local current_favorite = core.get_table_index("favorites")
|
|
|
|
if not current_favorite then return end
|
2016-04-18 18:20:04 +02:00
|
|
|
|
2021-01-22 15:08:57 +00:00
|
|
|
serverlistmgr.delete_favorite(serverlistmgr.servers[current_favorite])
|
|
|
|
serverlistmgr.sync()
|
|
|
|
tabdata.selected = nil
|
2014-04-18 15:39:15 +02:00
|
|
|
|
2021-06-11 18:14:03 +12:00
|
|
|
core.settings:set("address", "")
|
|
|
|
core.settings:set("remote_port", "30000")
|
2014-04-18 15:39:15 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2022-04-23 09:36:46 +03:00
|
|
|
if fields.btn_mp_refresh or fields.btn_mp_mobile then
|
|
|
|
if fields.btn_mp_mobile then
|
|
|
|
serverlistmgr.mobile_only = not serverlistmgr.mobile_only
|
|
|
|
end
|
|
|
|
serverlistmgr.sync()
|
2020-12-20 00:00:20 +03:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2022-04-23 09:36:46 +03:00
|
|
|
if (fields.Dte_search or fields.btn_mp_search) and not
|
|
|
|
(fields.btn_mp_connect or fields.key_enter) then
|
2021-01-22 15:08:57 +00:00
|
|
|
tabdata.selected = 1
|
2022-04-23 09:36:46 +03:00
|
|
|
local input = lower(fields.Dte_search)
|
|
|
|
tabdata.search_for = fields.Dte_search
|
2017-01-06 20:29:29 +00:00
|
|
|
|
2021-01-22 15:08:57 +00:00
|
|
|
if #serverlistmgr.servers < 2 then
|
2017-01-06 20:29:29 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
menudata.search_result = {}
|
|
|
|
|
|
|
|
-- setup the keyword list
|
|
|
|
local keywords = {}
|
|
|
|
for word in input:gmatch("%S+") do
|
2018-11-10 23:46:51 +10:00
|
|
|
word = word:gsub("(%W)", "%%%1")
|
2017-01-06 20:29:29 +00:00
|
|
|
table.insert(keywords, word)
|
|
|
|
end
|
|
|
|
|
|
|
|
if #keywords == 0 then
|
|
|
|
menudata.search_result = nil
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Search the serverlist
|
|
|
|
local search_result = {}
|
2021-01-22 15:08:57 +00:00
|
|
|
for i = 1, #serverlistmgr.servers do
|
|
|
|
local server = serverlistmgr.servers[i]
|
2017-01-06 20:29:29 +00:00
|
|
|
local found = 0
|
|
|
|
for k = 1, #keywords do
|
|
|
|
local keyword = keywords[k]
|
|
|
|
if server.name then
|
2022-04-23 09:36:46 +03:00
|
|
|
local sername = lower(server.name)
|
2019-08-06 19:30:18 +01:00
|
|
|
local _, count = sername:gsub(keyword, keyword)
|
2017-01-06 20:29:29 +00:00
|
|
|
found = found + count * 4
|
|
|
|
end
|
|
|
|
|
|
|
|
if server.description then
|
2022-04-23 09:36:46 +03:00
|
|
|
local desc = lower(server.description)
|
2017-01-06 20:29:29 +00:00
|
|
|
local _, count = desc:gsub(keyword, keyword)
|
|
|
|
found = found + count * 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if found > 0 then
|
2021-01-22 15:08:57 +00:00
|
|
|
local points = (#serverlistmgr.servers - i) / 5 + found
|
2017-01-06 20:29:29 +00:00
|
|
|
server.points = points
|
|
|
|
table.insert(search_result, server)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if #search_result > 0 then
|
|
|
|
table.sort(search_result, function(a, b)
|
|
|
|
return a.points > b.points
|
|
|
|
end)
|
|
|
|
menudata.search_result = search_result
|
|
|
|
local first_server = search_result[1]
|
2022-06-14 20:58:04 +12:00
|
|
|
if first_server.address and first_server.port then
|
|
|
|
core.settings:set("address", first_server.address)
|
|
|
|
core.settings:set("remote_port", first_server.port)
|
|
|
|
gamedata.serverdescription = first_server.description
|
|
|
|
end
|
2017-01-06 20:29:29 +00:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-05-10 22:25:45 +01:00
|
|
|
if (fields.btn_mp_connect or fields.key_enter)
|
|
|
|
and fields.te_address ~= "" and fields.te_port then
|
2016-04-18 22:43:12 +02:00
|
|
|
gamedata.playername = fields.te_name
|
|
|
|
gamedata.password = fields.te_pwd
|
|
|
|
gamedata.address = fields.te_address
|
2022-06-25 21:05:54 +12:00
|
|
|
gamedata.port = tonumber(fields.te_port) or 30000
|
2016-04-18 22:43:12 +02:00
|
|
|
gamedata.selected_world = 0
|
2021-01-22 15:08:57 +00:00
|
|
|
local fav_idx = core.get_table_index("favorites")
|
2017-01-06 20:29:29 +00:00
|
|
|
local fav = serverlist[fav_idx]
|
2014-04-18 15:39:15 +02:00
|
|
|
|
2017-01-06 20:29:29 +00:00
|
|
|
if fav_idx and fav_idx <= #serverlist and
|
2021-01-22 15:08:57 +00:00
|
|
|
fav.address == gamedata.address and
|
|
|
|
fav.port == gamedata.port then
|
2022-06-14 20:58:04 +12:00
|
|
|
if not is_server_protocol_compat_or_error(
|
|
|
|
fav.proto_min, fav.proto_max) then
|
|
|
|
return true
|
|
|
|
elseif fav.proto_max and fav.proto_max < 37 and not is_favorite(fav) then
|
|
|
|
local dlg = create_outdated_server_dlg(fav)
|
|
|
|
dlg:set_parent(tabview)
|
|
|
|
tabview:hide()
|
|
|
|
dlg:show()
|
|
|
|
return true
|
|
|
|
end
|
2021-01-22 15:08:57 +00:00
|
|
|
|
|
|
|
serverlistmgr.add_favorite(fav)
|
2014-04-18 15:39:15 +02:00
|
|
|
|
2016-04-15 04:13:53 +02:00
|
|
|
gamedata.servername = fav.name
|
|
|
|
gamedata.serverdescription = fav.description
|
2014-04-18 15:39:15 +02:00
|
|
|
else
|
|
|
|
gamedata.servername = ""
|
|
|
|
gamedata.serverdescription = ""
|
2021-01-22 15:08:57 +00:00
|
|
|
|
|
|
|
serverlistmgr.add_favorite({
|
|
|
|
address = gamedata.address,
|
|
|
|
port = gamedata.port,
|
|
|
|
})
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
|
2020-08-06 20:33:21 +02:00
|
|
|
local auto_connect = false
|
|
|
|
for _, server in pairs(serverlist) do
|
|
|
|
if server.server_id == "multicraft" and server.address == gamedata.address then
|
|
|
|
auto_connect = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
core.settings:set_bool("auto_connect", auto_connect)
|
|
|
|
core.settings:set("connect_time", os.time())
|
|
|
|
core.settings:set("maintab_LAST", "online")
|
2021-06-11 18:14:03 +12:00
|
|
|
core.settings:set("address", gamedata.address)
|
|
|
|
core.settings:set("remote_port", gamedata.port)
|
2014-04-18 15:39:15 +02:00
|
|
|
|
|
|
|
core.start()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2016-04-18 18:20:04 +02:00
|
|
|
local function on_change(type, old_tab, new_tab)
|
|
|
|
if type == "LEAVE" then return end
|
2021-01-22 15:08:57 +00:00
|
|
|
serverlistmgr.sync()
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2016-03-31 17:26:39 +09:00
|
|
|
return {
|
2017-05-21 01:07:05 -07:00
|
|
|
name = "online",
|
2021-06-11 18:14:03 +12:00
|
|
|
caption = fgettext("Join Game"),
|
2014-04-18 15:39:15 +02:00
|
|
|
cbf_formspec = get_formspec,
|
|
|
|
cbf_button_handler = main_button_handler,
|
|
|
|
on_change = on_change
|
2016-03-31 17:26:39 +09:00
|
|
|
}
|