41 #define ERR_CF LOG_STREAM(err, log_config)
44 #define LOG_NW LOG_STREAM(info, log_network)
45 #define ERR_NW LOG_STREAM(err, log_network)
48 #define DBG_MP LOG_STREAM(debug, log_mp)
52 const size_t max_messages = 256;
57 0x000000, 0x4a4440, 0x999999,
72 scale_images(-1, item_size_.h);
76 user_menu_style umenu_style;
87 return prefix + name->second;
89 return prefix +
_(
"Invalid Color");
100 return rgb2highlight(has_color ? i_color->second.mid() : 0x00FF0000) + (has_name ?
std::string(i_name->second) :
_(
"Invalid Color"));
153 if(message.
user ==
"server"
154 || message.
user.substr(0,29) ==
"whisper: server message from ") {
155 std::string::const_iterator after_markup =
160 if(message.
message.substr(0,3) ==
"/me") {
162 + msg_text.substr(3) +
">\n";
165 +
"> " + msg_text +
"\n";
172 if(message.
user ==
"server"
173 || message.
user.substr(0,29) ==
"whisper: server message from ") {
176 }
else if(message.
user.substr(0,8) ==
"whisper:") {
185 wesnothd_connection_(wesnothd_connection),
187 gamelist_initialized_(false),
194 entry_textbox_(video_, 100),
195 chat_textbox_(video_, 100,
"", false),
196 users_menu_(video_,
std::vector<
std::
string>(), false, -1, -1, nullptr, &umenu_style),
201 selected_user_changed_(false),
204 gamelist_refresh_(false),
207 plugins_context_(nullptr)
281 if(background ==
nullptr)
283 sdl_blit(background,
nullptr,
video().getSurface(),
nullptr);
290 widget::set_location(rect);
312 if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED) {
313 SDL_Rect new_location;
316 new_location.w =
event.window.data1;
317 new_location.h =
event.window.data2;
321 if(event.type == SDL_KEYDOWN) {
326 Uint32 show_time = SDL_GetTicks();
335 std::stringstream
msg;
338 if(!dlg.
message().empty()) msg <<
"/msg " << usr_text <<
' ' << dlg.
message();
341 msg <<
"/friend " << usr_text;
344 msg <<
"/ignore " << usr_text;
347 msg <<
"/remove " << usr_text;
350 msg <<
"/query status " << usr_text;
353 msg <<
"/query kick " << usr_text;
357 msg <<
"/query kban " << usr_text;
358 if(!dlg.
time().empty()) msg <<
' ' << dlg.
time();
362 chat_handler::do_speak(msg.str());
364 if(show_time + 60000 < SDL_GetTicks()) {
398 if((event.keysym.sym == SDLK_RETURN || event.keysym.sym == SDLK_KP_ENTER) && !
entry_textbox_.
text().empty()) {
403 }
else if(event.keysym.sym == SDLK_TAB ) {
405 std::vector<std::string> matches =
user_list_;
407 matches.erase(
std::remove(matches.begin(), matches.end(),
411 if (matches.empty())
return;
413 if (matches.size() == 1) {
414 text.append(line_start ?
": " :
" ");
435 sender !=
"server" &&
436 sender.find(
' ') == std::string::npos &&
439 LOG_NW <<
"Accepting whispers from friends only, ignored whisper from " << sender <<
'\n';
441 typedef std::map<std::string, time_t> timetable;
444 time_t last_warning = 0;
445 const time_t cur_time = time(
nullptr);
446 static const time_t warning_duration = 5 * 60;
449 last_warning = i->second;
461 if (last_warning && last_warning < cur_time && cur_time - last_warning < warning_duration) {
466 symbols[
"sender"] = sender;
470 VGETTEXT(
"$sender is messaging you, and you accept whispers from friends only.", symbols));
480 bool is_lobby =
dynamic_cast<mp::lobby*
>(
this) !=
nullptr;
486 }
else if (sender ==
"server") {
496 symbols[
"sender"] = msg[
"sender"].str();
497 prefix =
VGETTEXT(
"whisper: $sender", symbols);
500 prefix = msg[
"sender"].str();
503 if (!room.empty()) room = room +
": ";
509 temp[
"whisper"] = whisper;
521 }
else if(data.
child(
"gamelist")) {
528 }
else if (
const config &
c = data.
child(
"gamelist_diff")) {
533 ERR_CF <<
"Error while applying the gamelist diff: '"
534 << e.
message <<
"' Getting a new gamelist.\n";
542 "You have joined the room '" +
c[
"room"].str() +
"'");
545 c[
"player"].str() +
" has joined the room '" +
c[
"room"].str() +
"'");
551 "You have left the room '" +
c[
"room"].str() +
"'");
554 c[
"player"].str() +
" has left the room '" +
c[
"room"].str() +
"'");
557 }
else if (
const config &
c = data.
child(
"room_query_response")) {
559 std::stringstream ss;
560 ss <<
"Room " <<
c[
"room"].str() <<
" members: ";
562 ss <<
m[
"name"] <<
" ";
568 std::stringstream ss;
571 ss <<
r[
"name"].str() <<
"(" <<
r[
"size"].str() <<
") ";
590 umenu_style.set_width(
xscale(159));
655 std::list<user_info> u_list;
660 u_elem.
name = user[
"name"].str();
662 u_elem.
registered = user[
"registered"].to_bool();
663 u_elem.
game_id = user[
"game_id"].str();
664 u_elem.
location = user[
"location"].str();
677 u_list.push_back(u_elem);
681 u_list.sort(std::greater<user_info>());
688 const std::string selgame_color_tag =
"<0,191,255>";
695 std::vector<std::string> user_strings;
696 std::vector<std::string> menu_strings;
698 std::list<user_info>::const_iterator u_itor = u_list.begin();
699 while (u_itor != u_list.end()) {
700 const std::string name_str = u_itor->name +
701 ((u_itor->state ==
LOBBY) ?
"" :
" (" + u_itor->location +
")");
702 std::string img_str =
"";
703 std::string color_str =
"";
704 std::string reg_str =
"";
705 switch (u_itor->state) {
706 case LOBBY: color_str = lobby_color_tag;
break;
707 case GAME: color_str = ingame_color_tag;
break;
708 case SEL_GAME: color_str = selgame_color_tag;
break;
711 switch (u_itor->relation) {
718 reg_str = u_itor->registered ? registered_user_tag :
"";
719 user_strings.push_back(u_itor->name);
742 std::vector<std::string>::const_iterator
i =
752 bool is_lobby =
dynamic_cast<mp::lobby*
>(
this) !=
nullptr;
767 if (u)
return u[
"game_id"];
An error occured during when trying to coommunicate with the wesnothd server.
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
child_itors child_range(const std::string &key)
gui::textbox entry_textbox_
char const IMG_TEXT_SEPARATOR
virtual void handle_key_event(const SDL_KeyboardEvent &event)
virtual void draw_contents()
static std::string get_side_highlight(int side)
const SDL_Color TITLE_COLOR
std::vector< std::string > user_list_
std::map< std::string, color_range > team_rgb_range
const std::string & set_text(const std::string &text)
void set_edit_target(textbox *target)
static lg::log_domain log_network("network")
static lg::log_domain log_config("config")
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
boost::scoped_ptr< plugins_context > plugins_context_
ui(CVideo &v, twesnothd_connection *wesnothd_connection, const std::string &title, const config &cfg, chat &c, config &gamelist)
std::map< std::string, time_t > whisper_warnings_
const SDL_Rect empty_rect
virtual void layout_children(const SDL_Rect &rect)
Lays the children out.
result get_result()
Returns the result of the current widget.
void parse_admin_authentication(const std::string &sender, const std::string &message)
bool receive_data(config &result)
void set_text(const std::string &text, const SDL_Color &color=font::NORMAL_COLOR)
std::string get_color_string(int id)
GLint GLint GLint GLint GLint GLint y
void add_message(const time_t &time, const std::string &user, const std::string &message)
surface scale_surface(const surface &surf, int w, int h)
const std::string text() const
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
const SDL_Color NORMAL_COLOR
std::string format_message(const msg &message)
unsigned thickness_
The thickness of the line.
bool whisper_friends_only()
msg_hist::size_type last_update_
void init_textbox(gui::textbox &textbox)
virtual void process_network_data(const config &data)
Processes any pending network data.
virtual void hide_children(bool hide=true)
Hides or shows all gui::widget children of this widget.
void send_data(const configr_of &request)
msg_hist message_history_
GLdouble GLdouble GLdouble b
This module controls the multiplayer lobby.
void friend_message(bool is_lobby, const std::string &sender, const std::string &message)
std::string selected_user_
static UNUSEDNOWARN std::string _(const char *str)
std::map< std::string, t_string > string_map
bool is_friend(const std::string &nick)
A class that represents a TCP/IP connection to the wesnothd server.
result set_result(result res)
Sets the result of this dialog, to be checked by get_result().
char const HELP_STRING_SEPARATOR
plugins_context * get_plugins_context()
static const int xscale_base
void private_message(bool is_lobby, const std::string &sender, const std::string &message)
const config & game_config() const
Returns the main game config, as defined by loading the preprocessed WML files.
const config & game_config_
The main game configuration, as defined by loading the preprocessed WML files.
std::string selected_game_
void add_chat_message(const time_t &time, const std::string &speaker, int side, const std::string &message, events::chat_handler::MESSAGE_TYPE type=events::chat_handler::MESSAGE_PRIVATE)
Override chat_handler.
GLboolean GLboolean GLboolean GLboolean a
const gui::label & title() const
virtual void process_event()
config & add_child(const std::string &key)
void send_to_server(const config &cfg) override
static lg::log_domain log_mp("mp/main")
void apply_diff(const config &diff, bool track=false)
A function to apply a diff config onto this config object.
bool initialized_
Set to true when the widgets are initialized.
void init()
Initializes the gui subsystems.
void append_text(const std::string &text, bool auto_scroll=false, const SDL_Color &color=font::NORMAL_COLOR)
bool registered
True if this user is registered on the server.
void process_message(const config &msg, const bool whisper=false)
Process chat messages.
int get_max_height(int size)
bool is_ignored(const std::string &nick)
const std::string & get_text() const
void append_to_title(const std::string &name)
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::string::const_iterator parse_markup(std::string::const_iterator i1, std::string::const_iterator i2, int *font_size, SDL_Color *color, int *style)
Parses the markup-tags at the front of a string.
gui::textbox chat_textbox_
virtual void handle_event(const SDL_Event &event)
void send_chat_message(const std::string &message, bool allies_only=false)
std::map< std::string, tfilter >::iterator itor
SDL_Rect client_area() const
void update_textbox(gui::textbox &textbox)
SDL_Color color_message(const msg &message)
const SDL_Color LABEL_COLOR
void public_message(bool is_lobby, const std::string &sender, const std::string &message)
void set_user_list(const std::vector< std::string > &, bool silent)
Sets the user list.
const std::string & time() const
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
GLint GLint GLint GLint GLint x
void server_message(bool is_lobby, const std::string &sender, const std::string &message)
GLdouble GLdouble GLdouble r
bool gamelist_initialized_
GLuint const GLchar * name
void player_leaves(bool is_lobby)
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
void set_user_menu_items(const std::vector< std::string > &list)
Contains the SDL_Rect helper code.
bool selected_user_changed_
bool find(E event, F functor)
Tests whether an event handler is available.
void set_selected_game(const std::string &game_name)
Sets the name of the selected game which is used to highlight the names of the players which have joi...
std::string get_chat_timestamp(const time_t &t)
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...
void process_network()
Asks the multiplayer_ui to pump some data from the network, and then to process it.
void player_joins(bool is_lobby)
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).
const std::string & message() const
void clear_all_help_strings()
void set_location(const SDL_Rect &rect)
Hides children, moves them (using layout_children), then shows them.
twesnothd_connection * wesnothd_connection_
GLsizei GLenum GLuint GLuint GLsizei char * message
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
std::string rgb2highlight(Uint32 rgb)
Converts a color value to WML text markup syntax for highlighting.
const std::string remove
remove directive
GLint GLint GLint GLint GLint GLint GLsizei width
this class memorizes a chat session.
static const int yscale_base
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
std::string get_selected_user_game()
A config object defines a single node in a WML file, with access to child nodes.
void notify_event(const std::string &name, const config &data)
bool receive_from_server(config &dst)
std::map< std::string, t_string > team_rgb_name
bool operator>(const user_info &b) const
GLsizei const GLcharARB ** string
bool word_completion(std::string &text, std::vector< std::string > &wordlist)
Try to complete the last word of 'text' with the 'wordlist'.
const std::string & reason() const
static plugins_manager * get()
virtual void gamelist_updated(bool silent=true)
Called each time the gamelist_ variable is updated.
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.