The Battle for Wesnoth
1.19.5+dev
chat_command_handler.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2017 - 2024
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
:
26
typedef
map_command_handler<chat_command_handler>
map
;
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
);
36
void
do_network_send_req_arg
();
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
54
std::string
get_command_flags_description
(
55
const
map_command_handler<chat_command_handler>::command
&
c
)
const
56
{
57
if
(
c
.has_flag(
'A'
)) {
58
return
std::string(
" "
) +
_
(
"(admin only)"
);
59
}
60
else
{
61
return
""
;
62
}
63
}
64
65
bool
is_enabled
(
const
map_command_handler<chat_command_handler>::command
&
c
)
const
;
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
);
73
register_command
(
"query"
, &
chat_command_handler::do_network_send
,
74
_
(
"Send a query to the server. Without arguments the server"
75
" should tell you the available commands."
));
76
register_alias
(
"query"
,
"q"
);
77
register_command
(
"ban"
, &
chat_command_handler::do_network_send_req_arg
,
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>"
));
80
register_command
(
"unban"
, &
chat_command_handler::do_network_send_req_arg
,
81
_
(
"Unban a user. He does not have to be in the game but on"
82
" the server."
),
_
(
"<nickname>"
));
83
register_command
(
"kick"
, &
chat_command_handler::do_network_send_req_arg
,
84
_
(
"Kick a player or observer."
),
_
(
"<nickname>"
));
85
register_command
(
"mute"
, &
chat_command_handler::do_network_send
,
86
_
(
"Mute an observer. Without an argument displays the mute status."
),
_
(
"<nickname>"
));
87
register_command
(
"unmute"
, &
chat_command_handler::do_network_send
,
88
_
(
"Unmute an observer. Without an argument unmutes everyone."
),
_
(
"<nickname>"
));
89
register_command
(
"muteall"
, &
chat_command_handler::do_network_send
,
90
_
(
"Mute/Unmute all observers. (toggles)"
),
""
);
91
register_command
(
"ping"
, &
chat_command_handler::do_network_send
,
92
_
(
"Send some data to the server. Can be used to verify the network connection and notice disconnects."
));
93
register_command
(
"report"
, &
chat_command_handler::do_mp_report
,
94
_
(
"Report abuse, rule violations, etc. to the server moderators. "
95
"Make sure to mention relevant nicknames, etc."
),
""
);
96
register_alias
(
"report"
,
"adminmsg"
);
// deprecated
97
register_command
(
"emote"
, &
chat_command_handler::do_emote
,
98
_
(
"Send an emotion or personal action in chat."
),
_
(
"<message>"
));
99
register_alias
(
"emote"
,
"me"
);
100
register_command
(
"whisper"
, &
chat_command_handler::do_whisper
,
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"
);
106
register_command
(
"log"
, &
chat_command_handler::do_log
,
107
_
(
"Change the log level of a log domain."
),
_
(
"<level> <domain>"
));
108
register_command
(
"ignore"
, &
chat_command_handler::do_ignore
,
109
_
(
"Add a nickname to your ignores list."
),
_
(
"<nickname>"
));
110
register_command
(
"friend"
, &
chat_command_handler::do_friend
,
111
_
(
"Add a nickname to your friends list."
),
_
(
"<nickname>"
));
112
register_command
(
"remove"
, &
chat_command_handler::do_remove
,
113
_
(
"Remove a nickname from your ignores or friends list."
),
_
(
"<nickname>"
));
114
register_command
(
"roll"
, &
chat_command_handler::do_network_send_req_arg
,
115
_
(
"Get a random number between 1 and N visible in the game setup lobby."
),
_
(
"<N>"
));
116
register_command
(
"version"
, &
chat_command_handler::do_version
,
117
_
(
"Display version information."
));
118
register_command
(
"info"
, &
chat_command_handler::do_info
,
119
_
(
"Request information about a nickname."
),
_
(
"<nickname>"
));
120
register_command
(
"clear"
, &
chat_command_handler::do_clear_messages
,
121
_
(
"Clear chat history."
));
122
}
123
private
:
124
chat_handler
&
chat_handler_
;
125
bool
allies_only_
;
126
};
127
128
}
events::chat_command_handler
Definition:
chat_command_handler.hpp:24
events::chat_command_handler::do_whisper
void do_whisper()
Definition:
chat_command_handler.cpp:58
events::chat_command_handler::do_mp_report
void do_mp_report()
Definition:
chat_command_handler.cpp:147
events::chat_command_handler::chat_command_handler
chat_command_handler(chat_handler &chathandler, bool allies_only)
Definition:
chat_command_handler.hpp:27
events::chat_command_handler::do_info
void do_info()
Request information about a user from the server.
Definition:
chat_command_handler.cpp:129
events::chat_command_handler::map
map_command_handler< chat_command_handler > map
Definition:
chat_command_handler.hpp:26
events::chat_command_handler::get_flags_description
std::string get_flags_description() const
Definition:
chat_command_handler.hpp:50
events::chat_command_handler::do_friend
void do_friend()
Definition:
chat_command_handler.cpp:90
events::chat_command_handler::get_command_flags_description
std::string get_command_flags_description(const map_command_handler< chat_command_handler >::command &c) const
Definition:
chat_command_handler.hpp:54
events::chat_command_handler::init_map
void init_map()
Definition:
chat_command_handler.hpp:69
events::chat_command_handler::do_version
void do_version()
Definition:
chat_command_handler.cpp:125
events::chat_command_handler::do_emote
void do_emote()
Definition:
chat_command_handler.cpp:37
events::chat_command_handler::do_clear_messages
void do_clear_messages()
Definition:
chat_command_handler.cpp:143
events::chat_command_handler::do_remove
void do_remove()
Definition:
chat_command_handler.cpp:109
events::chat_command_handler::is_enabled
bool is_enabled(const map_command_handler< chat_command_handler >::command &c) const
Definition:
chat_command_handler.cpp:27
events::chat_command_handler::allies_only_
bool allies_only_
Definition:
chat_command_handler.hpp:125
events::chat_command_handler::do_display
void do_display()
Definition:
chat_command_handler.cpp:120
events::chat_command_handler::print
void print(const std::string &title, const std::string &message)
Definition:
chat_command_handler.cpp:32
events::chat_command_handler::chat_handler_
chat_handler & chat_handler_
Definition:
chat_command_handler.hpp:124
events::chat_command_handler::do_network_send
void do_network_send()
Definition:
chat_command_handler.cpp:42
events::chat_command_handler::do_network_send_req_arg
void do_network_send_req_arg()
Definition:
chat_command_handler.cpp:52
events::chat_command_handler::do_ignore
void do_ignore()
Definition:
chat_command_handler.cpp:71
events::chat_command_handler::do_log
void do_log()
Definition:
chat_command_handler.cpp:66
events::chat_handler
Definition:
chat_events.hpp:26
events::map_command_handler
Definition:
map_command_handler.hpp:123
events::map_command_handler< chat_command_handler >::register_command
virtual void register_command(const std::string &cmd, command_handler h, const std::string &help="", const std::string &usage="", const std::string &flags="")
Definition:
map_command_handler.hpp:419
events::map_command_handler< chat_command_handler >::set_cmd_prefix
static void set_cmd_prefix(const std::string &value)
Definition:
map_command_handler.hpp:408
events::map_command_handler< chat_command_handler >::set_cmd_flag
static void set_cmd_flag(bool value)
Definition:
map_command_handler.hpp:415
events::map_command_handler< chat_command_handler >::register_alias
virtual void register_alias(const std::string &to_cmd, const std::string &cmd)
Definition:
map_command_handler.hpp:431
gettext.hpp
_
static std::string _(const char *str)
Definition:
gettext.hpp:93
map_command_handler.hpp
events
Handling of system events.
Definition:
chat_command_handler.cpp:25
data
std::string_view data
Definition:
picture.cpp:178
c
mock_char c
Definition:
test_formula_core.cpp:68
Generated by
1.9.1