Skip to content

Commit

Permalink
Logging, Bugfix, Default channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Chykary committed Feb 20, 2021
1 parent 10aa6b5 commit d0ac434
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
30 changes: 22 additions & 8 deletions Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ private async void Connect(string host)

OnConnected += SetConnectedComplete;
SendInternal(hostSteamID, InternalMessages.CONNECT);

Task connectedCompleteTask = connectedComplete.Task;
Task timeOutTask = Task.Delay(ConnectionTimeout, cancelToken.Token);

if (await Task.WhenAny(connectedCompleteTask, Task.Delay(ConnectionTimeout, cancelToken.Token)) != connectedCompleteTask)
if (await Task.WhenAny(connectedCompleteTask, timeOutTask) != connectedCompleteTask)
{
if (cancelToken.IsCancellationRequested)
{
Debug.LogError($"The connection attempt was cancelled.");
}
else if (timeOutTask.IsCompleted)
{
Debug.LogError($"Connection to {host} timed out.");
}
OnConnected -= SetConnectedComplete;
Debug.LogError("Connection timed out.");
OnConnectionFailed(hostSteamID);
Expand Down Expand Up @@ -128,14 +136,20 @@ protected override void OnReceiveInternalData(InternalMessages type, SteamId cli
switch (type)
{
case InternalMessages.ACCEPT_CONNECT:
Connected = true;
Debug.Log("Connection established.");
OnConnected.Invoke();
if (!Connected)
{
Connected = true;
Debug.Log("Connection established.");
OnConnected.Invoke();
}
break;
case InternalMessages.DISCONNECT:
Connected = false;
Debug.Log("Disconnected.");
OnDisconnected.Invoke();
if (Connected)
{
Connected = false;
Debug.Log("Disconnected.");
OnDisconnected.Invoke();
}
break;
default:
Debug.Log("Received unknown message type");
Expand Down
26 changes: 16 additions & 10 deletions FizzyFacepunch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class FizzyFacepunch : Transport
{
private const string STEAM_SCHEME = "steam";

private Client client;
private Server server;
private static Client client;
private static Server server;

private Common activeNode;
private static Common activeNode;

[SerializeField]
public P2PSend[] Channels = new P2PSend[1] { P2PSend.Reliable };
public P2PSend[] Channels = new P2PSend[2] { P2PSend.Reliable , P2PSend.UnreliableNoDelay };

[Tooltip("Timeout for connecting in seconds.")]
public int Timeout = 25;
Expand Down Expand Up @@ -180,13 +180,19 @@ public override void ServerStop()

public override void Shutdown()
{
server?.Shutdown();
client?.Disconnect();
if (server != null)
{
server.Shutdown();
server = null;
Debug.Log("Transport shut down - was server.");
}

server = null;
client = null;
activeNode = null;
Debug.Log("Transport shut down.");
if (client != null)
{
client.Disconnect();
client = null;
Debug.Log("Transport shut down - was client.");
}
}

public override int GetMaxPacketSize(int channelId)
Expand Down
2 changes: 1 addition & 1 deletion Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override void OnReceiveInternalData(InternalMessages type, SteamId cli
}
else
{
OnReceivedError.Invoke(-1, new Exception("ERROR Unknown SteamID"));
OnReceivedError.Invoke(-1, new Exception("ERROR Unknown SteamID while receiving disconnect message."));
}

break;
Expand Down

0 comments on commit d0ac434

Please sign in to comment.