From 06358cf84e5954cfda171427563bab93562b2c8e Mon Sep 17 00:00:00 2001 From: Glenn Fiedler Date: Mon, 25 Dec 2023 22:19:44 -0500 Subject: [PATCH] this should fix message sends across reconnect --- include/yojimbo_base_client.h | 4 ++++ include/yojimbo_base_server.h | 4 ++++ source/yojimbo_base_client.cpp | 9 +++++++++ source/yojimbo_base_server.cpp | 5 +++++ source/yojimbo_server.cpp | 6 ++++++ 5 files changed, 28 insertions(+) diff --git a/include/yojimbo_base_client.h b/include/yojimbo_base_client.h index bbaf31ac..caf97316 100644 --- a/include/yojimbo_base_client.h +++ b/include/yojimbo_base_client.h @@ -137,6 +137,10 @@ namespace yojimbo static void StaticFreeFunction( void * context, void * pointer ); + protected: + + virtual void Reset(); + private: ClientServerConfig m_config; ///< The client/server configuration. diff --git a/include/yojimbo_base_server.h b/include/yojimbo_base_server.h index f1ae113d..42914de7 100644 --- a/include/yojimbo_base_server.h +++ b/include/yojimbo_base_server.h @@ -117,6 +117,10 @@ namespace yojimbo static void StaticFreeFunction( void * context, void * pointer ); + protected: + + virtual void ResetClient( int clientIndex ); + private: ClientServerConfig m_config; ///< Base client/server config. diff --git a/source/yojimbo_base_client.cpp b/source/yojimbo_base_client.cpp index ec477bc8..d58a1339 100644 --- a/source/yojimbo_base_client.cpp +++ b/source/yojimbo_base_client.cpp @@ -59,6 +59,7 @@ namespace yojimbo void BaseClient::Disconnect() { SetClientState( CLIENT_STATE_DISCONNECTED ); + Reset(); } void BaseClient::AdvanceTime( double time ) @@ -275,4 +276,12 @@ namespace yojimbo reliable_endpoint_bandwidth( m_endpoint, &info.sentBandwidth, &info.receivedBandwidth, &info.ackedBandwidth ); } } + + void BaseClient::Reset() + { + if ( m_connection ) + { + m_connection->Reset(); + } + } } diff --git a/source/yojimbo_base_server.cpp b/source/yojimbo_base_server.cpp index 7c0dccf5..17e53811 100644 --- a/source/yojimbo_base_server.cpp +++ b/source/yojimbo_base_server.cpp @@ -328,4 +328,9 @@ namespace yojimbo Allocator * allocator = (Allocator*) context; YOJIMBO_FREE( *allocator, pointer ); } + + void BaseServer::ResetClient( int clientIndex ) + { + m_clientConnection[clientIndex]->Reset(); + } } diff --git a/source/yojimbo_server.cpp b/source/yojimbo_server.cpp index 4eea531d..634bbc22 100644 --- a/source/yojimbo_server.cpp +++ b/source/yojimbo_server.cpp @@ -98,12 +98,18 @@ namespace yojimbo { yojimbo_assert( m_server ); netcode_server_disconnect_client( m_server, clientIndex ); + ResetClient( clientIndex ); } void Server::DisconnectAllClients() { yojimbo_assert( m_server ); netcode_server_disconnect_all_clients( m_server ); + const int maxClients = GetMaxClients(); + for ( int i = 0; i < maxClients; ++i ) + { + ResetClient( i ); + } } void Server::SendPackets()