summaryrefslogtreecommitdiff
path: root/src/network/network_client.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/network/network_client.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/network/network_client.cpp')
-rw-r--r--src/network/network_client.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 08ec7823e..74b802f91 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -687,8 +687,15 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p
StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
if (error < (ptrdiff_t)lengthof(network_error_strings)) err = network_error_strings[error];
-
- ShowErrorMessage(err, INVALID_STRING_ID, WL_CRITICAL);
+ /* In case of kicking a client, we assume there is a kick message in the packet if we can read one byte */
+ if (error == NETWORK_ERROR_KICKED && p->CanReadFromPacket(1)) {
+ char kick_msg[255];
+ p->Recv_string(kick_msg, sizeof(kick_msg));
+ SetDParamStr(0, kick_msg);
+ ShowErrorMessage(err, STR_NETWORK_ERROR_KICK_MESSAGE, WL_CRITICAL);
+ } else {
+ ShowErrorMessage(err, INVALID_STRING_ID, WL_CRITICAL);
+ }
/* Perform an emergency save if we had already entered the game */
if (this->status == STATUS_ACTIVE) ClientNetworkEmergencySave();