14 #define GETTEXT_DOMAIN "wesnoth-lib" 43 #define DBG_LB LOG_STREAM(debug, log_lobby) 44 #define LOG_LB LOG_STREAM(info, log_lobby) 45 #define ERR_LB LOG_STREAM(err, log_lobby) 47 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__ 48 #define LOG_HEADER LOG_SCOPE_HEADER + ':' 59 , roomlistbox_(
nullptr)
60 , chat_log_container_(
nullptr)
61 , chat_input_(
nullptr)
63 , active_window_changed_callback_()
64 , lobby_info_(
nullptr)
65 , wesnothd_connection_(
nullptr)
74 connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(
80 roomlistbox_ = find_widget<listbox>(
this,
"room_list",
false,
true);
89 chat_input_ = find_widget<text_box>(
this,
"chat_input",
false,
true);
97 for(
const auto& l : log) {
98 const bool is_lobby = l.first ==
"lobby";
100 if(!show_lobby && is_lobby && !l.second.whisper) {
153 case SDLK_KP_ENTER: {
154 if(input[0] ==
'/') {
158 chat_handler::do_speak(input);
179 std::vector<std::string> matches;
182 matches.push_back(ui.name);
188 if(matches.empty()) {
192 if(matches.size() == 1) {
193 input.append(line_start ?
": " :
" ");
195 std::string completion_list =
utils::join(matches,
" ");
228 if(
log_ !=
nullptr) {
231 log_->at(room_name).log = new_text;
232 }
catch(
const std::out_of_range&) {
236 if(chatbox_at_end || force_scroll) {
259 const std::string& speaker,
269 if(message.compare(0, 4,
"/me ") == 0) {
310 }
else if(can_go_to_active) {
314 LOG_LB <<
"Ignoring whisper from " << sender <<
"\n";
322 LOG_LB <<
"Cannot add sent message to ui for room " << room <<
", player not in the room\n";
339 const std::string& speaker,
344 LOG_LB <<
"Discarding message to room " << room <<
" from " << speaker <<
" (room not open)\n";
360 if(speaker ==
"server") {
368 do_notify(notify_mode, speaker, message);
392 VGETTEXT(
"Whisper session with <i>“$name”</i> started. " 393 "If you do not want to receive messages from this user, type <i>/ignore $name</i>", { {
"name", name } }));
399 const bool allow_close,
400 const std::string& initial_text)
403 if(
t.name == name &&
t.whisper == whisper) {
412 open_windows_.emplace_back(name, whisper);
418 item[
"use_markup"] =
"true";
419 item[
"label"] = initial_text;
420 std::map<std::string, string_map> data{{
"log_text", item}};
426 if(
log_ !=
nullptr) {
441 item[
"label"] =
"<" + name +
">";
444 data.emplace(
"room", item);
451 button& close_button = find_widget<button>(&row_grid,
"close_window",
false);
460 return &open_windows_.back();
471 handled = halt =
true;
484 ++
t->pending_messages;
486 if(
t->pending_messages == 1) {
498 ++
t->pending_messages;
500 if(
t->pending_messages == 1) {
503 DBG_LB <<
"do room pending mark row " << idx <<
" with " <<
t->name <<
"\n";
515 ERR_LB <<
"Whisper window not open in add_whisper_window_whisper for " << sender <<
"\n";
525 const bool force_scroll)
535 DBG_LB <<
"Close window " << idx <<
" - " << t.
name <<
"\n";
545 msg[
"room"] = t.
name;
547 data.
add_child(
"room_part", std::move(msg));
565 if(
log_ !=
nullptr) {
583 const std::string& sender,
588 ERR_LB <<
"Room window not open in add_room_window_message for " << room <<
"\n";
598 const bool force_scroll)
616 const std::string& room = data[
"room"];
617 const std::string& player = data[
"player"];
619 DBG_LB <<
"room join: " << room <<
" " << player <<
"\n";
624 if(
const auto& members = data.child(
"members")) {
645 if(
const auto& members = data.child(
"members")) {
651 const std::string& topic = data[
"topic"];
656 LOG_LB <<
"Discarding join info for a room the player is not in\n";
664 const std::string& room = data[
"room"];
665 const std::string& player = data[
"player"];
667 DBG_LB <<
"Room part: " << room <<
" " << player <<
"\n";
670 r->remove_member(player);
678 LOG_LB <<
"Discarding part info for a room the player is not in\n";
684 const std::string& room = data[
"room"];
685 const std::string&
message = data[
"message"];
687 DBG_LB <<
"room query response: " << room <<
" " << message <<
"\n";
690 if(!message.empty()) {
694 if(const ::config& rooms = data.child(
"rooms")) {
696 std::stringstream ss;
699 for(
const auto & r : rooms.child_range(
"room")) {
700 ss <<
" " << r[
"name"];
707 if(!message.empty()) {
711 if(const ::config& members = data.child(
"members")) {
720 if(!message.empty()) {
729 std::string sender = data[
"sender"];
730 DBG_LB <<
"process message from " << sender <<
" " << (whisper ?
"(w)" :
"")
731 <<
", len " << data[
"message"].str().size() <<
'\n';
737 const std::string&
message = data[
"message"];
743 std::string room = data[
"room"];
747 LOG_LB <<
"Message without a room from " << sender <<
", falling back to active window\n";
753 LOG_LB <<
"Message without a room from " << sender <<
", assuming lobby\n";
762 plugin_data[
"whisper"] = whisper;
768 if(const ::config&
message = data.child(
"message")) {
770 }
else if(const ::config& whisper = data.child(
"whisper")) {
772 }
else if(const ::config& room_join = data.child(
"room_join")) {
774 }
else if(const ::config& room_part = data.child(
"room_part")) {
776 }
else if(const ::config& room_query_response = data.child(
"room_query_response")) {
794 load_resolutions<resolution>(cfg);
806 grid = std::make_shared<builder_grid>(child);
813 builder_chatbox::builder_chatbox(
const config& cfg)
822 DBG_GUI_G <<
"Window builder: placed unit preview pane '" <<
id 823 <<
"' with definition '" <<
definition <<
"'.\n";
bool is_composing() const
void send_data(const configr_of &request)
void switch_to_window(lobby_chat_window *t)
Switch to the window given by a valid pointer (e.g.
void active_window_changed()
Base class of a resolution, contains the common keys for a resolution.
void keyboard_capture(widget *widget)
wesnothd_connection * wesnothd_connection_
void increment_waiting_messages(const std::string &room)
Mark the room window for "room" as having one more pending message.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
void add_message(const std::time_t ×tamp, const std::string &user, const std::string &message)
multi_page * chat_log_container_
std::vector< state_definition > state
bool room_window_active(const std::string &room)
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
void add_room_window_message(const std::string &room, const std::string &sender, const std::string &message)
Add a message to the window for room "room".
void signal_handler_receive_keyboard_focus(const event::ui_event event)
Main class to show messages to the user.
grid & add_page(const string_map &item)
Adds single page to the grid.
chatbox_definition(const config &cfg)
std::string get_value() const
std::map< std::string, chatroom_log > * log_
void parse_admin_authentication(const std::string &sender, const std::string &message)
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
void save_to_history()
Saves the text in the widget to the history.
std::vector< lobby_chat_window > open_windows_
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
void process_room_query_response(const ::config &data)
void send_to_server(const ::config &cfg) override
int get_selected_row() const
Returns the first selected row.
bool whisper_window_active(const std::string &name)
const chat_session & log() const
std::size_t active_window_
resolution(const config &cfg)
std::string dsgettext(const char *domainname, const char *msgid)
room_info * get_room(const std::string &name)
Returns info on room with the given name, or nullptr if it doesn't exist.
bool whisper_friends_only()
bool select_row(const unsigned row, const bool select=true)
Selects a row.
void process_room_part(const ::config &data)
void process_message(const ::config &data, bool whisper=false)
static UNUSEDNOWARN std::string _(const char *str)
void do_notify(notify_mode mode, const std::string &sender, const std::string &message)
bool auto_open_whisper_windows()
virtual void add_chat_message(const std::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
Inherited form chat_handler.
virtual void send_whisper(const std::string &receiver, const std::string &message)
void close_window_button_callback(std::string room_name, bool &handled, bool &halt)
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
bool is_friend(const std::string &nick)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
This file contains the settings handling of the widget library.
const grid & page_grid(const unsigned page) const
Returns the grid for the page.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
mp::lobby_info * lobby_info_
lobby_chat_window * whisper_window_open(const std::string &name, bool open_new)
Check if a whisper window for user "name" is open, if open_new is true then it will be created if not...
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
std::function< void(void)> active_window_changed_callback_
void add_active_window_message(const std::string &sender, const std::string &message, const bool force_scroll=false)
Add a message to the window for room "room".
void load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
void init_grid(const std::shared_ptr< builder_grid > &grid_builder)
Initializes and builds the grid.
void process_room_join(const ::config &data)
bool is_ignored(const std::string &nick)
mp::room_info * active_window_room()
Get the room* corresponding to the currently active window, or nullptr if a whisper window is active ...
void process_network_data(const ::config &data)
static lg::log_domain log_lobby("lobby")
virtual void user_relation_changed(const std::string &name) override
Inherited form chat_handler.
std::string escape_text(const std::string &text)
Escapes the pango markup characters in a text.
void increment_waiting_whispers(const std::string &name)
Mark the whisper window for "name" as having one more pending message.
void chat_input_keypress_callback(const SDL_Keycode key)
virtual void add_whisper_received(const std::string &sender, const std::string &message) override
Inherited form chat_handler.
void select_page(const unsigned page, const bool select=true)
Selectes a page.
grid & add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
This class represents the information a client has about a room.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
A generic container base class.
config & add_child(config_key_type key)
std::string get_chat_timestamp(const std::time_t &t)
virtual void add_chat_room_message_received(const std::string &room, const std::string &speaker, const std::string &message) override
Inherited form chat_handler.
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
void append_to_chatbox(const std::string &text, const bool force_scroll=false)
void close_room(const std::string &name)
Close the chat room with the given name.
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard_function &signal)
Connects the signal for 'snooping' on the keypress.
virtual void add_chat_room_message_sent(const std::string &room, const std::string &message) override
Inherited form chat_handler.
chat_session & get_whisper_log(const std::string &name)
Standard logging facilities (interface).
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
void add_active_window_whisper(const std::string &sender, const std::string &message, const bool force_scroll=false)
Add a whisper message to the current window which is not the whisper window for "name".
lobby_chat_window * find_or_create_window(const std::string &name, const bool whisper, const bool open_new, const bool allow_close, const std::string &initial_text)
Helper function to find and open a new window, used by *_window_open.
const std::vector< user_info > & users() const
virtual void add_whisper_sent(const std::string &receiver, const std::string &message) override
Inherited form chat_handler.
void open_room(const std::string &name)
Open a new chat room with the given name.
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)
void finalize_setup()
Initializes the internal sub-widget pointers.
virtual void send_chat_room_message(const std::string &room, const std::string &message)
bool word_completion(std::string &text, std::vector< std::string > &wordlist)
Try to complete the last word of 'text' with the 'wordlist'.
lobby_chat_window * room_window_open(const std::string &room, const bool open_new, const bool allow_close=true)
Check if a room window for "room" is open, if open_new is true then it will be created if not found...
Contains the implementation details for lexical_cast and shouldn't be used directly.
ui_event
The event send to the dispatcher.
static plugins_manager * get()
std::pair< std::string, unsigned > item
void process_room_members(const config &data)
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.
void close_window(std::size_t idx)
void add_whisper_window_whisper(const std::string &sender, const std::string &message)
Add a whisper message to the whisper window.
void add_member(const std::string &user)