Skip to content

fix: Fixing an issue where OnClientDisconnectCallback was not being called when using UTP #1243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 1, 2021
20 changes: 17 additions & 3 deletions com.unity.netcode.adapter.utp/Runtime/UnityTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,22 @@ private static unsafe NetworkConnection ParseClientId(ulong netcodeConnectionId)

public override void DisconnectLocalClient()
{
Debug.Assert(m_State == State.Connected, "DisconnectLocalClient should be called on a connected client");

if (m_State == State.Connected)
{
m_Driver.Disconnect(ParseClientId(m_ServerClientId));
if (m_Driver.Disconnect(ParseClientId(m_ServerClientId)) == 0)
{

m_State = State.Disconnected;


// If we successfully disconnect we dispatch a local disconnect message
// this how uNET and other transports worked and so this is just keeping with the old behavior
// should be also noted on the client this will call shutdown on the NetworkManager and the Transport
InvokeOnTransportEvent(NetcodeNetworkEvent.Disconnect,
m_ServerClientId,
default(ArraySegment<byte>),
Time.realtimeSinceStartup);
}
}
}

Expand Down Expand Up @@ -699,6 +710,9 @@ public override void Shutdown()

// make sure we don't leak queues when we shutdown
m_SendQueue.Clear();

// We must reset this to zero because UTP actually re-uses clientIds if there is a clean disconnect
m_ServerClientId = 0;
}

public void CreateDriver(UnityTransport transport, out NetworkDriver driver, out NetworkPipeline unreliableSequencedPipeline, out NetworkPipeline reliableSequencedPipeline, out NetworkPipeline reliableSequencedFragmentedPipeline)
Expand Down