summaryrefslogtreecommitdiff
path: root/src/network/core
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-05-11 12:26:16 +0200
committerGitHub <noreply@github.com>2021-05-11 12:26:16 +0200
commit36e22f3a7bc0f86c650a293e2f624ac5ddfffa84 (patch)
tree156871620c6199f7c7411288ccf0bfab4e7957f6 /src/network/core
parent2e429ee4853fb4baf78c864be6ba462bd5758096 (diff)
downloadopenttd-36e22f3a7bc0f86c650a293e2f624ac5ddfffa84.tar.xz
Fix: [Network] clients leaving because of broken connections was not broadcasted (#9238)
The code mixed up "client has quit but we already told everyone" with "client lost connection, handle this". Split up those two signals: - CLIENT_QUIT means we told everyone and the connection is now dead - CONNECTION_LIST means we should tell everyone we lost a client
Diffstat (limited to 'src/network/core')
-rw-r--r--src/network/core/core.h21
-rw-r--r--src/network/core/tcp_admin.cpp2
-rw-r--r--src/network/core/tcp_game.cpp4
3 files changed, 14 insertions, 13 deletions
diff --git a/src/network/core/core.h b/src/network/core/core.h
index aac36080f..37948ad52 100644
--- a/src/network/core/core.h
+++ b/src/network/core/core.h
@@ -20,16 +20,17 @@ void NetworkCoreShutdown();
/** Status of a network client; reasons why a client has quit */
enum NetworkRecvStatus {
- NETWORK_RECV_STATUS_OKAY, ///< Everything is okay
- NETWORK_RECV_STATUS_DESYNC, ///< A desync did occur
- NETWORK_RECV_STATUS_NEWGRF_MISMATCH, ///< We did not have the required NewGRFs
- NETWORK_RECV_STATUS_SAVEGAME, ///< Something went wrong (down)loading the savegame
- NETWORK_RECV_STATUS_CONN_LOST, ///< The connection is 'just' lost
- NETWORK_RECV_STATUS_MALFORMED_PACKET, ///< We apparently send a malformed packet
- NETWORK_RECV_STATUS_SERVER_ERROR, ///< The server told us we made an error
- NETWORK_RECV_STATUS_SERVER_FULL, ///< The server is full
- NETWORK_RECV_STATUS_SERVER_BANNED, ///< The server has banned us
- NETWORK_RECV_STATUS_CLOSE_QUERY, ///< Done querying the server
+ NETWORK_RECV_STATUS_OKAY, ///< Everything is okay.
+ NETWORK_RECV_STATUS_DESYNC, ///< A desync did occur.
+ NETWORK_RECV_STATUS_NEWGRF_MISMATCH, ///< We did not have the required NewGRFs.
+ NETWORK_RECV_STATUS_SAVEGAME, ///< Something went wrong (down)loading the savegame.
+ NETWORK_RECV_STATUS_CLIENT_QUIT, ///< The connection is lost gracefully. Other clients are already informed of this leaving client.
+ NETWORK_RECV_STATUS_MALFORMED_PACKET, ///< We apparently send a malformed packet.
+ NETWORK_RECV_STATUS_SERVER_ERROR, ///< The server told us we made an error.
+ NETWORK_RECV_STATUS_SERVER_FULL, ///< The server is full.
+ NETWORK_RECV_STATUS_SERVER_BANNED, ///< The server has banned us.
+ NETWORK_RECV_STATUS_CLOSE_QUERY, ///< Done querying the server.
+ NETWORK_RECV_STATUS_CONNECTION_LOST, ///< The connection is lost unexpectedly.
};
/** Forward declaration due to circular dependencies */
diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp
index c72583f55..36daae4a1 100644
--- a/src/network/core/tcp_admin.cpp
+++ b/src/network/core/tcp_admin.cpp
@@ -41,7 +41,7 @@ NetworkAdminSocketHandler::~NetworkAdminSocketHandler()
NetworkRecvStatus NetworkAdminSocketHandler::CloseConnection(bool error)
{
delete this;
- return NETWORK_RECV_STATUS_CONN_LOST;
+ return NETWORK_RECV_STATUS_CLIENT_QUIT;
}
/**
diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp
index eb53db5ac..771ea37b1 100644
--- a/src/network/core/tcp_game.cpp
+++ b/src/network/core/tcp_game.cpp
@@ -48,10 +48,10 @@ NetworkRecvStatus NetworkGameSocketHandler::CloseConnection(bool error)
_networking = false;
ShowErrorMessage(STR_NETWORK_ERROR_LOSTCONNECTION, INVALID_STRING_ID, WL_CRITICAL);
- return NETWORK_RECV_STATUS_CONN_LOST;
+ return NETWORK_RECV_STATUS_CLIENT_QUIT;
}
- return this->CloseConnection(error ? NETWORK_RECV_STATUS_SERVER_ERROR : NETWORK_RECV_STATUS_CONN_LOST);
+ return this->CloseConnection(NETWORK_RECV_STATUS_CONNECTION_LOST);
}