Refactor Steam Networking Components
- Removed SteamMessageHandler class and its implementation files. - Integrated control packet handling directly into the SteamMessageHandler. - Updated TCPClient and TCPServer classes to improve connection management and error handling. - Added SteamNetworkingManager class to manage Steam networking, including lobby creation and connection handling. - Implemented callbacks for Steam Friends and Matchmaking to handle lobby events. - Enhanced message forwarding logic between TCP clients and Steam connections. - Introduced control packet handling for ping responses. - Improved thread safety with mutexes for shared resources.
This commit is contained in:
@@ -28,16 +28,21 @@ bool TCPClient::connect() {
|
||||
void TCPClient::disconnect() {
|
||||
if (disconnected_) return;
|
||||
disconnected_ = true;
|
||||
if (disconnectCallback_) {
|
||||
disconnectCallback_();
|
||||
}
|
||||
connected_ = false;
|
||||
io_context_.stop();
|
||||
if (clientThread_.joinable()) {
|
||||
clientThread_.join();
|
||||
if (clientThread_.get_id() == std::this_thread::get_id()) {
|
||||
clientThread_.detach();
|
||||
} else {
|
||||
clientThread_.join();
|
||||
}
|
||||
}
|
||||
if (socket_->is_open()) {
|
||||
socket_->close();
|
||||
try {
|
||||
if (socket_->is_open()) {
|
||||
socket_->close();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error closing socket: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +95,9 @@ void TCPClient::handle_read(const boost::system::error_code& error, std::size_t
|
||||
} else {
|
||||
std::cerr << "Read failed: " << error.message() << std::endl;
|
||||
}
|
||||
if (disconnectCallback_) {
|
||||
disconnectCallback_();
|
||||
}
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user