Skip to content

Commit

Permalink
Bump FN 4.16
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyro-Games authored and Tyro-Games committed Apr 2, 2024
1 parent 17f7e7f commit 091a51b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
34 changes: 12 additions & 22 deletions FishNet/Plugins/FishyFacepunch/Core/ClientSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using FishNet.Managing;
using UnityEngine;

namespace FishyFacepunch.Client
Expand Down Expand Up @@ -87,45 +88,39 @@ internal async void StartConnection(string address, ushort port)
{
if (cancelToken.IsCancellationRequested)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"The connection attempt was cancelled.");
Transport.NetworkManager.LogError($"The connection attempt was cancelled.");
}
else if (timeOutTask.IsCompleted)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"Connection to {address} timed out.");
Transport.NetworkManager.LogError($"Connection to {address} timed out.");
StopConnection();
}
SetLocalConnectionState(LocalConnectionState.Stopped, false);
}
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("SteamWorks not initialized");
Transport.NetworkManager.LogError("SteamWorks not initialized");
SetLocalConnectionState(LocalConnectionState.Stopped, false);
}
}
catch (FormatException)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"Connection string was not in the right format. Did you enter a SteamId?");
Transport.NetworkManager.LogError($"Connection string was not in the right format. Did you enter a SteamId?");
SetLocalConnectionState(LocalConnectionState.Stopped, false);
_Error = true;
}
catch (Exception ex)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError(ex.Message);
Transport.NetworkManager.LogError(ex.Message);
SetLocalConnectionState(LocalConnectionState.Stopped, false);
_Error = true;
}
finally
{
if (_Error)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("Connection failed.");
Transport.NetworkManager.LogError("Connection failed.");
SetLocalConnectionState(LocalConnectionState.Stopped, false);
}
}
Expand All @@ -143,14 +138,12 @@ private void OnConnectionStatusChanged(Connection conn, ConnectionInfo info)
}
else if (info.State == ConnectionState.ClosedByPeer || info.State == ConnectionState.ProblemDetectedLocally)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection was closed by peer, {info.EndReason}");
Transport.NetworkManager.Log($"Connection was closed by peer, {info.EndReason}");
StopConnection();
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection state changed: {info.State.ToString()} - {info.EndReason}");
Transport.NetworkManager.Log($"Connection state changed: {info.State.ToString()} - {info.EndReason}");
}
}

Expand All @@ -171,8 +164,7 @@ internal bool StopConnection()

if (HostConnectionManager != null)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log("Sending Disconnect message");
Transport.NetworkManager.Log("Sending Disconnect message");
HostConnection.Close(false, 0, "Graceful disconnect");
HostConnectionManager = null;
}
Expand Down Expand Up @@ -212,14 +204,12 @@ internal void SendToServer(byte channelId, ArraySegment<byte> segment)
Result res = base.Send(HostConnection, segment, channelId);
if (res == Result.NoConnection || res == Result.InvalidParam)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection to server was lost.");
Transport.NetworkManager.Log($"Connection to server was lost.");
StopConnection();
}
else if (res != Result.OK)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"Could not send: {res.ToString()}");
Transport.NetworkManager.LogError($"Could not send: {res.ToString()}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions FishNet/Plugins/FishyFacepunch/Core/CommonSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Net;
using System.Runtime.InteropServices;
using FishNet.Managing;
using UnityEngine;

namespace FishyFacepunch
Expand Down Expand Up @@ -150,8 +151,7 @@ protected Result Send(Connection conn, ArraySegment<byte> segment, byte channelI
Result result = conn.SendMessage(pData, segment.Count, sendFlag);
if (result != Result.OK)
{
if (Transport.NetworkManager.CanLog(LoggingType.Warning))
Debug.LogWarning($"Send issue: {result}");
Transport.NetworkManager.LogWarning($"Send issue: {result}");
}

pinnedArray.Free();
Expand Down
34 changes: 12 additions & 22 deletions FishNet/Plugins/FishyFacepunch/Core/ServerSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Steamworks.Data;
using System;
using System.Collections.Generic;
using FishNet.Managing;
using UnityEngine;

namespace FishyFacepunch.Server
Expand Down Expand Up @@ -167,8 +168,7 @@ internal bool StopConnection(int connectionId)
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"Steam connection not found for connectionId {connectionId}.");
Transport.NetworkManager.LogError($"Steam connection not found for connectionId {connectionId}.");
return false;
}
}
Expand All @@ -183,8 +183,7 @@ private bool StopConnection(int connectionId, Connection socket)
socket.Close(false, 0, "Graceful disconnect");
_steamConnections.Remove(connectionId);
_steamIds.Remove(connectionId);
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Client with ConnectionID {connectionId} disconnected.");
Transport.NetworkManager.Log($"Client with ConnectionID {connectionId} disconnected.");
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Stopped, connectionId, Transport.Index));
_cachedConnectionIds.Enqueue(connectionId);

Expand All @@ -201,8 +200,7 @@ private void OnRemoteConnectionState(Connection conn, ConnectionInfo info)
{
if (_steamConnections.Count >= _maximumClients)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Incoming connection {clientSteamID} was rejected because would exceed the maximum connection count.");
Transport.NetworkManager.Log($"Incoming connection {clientSteamID} was rejected because would exceed the maximum connection count.");

conn.Close(false, 0, "Max Connection Count");
return;
Expand All @@ -212,13 +210,11 @@ private void OnRemoteConnectionState(Connection conn, ConnectionInfo info)

if ((res = conn.Accept()) == Result.OK)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Accepting connection {clientSteamID}");
Transport.NetworkManager.Log($"Accepting connection {clientSteamID}");
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection {clientSteamID} could not be accepted: {res.ToString()}");
Transport.NetworkManager.Log($"Connection {clientSteamID} could not be accepted: {res.ToString()}");
}
}
else if (info.State == ConnectionState.Connected)
Expand All @@ -227,8 +223,7 @@ private void OnRemoteConnectionState(Connection conn, ConnectionInfo info)
_steamConnections.Add(conn, connectionId);
_steamIds.Add(clientSteamID, connectionId);

if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
Transport.NetworkManager.Log($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Started, connectionId, Transport.Index));
}
else if (info.State == ConnectionState.ClosedByPeer || info.State == ConnectionState.ProblemDetectedLocally)
Expand All @@ -240,8 +235,7 @@ private void OnRemoteConnectionState(Connection conn, ConnectionInfo info)
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection {clientSteamID} state changed: {info.State.ToString()}");
Transport.NetworkManager.Log($"Connection {clientSteamID} state changed: {info.State.ToString()}");
}
}

Expand Down Expand Up @@ -316,20 +310,17 @@ internal void SendToClient(byte channelId, ArraySegment<byte> segment, int conne

if (res == Result.NoConnection || res == Result.InvalidParam)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection to {connectionId} was lost.");
Transport.NetworkManager.Log($"Connection to {connectionId} was lost.");
StopConnection(connectionId, steamConn);
}
else if (res != Result.OK)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"Could not send: {res.ToString()}");
Transport.NetworkManager.LogError($"Could not send: {res.ToString()}");
}
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"ConnectionId {connectionId} does not exist, data will not be sent.");
Transport.NetworkManager.LogError($"ConnectionId {connectionId} does not exist, data will not be sent.");
}
}

Expand All @@ -346,8 +337,7 @@ internal string GetConnectionAddress(int connectionId)
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"ConnectionId {connectionId} is invalid; address cannot be returned.");
Transport.NetworkManager.LogError($"ConnectionId {connectionId} is invalid; address cannot be returned.");

return string.Empty;
}
Expand Down

0 comments on commit 091a51b

Please sign in to comment.