Skip to content

Commit

Permalink
1.2.5
Browse files Browse the repository at this point in the history
- Added Ssl support.
  • Loading branch information
FirstGearGames committed Apr 29, 2022
1 parent fbcdfc8 commit fef8529
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 35 deletions.
81 changes: 49 additions & 32 deletions FishNet/Plugins/Bayou/Bayou.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FishNet.Managing;
using FishNet.Managing.Logging;
using FishNet.Managing.Transporting;
using JamesFrowen.SimpleWeb;
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
Expand All @@ -12,6 +13,22 @@ public class Bayou : Transport
{

#region Serialized.
[Header("Security")]
/// <summary>
/// True to connect using WSS.
/// </summary>
[Tooltip("True to connect using WSS.")]
[SerializeField]
private bool _useWss = false;
#if UNITY_SERVER || UNITY_EDITOR
/// <summary>
/// Configuration to use for SSL.
/// </summary>
[Tooltip("Configuration to use for SSL.")]
[SerializeField]
private SslConfiguration _sslConfiguration;
#endif

[Header("Channels")]
/// <summary>
/// Maximum transmission unit for this transport.
Expand All @@ -38,20 +55,14 @@ public class Bayou : Transport

[Header("Client")]
/// <summary>
/// True to connect using WSS.
/// </summary>
[Tooltip("True to connect using WSS.")]
[SerializeField]
private bool _useWss = false;
/// <summary>
/// Address to connect.
/// </summary>
[Tooltip("Address to connect.")]
[SerializeField]
private string _clientAddress = "localhost";
#endregion
#endregion

#region Private.
#region Private.
/// <summary>
/// Server socket and handler.
/// </summary>
Expand All @@ -60,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 @@ -71,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 Down Expand Up @@ -145,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 @@ -171,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 @@ -198,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 @@ -224,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 @@ -313,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 @@ -360,13 +371,19 @@ public override void Shutdown()
StopConnection(true);
}

#region Privates.
#region Privates.
/// <summary>
/// Starts server.
/// </summary>
private bool StartServer()
{
_server.Initialize(this, _mtu);
SslConfiguration config;
#if UNITY_SERVER
config = _sslConfiguration;
#else
config = new SslConfiguration();
#endif
_server.Initialize(this, _mtu, config);
return _server.StartConnection(_port, _maximumClients);
}

Expand Down Expand Up @@ -405,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 @@ -432,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 @@ -444,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 @@
1.2.5
- Added SSL support.

1.2.4
- Fixed maximum clients allowing 1 additional client to connect.
- UseWSS is now false by default.
Expand Down
15 changes: 13 additions & 2 deletions FishNet/Plugins/Bayou/Core/ServerSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ internal RemoteConnectionStates GetConnectionState(int connectionId)
/// Server socket manager.
/// </summary>
private SimpleWebServer _server;
/// <summary>
/// SslConfiguration to use.
/// </summary>
private SslConfiguration _sslConfiguration;
#endregion

~ServerSocket()
Expand All @@ -73,8 +77,9 @@ internal RemoteConnectionStates GetConnectionState(int connectionId)
/// Initializes this for use.
/// </summary>
/// <param name="t"></param>
internal void Initialize(Transport t, int unreliableMTU)
internal void Initialize(Transport t, int unreliableMTU, SslConfiguration config)
{
_sslConfiguration = config;
base.Transport = t;
_mtu = unreliableMTU;
}
Expand All @@ -86,7 +91,13 @@ internal void Initialize(Transport t, int unreliableMTU)
private void Socket()
{
TcpConfig tcpConfig = new TcpConfig(false, 5000, 20000);
_server = new SimpleWebServer(5000, tcpConfig, _mtu, 5000, new SslConfig());
SslConfig config;
if (!_sslConfiguration.Enabled)
config = new SslConfig();
else
config = new SslConfig(_sslConfiguration.Enabled, _sslConfiguration.CertificatePath, _sslConfiguration.CertificatePassword,
_sslConfiguration.SslProtocol);
_server = new SimpleWebServer(5000, tcpConfig, _mtu, 5000, config);

_server.onConnect += _server_onConnect;
_server.onDisconnect += _server_onDisconnect;
Expand Down
2 changes: 1 addition & 1 deletion FishNet/Plugins/Bayou/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.4
1.2.5

0 comments on commit fef8529

Please sign in to comment.