Fix client reconnect

This commit is contained in:
Pieter-Jan Briers
2022-04-15 15:28:36 +02:00
parent 7cb0978468
commit 24b124fb17
4 changed files with 26 additions and 9 deletions

View File

@@ -74,7 +74,7 @@ namespace Robust.Client
{
if (RunLevel == ClientRunLevel.Connecting)
{
_net.Shutdown("Client mashing that connect button.");
_net.Reset("Client mashing that connect button.");
Reset();
}

View File

@@ -40,5 +40,7 @@ namespace Robust.Shared.Network
/// </summary>
/// <param name="reason">The reason why disconnect was called.</param>
void ClientDisconnect(string reason);
void Reset(string reason);
}
}
}

View File

@@ -375,11 +375,12 @@ namespace Robust.Shared.Network
InitUpnp();
}
/// <inheritdoc />
public void Shutdown(string reason)
public void Reset(string reason)
{
foreach (var kvChannel in _channels)
{
DisconnectChannel(kvChannel.Value, reason);
}
// request shutdown of the netPeer
_netPeers.ForEach(p => p.Peer.Shutdown(reason));
@@ -398,10 +399,22 @@ namespace Robust.Shared.Network
// Clear cached message functions.
Array.Clear(_netMsgFunctions, 0, _netMsgFunctions.Length);
_blankNetMsgFunctions.Clear();
// Clear string table.
// This has to be done AFTER clearing _netMsgFunctions so that it re-initializes NetMsg 0.
_strings.Reset();
_cancelConnectTokenSource?.Cancel();
ClientConnectState = ClientConnectionState.NotConnecting;
}
/// <inheritdoc />
public void Shutdown(string reason)
{
Reset(reason);
_blankNetMsgFunctions.Clear();
_messages.Clear();
_config.UnsubValueChanged(CVars.NetVerbose, NetVerboseChanged);
@@ -418,9 +431,6 @@ namespace Robust.Shared.Network
_serializer.ClientHandshakeComplete -= OnSerializerOnClientHandshakeComplete;
_cancelConnectTokenSource?.Cancel();
ClientConnectState = ClientConnectionState.NotConnecting;
ConnectFailed = null;
Connected = null;
Disconnect = null;
@@ -555,7 +565,7 @@ namespace Robust.Shared.Network
Disconnect?.Invoke(this, new NetDisconnectedArgs(ServerChannel, reason));
}
Shutdown(reason);
Reset(reason);
}
private NetPeerConfiguration _getBaseNetPeerConfig()

View File

@@ -82,6 +82,11 @@ namespace Robust.UnitTesting
}
public void Shutdown(string reason)
{
Reset(reason);
}
public void Reset(string reason)
{
foreach (var channel in _channels.Values.ToList())
{