58 #define LOG_NW LOG_STREAM(info, log_network)
61 #define DBG_MP LOG_STREAM(debug, log_mp)
74 DBG_MP <<
"running lobby loop" << std::endl;
112 DBG_MP <<
"opening connection" << std::endl;
125 std::unique_ptr<twesnothd_connection> sock;
127 const int pos = h.find_first_of(
":");
135 host = h.substr(0, pos);
136 port = lexical_cast_default<unsigned int>(h.substr(pos + 1), 15000);
141 typedef std::pair<std::string, int> hostpair;
142 std::set<hostpair> shown_hosts;
143 shown_hosts.insert(hostpair(host, port));
151 return std::move(sock);
161 version = reject[
"accepted_versions"].str();
164 version = data[
"version"].str();
168 i18n_symbols[
"version1"] =
version;
170 const std::string errorstring =
vgettext(
"The server accepts versions '$version1' while you are using version '$version2'", i18n_symbols);
175 if (
const config &redirect = data.
child(
"redirect"))
177 host = redirect[
"host"].str();
178 port =redirect[
"port"].to_int(15000);
180 if(shown_hosts.find(hostpair(host,port)) != shown_hosts.end()) {
183 shown_hosts.insert(hostpair(host, port));
189 if(data.
child(
"version")) {
198 if(data.
child(
"mustlogin")) {
207 sp[
"username"] =
login ;
215 sp[
"selective_ping"] =
false;
219 sp[
"selective_ping"] =
true;
229 i18n_symbols[
"nick"] =
login;
232 warning_msg =
vgettext(
"The nickname ‘$nick’ is inactive. "
233 "You cannot claim ownership of this nickname until you "
234 "activate your account via email or ask an "
235 "administrator to do it for you.", i18n_symbols);
237 warning_msg = (*warning)[
"message"].str();
240 warning_msg +=
"\n\n";
241 warning_msg +=
_(
"Do you want to continue?");
256 bool fall_through = (*error)[
"force_confirmation"].to_bool() ?
260 const bool is_pw_request = !((*error)[
"password_request"].empty()) && !(password.empty());
266 if((is_pw_request || !password_reminder.empty()) && !fall_through) {
268 if ((*error)[
"phpbb_encryption"].to_bool())
275 for(std::string::size_type pos = 0; (pos = password.find(
'&', pos)) != std::string::npos; ++
pos )
276 password.replace(pos, 1,
"&");
277 for(std::string::size_type pos = 0; (pos = password.find(
'\"', pos)) != std::string::npos; ++
pos )
278 password.replace(pos, 1,
""");
279 for(std::string::size_type pos = 0; (pos = password.find(
'<', pos)) != std::string::npos; ++
pos )
280 password.replace(pos, 1,
"<");
281 for(std::string::size_type pos = 0; (pos = password.find(
'>', pos)) != std::string::npos; ++
pos )
282 password.replace(pos, 1,
">");
286 if (salt.length() < 12) {
298 sp[
"password_reminder"] = password_reminder;
305 error = &data.
child(
"error");
313 password_reminder =
"";
322 i18n_symbols[
"nick"] =
login;
325 error_message =
_(
"You must login first.");
327 error_message =
vgettext(
"The nickname ‘$nick’ is already taken.", i18n_symbols);
329 error_message =
vgettext(
"The nickname ‘$nick’ contains invalid "
330 "characters. Only alpha-numeric characters, underscores and "
331 "hyphens are allowed.", i18n_symbols);
333 error_message =
vgettext(
"The nickname ‘$nick’ is too long. Nicks must "
334 "be 20 characters or less.", i18n_symbols);
336 error_message =
vgettext(
"The nickname ‘$nick’ is reserved and cannot be used by players.", i18n_symbols);
338 error_message =
vgettext(
"The nickname ‘$nick’ is not registered on this server.", i18n_symbols)
339 +
_(
" This server disallows unregistered nicknames.");
341 error_message =
vgettext(
"The nickname ‘$nick’ is registered on this server.", i18n_symbols);
343 error_message =
vgettext(
"The nickname ‘$nick’ is registered on this server.", i18n_symbols)
344 +
"\n\n" +
_(
"WARNING: There is already a client using this nickname, "
345 "logging in will cause that client to be kicked!");
347 error_message =
_(
"Error in the login procedure (the server had no "
348 "seed for your connection).");
350 error_message =
_(
"The password you provided was incorrect.");
352 error_message =
_(
"You have made too many login attempts.");
354 error_message = (*error)[
"message"].str();
357 gui2::tmp_login dlg(error_message, !((*error)[
"password_request"].empty()));
366 password_reminder =
"yes";
382 }
while(!(data.
child(
"join_lobby") || data.
child(
"join_game")));
387 if (data.
child(
"join_lobby")) {
409 bool observe,
int current_turn = 0)
411 DBG_MP <<
"entering wait mode" << std::endl;
425 mp::wait ui(video, wesnothd_connection, game_config, state, gamechat, gamelist);
436 DBG_MP <<
"skipped wait mode, result = " << res << std::endl;
455 bool local_players_only =
false);
459 bool local_players_only =
false)
461 DBG_MP <<
"entering connect mode" << std::endl;
467 std::unique_ptr<mp_campaign_info> campaign_info;
468 if(!local_players_only) {
469 assert(wesnothd_connection);
481 res = ui.get_result();
495 if (wesnothd_connection) {
501 enter_create_mode(video, game_config, state, wesnothd_connection, local_players_only);
502 if (wesnothd_connection) {
508 if (wesnothd_connection) {
519 bool local_players_only =
false);
524 DBG_MP <<
"entering create mode" << std::endl;
526 bool configure_canceled;
527 bool connect_canceled;
530 configure_canceled =
false;
531 connect_canceled =
false;
539 if (wesnothd_connection) {
547 mp::create ui(video, wesnothd_connection, game_config, state, gamechat, gamelist);
555 configure_canceled = !
enter_configure_mode(video, game_config, state, wesnothd_connection, local_players_only);
558 connect_canceled = !
enter_connect_mode(video, game_config, state, wesnothd_connection, local_players_only);
563 if (wesnothd_connection) {
569 }
while(configure_canceled || connect_canceled);
575 DBG_MP <<
"entering configure mode" << std::endl;
577 bool connect_canceled;
580 connect_canceled =
false;
586 mp::configure ui(video, wesnothd_connection, game_config, gamechat, gamelist, state,
599 connect_canceled = !
enter_connect_mode(video, game_config, state, wesnothd_connection, local_players_only);
604 if (wesnothd_connection) {
609 }
while(connect_canceled);
616 DBG_MP <<
"displaying preferences dialog" << std::endl;
637 assert(wesnothd_connection);
638 DBG_MP <<
"entering lobby mode" << std::endl;
641 int current_turn = 0;
643 const config &cfg = game_config.
child(
"lobby_music");
653 lobby_info li(game_config, *wesnothd_connection);
685 mp::lobby ui(video, wesnothd_connection, game_config, gamechat, gamelist, installed_addons);
734 DBG_MP <<
"starting local game" << std::endl;
735 gamechat.clear_history();
744 DBG_MP <<
"starting local MP game from commandline" << std::endl;
749 gamechat.clear_history();
753 DBG_MP <<
"entering create mode" << std::endl;
759 parameters.
mp_era =
"era_default";
760 parameters.
name =
"multiplayer_The_Freelands";
770 DBG_MP <<
"ignoring map settings" << std::endl;
779 state.
classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
788 std::cerr <<
"Could not find era '" << parameters.
mp_era <<
"'\n";
795 if (
const config& cfg_multiplayer = game_config.
find_child(
"multiplayer",
"id", parameters.
name)) {
799 std::cerr <<
"Could not find [multiplayer] '" << parameters.
name <<
"'\n";
816 DBG_MP <<
"entering connect mode" << std::endl;
835 for(
unsigned int i = 0;
i < repeat;
i++){
846 const config * game_config_ptr = &game_config;
852 DBG_MP <<
"starting client" << std::endl;
856 gamechat.clear_history();
858 std::unique_ptr<twesnothd_connection> wesnothd_connection =
open_connection(video, host);
859 if(wesnothd_connection) {
887 mp::connect ui(video, wesnothd_connection, game_name, game_config, gamechat, gamelist,
905 mp::wait ui(video, wesnothd_connection, game_config, state, gamechat, gamelist,
false);
An error occured during when trying to coommunicate with the wesnothd server.
bool new_widgets
Do we wish to use the new library or not.
child_itors child_range(const std::string &key)
void show_error_message(CVideo &video, const std::string &message, bool message_use_markup)
Shows an error message to the user.
int skip_replay_until_turn
std::unique_ptr< twesnothd_connection > network_connect_dialog(CVideo &video, const std::string &msg, const std::string &hostname, int port)
bool skip_replay_blindfolded
static bool enter_configure_mode(CVideo &video, const config &game_config, saved_game &state, twesnothd_connection *wesnothd_connection, bool local_players_only=false)
static void enter_create_mode(CVideo &video, const config &game_config, saved_game &state, twesnothd_connection *wesnothd_connection, bool local_players_only=false)
void fill_rect(surface &dst, SDL_Rect *dst_rect, const Uint32 color)
Fill a rectangle on a given surface.
unsigned int get_ping_timeout()
void set_resolution(const std::pair< int, int > &res)
Set the resolution.
void set_mp_info(mp_campaign_info *mp_info)
void start_client(CVideo &video, const config &game_config, saved_game &state, const std::string &host)
Starts a multiplayer game in client mode.
const mp_game_settings & get_parameters()
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
static l_noret error(LoadState *S, const char *why)
#define MP_TOO_MANY_ATTEMPTS_ERROR
void set_preferences_callback(std::function< void()> f)
Set the callback used to show the preferences.
static void do_preferences_dialog(CVideo &video, const config &game_config)
mp::ui::result goto_mp_connect(CVideo &video, ng::connect_engine &engine, const config &game_config, twesnothd_connection *wesnothd_connection, const std::string &game_name)
Opens mp::connect screen and sets game state according to the changes made.
std::set< std::string > connected_players
players and observers
static std::unique_ptr< twesnothd_connection > open_connection(CVideo &video, const std::string &original_host)
result get_result()
Returns the result of the current widget.
std::string network_host()
boost::optional< std::string > multiplayer_scenario
Non-empty if –scenario was given on the command line. Dependent on –multiplayer.
void expand_random_scenario()
takes care of generate_map=, generate_scenario=, map= attributes This should be called before expandi...
This class represents the collective information the client has about the players and games on the se...
bool multiplayer_ignore_map_settings
True if –ignore-map-settings was given at the command line. Do not use map settings.
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
static void enter_wait_mode(CVideo &video, const config &game_config, saved_game &state, twesnothd_connection *wesnothd_connection, bool observe, int current_turn=0)
#define MP_NAME_TOO_LONG_ERROR
void set_network_host(const std::string &host)
unsigned gamemap_width
The size of the map area, if not available equal to the screen size.
Define the errors the server may send during the login procedure.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
boost::optional< std::string > multiplayer_era
Non-empty if –era was given on the command line. Dependent on –multiplayer.
std::string get_salt(const std::string &hash)
boost::optional< std::string > multiplayer_label
Non-empty if –label was given on the command line. Dependent on –multiplayer.
void send_data(const configr_of &request)
#define MP_INCORRECT_PASSWORD_ERROR
int get_village_support(const std::string &value)
Gets the village unit level support.
This module controls the multiplayer lobby.
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
static game_config_manager * get()
static UNUSEDNOWARN std::string _(const char *str)
#define MP_NAME_UNREGISTERED_ERROR
Dialog is closed with ok button.
std::map< std::string, t_string > string_map
A class that represents a TCP/IP connection to the wesnothd server.
plugins_context * get_plugins_context()
void expand_mp_options()
adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next...
std::string create_hash(const std::string &password, const std::string &salt, int iteration_count)
Dialog is closed with the cancel button.
void show_preferences_dialog(CVideo &video, const config &game_cfg, const DIALOG_OPEN_TO initial_view)
void show_message(CVideo &video, const std::string &title, const std::string &message, const std::string &button_caption, const bool auto_close, const bool message_use_markup)
Shows a message to the user.
void play_music_config(const config &music_node)
const std::vector< game_config::server_info > & server_list()
Shows an ok and cancel button.
config & add_child(const std::string &key)
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Used to reset is_authenticated flag after disconnecting.
config & get_starting_pos()
void start_game_commandline(const commandline_options &cmdline_opts)
static lg::log_domain log_network("network")
void set_message_private(bool value)
std::string era_define
If there is a define the era uses to customize data.
mp::ui::result goto_mp_wait(CVideo &video, saved_game &state, const config &game_config, twesnothd_connection *wesnothd_connection, bool observe)
Opens mp::wait screen and sets game state according to the changes made.
bool network_receive_dialog(CVideo &video, const std::string &msg, config &cfg, twesnothd_connection &wesnothd_connection)
void raise_process_event()
void cache_mode(CACHE mode)
static bool enter_connect_mode(CVideo &video, const config &game_config, saved_game &state, twesnothd_connection *wesnothd_connection, bool local_players_only=false)
Game configuration data as global variables.
const config & game_config() const
std::string scenario_define
If there is a define the scenario uses to customize data.
const std::string & parameters
GLfloat GLfloat GLfloat GLfloat h
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
unsigned screen_width
The screen resolution should be available for all widgets since their drawing method will depend on i...
void expand_mp_events()
adds [event]s from [era] and [modification] into this scenario does NOT expand [option]s because vari...
GLdouble GLdouble GLdouble r
#define MP_PASSWORD_REQUEST
static lg::log_domain log_mp("mp/main")
#define MP_NAME_INACTIVE_WARNING
const std::vector< std::string > & user_list() const
#define MP_PASSWORD_REQUEST_FOR_LOGGED_IN_NAME
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
#define MP_NAME_TAKEN_ERROR
void load_game_config_for_game(const game_classification &classification)
Contains the SDL_Rect helper code.
void start_local_game_commandline(CVideo &video, const config &game_config, saved_game &state, const commandline_options &cmdline_opts)
Starts a multiplayer game in single-user mode.
bool has_attribute(const std::string &key) const
boost::optional< unsigned int > multiplayer_repeat
Repeats specified by –multiplayer-repeat option. Repeats a multiplayer game after it is finished...
game_classification & classification()
void join_game(bool observe)
void set_carryover_sides_start(config carryover_sides_start)
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
static void enter_lobby_mode(CVideo &video, const config &game_config, saved_game &state, twesnothd_connection *wesnothd_connection, const std::vector< std::string > &installed_addons)
void process_network()
Asks the multiplayer_ui to pump some data from the network, and then to process it.
config & find_child(const std::string &key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Standard logging facilities (interface).
void set_location(const SDL_Rect &rect)
Hides children, moves them (using layout_children), then shows them.
static void delay(unsigned int milliseconds)
this class memorizes a chat session.
void reload_changed_game_config()
#define MP_NAME_RESERVED_ERROR
void commit_music_changes()
A config object defines a single node in a WML file, with access to child nodes.
boost::scoped_ptr< connect_engine > connect_engine_ptr
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
int get_turns(const std::string &value)
Gets the number of turns.
const std::string version
GLsizei const GLcharARB ** string
Shows a yes and no button.
int get_iteration_count(const std::string &hash)
a base class for the different multiplayer base dialogs: game list, create game, wait game...
#define MP_INVALID_CHARS_IN_NAME_ERROR
legacy_result get_legacy_result() const
void run_lobby_loop(CVideo &video, mp::ui &ui)
void start_local_game(CVideo &video, const config &game_config, saved_game &state)
Starts a multiplayer game in single-user mode.