Skip to content

Commit

Permalink
4 .1.0
Browse files Browse the repository at this point in the history
- Fish-Networking 4.1.0 support.
  • Loading branch information
FirstGearGames committed Feb 24, 2024
1 parent 418e7f0 commit 9aaab37
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 53 deletions.
3 changes: 3 additions & 0 deletions FishNet/Plugins/FishySteamworks/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
4.1.0
- Fish-Networking 4.1.0 support.

4.0.0
- Fish-Networking 4.0.0 support.
- Added check to prevent Shutdown from calling multiple times without a prior initialization.
Expand Down
13 changes: 5 additions & 8 deletions FishNet/Plugins/FishySteamworks/Core/ClientSocket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if !FISHYSTEAMWORKS
using FishNet.Managing;
using FishNet.Managing.Logging;
using FishNet.Transporting;
using Steamworks;
Expand Down Expand Up @@ -126,14 +127,12 @@ private void OnLocalConnectionState(SteamNetConnectionStatusChangedCallback_t ar
}
else if (args.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ClosedByPeer || args.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ProblemDetectedLocally)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection was closed by peer, {args.m_info.m_szEndDebug}");
base.Transport.NetworkManager.Log($"Connection was closed by peer, {args.m_info.m_szEndDebug}");
StopConnection();
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection state changed: {args.m_info.m_eState.ToString()} - {args.m_info.m_szEndDebug}");
base.Transport.NetworkManager.Log($"Connection state changed: {args.m_info.m_eState.ToString()} - {args.m_info.m_szEndDebug}");
}
}

Expand Down Expand Up @@ -202,14 +201,12 @@ internal void SendToServer(byte channelId, ArraySegment<byte> segment)
EResult res = base.Send(_socket, segment, channelId);
if (res == EResult.k_EResultNoConnection || res == EResult.k_EResultInvalidParam)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection to server was lost.");
base.Transport.NetworkManager.Log($"Connection to server was lost.");
StopConnection();
}
else if (res != EResult.k_EResultOK)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"Could not send: {res.ToString()}");
base.Transport.NetworkManager.LogError($"Could not send: {res.ToString()}");
}
}

Expand Down
9 changes: 3 additions & 6 deletions FishNet/Plugins/FishySteamworks/Core/CommonSocket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if !FISHYSTEAMWORKS
using FishNet.Managing;
using FishNet.Managing.Logging;
using FishNet.Transporting;
using FishNet.Utility.Performance;
Expand Down Expand Up @@ -99,8 +100,7 @@ protected byte[] GetIPBytes(string address)
{
if (!IPAddress.TryParse(address, out IPAddress result))
{
if (Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"Could not parse address {address} to IPAddress.");
Transport.NetworkManager.LogError($"Could not parse address {address} to IPAddress.");
return null;
}
else
Expand Down Expand Up @@ -153,10 +153,7 @@ protected EResult Send(HSteamNetConnection steamConnection, ArraySegment<byte> s
EResult result = SteamNetworkingSockets.SendMessageToConnection(steamConnection, pData, (uint)segment.Count, sendFlag, out long _);
#endif
if (result != EResult.k_EResultOK)
{
if (Transport.NetworkManager.CanLog(LoggingType.Warning))
Debug.LogWarning($"Send issue: {result}");
}
Transport.NetworkManager.LogWarning($"Send issue: {result}");

pinnedArray.Free();
return result;
Expand Down
40 changes: 13 additions & 27 deletions FishNet/Plugins/FishySteamworks/Core/ServerSocket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if !FISHYSTEAMWORKS
using FishNet.Managing;
using FishNet.Managing.Logging;
using FishNet.Transporting;
using FishySteamworks.Client;
Expand Down Expand Up @@ -147,7 +148,7 @@ internal bool StopConnection()
if (_socket != HSteamListenSocket.Invalid)
{
#if UNITY_SERVER
SteamGameServerNetworkingSockets.CloseListenSocket(_socket);
SteamGameServerNetworkingSockets.CloseListenSocket(_socket);
#else
SteamNetworkingSockets.CloseListenSocket(_socket);
#endif
Expand Down Expand Up @@ -196,8 +197,7 @@ internal bool StopConnection(int connectionId)
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"Steam connection not found for connectionId {connectionId}.");
base.Transport.NetworkManager.LogError($"Steam connection not found for connectionId {connectionId}.");
return false;
}
}
Expand All @@ -216,8 +216,7 @@ private bool StopConnection(int connectionId, HSteamNetConnection socket)
#endif
_steamConnections.Remove(connectionId);
_steamIds.Remove(connectionId);
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Client with ConnectionID {connectionId} disconnected.");
base.Transport.NetworkManager.Log($"Client with ConnectionID {connectionId} disconnected.");
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Stopped, connectionId, Transport.Index));
_cachedConnectionIds.Enqueue(connectionId);

Expand All @@ -235,8 +234,7 @@ private void OnRemoteConnectionState(SteamNetConnectionStatusChangedCallback_t a
{
if (_steamConnections.Count >= GetMaximumClients())
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Incoming connection {clientSteamID} was rejected because would exceed the maximum connection count.");
base.Transport.NetworkManager.Log($"Incoming connection {clientSteamID} was rejected because would exceed the maximum connection count.");
#if UNITY_SERVER
SteamGameServerNetworkingSockets.CloseConnection(args.m_hConn, 0, "Max Connection Count", false);
#else
Expand All @@ -251,24 +249,17 @@ private void OnRemoteConnectionState(SteamNetConnectionStatusChangedCallback_t a
EResult res = SteamNetworkingSockets.AcceptConnection(args.m_hConn);
#endif
if (res == EResult.k_EResultOK)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Accepting connection {clientSteamID}");
}
base.Transport.NetworkManager.Log($"Accepting connection {clientSteamID}");
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection {clientSteamID} could not be accepted: {res.ToString()}");
}
base.Transport.NetworkManager.Log($"Connection {clientSteamID} could not be accepted: {res.ToString()}");
}
else if (args.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_Connected)
{
int connectionId = (_cachedConnectionIds.Count > 0) ? _cachedConnectionIds.Dequeue() : _nextConnectionId++;
_steamConnections.Add(args.m_hConn, connectionId);
_steamIds.Add(args.m_info.m_identityRemote.GetSteamID(), connectionId);

if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
base.Transport.NetworkManager.Log($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Started, connectionId, Transport.Index));
}
else if (args.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ClosedByPeer || args.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ProblemDetectedLocally)
Expand All @@ -280,8 +271,7 @@ private void OnRemoteConnectionState(SteamNetConnectionStatusChangedCallback_t a
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection {clientSteamID} state changed: {args.m_info.m_eState.ToString()}");
base.Transport.NetworkManager.Log($"Connection {clientSteamID} state changed: {args.m_info.m_eState.ToString()}");
}
}

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

if (res == EResult.k_EResultNoConnection || res == EResult.k_EResultInvalidParam)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Connection to {connectionId} was lost.");
base.Transport.NetworkManager.Log($"Connection to {connectionId} was lost.");
StopConnection(connectionId, steamConn);
}
else if (res != EResult.k_EResultOK)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"Could not send: {res.ToString()}");
base.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.");
base.Transport.NetworkManager.LogError($"ConnectionId {connectionId} does not exist, data will not be sent.");
}
}

Expand All @@ -402,8 +389,7 @@ internal string GetConnectionAddress(int connectionId)
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"ConnectionId {connectionId} is invalid; address cannot be returned.");
base.Transport.NetworkManager.LogError($"ConnectionId {connectionId} is invalid; address cannot be returned.");
return string.Empty;
}
}
Expand Down
18 changes: 6 additions & 12 deletions FishNet/Plugins/FishySteamworks/FishySteamworks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,21 +421,18 @@ private bool StartServer()
{
if (!InitializeRelayNetworkAccess())
{
if (NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"RelayNetworkAccess could not be initialized.");
base.NetworkManager.LogError($"RelayNetworkAccess could not be initialized.");
return false;
}
if (!IsNetworkAccessAvailable())
{
if (NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("Server network access is not available.");
base.NetworkManager.LogError("Server network access is not available.");
return false;
}
_server.ResetInvalidSocket();
if (_server.GetLocalConnectionState() != LocalConnectionState.Stopped)
{
if (NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("Server is already running.");
base.NetworkManager.LogError("Server is already running.");
return false;
}

Expand Down Expand Up @@ -476,8 +473,7 @@ private bool StartClient(string address)
{
if (_client.GetLocalConnectionState() != LocalConnectionState.Stopped)
{
if (NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("Client is already running.");
base.NetworkManager.LogError("Client is already running.");
return false;
}
//Stop client host if running.
Expand All @@ -486,14 +482,12 @@ private bool StartClient(string address)
//Initialize.
if (!InitializeRelayNetworkAccess())
{
if (NetworkManager.CanLog(LoggingType.Error))
Debug.LogError($"RelayNetworkAccess could not be initialized.");
base.NetworkManager.LogError($"RelayNetworkAccess could not be initialized.");
return false;
}
if (!IsNetworkAccessAvailable())
{
if (NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("Client network access is not available.");
base.NetworkManager.LogError("Client network access is not available.");
return false;
}

Expand Down

0 comments on commit 9aaab37

Please sign in to comment.