The Battle for Wesnoth  1.17.17+dev
chat_command_handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2023
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "map_command_handler.hpp"
18 #include "gettext.hpp"
19 
20 namespace events {
21  class chat_handler;
22 //command handler for chat /commands
23 class chat_command_handler : public map_command_handler<chat_command_handler>
24 {
25 public:
27  chat_command_handler(chat_handler& chathandler, bool allies_only)
28  : map(), chat_handler_(chathandler), allies_only_(allies_only)
29  {
30  }
31 
32 protected:
33  void do_emote();
34  void do_network_send();
35  void do_network_send(const std::string& data);
37  void do_whisper();
38  void do_log();
39  void do_ignore();
40  void do_friend();
41  void do_remove();
42  void do_display();
43  void do_version();
44  void do_clear_messages();
45  void do_mp_report();
46 
47  /** Request information about a user from the server. */
48  void do_info();
49 
50  std::string get_flags_description() const {
51  return _("(A) — admin command");
52  }
53 
56  {
57  if (c.has_flag('A')) {
58  return std::string(" ") + _("(admin only)");
59  }
60  else {
61  return "";
62  }
63  }
64 
66 
67  void print(const std::string& title, const std::string& message);
68 
69  void init_map()
70  {
71  set_cmd_prefix("/");
72  set_cmd_flag(false);
74  _("Send a query to the server. Without arguments the server"
75  " should tell you the available commands."));
76  register_alias("query", "q");
78  _("Ban and kick a player or observer. If he is not in the"
79  " game but on the server he will only be banned."), _("<nickname>"));
81  _("Unban a user. He does not have to be in the game but on"
82  " the server."), _("<nickname>"));
84  _("Kick a player or observer."), _("<nickname>"));
86  _("Mute an observer. Without an argument displays the mute status."), _("<nickname>"));
88  _("Unmute an observer. Without an argument unmutes everyone."), _("<nickname>"));
90  _("Mute/Unmute all observers. (toggles)"), "");
92  _("Send some data to the server. Can be used to verify the network connection and notice disconnects."));
94  _("Report abuse, rule violations, etc. to the server moderators. "
95  "Make sure to mention relevant nicknames, etc."), "");
96  register_alias("report", "adminmsg"); // deprecated
98  _("Send an emotion or personal action in chat."), _("<message>"));
99  register_alias("emote", "me");
101  _("Send a private message. "
102  "You cannot send private messages to players in a running game you observe or play in."),
103  _("<nickname> <message>"));
104  register_alias("whisper", "msg");
105  register_alias("whisper", "m");
107  _("Change the log level of a log domain."), _("<level> <domain>"));
109  _("Add a nickname to your ignores list."), _("<nickname>"));
111  _("Add a nickname to your friends list."), _("<nickname>"));
113  _("Remove a nickname from your ignores or friends list."), _("<nickname>"));
115  _("Get a random number between 1 and N visible in the game setup lobby."), _("<N>"));
117  _("Display version information."));
119  _("Request information about a nickname."), _("<nickname>"));
121  _("Clear chat history."));
122  }
123 private:
126 };
127 
128 }
chat_command_handler(chat_handler &chathandler, bool allies_only)
void do_info()
Request information about a user from the server.
map_command_handler< chat_command_handler > map
std::string get_flags_description() const
std::string get_command_flags_description(const map_command_handler< chat_command_handler >::command &c) const
bool is_enabled(const map_command_handler< chat_command_handler >::command &c) const
void print(const std::string &title, const std::string &message)
virtual void register_command(const std::string &cmd, command_handler h, const std::string &help="", const std::string &usage="", const std::string &flags="")
static void set_cmd_prefix(const std::string &value)
virtual void register_alias(const std::string &to_cmd, const std::string &cmd)
static std::string _(const char *str)
Definition: gettext.hpp:93
Handling of system events.
Definition: manager.hpp:43
std::string_view data
Definition: picture.cpp:199
mock_char c