diff options
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/common/misc_helpers.lua | 8 | ||||
-rw-r--r-- | builtin/mainmenu/common.lua | 56 | ||||
-rw-r--r-- | builtin/mainmenu/tab_multiplayer.lua | 13 | ||||
-rw-r--r-- | builtin/mainmenu/tab_simple_main.lua | 7 |
4 files changed, 76 insertions, 8 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index d9ebc39c3..39fca7d1e 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -564,7 +564,7 @@ if INIT == "mainmenu" then return nil end - function fgettext(text, ...) + function fgettext_ne(text, ...) text = core.gettext(text) local arg = {n=select('#', ...), ...} if arg.n >= 1 then @@ -586,7 +586,11 @@ if INIT == "mainmenu" then end text = result end - return core.formspec_escape(text) + return text + end + + function fgettext(text, ...) + return core.formspec_escape(fgettext_ne(text, ...)) end end diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 549c0967b..f32d77f2a 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -16,10 +16,16 @@ --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -------------------------------------------------------------------------------- -- Global menu data ---------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- menudata = {} -------------------------------------------------------------------------------- +-- Local cached values +-------------------------------------------------------------------------------- +local min_supp_proto = core.get_min_supp_proto() +local max_supp_proto = core.get_max_supp_proto() + +-------------------------------------------------------------------------------- -- Menu helper functions -------------------------------------------------------------------------------- @@ -43,6 +49,25 @@ function image_column(tooltip, flagname) end -------------------------------------------------------------------------------- +function order_favorite_list(list) + local res = {} + --orders the favorite list after support + for i=1,#list,1 do + local fav = list[i] + if is_server_protocol_compat(fav.proto_min, fav.proto_max) then + table.insert(res, fav) + end + end + for i=1,#list,1 do + local fav = list[i] + if not is_server_protocol_compat(fav.proto_min, fav.proto_max) then + table.insert(res, fav) + end + end + return res +end + +-------------------------------------------------------------------------------- function render_favorite(spec,render_details) local text = "" @@ -68,6 +93,7 @@ function render_favorite(spec,render_details) end local details = "" + local grey_out = not is_server_protocol_compat(spec.proto_max, spec.proto_min) if spec.clients ~= nil and spec.clients_max ~= nil then local clients_color = '' @@ -87,11 +113,17 @@ function render_favorite(spec,render_details) clients_color = '#ffba97' -- 90-100%: orange end + if grey_out then + clients_color = '#aaaaaa' + end + details = details .. clients_color .. ',' .. render_client_count(spec.clients) .. ',' .. '/,' .. render_client_count(spec.clients_max) .. ',' + elseif grey_out then + details = details .. '#aaaaaa,?,/,?,' else details = details .. ',?,/,?,' end @@ -114,7 +146,7 @@ function render_favorite(spec,render_details) details = details .. "0," end - return details .. text + return details .. (grey_out and '#aaaaaa,' or ',') .. text end -------------------------------------------------------------------------------- @@ -195,7 +227,7 @@ function asyncOnlineFavourites() nil, function(result) if core.setting_getbool("public_serverlist") then - menudata.favorites = result + menudata.favorites = order_favorite_list(result) core.event_handler("Refresh") end end @@ -225,3 +257,21 @@ function text2textlist(xpos,ypos,width,height,tl_name,textlen,text,transparency) return retval end + +-------------------------------------------------------------------------------- +function is_server_protocol_compat(proto_min, proto_max) + return not ((min_supp_proto > (proto_max or 24)) or (max_supp_proto < (proto_min or 13))) +end +-------------------------------------------------------------------------------- +function is_server_protocol_compat_or_error(proto_min, proto_max) + if not is_server_protocol_compat(proto_min, proto_max) then + gamedata.errormessage = fgettext_ne("Protocol version mismatch, server " .. + ((proto_min ~= proto_max) and "supports protocols between $1 and $2" or "enforces protocol version $1") .. + ", we " .. + ((min_supp_proto ~= max_supp_proto) and "support protocols between version $3 and $4." or "only support protocol version $3"), + proto_min or 13, proto_max or 24, min_supp_proto, max_supp_proto) + return false + end + + return true +end diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index 734cb5d3e..f9ac78f17 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -62,6 +62,7 @@ local function get_formspec(tabview, name, tabdata) image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" .. image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" .. image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" .. + "color,span=1;" .. "text,padding=1]" -- name else retval = retval .. "tablecolumns[text]" @@ -88,7 +89,6 @@ end -------------------------------------------------------------------------------- local function main_button_handler(tabview, fields, name, tabdata) - if fields["te_name"] ~= nil then gamedata.playername = fields["te_name"] core.setting_set("name", fields["te_name"]) @@ -98,6 +98,10 @@ local function main_button_handler(tabview, fields, name, tabdata) local event = core.explode_table_event(fields["favourites"]) if event.type == "DCL" then if event.row <= #menudata.favorites then + if not is_server_protocol_compat_or_error(menudata.favorites[event.row].proto_min, + menudata.favorites[event.row].proto_max) then + return true + end gamedata.address = menudata.favorites[event.row].address gamedata.port = menudata.favorites[event.row].port gamedata.playername = fields["te_name"] @@ -189,7 +193,7 @@ local function main_button_handler(tabview, fields, name, tabdata) local current_favourite = core.get_table_index("favourites") if current_favourite == nil then return end core.delete_favorite(current_favourite) - menudata.favorites = core.get_favorites() + menudata.favorites = order_favorite_list(core.get_favorites()) tabdata.fav_selected = nil core.setting_set("address","") @@ -214,6 +218,11 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.servername = menudata.favorites[fav_idx].name gamedata.serverdescription = menudata.favorites[fav_idx].description + + if not is_server_protocol_compat_or_error(menudata.favorites[fav_idx].proto_min, + menudata.favorites[fav_idx].proto_max)then + return true + end else gamedata.servername = "" gamedata.serverdescription = "" diff --git a/builtin/mainmenu/tab_simple_main.lua b/builtin/mainmenu/tab_simple_main.lua index 87bd551c0..b9a6b650f 100644 --- a/builtin/mainmenu/tab_simple_main.lua +++ b/builtin/mainmenu/tab_simple_main.lua @@ -45,6 +45,7 @@ local function get_formspec(tabview, name, tabdata) image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" .. image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" .. image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" .. + "color,span=1;" .. "text,padding=1]" -- name else retval = retval .. "tablecolumns[text]" @@ -87,7 +88,6 @@ local function get_formspec(tabview, name, tabdata) end -------------------------------------------------------------------------------- - local function main_button_handler(tabview, fields, name, tabdata) if fields["btn_start_singleplayer"] then @@ -159,6 +159,11 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.servername = menudata.favorites[fav_idx].name gamedata.serverdescription = menudata.favorites[fav_idx].description + + if not is_server_protocol_compat_or_error(menudata.favorites[fav_idx].proto_min, + menudata.favorites[fav_idx].proto_max) then + return true + end else gamedata.servername = "" gamedata.serverdescription = "" |