Fix serverlist

This commit is contained in:
sapier 2013-07-09 21:54:30 +02:00 committed by PilzAdam
parent e3b7c8e0cc
commit 1c7c5d571d
4 changed files with 54 additions and 29 deletions

@ -15,7 +15,7 @@ function render_favourite(spec)
local text = ""
if spec.name ~= nil then
text = text .. spec.name:trim()
text = text .. fs_escape_string(spec.name:trim())
if spec.description ~= nil then
--TODO make sure there's no invalid chat in spec.description
@ -52,12 +52,6 @@ function render_favourite(spec)
details = details .. " "
end
if spec.port ~= nil then
text = text .. ":" .. spec.port:trim()
else
text = text .. ":??"
end
return text
end
@ -119,6 +113,8 @@ function cleanup_path(temppath)
return temppath
end
--------------------------------------------------------------------------------
function menu.set_texture(identifier,gamedetails)
local texture_set = false
if menu.texturepack ~= nil and gamedetails ~= nil then
@ -696,6 +692,11 @@ function tabbuilder.handle_multiplayer_buttons(fields)
end
gamedata.selected_world = 0
if menu.favorites ~= nil then
gamedata.servername = menu.favorites[event.index].name
gamedata.serverdescription = menu.favorites[event.index].description
end
if gamedata.address ~= nil and
gamedata.port ~= nil then
@ -704,10 +705,7 @@ function tabbuilder.handle_multiplayer_buttons(fields)
end
if event.typ == "CHG" then
local address = menu.favorites[event.index].name
if address == nil then
address = menu.favorites[event.index].address
end
local address = menu.favorites[event.index].address
local port = menu.favorites[event.index].port
if address ~= nil and
@ -757,7 +755,7 @@ function tabbuilder.handle_multiplayer_buttons(fields)
else
menu.favorites = engine.get_favorites("local")
end
menu.fav_selected = nil
return
end
@ -765,6 +763,7 @@ function tabbuilder.handle_multiplayer_buttons(fields)
local current_favourite = engine.get_textlist_index("favourites")
engine.delete_favorite(current_favourite)
menu.favorites = engine.get_favorites()
menu.fav_selected = nil
engine.setting_set("address","")
engine.setting_get("port","")
@ -779,6 +778,20 @@ function tabbuilder.handle_multiplayer_buttons(fields)
gamedata.password = fields["te_pwd"]
gamedata.address = fields["te_address"]
gamedata.port = fields["te_port"]
local fav_idx = engine.get_textlist_index("favourites")
if fav_idx > 0 and fav_idx <= #menu.favorites and
menu.favorites[fav_idx].address == fields["te_address"] and
menu.favorites[fav_idx].port == fields["te_port"] then
gamedata.servername = menu.favorites[fav_idx].name
gamedata.serverdescription = menu.favorites[fav_idx].description
else
gamedata.servername = ""
gamedata.serverdescription = ""
end
gamedata.selected_world = 0
engine.start()
@ -1134,12 +1147,18 @@ function tabbuilder.tab_multiplayer()
"label[9,0;Name/Password]" ..
"field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
"field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("port") .."]" ..
"button[6.45,3.95;2.25,0.5;btn_delete_favorite;Delete]" ..
"checkbox[1,3.6;cb_public_serverlist;Public Serverlist;" ..
dump(engine.setting_getbool("public_serverlist")) .. "]"
if not engine.setting_getbool("public_serverlist") then
retval = retval ..
"button[6.45,3.95;2.25,0.5;btn_delete_favorite;Delete]"
end
retval = retval ..
"button[9,4.95;2.5,0.5;btn_mp_connect;Connect]" ..
"field[9.25,1;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
"pwdfield[9.25,1.75;2.5,0.5;te_pwd;]" ..
"checkbox[1,3.6;cb_public_serverlist;Public Serverlist;" ..
dump(engine.setting_getbool("public_serverlist")) .. "]" ..
"textlist[1,0.35;7.5,3.35;favourites;"
if #menu.favorites > 0 then
@ -1150,7 +1169,6 @@ function tabbuilder.tab_multiplayer()
end
end
print("cfav: " .. dump(menu.fav_selected))
if menu.fav_selected ~= nil then
retval = retval .. ";" .. menu.fav_selected .. "]"
else
@ -1195,10 +1213,11 @@ function tabbuilder.tab_server()
retval = retval .. "," .. menu.worldlist[i].name ..
" \\[" .. menu.worldlist[i].gameid .. "\\]"
end
retval = retval .. ";" .. index .. "]"
else
retval = retval .. ";0]"
end
retval = retval .. ";" .. index .. "]"
return retval
end
@ -1227,7 +1246,8 @@ end
function tabbuilder.tab_singleplayer()
local index = engine.setting_get("main_menu_singleplayer_world_idx")
if index == nil then
if index == nil or
#menu.filtered_game_list_raw() == 0 then
index = 0
end

@ -77,9 +77,11 @@ function fs_escape_string(text)
text = newtext
end
text = text:gsub("%[","\\%[")
text = text:gsub("]","\\]")
text = text:gsub(";","\\;")
text = string.gsub(text,"\\","\\\\")
text = string.gsub(text,"%]","\\]")
text = string.gsub(text,"%[","\\[")
text = string.gsub(text,";","\\;")
text = string.gsub(text,",","\\,")
end
return text
end

@ -611,7 +611,7 @@ void GUIFormSpecMenu::parseTextList(parserData* data,std::string element) {
std::vector<std::string> v_pos = split(parts[0],',');
std::vector<std::string> v_geom = split(parts[1],',');
std::string name = parts[2];
std::vector<std::string> items = split(parts[3],',');
std::vector<std::string> items = split(parts[3],',',true);
std::string str_initial_selection = "";
std::string str_transparent = "false";
@ -1352,6 +1352,7 @@ void GUIFormSpecMenu::parseBox(parserData* data,std::string element) {
}
void GUIFormSpecMenu::parseElement(parserData* data,std::string element) {
//some prechecks
if (element == "")
return;

@ -197,12 +197,14 @@ int guiLuaApi::l_start(lua_State *L)
bool valid = false;
engine->m_data->selected_world = getIntegerData(L, "selected_world",valid) -1;
engine->m_data->selected_world = getIntegerData(L, "selected_world",valid) -1;
engine->m_data->simple_singleplayer_mode = getBoolData(L,"singleplayer",valid);
engine->m_data->name = getTextData(L,"playername");
engine->m_data->password = getTextData(L,"password");
engine->m_data->address = getTextData(L,"address");
engine->m_data->port = getTextData(L,"port");
engine->m_data->name = getTextData(L,"playername");
engine->m_data->password = getTextData(L,"password");
engine->m_data->address = getTextData(L,"address");
engine->m_data->port = getTextData(L,"port");
engine->m_data->serverdescription = getTextData(L,"serverdescription");
engine->m_data->servername = getTextData(L,"servername");
//close menu next time
engine->m_startgame = true;