The Battle for Wesnoth  1.15.2+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 
15 #include "map_command_handler.hpp"
16 #include "chat_command_handler.hpp"
17 #include "chat_events.hpp"
18 #include "preferences/game.hpp"
19 #include "preferences/display.hpp"
20 #include "game_config_manager.hpp"
21 
22 namespace events {
23 
25 {
26  return !(c.has_flag('A') && !preferences::is_authenticated());
27 }
28 
29 void chat_command_handler::print(const std::string& title, const std::string& message)
30 {
31  chat_handler_.add_chat_message(std::time(nullptr), title, 0, message);
32 }
33 
34 
36 {
38 }
39 
41 {
43 }
44 
46 {
47  if (get_data(1).empty()) return command_failed_need_arg(1);
49 }
50 
52 {
53  config data;
54  config& q = data.add_child("room_query");
55  q.add_child(get_cmd());
57 }
58 
60 {
61  if (get_data(1).empty()) return command_failed_need_arg(1);
62  config data;
63  config& q = data.add_child("room_query");
64  q["room"] = get_arg(1);
65  q.add_child(get_cmd());
67 }
68 
70 {
71  if (get_data(1).empty()) return command_failed_need_arg(1);
72  config data;
73  config& q = data.add_child("room_query");
74  q["room"] = get_arg(1);
75  config& c = q.add_child(get_arg(2));
76  c["value"] = get_data(3);
78 }
79 
81 {
82  if (get_data(1).empty()) return command_failed_need_arg(1);
83  if (get_data(2).empty()) return command_failed_need_arg(2);
86 }
87 
89 {
90  if (get_data(1).empty()) return command_failed_need_arg(1);
91  if (get_data(2).empty()) return command_failed_need_arg(2);
94 }
95 
97 {
99 }
100 
102 {
103  if (get_arg(1).empty()) {
104  do_display();
105  }
106  else {
107  utils::string_map symbols;
108  symbols["nick"] = get_arg(1);
109 
110  if (preferences::add_acquaintance(get_arg(1), "ignore", get_data(2)).first) {
111  print(_("ignores list"), VGETTEXT("Added to ignore list: $nick", symbols));
113  }
114  else {
115  command_failed(VGETTEXT("Invalid username: $nick", symbols));
116  }
117  }
118 }
119 
121 {
122  if (get_arg(1).empty()) {
123  do_display();
124  }
125  else {
126  utils::string_map symbols;
127  symbols["nick"] = get_arg(1);
128 
129  if (preferences::add_acquaintance(get_arg(1), "friend", get_data(2)).first) {
130  print(_("friends list"), VGETTEXT("Added to friends list: $nick", symbols));
132  }
133  else {
134  command_failed(VGETTEXT("Invalid username: $nick", symbols));
135  }
136  }
137 }
138 
140 {
141  for (int i = 1;!get_arg(i).empty();i++) {
144  utils::string_map symbols;
145  symbols["nick"] = get_arg(i);
146  print(_("friends and ignores list"), VGETTEXT("Removed from list: $nick", symbols));
147  }
148 }
149 
151 {
152  // TODO: add game config argument to chat_command_handler?
155 }
156 
158  print(_("version"), game_config::revision);
159 }
160 
162  if (get_data(1).empty()) return command_failed_need_arg(1);
163 
164  config data;
165  config& nickserv = data.add_child("nickserv");
166 
167  nickserv.add_child("info")["name"] = get_data(1);
168  utils::string_map symbols;
169  symbols["nick"] = get_arg(1);
170  print(_("nick registration"), VGETTEXT("requesting information for user $nick", symbols));
171 
173 }
174 
175 }
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
bool is_authenticated()
Definition: game.cpp:181
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:86
void print(const std::string &title, const std::string &message)
virtual std::string get_arg(unsigned argn) const
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:281
static game_config_manager * get()
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:91
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:259
void change_logging(const std::string &data)
Change the log level of a log domain.
Definition: chat_events.cpp:46
static void display(const config &game_cfg, const preferences::PREFERENCE_VIEW initial_view=preferences::VIEW_DEFAULT)
The display function – see modal_dialog for more information.
std::size_t i
Definition: function.cpp:933
const std::string revision
Game configuration data as global variables.
Definition: build_info.cpp:49
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
config & add_child(config_key_type key)
Definition: config.cpp:476
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:68
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