The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
chat_command_handler.cpp
Go to the documentation of this file.
3 #include "chat_events.hpp"
4 #include "game_preferences.hpp"
6 #include "video.hpp"
8 
9 namespace events {
10 
12 {
13  return !(c.has_flag('A') && !preferences::is_authenticated());
14 }
15 
17 {
18  chat_handler_.add_chat_message(time(nullptr), title, 0, message);
19 }
20 
21 
23 {
25 }
26 
28 {
30 }
31 
33 {
34  if (get_data(1).empty()) return command_failed_need_arg(1);
36 }
37 
39 {
40  config data;
41  config& q = data.add_child("room_query");
42  q.add_child(get_cmd());
44 }
45 
47 {
48  if (get_data(1).empty()) return command_failed_need_arg(1);
49  config data;
50  config& q = data.add_child("room_query");
51  q["room"] = get_arg(1);
52  q.add_child(get_cmd());
54 }
55 
57 {
58  if (get_data(1).empty()) return command_failed_need_arg(1);
59  config data;
60  config& q = data.add_child("room_query");
61  q["room"] = get_arg(1);
62  config& c = q.add_child(get_arg(2));
63  c["value"] = get_data(3);
65 }
66 
68 {
69  if (get_data(1).empty()) return command_failed_need_arg(1);
70  if (get_data(2).empty()) return command_failed_need_arg(2);
73 }
74 
76 {
77  if (get_data(1).empty()) return command_failed_need_arg(1);
78  if (get_data(2).empty()) return command_failed_need_arg(2);
81 }
82 
84 {
86 }
87 
89 {
90  if (get_arg(1).empty()) {
91  do_display();
92  }
93  else {
94  utils::string_map symbols;
95  symbols["nick"] = get_arg(1);
96 
98  print(_("ignores list"), VGETTEXT("Added to ignore list: $nick", symbols));
100  }
101  else {
102  command_failed(VGETTEXT("Invalid username: $nick", symbols));
103  }
104  }
105 }
106 
108 {
109  if (get_arg(1).empty()) {
110  do_display();
111  }
112  else {
113  utils::string_map symbols;
114  symbols["nick"] = get_arg(1);
115 
117  print(_("friends list"), VGETTEXT("Added to friends list: $nick", symbols));
119  }
120  else {
121  command_failed(VGETTEXT("Invalid username: $nick", symbols));
122  }
123  }
124 }
125 
127 {
128  for (int i = 1;!get_arg(i).empty();i++) {
131  utils::string_map symbols;
132  symbols["nick"] = get_arg(i);
133  print(_("friends and ignores list"), VGETTEXT("Removed from list: $nick", symbols));
134  }
135 }
136 
138 {
139  // TODO: add video and game config argument to chat_command_handler?
142 }
143 
145  print(_("version"), game_config::revision);
146 }
147 
149  config data;
150  config& nickserv = data.add_child("nickserv");
151 
152  if (get_data(1).empty()) return command_failed_need_arg(1);
153 
154  config &reg = nickserv.add_child("register");
155  reg["password"] = get_arg(1);
156  if (!get_data(2).empty()) {
157  reg["mail"] = get_arg(2);
158  }
160  if (get_data(2).empty()) {
161  msg = _("registering with password *** and no email address");
162  }
163  else {
164  utils::string_map symbols;
165  symbols["email"] = get_data(2);
166  msg = VGETTEXT("registering with password *** and "
167  "email address $email", symbols);
168  }
169  print(_("nick registration"), msg);
170 
172 }
173 
175  config data;
176  config& nickserv = data.add_child("nickserv");
177 
178  nickserv.add_child("drop");
179 
180  print(_("nick registration"), _("dropping your username"));
181 
183 }
184 
186  config data;
187  config& nickserv = data.add_child("nickserv");
188 
189  if (get_data(1).empty()) return command_failed_need_arg(1);
190  if (get_data(2).empty()) return command_failed_need_arg(2);
191 
192  config &set = nickserv.add_child("set");
193  set["detail"] = get_arg(1);
194  set["value"] = get_data(2);
195  utils::string_map symbols;
196  symbols["var"] = get_arg(1);
197  symbols["value"] = get_arg(2);
198  print(_("nick registration"), VGETTEXT("setting $var to $value", symbols));
199 
201 }
202 
204  if (get_data(1).empty()) return command_failed_need_arg(1);
205 
206  config data;
207  config& nickserv = data.add_child("nickserv");
208 
209  nickserv.add_child("info")["name"] = get_data(1);
210  utils::string_map symbols;
211  symbols["nick"] = get_arg(1);
212  print(_("nick registration"), VGETTEXT("requesting information for user $nick", symbols));
213 
215 }
216 
218 
219  config data;
220  config& nickserv = data.add_child("nickserv");
221  nickserv.add_child("details");
222 
224 }
225 
226 }
void command_failed(const std::string &message, bool=false)
void do_info()
Request information about a user from the server.
void do_details()
Request a list of details that can be set for a username as these might vary depending on the configu...
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:154
void do_drop()
Ask the server do drop the currently used (and registered) nick.
const GLfloat * c
Definition: glew.h:12741
bool is_enabled(const map_command_handler< chat_command_handler >::command &c) 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:75
void print(const std::string &title, const std::string &message)
static CVideo & get_singleton()
Definition: video.hpp:75
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
-file util.hpp
bool remove_acquaintance(const std::string &nick)
GLdouble GLdouble GLdouble GLdouble q
Definition: glew.h:1382
static game_config_manager * get()
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
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::map< std::string, t_string > string_map
void do_set()
Update details for the currently used username.
void show_preferences_dialog(CVideo &video, const config &game_cfg, const DIALOG_OPEN_TO initial_view)
config & add_child(const std::string &key)
Definition: config.cpp:743
void change_logging(const std::string &data)
Change the log level of a log domain.
Definition: chat_events.cpp:35
bool add_friend(const std::string &nick, const std::string &notes)
bool add_ignore(const std::string &nick, const std::string &reason)
const std::string revision
Definition: game_config.cpp:57
Game configuration data as global variables.
Definition: build_info.cpp:38
#define VGETTEXT(msgid, symbols)
virtual void add_chat_message(const time_t &time, const std::string &speaker, int side, const std::string &message, MESSAGE_TYPE type=MESSAGE_PRIVATE)=0
size_t i
Definition: function.cpp:1057
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:112
virtual std::string get_arg(unsigned argn) const
Handling of system events.
Definition: manager.hpp:42
void do_register()
Ask the server to register the currently used nick.
virtual void add_whisper_sent(const std::string &receiver, const std::string &message)
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
virtual std::string get_data(unsigned argn=1) const
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...
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
virtual void send_chat_room_message(const std::string &room, const std::string &message)
GLsizei const GLcharARB ** string
Definition: glew.h:4503