fix crash when double closing

This commit is contained in:
Lion Kortlepel 2024-11-01 15:07:54 +01:00
parent e3416804e4
commit 576d765557
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B

View File

@ -79,13 +79,17 @@ std::string TClient::GetCarPositionRaw(int Ident) {
void TClient::Disconnect(std::string_view Reason) { void TClient::Disconnect(std::string_view Reason) {
beammp_debugf("Disconnecting client {} for reason: {}", GetID(), Reason); beammp_debugf("Disconnecting client {} for reason: {}", GetID(), Reason);
boost::system::error_code ec; boost::system::error_code ec;
mSocket.shutdown(socket_base::shutdown_both, ec); if (mSocket.is_open()) {
if (ec) { mSocket.shutdown(socket_base::shutdown_both, ec);
beammp_debugf("Failed to shutdown client socket: {}", ec.message()); if (ec) {
} beammp_debugf("Failed to shutdown client socket: {}", ec.message());
mSocket.close(ec); }
if (ec) { mSocket.close(ec);
beammp_debugf("Failed to close client socket: {}", ec.message()); if (ec) {
beammp_debugf("Failed to close client socket: {}", ec.message());
}
} else {
beammp_debug("Socket is already closed.");
} }
} }