using FishNet.Connection; using FishNet.Managing; using System; using UnityEngine; namespace FishNet.Transporting.Yak { [AddComponentMenu("FishNet/Transport/Yak")] public class Yak : Transport { #region Private. /// /// Client when acting as host. /// private Client.ClientSocket _client; /// /// Server for the transport. /// private Server.ServerSocket _server; #endregion #region Const. /// /// Maximum packet size for this transport. /// private const int MTU = 5000; #endregion public override void Initialize(NetworkManager networkManager, int transportIndex) { } private void OnDestroy() { } #region ConnectionStates. /// /// Gets the IP address of a remote connection Id. /// /// /// public override string GetConnectionAddress(int connectionId) { return String.Empty; } #pragma warning disable CS0067 /// /// Called when a connection state changes for the local client. /// public override event Action OnClientConnectionState; /// /// Called when a connection state changes for the local server. /// public override event Action OnServerConnectionState; /// /// Called when a connection state changes for a remote client. /// public override event Action OnRemoteConnectionState; #pragma warning restore CS0067 /// /// Gets the current local ConnectionState. /// /// True if getting ConnectionState for the server. public override LocalConnectionState GetConnectionState(bool server) { return LocalConnectionState.Stopped; } /// /// Gets the current ConnectionState of a remote client on the server. /// /// ConnectionId to get ConnectionState for. public override RemoteConnectionState GetConnectionState(int connectionId) { return (_server == null) ? RemoteConnectionState.Stopped : _server.GetConnectionState(connectionId); } /// /// Handles a ConnectionStateArgs for the local client. /// /// public override void HandleClientConnectionState(ClientConnectionStateArgs connectionStateArgs) { } /// /// Handles a ConnectionStateArgs for the local server. /// /// public override void HandleServerConnectionState(ServerConnectionStateArgs connectionStateArgs) { } /// /// Handles a ConnectionStateArgs for a remote client. /// /// public override void HandleRemoteConnectionState(RemoteConnectionStateArgs connectionStateArgs) { } #endregion #region Iterating. /// /// Processes data received by the socket. /// /// True to process data received on the server. public override void IterateIncoming(bool server) { } /// /// Processes data to be sent by the socket. /// /// True to process data received on the server. public override void IterateOutgoing(bool server) { } #endregion #region ReceivedData. /// /// Called when client receives data. /// public override event Action OnClientReceivedData; /// /// Handles a ClientReceivedDataArgs. /// /// public override void HandleClientReceivedDataArgs(ClientReceivedDataArgs receivedDataArgs) { OnClientReceivedData?.Invoke(receivedDataArgs); } /// /// Called when server receives data. /// public override event Action OnServerReceivedData; /// /// Handles a ClientReceivedDataArgs. /// /// public override void HandleServerReceivedDataArgs(ServerReceivedDataArgs receivedDataArgs) { OnServerReceivedData?.Invoke(receivedDataArgs); } #endregion #region Sending. /// /// Sends to the server or all clients. /// /// Channel to use. /// /// Data to send. public override void SendToServer(byte channelId, ArraySegment segment) { } /// /// Sends data to a client. /// /// /// /// public override void SendToClient(byte channelId, ArraySegment segment, int connectionId) { } #endregion #region Configuration. /// /// Returns if the transport is a local transport. /// While true several security checks are disabled. /// public override bool IsLocalTransport(int connectionId) => true; /// /// 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. /// /// public override int GetMaximumClients() { return NetworkConnection.MAXIMUM_CLIENTID_WITHOUT_SIMULATED_VALUE; } /// /// 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. /// /// public override void SetMaximumClients(int value) { } /// /// Sets which address the client will connect to. /// /// public override void SetClientAddress(string address) { } /// /// Sets which address the server will bind to. /// /// public override void SetServerBindAddress(string address, IPAddressType addressType) { } /// /// Sets which port to use. /// /// public override void SetPort(ushort port) { } #endregion #region Start and stop. /// /// Starts the local server or client using configured settings. /// /// True to start server. public override bool StartConnection(bool server) { if (server) return StartServer(); else return StartClient(); } /// /// Stops the local server or client. /// /// True to stop server. public override bool StopConnection(bool server) { if (server) return StopServer(); else return StopClient(); } /// /// Stops a remote client from the server, disconnecting the client. /// /// ConnectionId of the client to disconnect. /// True to abrutly stp the client socket without waiting socket thread. public override bool StopConnection(int connectionId, bool immediately) { return StopClient(connectionId, immediately); } /// /// Stops both client and server. /// public override void Shutdown() { } #region Privates. /// /// Starts server. /// /// True if there were no blocks. A true response does not promise a socket will or has connected. private bool StartServer() { return (_server == null) ? false : _server.StartConnection(); } /// /// Stops server. /// private bool StopServer() { return (_server == null) ? false : _server.StopConnection(); } /// /// Starts the client. /// /// /// True if there were no blocks. A true response does not promise a socket will or has connected. private bool StartClient() { return true; } /// /// Stops the client. /// private bool StopClient() { return false; } /// /// Stops a remote client on the server. /// /// /// True to abrutly stp the client socket without waiting socket thread. private bool StopClient(int connectionId, bool immediately) { return (_server == null) ? false : _server.StopConnection(connectionId); } #endregion #endregion #region Channels. /// /// 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. /// /// /// public override int GetMTU(byte channel) { return MTU; } #endregion } }