fix crash when double closing (#383)

This commit is contained in:
Tixx 2024-11-30 21:14:09 +01:00 committed by GitHub
commit 5e13f9dd2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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.");
} }
} }