Author: sapient
Date: Sat Jun 2 09:48:47 2007
New Revision: 18008
URL: http://svn.gna.org/viewcvs/wesnoth?rev=18008&view=rev
Log:
backport r18005 to the 1.2 version... slightly different due to lack of
gui::dialog
Modified:
branches/1.2/changelog
branches/1.2/data/game.cfg
branches/1.2/src/game.cpp
branches/1.2/src/game_config.cpp
branches/1.2/src/game_config.hpp
branches/1.2/src/multiplayer.cpp
branches/1.2/src/preferences.cpp
branches/1.2/src/preferences.hpp
branches/1.2/src/wesconfig.h
Modified: branches/1.2/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/changelog?rev=18008&r1=18007&r2=18008&view=diff
==============================================================================
--- branches/1.2/changelog (original)
+++ branches/1.2/changelog Sat Jun 2 09:48:47 2007
@@ -12,6 +12,8 @@
* multiplayer maps:
* revised maps: Den of Onis, Hamlets, Meteor Lake, Sablestone Delta,
Silverhead Crossing, Blue Water Province, Wilderlands
+ * user interface:
+ * ability to view a list of MP servers with the Join Game dialog
* misc:
* corrected all wrong image references found via macroscope
Modified: branches/1.2/data/game.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/data/game.cfg?rev=18008&r1=18007&r2=18008&view=diff
==============================================================================
--- branches/1.2/data/game.cfg (original)
+++ branches/1.2/data/game.cfg Sat Jun 2 09:48:47 2007
@@ -54,6 +54,15 @@
[/advanced_preference]
[game_config]
+ [server]
+ name=_"Official Wesnoth Server"
+ address=devsrv.wesnoth.org:14999
+ [/server]
+ [server]
+ name=_"Alternate Wesnoth Server"
+ address=games.tuxfamily.org:14999
+ [/server]
+
base_income=2
village_income=1
poison_amount=8
Modified: branches/1.2/src/game.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/game.cpp?rev=18008&r1=18007&r2=18008&view=diff
==============================================================================
--- branches/1.2/src/game.cpp (original)
+++ branches/1.2/src/game.cpp Sat Jun 2 09:48:47 2007
@@ -1223,7 +1223,7 @@
} else if(res == 0 || res == 1) {
std::string host;
if(res == 0) {
- host = preferences::official_network_host();
+ host =
preferences::server_list().front().address;
}
mp::start_client(disp(), game_config_, units_data_,
host);
Modified: branches/1.2/src/game_config.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/game_config.cpp?rev=18008&r1=18007&r2=18008&view=diff
==============================================================================
--- branches/1.2/src/game_config.cpp (original)
+++ branches/1.2/src/game_config.cpp Sat Jun 2 09:48:47 2007
@@ -92,6 +92,7 @@
std::string path = "";
#endif
#endif
+ std::vector<server_info> server_list;
void load_config(const config* cfg)
{
@@ -181,6 +182,14 @@
for(int i=255;i>0;i--){
flag_rgb.push_back((Uint32)(i<<8));
}
+ }
+ const std::vector<config *> &servers = v.get_children("server");
+ std::vector<config *>::const_iterator server;
+ for(server = servers.begin(); server != servers.end();
++server) {
+ server_info sinf;
+ sinf.name = (**server)["name"];
+ sinf.address = (**server)["address"];
+ server_list.push_back(sinf);
}
}
const std::vector<Uint32>& tc_info(const std::string& name)
Modified: branches/1.2/src/game_config.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/game_config.hpp?rev=18008&r1=18007&r2=18008&view=diff
==============================================================================
--- branches/1.2/src/game_config.hpp (original)
+++ branches/1.2/src/game_config.hpp Sat Jun 2 09:48:47 2007
@@ -37,6 +37,12 @@
extern std::string path;
+ struct server_info {
+ std::string name;
+ std::string address; //may include ':' followed by port number
+ };
+ extern std::vector<server_info> server_list;
+
extern std::string game_icon, game_title, game_logo, title_music,
map_image, rightside_image, rightside_image_bot,
anonymous_music, victory_music, defeat_music,
moved_ball_image, unmoved_ball_image, partmoved_ball_image,
Modified: branches/1.2/src/multiplayer.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/multiplayer.cpp?rev=18008&r1=18007&r2=18008&view=diff
==============================================================================
--- branches/1.2/src/multiplayer.cpp (original)
+++ branches/1.2/src/multiplayer.cpp Sat Jun 2 09:48:47 2007
@@ -32,6 +32,7 @@
#include "statistics.hpp"
#include "serialization/string_utils.hpp"
#include "upload_log.hpp"
+#include "wml_separators.hpp"
#define LOG_NW LOG_STREAM(info, network)
@@ -86,19 +87,59 @@
SIMPLE_SERVER
};
+class server_list_action : public gui::dialog_button_action
+{
+public:
+ server_list_action(display& disp, std::string& result) : disp_(disp),
result_(result)
+ {}
+private:
+ gui::dialog_button_action::RESULT button_pressed(int /*menu_selection*/)
+ {
+ std::vector<std::string> servers;
+ const std::vector<game_config::server_info>& pref_servers =
preferences::server_list();
+ std::vector<game_config::server_info>::const_iterator server;
+ for(server = pref_servers.begin(); server !=
pref_servers.end(); ++server) {
+ servers.push_back(server->address +
HELP_STRING_SEPARATOR + server->name);
+ }
+ int res = gui::show_dialog(disp_, NULL, _("List of Servers"),
+ _("Choose a known server from the list"),
gui::OK_CANCEL, &servers);
+ if(res >= 0) {
+ result_ = pref_servers[res].address;
+ } else {
+ result_ = "invalid";
+ }
+ return gui::dialog_button_action::CLOSE_DIALOG;
+ }
+
+ display& disp_;
+ std::string& result_;
+};
+
server_type open_connection(display& disp, const std::string& original_host)
{
std::string h = original_host;
if(h.empty()) {
h = preferences::network_host();
- const int res = gui::show_dialog(disp, NULL, _("Connect to
Host"), "",
+ std::string list_return;
+ do {
+ if(!(list_return.empty() || list_return == "invalid")) {
+ h = list_return;
+ }
+ list_return = "";
+ server_list_action sla(disp, list_return);
+ gui::dialog_button sla_button(&sla,_("View List"));
+ std::vector<gui::dialog_button> buttons;
+ buttons.push_back(sla_button);
+ const int res = gui::show_dialog(disp, NULL, _("Connect
to Host"), "",
gui::OK_CANCEL, NULL, NULL,
- _("Choose host to connect to: "), &h);
-
- if(res != 0 || h.empty()) {
- return ABORT_SERVER;
- }
+ _("Choose host to connect to: "), &h,
+ -1, NULL, NULL, -1, -1, NULL, &buttons);
+
+ if(list_return.empty() && (res != 0 || h.empty())) {
+ return ABORT_SERVER;
+ }
+ } while(!list_return.empty());
}
network::connection sock;
@@ -215,7 +256,7 @@
}
} while(!(data.child("join_lobby") || data.child("join_game")));
- if (h != preferences::official_network_host())
+ if (h != preferences::server_list().front().address)
preferences::set_network_host(h);
if (data.child("join_lobby")) {
Modified: branches/1.2/src/preferences.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/preferences.cpp?rev=18008&r1=18007&r2=18008&view=diff
==============================================================================
--- branches/1.2/src/preferences.cpp (original)
+++ branches/1.2/src/preferences.cpp Sat Jun 2 09:48:47 2007
@@ -25,6 +25,7 @@
#include "sound.hpp"
#include "util.hpp"
#include "video.hpp" // non_interactive()
+#include "wassert.hpp"
#include "wesconfig.h"
#include "serialization/parser.hpp"
#include "serialization/string_utils.hpp"
@@ -297,17 +298,32 @@
prefs["lobby_joins"] = "no";
}
-const std::string& official_network_host()
-{
- static const std::string host = WESNOTH_DEFAULT_SERVER;
- return host;
-}
+const std::vector<game_config::server_info>& server_list()
+{
+ static std::vector<game_config::server_info> pref_servers;
+ if(pref_servers.empty()) {
+ std::vector<game_config::server_info> &game_servers =
game_config::server_list;
+ wassert(game_servers.size() > 0);
+ pref_servers.insert(pref_servers.begin(), game_servers.begin(),
game_servers.end());
+ const std::vector<config *> &user_servers =
prefs.get_children("server");
+ std::vector<config *>::const_iterator server;
+ for(server = user_servers.begin(); server !=
user_servers.end(); ++server) {
+ game_config::server_info sinf;
+ sinf.name = (**server)["name"];
+ sinf.address = (**server)["address"];
+ pref_servers.push_back(sinf);
+ }
+ }
+ return pref_servers;
+}
+
const std::string& network_host()
{
t_string& res = prefs["host"];
if(res.empty())
- res = WESNOTH_DEFAULT_SERVER;
+ res = server_list().front().address;
+
return res;
}
Modified: branches/1.2/src/preferences.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/preferences.hpp?rev=18008&r1=18007&r2=18008&view=diff
==============================================================================
--- branches/1.2/src/preferences.hpp (original)
+++ branches/1.2/src/preferences.hpp Sat Jun 2 09:48:47 2007
@@ -18,6 +18,7 @@
class team;
struct game_state;
+#include "game_config.hpp"
#include "unit.hpp"
#include <string>
@@ -91,7 +92,7 @@
bool lobby_joins();
void _set_lobby_joins(bool show);
- const std::string& official_network_host();
+ const std::vector<game_config::server_info>& server_list();
const std::string& network_host();
void set_network_host(const std::string& host);
Modified: branches/1.2/src/wesconfig.h
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.2/src/wesconfig.h?rev=18008&r1=18007&r2=18008&view=diff
==============================================================================
--- branches/1.2/src/wesconfig.h (original)
+++ branches/1.2/src/wesconfig.h Sat Jun 2 09:48:47 2007
@@ -5,7 +5,6 @@
# include "config.h"
#else
# define VERSION "1.2.4"
-# define WESNOTH_DEFAULT_SERVER "devsrv.wesnoth.org:14999"
# define PACKAGE "wesnoth"
# ifndef LOCALEDIR
# define LOCALEDIR "translations"
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits