Skip to content

Commit

Permalink
this should fix message sends across reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
gafferongames committed Dec 26, 2023
1 parent 98aa26f commit 06358cf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/yojimbo_base_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions include/yojimbo_base_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions source/yojimbo_base_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace yojimbo
void BaseClient::Disconnect()
{
SetClientState( CLIENT_STATE_DISCONNECTED );
Reset();
}

void BaseClient::AdvanceTime( double time )
Expand Down Expand Up @@ -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();
}
}
}
5 changes: 5 additions & 0 deletions source/yojimbo_base_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,9 @@ namespace yojimbo
Allocator * allocator = (Allocator*) context;
YOJIMBO_FREE( *allocator, pointer );
}

void BaseServer::ResetClient( int clientIndex )
{
m_clientConnection[clientIndex]->Reset();
}
}
6 changes: 6 additions & 0 deletions source/yojimbo_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 06358cf

Please sign in to comment.