Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
- FishNetworking 2.0.0 support.
  • Loading branch information
FirstGearGames committed Jun 12, 2022
1 parent 7953e35 commit 822380d
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 263 deletions.
32 changes: 20 additions & 12 deletions FishNet/Plugins/FishyFacepunch/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
1.0.0
- Initial release.
2.0.0
- FishNetworking 2.0.0 support.

1.3.1
- FishNetworking 1.3.1 Support

1.3.0
- Removed obsolete methods
- FishNetworking 1.3.0 Support

1.2.0
- Removed GC (Full Credits to Punfish - Thank you)
- Removed obsolete method

1.1.1
- FishNetworking 0.1.5.Nightly.10 Support

1.1.0
- Support for client hosted games (needs two separated steam accounts, to test) - Thank to Punfish
- Organized folder structure
- Removed ChannelData
1.1.1
- FishNetworking 0.1.5.Nightly.10 Support
1.2.0
- Removed GC (Full Credits to Punfish - Thank you)
- Removed obsolete method
1.3.0
- Removed obsolete methods
- FishNetworking 1.3.0 Support
1.3.1
- FishNetworking 1.3.1 Support

1.0.0
- Initial release.
26 changes: 13 additions & 13 deletions FishNet/Plugins/FishyFacepunch/Core/ClientHostSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class ClientHostSocket : CommonSocket
internal void CheckSetStarted()
{
//Check to set as started.
if (_server != null && base.GetLocalConnectionState() == LocalConnectionStates.Starting)
if (_server != null && base.GetLocalConnectionState() == LocalConnectionState.Starting)
{
if (_server.GetLocalConnectionState() == LocalConnectionStates.Started)
SetLocalConnectionState(LocalConnectionStates.Started, false);
if (_server.GetLocalConnectionState() == LocalConnectionState.Started)
SetLocalConnectionState(LocalConnectionState.Started, false);
}
}

Expand All @@ -47,20 +47,20 @@ internal bool StartConnection(ServerSocket serverSocket)
{
_server = serverSocket;
_server.SetClientHostSocket(this);
if (_server.GetLocalConnectionState() != LocalConnectionStates.Started)
if (_server.GetLocalConnectionState() != LocalConnectionState.Started)
return false;

SetLocalConnectionState(LocalConnectionStates.Starting, false);
SetLocalConnectionState(LocalConnectionState.Starting, false);
return true;
}

/// <summary>
/// Sets a new connection state.
/// </summary>
protected override void SetLocalConnectionState(LocalConnectionStates connectionState, bool server)
protected override void SetLocalConnectionState(LocalConnectionState connectionState, bool server)
{
base.SetLocalConnectionState(connectionState, server);
if (connectionState == LocalConnectionStates.Started)
if (connectionState == LocalConnectionState.Started)
_server.OnClientHostState(true);
else
_server.OnClientHostState(false);
Expand All @@ -71,13 +71,13 @@ protected override void SetLocalConnectionState(LocalConnectionStates connection
/// </summary>
internal bool StopConnection()
{
if (base.GetLocalConnectionState() == LocalConnectionStates.Stopped || base.GetLocalConnectionState() == LocalConnectionStates.Stopping)
if (base.GetLocalConnectionState() == LocalConnectionState.Stopped || base.GetLocalConnectionState() == LocalConnectionState.Stopping)
return false;

base.ClearQueue(_incoming);
//Immediately set stopped since no real connection exists.
SetLocalConnectionState(LocalConnectionStates.Stopping, false);
SetLocalConnectionState(LocalConnectionStates.Stopped, false);
SetLocalConnectionState(LocalConnectionState.Stopping, false);
SetLocalConnectionState(LocalConnectionState.Stopped, false);
_server.SetClientHostSocket(null);

return true;
Expand All @@ -88,7 +88,7 @@ internal bool StopConnection()
/// </summary>
internal void IterateIncoming()
{
if (base.GetLocalConnectionState() != LocalConnectionStates.Started)
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;

while (_incoming.Count > 0)
Expand All @@ -113,9 +113,9 @@ internal void ReceivedFromLocalServer(LocalPacket packet)
/// </summary>
internal void SendToServer(byte channelId, ArraySegment<byte> segment)
{
if (base.GetLocalConnectionState() != LocalConnectionStates.Started)
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;
if (_server.GetLocalConnectionState() != LocalConnectionStates.Started)
if (_server.GetLocalConnectionState() != LocalConnectionState.Started)
return;

LocalPacket packet = new LocalPacket(segment, channelId);
Expand Down
26 changes: 13 additions & 13 deletions FishNet/Plugins/FishyFacepunch/Core/ClientSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal async void StartConnection(string address, ushort port)
SteamNetworkingSockets.OnConnectionStatusChanged += OnConnectionStatusChanged;
ConnectionTimeout = TimeSpan.FromSeconds(Math.Max(1, base.Transport.GetTimeout(false)));

SetLocalConnectionState(LocalConnectionStates.Starting, false);
SetLocalConnectionState(LocalConnectionState.Starting, false);

try
{
Expand Down Expand Up @@ -96,28 +96,28 @@ internal async void StartConnection(string address, ushort port)
Debug.LogError($"Connection to {address} timed out.");
StopConnection();
}
SetLocalConnectionState(LocalConnectionStates.Stopped, false);
SetLocalConnectionState(LocalConnectionState.Stopped, false);
}
}
else
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("SteamWorks not initialized");
SetLocalConnectionState(LocalConnectionStates.Stopped, false);
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?");
SetLocalConnectionState(LocalConnectionStates.Stopped, false);
SetLocalConnectionState(LocalConnectionState.Stopped, false);
_Error = true;
}
catch (Exception ex)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError(ex.Message);
SetLocalConnectionState(LocalConnectionStates.Stopped, false);
SetLocalConnectionState(LocalConnectionState.Stopped, false);
_Error = true;
}
finally
Expand All @@ -126,7 +126,7 @@ internal async void StartConnection(string address, ushort port)
{
if (base.Transport.NetworkManager.CanLog(LoggingType.Error))
Debug.LogError("Connection failed.");
SetLocalConnectionState(LocalConnectionStates.Stopped, false);
SetLocalConnectionState(LocalConnectionState.Stopped, false);
}
}
}
Expand All @@ -138,7 +138,7 @@ private void OnConnectionStatusChanged(Connection conn, ConnectionInfo info)
{
if (info.State == ConnectionState.Connected)
{
SetLocalConnectionState(LocalConnectionStates.Started, false);
SetLocalConnectionState(LocalConnectionState.Started, false);
connectedComplete.SetResult(connectedComplete.Task);
}
else if (info.State == ConnectionState.ClosedByPeer || info.State == ConnectionState.ProblemDetectedLocally)
Expand All @@ -159,10 +159,10 @@ private void OnConnectionStatusChanged(Connection conn, ConnectionInfo info)
/// </summary>
internal bool StopConnection()
{
if (base.GetLocalConnectionState() == LocalConnectionStates.Stopped || base.GetLocalConnectionState() == LocalConnectionStates.Stopping)
if (base.GetLocalConnectionState() == LocalConnectionState.Stopped || base.GetLocalConnectionState() == LocalConnectionState.Stopping)
return false;

SetLocalConnectionState(LocalConnectionStates.Stopping, false);
SetLocalConnectionState(LocalConnectionState.Stopping, false);

cancelToken?.Cancel();

Expand All @@ -177,7 +177,7 @@ internal bool StopConnection()
HostConnectionManager = null;
}

SetLocalConnectionState(LocalConnectionStates.Stopped, false);
SetLocalConnectionState(LocalConnectionState.Stopped, false);

return true;
}
Expand All @@ -187,7 +187,7 @@ internal bool StopConnection()
/// </summary>
internal void IterateIncoming()
{
if (base.GetLocalConnectionState() != LocalConnectionStates.Started)
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;

HostConnectionManager.Receive(MAX_MESSAGES);
Expand All @@ -206,7 +206,7 @@ private void OnMessageReceived(IntPtr dataPtr, int size)
/// <param name="segment"></param>
internal void SendToServer(byte channelId, ArraySegment<byte> segment)
{
if (base.GetLocalConnectionState() != LocalConnectionStates.Started)
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;

Result res = base.Send(HostConnection, segment, channelId);
Expand All @@ -228,7 +228,7 @@ internal void SendToServer(byte channelId, ArraySegment<byte> segment)
/// </summary>
internal void IterateOutgoing()
{
if (base.GetLocalConnectionState() != LocalConnectionStates.Started)
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;

HostConnection.Flush();
Expand Down
6 changes: 3 additions & 3 deletions FishNet/Plugins/FishyFacepunch/Core/CommonSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ public abstract class CommonSocket
/// <summary>
/// Current ConnectionState.
/// </summary>
private LocalConnectionStates _connectionState = LocalConnectionStates.Stopped;
private LocalConnectionState _connectionState = LocalConnectionState.Stopped;
/// <summary>
/// Returns the current ConnectionState.
/// </summary>
/// <returns></returns>
internal LocalConnectionStates GetLocalConnectionState()
internal LocalConnectionState GetLocalConnectionState()
{
return _connectionState;
}
/// <summary>
/// Sets a new connection state.
/// </summary>
/// <param name="connectionState"></param>
protected virtual void SetLocalConnectionState(LocalConnectionStates connectionState, bool asServer)
protected virtual void SetLocalConnectionState(LocalConnectionState connectionState, bool asServer)
{
//If state hasn't changed.
if (connectionState == _connectionState)
Expand Down
32 changes: 16 additions & 16 deletions FishNet/Plugins/FishyFacepunch/Core/ServerSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class ServerSocket : CommonSocket
/// Gets the current ConnectionState of a remote client on the server.
/// </summary>
/// <param name="connectionId">ConnectionId to get ConnectionState for.</param>
internal RemoteConnectionStates GetConnectionState(int connectionId)
internal RemoteConnectionState GetConnectionState(int connectionId)
{
//Remote clients can only have Started or Stopped states since we cannot know in between.
if (_steamConnections.Second.ContainsKey(connectionId))
return RemoteConnectionStates.Started;
return RemoteConnectionState.Started;
else
return RemoteConnectionStates.Stopped;
return RemoteConnectionState.Stopped;
}
#endregion

Expand Down Expand Up @@ -85,7 +85,7 @@ internal void ResetInvalidSocket()
* safe than sorry and check before trying to connect
* rather than being stuck in the incorrect state. */
if (_socket == default)
base.SetLocalConnectionState(LocalConnectionStates.Stopped, true);
base.SetLocalConnectionState(LocalConnectionState.Stopped, true);
}
/// <summary>
/// Starts the server.
Expand All @@ -98,7 +98,7 @@ internal bool StartConnection(string address, ushort port, int maximumClients)
_nextConnectionId = 0;
_cachedConnectionIds.Clear();

base.SetLocalConnectionState(LocalConnectionStates.Starting, true);
base.SetLocalConnectionState(LocalConnectionState.Starting, true);

if (_socket != null)
{
Expand All @@ -113,7 +113,7 @@ internal bool StartConnection(string address, ushort port, int maximumClients)
#endif
_socket.ForwardMessage = OnMessageReceived;

base.SetLocalConnectionState(LocalConnectionStates.Started, true);
base.SetLocalConnectionState(LocalConnectionState.Started, true);

return true;
}
Expand All @@ -123,10 +123,10 @@ internal bool StartConnection(string address, ushort port, int maximumClients)
/// </summary>
internal bool StopConnection()
{
if (base.GetLocalConnectionState() == LocalConnectionStates.Stopped)
if (base.GetLocalConnectionState() == LocalConnectionState.Stopped)
return false;

base.SetLocalConnectionState(LocalConnectionStates.Stopping, true);
base.SetLocalConnectionState(LocalConnectionState.Stopping, true);

if (_socket != null)
{
Expand All @@ -135,7 +135,7 @@ internal bool StopConnection()
_socket = default;
}

base.SetLocalConnectionState(LocalConnectionStates.Stopped, true);
base.SetLocalConnectionState(LocalConnectionState.Stopped, true);

return true;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ private bool StopConnection(int connectionId, Connection socket)
_steamIds.Remove(connectionId);
if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Client with ConnectionID {connectionId} disconnected.");
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionStates.Stopped, connectionId, Transport.Index));
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Stopped, connectionId, Transport.Index));
_cachedConnectionIds.Enqueue(connectionId);

return true;
Expand Down Expand Up @@ -229,7 +229,7 @@ private void OnRemoteConnectionState(Connection conn, ConnectionInfo info)

if (base.Transport.NetworkManager.CanLog(LoggingType.Common))
Debug.Log($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionStates.Started, connectionId, Transport.Index));
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Started, connectionId, Transport.Index));
}
else if (info.State == ConnectionState.ClosedByPeer || info.State == ConnectionState.ProblemDetectedLocally)
{
Expand All @@ -251,7 +251,7 @@ private void OnRemoteConnectionState(Connection conn, ConnectionInfo info)
/// </summary>
internal void IterateOutgoing()
{
if (base.GetLocalConnectionState() != LocalConnectionStates.Started)
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;

foreach (Connection conn in _steamConnections.FirstTypes)
Expand All @@ -267,7 +267,7 @@ internal void IterateOutgoing()
internal void IterateIncoming()
{
//Stopped or trying to stop.
if (base.GetLocalConnectionState() == LocalConnectionStates.Stopped || base.GetLocalConnectionState() == LocalConnectionStates.Stopping)
if (base.GetLocalConnectionState() == LocalConnectionState.Stopped || base.GetLocalConnectionState() == LocalConnectionState.Stopping)
return;

//Iterate local client packets first.
Expand Down Expand Up @@ -296,7 +296,7 @@ private void OnMessageReceived(Connection conn, IntPtr dataPtr, int size)
/// <param name="connectionId"></param>
internal void SendToClient(byte channelId, ArraySegment<byte> segment, int connectionId)
{
if (base.GetLocalConnectionState() != LocalConnectionStates.Started)
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
return;

//Check if sending local client first, send and exit if so.
Expand Down Expand Up @@ -393,13 +393,13 @@ internal void OnClientHostState(bool started)
if (!started)
{
base.ClearQueue(_clientHostIncoming);
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionStates.Stopped, FishyFacepunch.CLIENT_HOST_ID, Transport.Index));
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Stopped, FishyFacepunch.CLIENT_HOST_ID, Transport.Index));
_steamIds.Remove(steamId);
}
else
{
_steamIds[steamId] = FishyFacepunch.CLIENT_HOST_ID;
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionStates.Started, FishyFacepunch.CLIENT_HOST_ID, Transport.Index));
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Started, FishyFacepunch.CLIENT_HOST_ID, Transport.Index));
}
}
/// <summary>
Expand Down
Loading

0 comments on commit 822380d

Please sign in to comment.