The Battle for Wesnoth  1.17.0-dev
chat_command_handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2021
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();
36  void do_whisper();
37  void do_log();
38  void do_ignore();
39  void do_friend();
40  void do_remove();
41  void do_display();
42  void do_version();
43 
44  /** Request information about a user from the server. */
45  void do_info();
46 
47  std::string get_flags_description() const {
48  return _("(A) — admin command");
49  }
50 
53  {
54  if (c.has_flag('A')) {
55  return std::string(" ") + _("(admin only)");
56  }
57  else {
58  return "";
59  }
60  }
61 
63 
64  void print(const std::string& title, const std::string& message);
65 
66  void init_map()
67  {
68  set_cmd_prefix("/");
70  _("Send a query to the server. Without arguments the server"
71  " should tell you the available commands."));
72  register_alias("query", "q");
74  _("Ban and kick a player or observer. If he is not in the"
75  " game but on the server he will only be banned."), _("<nickname>"));
77  _("Unban a user. He does not have to be in the game but on"
78  " the server."), _("<nickname>"));
80  _("Kick a player or observer."), _("<nickname>"));
82  _("Mute an observer. Without an argument displays the mute status."), _("<nickname>"));
84  _("Unmute an observer. Without an argument unmutes everyone."), _("<nickname>"));
86  _("Mute/Unmute all observers. (toggles)"), "");
88  _("Send some data to the server. Can be used to verify the network connection and notice disconnects."));
90  _("Report abuse, rule violations, etc. to the server moderators. "
91  "Make sure to mention relevant nicknames, etc."), "");
92  register_alias("report", "adminmsg"); // deprecated
94  _("Send an emotion or personal action in chat."), _("<message>"));
95  register_alias("emote", "me");
97  _("Send a private message. "
98  "You cannot send private messages to players in a running game you observe or play in."),
99  _("<nickname> <message>"));
100  register_alias("whisper", "msg");
101  register_alias("whisper", "m");
103  _("Change the log level of a log domain."), _("<level> <domain>"));
105  _("Add a nickname to your ignores list."), _("<nickname>"));
107  _("Add a nickname to your friends list."), _("<nickname>"));
109  _("Remove a nickname from your ignores or friends list."), _("<nickname>"));
111  _("Get a random number between 1 and N visible in the game setup lobby."), _("<N>"));
113  _("Display version information."));
115  _("Request information about a nickname."), _("<nickname>"));
116  }
117 private:
120 };
121 
122 }
void do_info()
Request information about a user from the server.
static void set_cmd_prefix(const std::string &value)
void print(const std::string &title, const std::string &message)
static std::string _(const char *str)
Definition: gettext.hpp:93
map_command_handler< chat_command_handler > map
virtual void register_alias(const std::string &to_cmd, const std::string &cmd)
Handling of system events.
Definition: manager.hpp:43
std::string get_flags_description() const
std::string get_command_flags_description(const map_command_handler< chat_command_handler >::command &c) const
chat_command_handler(chat_handler &chathandler, bool allies_only)
bool is_enabled(const map_command_handler< chat_command_handler >::command &c) const
virtual void register_command(const std::string &cmd, command_handler h, const std::string &help="", const std::string &usage="", const std::string &flags="")
mock_char c