Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
- Fish-Networking 2.0.0 support.
  • Loading branch information
FirstGearGames committed Jun 13, 2022
1 parent fef8529 commit e87609d
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 56 deletions.
60 changes: 30 additions & 30 deletions FishNet/Plugins/Bayou/Bayou.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public class Bayou : Transport
[Tooltip("Address to connect.")]
[SerializeField]
private string _clientAddress = "localhost";
#endregion
#endregion

#region Private.
#region Private.
/// <summary>
/// Server socket and handler.
/// </summary>
Expand All @@ -71,9 +71,9 @@ public class Bayou : Transport
/// Client socket and handler.
/// </summary>
private Client.ClientSocket _client = new Client.ClientSocket();
#endregion
#endregion

#region Const.
#region Const.
/// <summary>
/// Minimum UDP packet size allowed.
/// </summary>
Expand All @@ -82,16 +82,16 @@ public class Bayou : Transport
/// Maximum UDP packet size allowed.
/// </summary>
private const int MAXIMUM_MTU = ushort.MaxValue;
#endregion
#endregion

#region Initialization and unity.
#region Initialization and unity.
protected void OnDestroy()
{
Shutdown();
}
#endregion
#endregion

#region ConnectionStates.
#region ConnectionStates.
/// <summary>
/// Gets the address of a remote connection Id.
/// </summary>
Expand All @@ -117,7 +117,7 @@ public override string GetConnectionAddress(int connectionId)
/// Gets the current local ConnectionState.
/// </summary>
/// <param name="server">True if getting ConnectionState for the server.</param>
public override LocalConnectionStates GetConnectionState(bool server)
public override LocalConnectionState GetConnectionState(bool server)
{
if (server)
return _server.GetConnectionState();
Expand All @@ -128,7 +128,7 @@ public override LocalConnectionStates GetConnectionState(bool server)
/// Gets the current ConnectionState of a remote client on the server.
/// </summary>
/// <param name="connectionId">ConnectionId to get ConnectionState for.</param>
public override RemoteConnectionStates GetConnectionState(int connectionId)
public override RemoteConnectionState GetConnectionState(int connectionId)
{
return _server.GetConnectionState(connectionId);
}
Expand Down Expand Up @@ -156,9 +156,9 @@ public override void HandleRemoteConnectionState(RemoteConnectionStateArgs conne
{
OnRemoteConnectionState?.Invoke(connectionStateArgs);
}
#endregion
#endregion

#region Iterating.
#region Iterating.
/// <summary>
/// Processes data received by the socket.
/// </summary>
Expand All @@ -182,9 +182,9 @@ public override void IterateOutgoing(bool server)
else
_client.IterateOutgoing();
}
#endregion
#endregion

#region ReceivedData.
#region ReceivedData.
/// <summary>
/// Called when client receives data.
/// </summary>
Expand All @@ -209,9 +209,9 @@ public override void HandleServerReceivedDataArgs(ServerReceivedDataArgs receive
{
OnServerReceivedData?.Invoke(receivedDataArgs);
}
#endregion
#endregion

#region Sending.
#region Sending.
/// <summary>
/// Sends to the server or all clients.
/// </summary>
Expand All @@ -235,9 +235,9 @@ public override void SendToClient(byte channelId, ArraySegment<byte> segment, in
SanitizeChannel(ref channelId);
_server.SendToClient(channelId, segment, connectionId);
}
#endregion
#endregion

#region Configuration.
#region Configuration.
/// <summary>
/// Sets UseWSS value.
/// </summary>
Expand Down Expand Up @@ -269,7 +269,7 @@ public override int GetMaximumClients()
/// <param name="value"></param>
public override void SetMaximumClients(int value)
{
if (_server.GetConnectionState() != LocalConnectionStates.Stopped)
if (_server.GetConnectionState() != LocalConnectionState.Stopped)
{
if (base.NetworkManager.CanLog(LoggingType.Warning))
Debug.LogWarning($"Cannot set maximum clients when server is running.");
Expand Down Expand Up @@ -299,12 +299,12 @@ public override string GetClientAddress()
/// Sets which address the server will bind to.
/// </summary>
/// <param name="address"></param>
public override void SetServerBindAddress(string address) { }
public override void SetServerBindAddress(string address, IPAddressType addressType) { }
/// <summary>
/// Gets which address the server will bind to.
/// </summary>
/// <param name="address"></param>
public override string GetServerBindAddress()
public override string GetServerBindAddress(IPAddressType addressType)
{
return "localhost";
}
Expand All @@ -324,9 +324,9 @@ public override ushort GetPort()
{
return _port;
}
#endregion
#endregion

#region Start and stop.
#region Start and stop.
/// <summary>
/// Starts the local server or client using configured settings.
/// </summary>
Expand Down Expand Up @@ -371,7 +371,7 @@ public override void Shutdown()
StopConnection(true);
}

#region Privates.
#region Privates.
/// <summary>
/// Starts server.
/// </summary>
Expand Down Expand Up @@ -422,10 +422,10 @@ private bool StopClient(int connectionId, bool immediately)
{
return _server.StopConnection(connectionId, immediately);
}
#endregion
#endregion
#endregion
#endregion

#region Channels.
#region Channels.
/// <summary>
/// If channelId is invalid then channelId becomes forced to reliable.
/// </summary>
Expand All @@ -449,9 +449,9 @@ public override int GetMTU(byte channel)
{
return _mtu;
}
#endregion
#endregion

#region Editor.
#region Editor.
#if UNITY_EDITOR
private void OnValidate()
{
Expand All @@ -461,6 +461,6 @@ private void OnValidate()
_mtu = MAXIMUM_MTU;
}
#endif
#endregion
#endregion
}
}
3 changes: 3 additions & 0 deletions FishNet/Plugins/Bayou/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.0.0
- Fish-Networking 2.0.0 support.

1.2.5
- Added SSL support.

Expand Down
16 changes: 8 additions & 8 deletions FishNet/Plugins/Bayou/Core/ClientSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void Socket(bool useWss)
Host = _address,
Port = _port
};
base.SetConnectionState(LocalConnectionStates.Starting, false);
base.SetConnectionState(LocalConnectionState.Starting, false);
_client.Connect(builder.Uri);
}

Expand All @@ -97,7 +97,7 @@ private void _client_onDisconnect()

private void _client_onConnect()
{
base.SetConnectionState(LocalConnectionStates.Started, false);
base.SetConnectionState(LocalConnectionState.Started, false);
}


Expand All @@ -110,10 +110,10 @@ private void _client_onConnect()
/// <param name="pollTime"></param>
internal bool StartConnection(string address, ushort port, bool useWss)
{
if (base.GetConnectionState() != LocalConnectionStates.Stopped)
if (base.GetConnectionState() != LocalConnectionState.Stopped)
return false;

base.SetConnectionState(LocalConnectionStates.Starting, false);
base.SetConnectionState(LocalConnectionState.Starting, false);
//Assign properties.
_port = port;
_address = address;
Expand All @@ -130,12 +130,12 @@ internal bool StartConnection(string address, ushort port, bool useWss)
/// </summary>
internal bool StopConnection()
{
if (base.GetConnectionState() == LocalConnectionStates.Stopped || base.GetConnectionState() == LocalConnectionStates.Stopping)
if (base.GetConnectionState() == LocalConnectionState.Stopped || base.GetConnectionState() == LocalConnectionState.Stopping)
return false;

base.SetConnectionState(LocalConnectionStates.Stopping, false);
base.SetConnectionState(LocalConnectionState.Stopping, false);
_client.Disconnect();
base.SetConnectionState(LocalConnectionStates.Stopped, false);
base.SetConnectionState(LocalConnectionState.Stopped, false);
return true;
}

Expand Down Expand Up @@ -191,7 +191,7 @@ internal void IterateIncoming()
internal void SendToServer(byte channelId, ArraySegment<byte> segment)
{
//Not started, cannot send.
if (base.GetConnectionState() != LocalConnectionStates.Started)
if (base.GetConnectionState() != LocalConnectionState.Started)
return;

base.Send(ref _outgoing, channelId, segment, -1);
Expand Down
8 changes: 4 additions & 4 deletions FishNet/Plugins/Bayou/Core/CommonSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,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 GetConnectionState()
internal LocalConnectionState GetConnectionState()
{
return _connectionState;
}
/// <summary>
/// Sets a new connection state.
/// </summary>
/// <param name="connectionState"></param>
protected void SetConnectionState(LocalConnectionStates connectionState, bool asServer)
protected void SetConnectionState(LocalConnectionState connectionState, bool asServer)
{
//If state hasn't changed.
if (connectionState == _connectionState)
Expand All @@ -50,7 +50,7 @@ protected void SetConnectionState(LocalConnectionStates connectionState, bool as
/// </summary>
internal void Send(ref Queue<Packet> queue, byte channelId, ArraySegment<byte> segment, int connectionId)
{
if (GetConnectionState() != LocalConnectionStates.Started)
if (GetConnectionState() != LocalConnectionState.Started)
return;

//ConnectionId isn't used from client to server.
Expand Down
26 changes: 13 additions & 13 deletions FishNet/Plugins/Bayou/Core/ServerSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ 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)
{
RemoteConnectionStates state = _clients.Contains(connectionId) ? RemoteConnectionStates.Started : RemoteConnectionStates.Stopped;
RemoteConnectionState state = _clients.Contains(connectionId) ? RemoteConnectionState.Started : RemoteConnectionState.Stopped;
return state;
}
#endregion
Expand Down Expand Up @@ -104,9 +104,9 @@ private void Socket()
_server.onData += _server_onData;
_server.onError += _server_onError;

base.SetConnectionState(LocalConnectionStates.Starting, true);
base.SetConnectionState(LocalConnectionState.Starting, true);
_server.Start(_port);
base.SetConnectionState(LocalConnectionStates.Started, true);
base.SetConnectionState(LocalConnectionState.Started, true);
}

/// <summary>
Expand Down Expand Up @@ -172,10 +172,10 @@ internal string GetConnectionAddress(int connectionId)
/// </summary>
internal bool StartConnection(ushort port, int maximumClients)
{
if (base.GetConnectionState() != LocalConnectionStates.Stopped)
if (base.GetConnectionState() != LocalConnectionState.Stopped)
return false;

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

//Assign properties.
_port = port;
Expand All @@ -190,13 +190,13 @@ internal bool StartConnection(ushort port, int maximumClients)
/// </summary>
internal bool StopConnection()
{
if (_server == null || base.GetConnectionState() == LocalConnectionStates.Stopped || base.GetConnectionState() == LocalConnectionStates.Stopping)
if (_server == null || base.GetConnectionState() == LocalConnectionState.Stopped || base.GetConnectionState() == LocalConnectionState.Stopping)
return false;

ResetQueues();
base.SetConnectionState(LocalConnectionStates.Stopping, true);
base.SetConnectionState(LocalConnectionState.Stopping, true);
_server.Stop();
base.SetConnectionState(LocalConnectionStates.Stopped, true);
base.SetConnectionState(LocalConnectionState.Stopped, true);

return true;
}
Expand All @@ -207,7 +207,7 @@ internal bool StopConnection()
/// <param name="connectionId">ConnectionId of the client to disconnect.</param>
internal bool StopConnection(int connectionId, bool immediately)
{
if (_server == null || base.GetConnectionState() != LocalConnectionStates.Started)
if (_server == null || base.GetConnectionState() != LocalConnectionState.Started)
return false;

//Don't disconnect immediately, wait until next command iteration.
Expand All @@ -220,7 +220,7 @@ internal bool StopConnection(int connectionId, bool immediately)
{
_server.KickClient(connectionId);
_clients.Remove(connectionId);
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionStates.Stopped, connectionId, base.Transport.Index));
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Stopped, connectionId, base.Transport.Index));
}

return true;
Expand Down Expand Up @@ -275,7 +275,7 @@ private void DequeueDisconnects()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DequeueOutgoing()
{
if (base.GetConnectionState() != LocalConnectionStates.Started || _server == null)
if (base.GetConnectionState() != LocalConnectionState.Started || _server == null)
{
//Not started, clear outgoing.
base.ClearPacketQueue(ref _outgoing);
Expand Down Expand Up @@ -329,7 +329,7 @@ internal void IterateIncoming()
RemoteConnectionEvent connectionEvent = _remoteConnectionEvents.Dequeue();
if (connectionEvent.Connected)
_clients.Add(connectionEvent.ConnectionId);
RemoteConnectionStates state = (connectionEvent.Connected) ? RemoteConnectionStates.Started : RemoteConnectionStates.Stopped;
RemoteConnectionState state = (connectionEvent.Connected) ? RemoteConnectionState.Started : RemoteConnectionState.Stopped;
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(state, connectionEvent.ConnectionId, base.Transport.Index));
}

Expand Down
Loading

0 comments on commit e87609d

Please sign in to comment.