The Battle for Wesnoth  1.15.11+dev
chat_command_handler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017-2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #include "chat_command_handler.hpp"
15 
16 #include "chat_events.hpp"
18 #include "game_version.hpp"
20 #include "map_command_handler.hpp"
21 #include "preferences/display.hpp"
22 #include "preferences/game.hpp"
23 
24 namespace events {
25 
27 {
28  return !(c.has_flag('A') && !mp::logged_in_as_moderator());
29 }
30 
31 void chat_command_handler::print(const std::string& title, const std::string& message)
32 {
33  chat_handler_.add_chat_message(std::time(nullptr), title, 0, message);
34 }
35 
37 {
39 }
40 
42 {
44 }
45 
47 {
48  if (get_data(1).empty()) return command_failed_need_arg(1);
50 }
51 
53 {
54  config data;
55  config& q = data.add_child("room_query");
56  q.add_child(get_cmd());
58 }
59 
61 {
62  if (get_data(1).empty()) return command_failed_need_arg(1);
63  config data;
64  config& q = data.add_child("room_query");
65  q["room"] = get_arg(1);
66  q.add_child(get_cmd());
68 }
69 
71 {
72  if (get_data(1).empty()) return command_failed_need_arg(1);
73  config data;
74  config& q = data.add_child("room_query");
75  q["room"] = get_arg(1);
76  config& c = q.add_child(get_arg(2));
77  c["value"] = get_data(3);
79 }
80 
82 {
83  if (get_data(1).empty()) return command_failed_need_arg(1);
84  if (get_data(2).empty()) return command_failed_need_arg(2);
87 }
88 
90 {
91  if (get_data(1).empty()) return command_failed_need_arg(1);
92  if (get_data(2).empty()) return command_failed_need_arg(2);
95 }
96 
98 {
100 }
101 
103 {
104  if (get_arg(1).empty()) {
105  do_display();
106  }
107  else {
108  utils::string_map symbols;
109  symbols["nick"] = get_arg(1);
110 
111  if (preferences::add_acquaintance(get_arg(1), "ignore", get_data(2)).first) {
112  print(_("ignores list"), VGETTEXT("Added to ignore list: $nick", symbols));
114  }
115  else {
116  command_failed(VGETTEXT("Invalid username: $nick", symbols));
117  }
118  }
119 }
120 
122 {
123  if (get_arg(1).empty()) {
124  do_display();
125  }
126  else {
127  utils::string_map symbols;
128  symbols["nick"] = get_arg(1);
129 
130  if (preferences::add_acquaintance(get_arg(1), "friend", get_data(2)).first) {
131  print(_("friends list"), VGETTEXT("Added to friends list: $nick", symbols));
133  }
134  else {
135  command_failed(VGETTEXT("Invalid username: $nick", symbols));
136  }
137  }
138 }
139 
141 {
142  for (int i = 1;!get_arg(i).empty();i++) {
145  utils::string_map symbols;
146  symbols["nick"] = get_arg(i);
147  print(_("friends and ignores list"), VGETTEXT("Removed from list: $nick", symbols));
148  }
149 }
150 
152 {
153  gui2::dialogs::preferences_dialog::display(preferences::VIEW_FRIENDS);
154 }
155 
157  print(_("version"), game_config::revision);
158 }
159 
161  if (get_data(1).empty()) return command_failed_need_arg(1);
162 
163  config data;
164  config& nickserv = data.add_child("nickserv");
165 
166  nickserv.add_child("info")["name"] = get_data(1);
167  utils::string_map symbols;
168  symbols["nick"] = get_arg(1);
169  print(_("nick registration"), VGETTEXT("requesting information for user $nick", symbols));
170 
172 }
173 
174 }
void command_failed(const std::string &message, bool=false)
void do_info()
Request information about a user from the server.
std::map< std::string, t_string > string_map
Interfaces for manipulating version numbers of engine, add-ons, etc.
virtual std::string get_data(unsigned argn=1) const
virtual void send_to_server(const config &cfg)=0
virtual void add_chat_room_message_sent(const std::string &room, const std::string &message)
void send_command(const std::string &cmd, const std::string &args="")
Definition: chat_events.cpp:84
void print(const std::string &title, const std::string &message)
virtual std::string get_arg(unsigned argn) const
static std::string _(const char *str)
Definition: gettext.hpp:92
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:249
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
virtual void send_chat_message(const std::string &message, bool allies_only=false)=0
virtual void send_whisper(const std::string &receiver, const std::string &message)
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:230
void change_logging(const std::string &data)
Change the log level of a log domain.
Definition: chat_events.cpp:44
std::size_t i
Definition: function.cpp:940
const std::string revision
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
config & add_child(config_key_type key)
Definition: config.cpp:500
Handling of system events.
Definition: manager.hpp:42
virtual void add_whisper_sent(const std::string &receiver, const std::string &message)
virtual void user_relation_changed(const std::string &name)
Called when a processed command results in a relation (friend/ignore) change for a user whose name is...
bool is_enabled(const map_command_handler< chat_command_handler >::command &c) const
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
mock_char c
virtual void send_chat_room_message(const std::string &room, const std::string &message)
virtual void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &message, MESSAGE_TYPE type=MESSAGE_PRIVATE)=0