summaryrefslogtreecommitdiff
path: root/src/console_cmds.cpp
diff options
context:
space:
mode:
authorBjarni Thor <bjarni@bjarnithor.com>2020-01-21 15:39:10 +0000
committerCharles Pigott <charlespigott@googlemail.com>2020-02-04 22:17:39 +0000
commit5880f1479f21157158dbe862e4cb1118e0cfbfae (patch)
tree83597e5e42c96594646ccc548a915f303488b044 /src/console_cmds.cpp
parentb5d56559d2ec16512dd8a0346406bf36486ebf7c (diff)
downloadopenttd-5880f1479f21157158dbe862e4cb1118e0cfbfae.tar.xz
Feature #7756: Allow server to supply a reason to kicked/banned clients
This commit adds the missing feature of allowing the server owner to provide a reason for kicking/banning a client, which the client sees in a pop-up window after being kicked. The implementation extends the network protocol by adding a new network action called NETWORK_ACTION_KICKED that is capable of having an error string, unlike the other network error packages. Additionally, the kick function broadcasts a message to all clients about the kicked client and the reason for the kick.
Diffstat (limited to 'src/console_cmds.cpp')
-rw-r--r--src/console_cmds.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 748e4ab4c..c4b454b51 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -470,7 +470,7 @@ DEF_CONSOLE_CMD(ConClearBuffer)
* Network Core Console Commands
**********************************/
-static bool ConKickOrBan(const char *argv, bool ban)
+static bool ConKickOrBan(const char *argv, bool ban, const char *reason)
{
uint n;
@@ -494,14 +494,14 @@ static bool ConKickOrBan(const char *argv, bool ban)
if (!ban) {
/* Kick only this client, not all clients with that IP */
- NetworkServerKickClient(client_id);
+ NetworkServerKickClient(client_id, reason);
return true;
}
/* When banning, kick+ban all clients with that IP */
- n = NetworkServerKickOrBanIP(client_id, ban);
+ n = NetworkServerKickOrBanIP(client_id, ban, reason);
} else {
- n = NetworkServerKickOrBanIP(argv, ban);
+ n = NetworkServerKickOrBanIP(argv, ban, reason);
}
if (n == 0) {
@@ -516,28 +516,48 @@ static bool ConKickOrBan(const char *argv, bool ban)
DEF_CONSOLE_CMD(ConKick)
{
if (argc == 0) {
- IConsoleHelp("Kick a client from a network game. Usage: 'kick <ip | client-id>'");
+ IConsoleHelp("Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'");
IConsoleHelp("For client-id's, see the command 'clients'");
return true;
}
- if (argc != 2) return false;
+ if (argc != 2 && argc != 3) return false;
+
+ /* No reason supplied for kicking */
+ if (argc == 2) return ConKickOrBan(argv[1], false, nullptr);
- return ConKickOrBan(argv[1], false);
+ /* Reason for kicking supplied */
+ int kick_message_length = strlen(argv[2]);
+ if (kick_message_length >= 255) {
+ IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered %d characters.", kick_message_length);
+ return false;
+ } else {
+ return ConKickOrBan(argv[1], false, argv[2]);
+ }
}
DEF_CONSOLE_CMD(ConBan)
{
if (argc == 0) {
- IConsoleHelp("Ban a client from a network game. Usage: 'ban <ip | client-id>'");
+ IConsoleHelp("Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'");
IConsoleHelp("For client-id's, see the command 'clients'");
IConsoleHelp("If the client is no longer online, you can still ban his/her IP");
return true;
}
- if (argc != 2) return false;
+ if (argc != 2 && argc != 3) return false;
+
+ /* No reason supplied for kicking */
+ if (argc == 2) return ConKickOrBan(argv[1], true, nullptr);
- return ConKickOrBan(argv[1], true);
+ /* Reason for kicking supplied */
+ int kick_message_length = strlen(argv[2]);
+ if (kick_message_length >= 255) {
+ IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered %d characters.", kick_message_length);
+ return false;
+ } else {
+ return ConKickOrBan(argv[1], true, argv[2]);
+ }
}
DEF_CONSOLE_CMD(ConUnBan)