上传YomovSDK
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
1.0.0
|
||||
- Initial release.
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65389c57cd9accf47967cc3e6cb7ac1b
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b79a48228ccfcd4cbf0a0514295abeb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,152 @@
|
||||
//PROSTART
|
||||
using FishNet.Transporting.Yak.Server;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FishNet.Transporting.Yak.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a fake client connection to interact with the ServerSocket.
|
||||
/// </summary>
|
||||
public class ClientSocket : CommonSocket
|
||||
{
|
||||
#region Private.
|
||||
/// <summary>
|
||||
/// Socket for the server.
|
||||
/// </summary>
|
||||
private ServerSocket _server;
|
||||
/// <summary>
|
||||
/// Incomimg data.
|
||||
/// </summary>
|
||||
private Queue<LocalPacket> _incoming = new Queue<LocalPacket>();
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Initializes this for use.
|
||||
/// </summary>
|
||||
internal override void Initialize(Transport t, CommonSocket socket)
|
||||
{
|
||||
base.Initialize(t, socket);
|
||||
_server = (ServerSocket)socket;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the client connection.
|
||||
/// </summary>
|
||||
internal bool StartConnection()
|
||||
{
|
||||
//Already starting/started, or stopping.
|
||||
if (base.GetLocalConnectionState() != LocalConnectionState.Stopped)
|
||||
return false;
|
||||
|
||||
SetLocalConnectionState(LocalConnectionState.Starting, false);
|
||||
/* Certain conditions need the client state to change as well.
|
||||
* Such as, if the server state is stopping then the client should
|
||||
* also be stopping, rather than starting. Or if the server state
|
||||
* is already started then client should immediately be set started
|
||||
* rather than waiting for server started callback. */
|
||||
LocalConnectionState serverState = _server.GetLocalConnectionState();
|
||||
if (serverState == LocalConnectionState.Stopping || serverState == LocalConnectionState.Started)
|
||||
OnLocalServerConnectionState(_server.GetLocalConnectionState());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a new connection state.
|
||||
/// </summary>
|
||||
protected override void SetLocalConnectionState(LocalConnectionState connectionState, bool server)
|
||||
{
|
||||
base.SetLocalConnectionState(connectionState, server);
|
||||
if (connectionState == LocalConnectionState.Started || connectionState == LocalConnectionState.Stopped)
|
||||
_server.OnLocalClientConnectionState(connectionState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the local socket.
|
||||
/// </summary>
|
||||
internal bool StopConnection()
|
||||
{
|
||||
if (base.GetLocalConnectionState() == LocalConnectionState.Stopped || base.GetLocalConnectionState() == LocalConnectionState.Stopping)
|
||||
return false;
|
||||
|
||||
base.ClearQueue(ref _incoming);
|
||||
//Immediately set stopped since no real connection exists.
|
||||
SetLocalConnectionState(LocalConnectionState.Stopping, false);
|
||||
SetLocalConnectionState(LocalConnectionState.Stopped, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Iterations data received.
|
||||
/// </summary>
|
||||
internal void IterateIncoming()
|
||||
{
|
||||
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
|
||||
return;
|
||||
|
||||
while (_incoming.Count > 0)
|
||||
{
|
||||
LocalPacket packet = _incoming.Dequeue();
|
||||
ArraySegment<byte> segment = new ArraySegment<byte>(packet.Data, 0, packet.Length);
|
||||
ClientReceivedDataArgs dataArgs = new ClientReceivedDataArgs(segment, (Channel)packet.Channel, base.Transport.Index);
|
||||
base.Transport.HandleClientReceivedDataArgs(dataArgs);
|
||||
packet.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the server sends the local client data.
|
||||
/// </summary>
|
||||
internal void ReceivedFromLocalServer(LocalPacket packet)
|
||||
{
|
||||
_incoming.Enqueue(packet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queues data to be sent to server.
|
||||
/// </summary>
|
||||
internal void SendToServer(byte channelId, ArraySegment<byte> segment)
|
||||
{
|
||||
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
|
||||
return;
|
||||
if (_server.GetLocalConnectionState() != LocalConnectionState.Started)
|
||||
return;
|
||||
|
||||
LocalPacket packet = new LocalPacket(segment, channelId);
|
||||
_server.ReceivedFromLocalClient(packet);
|
||||
}
|
||||
|
||||
#region Local server.
|
||||
/// <summary>
|
||||
/// Called when the local server starts or stops.
|
||||
/// </summary>
|
||||
internal void OnLocalServerConnectionState(LocalConnectionState state)
|
||||
{
|
||||
//Server started.
|
||||
if (state == LocalConnectionState.Started &&
|
||||
base.GetLocalConnectionState() == LocalConnectionState.Starting)
|
||||
{
|
||||
SetLocalConnectionState(LocalConnectionState.Started, false);
|
||||
}
|
||||
//Server not started.
|
||||
else
|
||||
{
|
||||
//If stopped or stopping then disconnect client if also not stopped or stopping.
|
||||
if ((state == LocalConnectionState.Stopping || state == LocalConnectionState.Stopped) &&
|
||||
(base.GetLocalConnectionState() == LocalConnectionState.Started ||
|
||||
base.GetLocalConnectionState() == LocalConnectionState.Starting)
|
||||
)
|
||||
{
|
||||
SetLocalConnectionState(LocalConnectionState.Stopping, false);
|
||||
SetLocalConnectionState(LocalConnectionState.Stopped, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//PROEND
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26269fe7187f5da4e957080519ea0f13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
//PROSTART
|
||||
using FishNet.Transporting;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FishNet.Transporting.Yak
|
||||
{
|
||||
|
||||
public abstract class CommonSocket
|
||||
{
|
||||
|
||||
#region Public.
|
||||
/// <summary>
|
||||
/// Current ConnectionState.
|
||||
/// </summary>
|
||||
private LocalConnectionState _connectionState = LocalConnectionState.Stopped;
|
||||
/// <summary>
|
||||
/// Returns the current ConnectionState.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal LocalConnectionState GetLocalConnectionState()
|
||||
{
|
||||
return _connectionState;
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets a new connection state.
|
||||
/// </summary>
|
||||
/// <param name="connectionState"></param>
|
||||
protected virtual void SetLocalConnectionState(LocalConnectionState connectionState, bool server)
|
||||
{
|
||||
//If state hasn't changed.
|
||||
if (connectionState == _connectionState)
|
||||
return;
|
||||
|
||||
_connectionState = connectionState;
|
||||
|
||||
if (server)
|
||||
Transport.HandleServerConnectionState(new ServerConnectionStateArgs(connectionState, Transport.Index));
|
||||
else
|
||||
Transport.HandleClientConnectionState(new ClientConnectionStateArgs(connectionState, Transport.Index));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Protected.
|
||||
/// <summary>
|
||||
/// Transport controlling this socket.
|
||||
/// </summary>
|
||||
protected Transport Transport = null;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Initializes this for use.
|
||||
/// </summary>
|
||||
internal virtual void Initialize(Transport t, CommonSocket socket)
|
||||
{
|
||||
Transport = t;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a queue.
|
||||
/// </summary>
|
||||
internal void ClearQueue(ref Queue<LocalPacket> queue)
|
||||
{
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
LocalPacket lp = queue.Dequeue();
|
||||
lp.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//PROEND
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63afa30fa0251df44b9496aded55d795
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
//PROSTART
|
||||
using FishNet.Utility.Performance;
|
||||
using System;
|
||||
|
||||
namespace FishNet.Transporting.Yak
|
||||
{
|
||||
internal struct LocalPacket
|
||||
{
|
||||
public byte[] Data;
|
||||
public int Length;
|
||||
public byte Channel;
|
||||
public LocalPacket(ArraySegment<byte> data, byte channel)
|
||||
{
|
||||
Data = ByteArrayPool.Retrieve(data.Count);
|
||||
Length = data.Count;
|
||||
Buffer.BlockCopy(data.Array, data.Offset, Data, 0, Length);
|
||||
Channel = channel;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ByteArrayPool.Store(Data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//PROEND
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f52ce359669f91c4d981dc605a8875b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,167 @@
|
||||
//PROSTART
|
||||
using FishNet.Transporting;
|
||||
using FishNet.Transporting.Yak.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FishNet.Transporting.Yak.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a fake socket acting as server.
|
||||
/// </summary>
|
||||
public class ServerSocket : CommonSocket
|
||||
{
|
||||
#region Public.
|
||||
/// <summary>
|
||||
/// Gets the current ConnectionState of a remote client on the server.
|
||||
/// </summary>
|
||||
/// <param name="connectionId">ConnectionId to get ConnectionState for.</param>
|
||||
internal RemoteConnectionState GetConnectionState(int connectionId)
|
||||
{
|
||||
if (connectionId != Yak.CLIENT_HOST_ID)
|
||||
return RemoteConnectionState.Stopped;
|
||||
|
||||
LocalConnectionState state = _client.GetLocalConnectionState();
|
||||
return (state == LocalConnectionState.Started) ? RemoteConnectionState.Started :
|
||||
RemoteConnectionState.Stopped;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private.
|
||||
/// <summary>
|
||||
/// Packets received from local client.
|
||||
/// </summary>
|
||||
private Queue<LocalPacket> _incoming = new Queue<LocalPacket>();
|
||||
/// <summary>
|
||||
/// Socket for client.
|
||||
/// </summary>
|
||||
private ClientSocket _client;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Initializes this for use.
|
||||
/// </summary>
|
||||
internal override void Initialize(Transport t, CommonSocket socket)
|
||||
{
|
||||
base.Initialize(t, socket);
|
||||
_client = (ClientSocket)socket;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the server.
|
||||
/// </summary>
|
||||
internal bool StartConnection()
|
||||
{
|
||||
SetLocalConnectionState(LocalConnectionState.Starting, true);
|
||||
SetLocalConnectionState(LocalConnectionState.Started, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets a new connection state.
|
||||
/// </summary>
|
||||
protected override void SetLocalConnectionState(LocalConnectionState connectionState, bool server)
|
||||
{
|
||||
base.SetLocalConnectionState(connectionState, server);
|
||||
_client.OnLocalServerConnectionState(connectionState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the local socket.
|
||||
/// </summary>
|
||||
internal bool StopConnection()
|
||||
{
|
||||
if (base.GetLocalConnectionState() == LocalConnectionState.Stopped)
|
||||
return false;
|
||||
|
||||
base.ClearQueue(ref _incoming);
|
||||
SetLocalConnectionState(LocalConnectionState.Stopping, true);
|
||||
SetLocalConnectionState(LocalConnectionState.Stopped, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops a remote client from the server, disconnecting the client.
|
||||
/// </summary>
|
||||
/// <param name="connectionId">ConnectionId of the client to disconnect.</param>
|
||||
internal bool StopConnection(int connectionId)
|
||||
{
|
||||
if (connectionId != Yak.CLIENT_HOST_ID)
|
||||
return false;
|
||||
|
||||
_client.StopConnection();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Iterates the Incoming queue.
|
||||
/// </summary>
|
||||
/// <param name="transport"></param>
|
||||
internal void IterateIncoming()
|
||||
{
|
||||
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
|
||||
return;
|
||||
|
||||
//Iterate local client packets first.
|
||||
while (_incoming.Count > 0)
|
||||
{
|
||||
LocalPacket packet = _incoming.Dequeue();
|
||||
ArraySegment<byte> segment = new ArraySegment<byte>(packet.Data, 0, packet.Length);
|
||||
ServerReceivedDataArgs args = new ServerReceivedDataArgs(segment, (Channel)packet.Channel, Yak.CLIENT_HOST_ID, base.Transport.Index);
|
||||
base.Transport.HandleServerReceivedDataArgs(args);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends data to a client.
|
||||
/// </summary>
|
||||
/// <param name="channelId"></param>
|
||||
/// <param name="segment"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
internal void SendToClient(byte channelId, ArraySegment<byte> segment, int connectionId)
|
||||
{
|
||||
if (base.GetLocalConnectionState() != LocalConnectionState.Started)
|
||||
return;
|
||||
if (connectionId != Yak.CLIENT_HOST_ID)
|
||||
return;
|
||||
|
||||
LocalPacket packet = new LocalPacket(segment, channelId);
|
||||
_client.ReceivedFromLocalServer(packet);
|
||||
}
|
||||
|
||||
#region Local client.
|
||||
/// <summary>
|
||||
/// Called when the local client starts or stops.
|
||||
/// </summary>
|
||||
internal void OnLocalClientConnectionState(LocalConnectionState state)
|
||||
{
|
||||
//If not started flush incoming from local client.
|
||||
if (state != LocalConnectionState.Started)
|
||||
{
|
||||
base.ClearQueue(ref _incoming);
|
||||
//If stopped then send stopped event as well.
|
||||
if (state == LocalConnectionState.Stopped)
|
||||
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Stopped, Yak.CLIENT_HOST_ID, base.Transport.Index));
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionState.Started, Yak.CLIENT_HOST_ID, base.Transport.Index));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queues a received packet from the local client.
|
||||
/// </summary>
|
||||
internal void ReceivedFromLocalClient(LocalPacket packet)
|
||||
{
|
||||
if (_client.GetLocalConnectionState() != LocalConnectionState.Started)
|
||||
return;
|
||||
|
||||
_incoming.Enqueue(packet);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
//PROEND
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9181ba25449c96446b966d0bd62e5813
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1 @@
|
||||
1.0.0
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f0e4449aaa7cf0499df1847fdbd5377
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
349
Packages/com.firstgeargames.fishnet/Runtime/Plugins/Yak/Yak.cs
Normal file
349
Packages/com.firstgeargames.fishnet/Runtime/Plugins/Yak/Yak.cs
Normal file
@@ -0,0 +1,349 @@
|
||||
//PROSTART
|
||||
using FishNet.Managing;
|
||||
using FishNet.Managing.Logging;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FishNet.Transporting.Yak
|
||||
{
|
||||
[AddComponentMenu("FishNet/Transport/Yak")]
|
||||
public class Yak : Transport
|
||||
{
|
||||
#region Private.
|
||||
/// <summary>
|
||||
/// Client when acting as host.
|
||||
/// </summary>
|
||||
private Client.ClientSocket _client;
|
||||
/// <summary>
|
||||
/// Server for the transport.
|
||||
/// </summary>
|
||||
private Server.ServerSocket _server;
|
||||
#endregion
|
||||
|
||||
#region Const.
|
||||
/// <summary>
|
||||
/// Id to use for client when acting as host.
|
||||
/// </summary>
|
||||
internal const int CLIENT_HOST_ID = short.MaxValue;
|
||||
private const int MTU = 5000;
|
||||
#endregion
|
||||
|
||||
public override void Initialize(NetworkManager networkManager, int transportIndex)
|
||||
{
|
||||
base.Initialize(networkManager, transportIndex);
|
||||
|
||||
_client = new Client.ClientSocket();
|
||||
_server = new Server.ServerSocket();
|
||||
|
||||
_client.Initialize(this, _server);
|
||||
_server.Initialize(this, _client);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
#region ConnectionStates.
|
||||
/// <summary>
|
||||
/// Gets the IP address of a remote connection Id.
|
||||
/// </summary>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public override string GetConnectionAddress(int connectionId)
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
/// <summary>
|
||||
/// Called when a connection state changes for the local client.
|
||||
/// </summary>
|
||||
public override event Action<ClientConnectionStateArgs> OnClientConnectionState;
|
||||
/// <summary>
|
||||
/// Called when a connection state changes for the local server.
|
||||
/// </summary>
|
||||
public override event Action<ServerConnectionStateArgs> OnServerConnectionState;
|
||||
/// <summary>
|
||||
/// Called when a connection state changes for a remote client.
|
||||
/// </summary>
|
||||
public override event Action<RemoteConnectionStateArgs> OnRemoteConnectionState;
|
||||
/// <summary>
|
||||
/// Gets the current local ConnectionState.
|
||||
/// </summary>
|
||||
/// <param name="server">True if getting ConnectionState for the server.</param>
|
||||
public override LocalConnectionState GetConnectionState(bool server)
|
||||
{
|
||||
if (server)
|
||||
return _server.GetLocalConnectionState();
|
||||
else
|
||||
return _client.GetLocalConnectionState();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the current ConnectionState of a remote client on the server.
|
||||
/// </summary>
|
||||
/// <param name="connectionId">ConnectionId to get ConnectionState for.</param>
|
||||
public override RemoteConnectionState GetConnectionState(int connectionId)
|
||||
{
|
||||
return _server.GetConnectionState(connectionId);
|
||||
}
|
||||
/// <summary>
|
||||
/// Handles a ConnectionStateArgs for the local client.
|
||||
/// </summary>
|
||||
/// <param name="connectionStateArgs"></param>
|
||||
public override void HandleClientConnectionState(ClientConnectionStateArgs connectionStateArgs)
|
||||
{
|
||||
OnClientConnectionState?.Invoke(connectionStateArgs);
|
||||
}
|
||||
/// <summary>
|
||||
/// Handles a ConnectionStateArgs for the local server.
|
||||
/// </summary>
|
||||
/// <param name="connectionStateArgs"></param>
|
||||
public override void HandleServerConnectionState(ServerConnectionStateArgs connectionStateArgs)
|
||||
{
|
||||
OnServerConnectionState?.Invoke(connectionStateArgs);
|
||||
}
|
||||
/// <summary>
|
||||
/// Handles a ConnectionStateArgs for a remote client.
|
||||
/// </summary>
|
||||
/// <param name="connectionStateArgs"></param>
|
||||
public override void HandleRemoteConnectionState(RemoteConnectionStateArgs connectionStateArgs)
|
||||
{
|
||||
OnRemoteConnectionState?.Invoke(connectionStateArgs);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Iterating.
|
||||
/// <summary>
|
||||
/// Processes data received by the socket.
|
||||
/// </summary>
|
||||
/// <param name="server">True to process data received on the server.</param>
|
||||
public override void IterateIncoming(bool server)
|
||||
{
|
||||
if (server)
|
||||
_server.IterateIncoming();
|
||||
else
|
||||
_client.IterateIncoming();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes data to be sent by the socket.
|
||||
/// </summary>
|
||||
/// <param name="server">True to process data received on the server.</param>
|
||||
public override void IterateOutgoing(bool server) { }
|
||||
#endregion
|
||||
|
||||
#region ReceivedData.
|
||||
/// <summary>
|
||||
/// Called when client receives data.
|
||||
/// </summary>
|
||||
public override event Action<ClientReceivedDataArgs> OnClientReceivedData;
|
||||
/// <summary>
|
||||
/// Handles a ClientReceivedDataArgs.
|
||||
/// </summary>
|
||||
/// <param name="receivedDataArgs"></param>
|
||||
public override void HandleClientReceivedDataArgs(ClientReceivedDataArgs receivedDataArgs)
|
||||
{
|
||||
OnClientReceivedData?.Invoke(receivedDataArgs);
|
||||
}
|
||||
/// <summary>
|
||||
/// Called when server receives data.
|
||||
/// </summary>
|
||||
public override event Action<ServerReceivedDataArgs> OnServerReceivedData;
|
||||
/// <summary>
|
||||
/// Handles a ClientReceivedDataArgs.
|
||||
/// </summary>
|
||||
/// <param name="receivedDataArgs"></param>
|
||||
public override void HandleServerReceivedDataArgs(ServerReceivedDataArgs receivedDataArgs)
|
||||
{
|
||||
OnServerReceivedData?.Invoke(receivedDataArgs);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Sending.
|
||||
/// <summary>
|
||||
/// Sends to the server or all clients.
|
||||
/// </summary>
|
||||
/// <param name="channelId">Channel to use.</param>
|
||||
/// /// <param name="segment">Data to send.</param>
|
||||
public override void SendToServer(byte channelId, ArraySegment<byte> segment)
|
||||
{
|
||||
_client.SendToServer(channelId, segment);
|
||||
}
|
||||
/// <summary>
|
||||
/// Sends data to a client.
|
||||
/// </summary>
|
||||
/// <param name="channelId"></param>
|
||||
/// <param name="segment"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
public override void SendToClient(byte channelId, ArraySegment<byte> segment, int connectionId)
|
||||
{
|
||||
_server.SendToClient(channelId, segment, connectionId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Configuration.
|
||||
/// <summary>
|
||||
/// Returns if the transport is a local transport.
|
||||
/// While true several security checks are disabled.
|
||||
/// </summary>
|
||||
public override bool IsLocalTransport(int connectionId) => true;
|
||||
/// <summary>
|
||||
/// Returns the maximum number of clients allowed to connect to the server. If the transport does not support this method the value -1 is returned.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetMaximumClients()
|
||||
{
|
||||
return short.MaxValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets maximum number of clients allowed to connect to the server. If applied at runtime and clients exceed this value existing clients will stay connected but new clients may not connect.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public override void SetMaximumClients(int value) { }
|
||||
/// <summary>
|
||||
/// Sets which address the client will connect to.
|
||||
/// </summary>
|
||||
/// <param name="address"></param>
|
||||
public override void SetClientAddress(string address) { }
|
||||
/// <summary>
|
||||
/// Sets which address the server will bind to.
|
||||
/// </summary>
|
||||
/// <param name="address"></param>
|
||||
public override void SetServerBindAddress(string address, IPAddressType addressType) { }
|
||||
/// <summary>
|
||||
/// Sets which port to use.
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
public override void SetPort(ushort port) { }
|
||||
#endregion
|
||||
|
||||
#region Start and stop.
|
||||
/// <summary>
|
||||
/// Starts the local server or client using configured settings.
|
||||
/// </summary>
|
||||
/// <param name="server">True to start server.</param>
|
||||
public override bool StartConnection(bool server)
|
||||
{
|
||||
if (server)
|
||||
return StartServer();
|
||||
else
|
||||
return StartClient();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the local server or client.
|
||||
/// </summary>
|
||||
/// <param name="server">True to stop server.</param>
|
||||
public override bool StopConnection(bool server)
|
||||
{
|
||||
if (server)
|
||||
return StopServer();
|
||||
else
|
||||
return StopClient();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops a remote client from the server, disconnecting the client.
|
||||
/// </summary>
|
||||
/// <param name="connectionId">ConnectionId of the client to disconnect.</param>
|
||||
/// <param name="immediately">True to abrutly stp the client socket without waiting socket thread.</param>
|
||||
public override bool StopConnection(int connectionId, bool immediately)
|
||||
{
|
||||
return StopClient(connectionId, immediately);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops both client and server.
|
||||
/// </summary>
|
||||
public override void Shutdown()
|
||||
{
|
||||
//Stops client then server connections.
|
||||
StopConnection(false);
|
||||
StopConnection(true);
|
||||
}
|
||||
|
||||
#region Privates.
|
||||
/// <summary>
|
||||
/// Starts server.
|
||||
/// </summary>
|
||||
/// <returns>True if there were no blocks. A true response does not promise a socket will or has connected.</returns>
|
||||
private bool StartServer()
|
||||
{
|
||||
if (_server.GetLocalConnectionState() != LocalConnectionState.Stopped)
|
||||
{
|
||||
if (NetworkManager.CanLog(LoggingType.Error))
|
||||
Debug.LogError("Server is already running.");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = _server.StartConnection();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops server.
|
||||
/// </summary>
|
||||
private bool StopServer()
|
||||
{
|
||||
if (_server != null)
|
||||
return _server.StopConnection();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the client.
|
||||
/// </summary>
|
||||
/// <param name="address"></param>
|
||||
/// <returns>True if there were no blocks. A true response does not promise a socket will or has connected.</returns>
|
||||
private bool StartClient()
|
||||
{
|
||||
if (_client.GetLocalConnectionState() != LocalConnectionState.Stopped)
|
||||
{
|
||||
if (NetworkManager.CanLog(LoggingType.Error))
|
||||
Debug.LogError("Client is already running.");
|
||||
return false;
|
||||
}
|
||||
|
||||
_client.StartConnection();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the client.
|
||||
/// </summary>
|
||||
private bool StopClient()
|
||||
{
|
||||
if (_client != null)
|
||||
return _client.StopConnection();
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops a remote client on the server.
|
||||
/// </summary>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="immediately">True to abrutly stp the client socket without waiting socket thread.</param>
|
||||
private bool StopClient(int connectionId, bool immediately)
|
||||
{
|
||||
return _server.StopConnection(connectionId);
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Channels.
|
||||
/// <summary>
|
||||
/// Gets the MTU for a channel. This should take header size into consideration.
|
||||
/// For example, if MTU is 1200 and a packet header for this channel is 10 in size, this method should return 1190.
|
||||
/// </summary>
|
||||
/// <param name="channel"></param>
|
||||
/// <returns></returns>
|
||||
public override int GetMTU(byte channel)
|
||||
{
|
||||
return MTU;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
//PROEND
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91f4cf5273666764789e6f8bada05e3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: bf9191e2e07d29749bca3a1ae44e4bc8, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user