diff --git a/Exomia.Network/ClientActionHandler.cs b/Exomia.Network/ClientActionHandler.cs index b7074ac..da98bf4 100644 --- a/Exomia.Network/ClientActionHandler.cs +++ b/Exomia.Network/ClientActionHandler.cs @@ -13,12 +13,10 @@ namespace Exomia.Network /// /// Called than a client action occurs. /// - /// Socket|EndPoint. /// Type of the server client. /// The server. /// The client. - public delegate void ClientActionHandler(IServer server, - TServerClient client) - where T : class - where TServerClient : ServerClientBase; + public delegate void ClientActionHandler(IServer server, + TServerClient client) + where TServerClient : IServerClient; } \ No newline at end of file diff --git a/Exomia.Network/ClientDataReceivedHandler.cs b/Exomia.Network/ClientDataReceivedHandler.cs index a76ba7e..a45b693 100644 --- a/Exomia.Network/ClientDataReceivedHandler.cs +++ b/Exomia.Network/ClientDataReceivedHandler.cs @@ -13,25 +13,22 @@ namespace Exomia.Network /// /// Handler, called when the server received client data. /// - /// Generic type parameter. /// Type of the server client. /// The server. /// The client. /// Identifier for the command. /// The data. /// Identifier for the response. - public delegate void ClientCommandDataReceivedHandler(IServer server, - TServerClient client, - uint commandID, - object data, - uint responseID) - where T : class - where TServerClient : ServerClientBase; + public delegate void ClientCommandDataReceivedHandler(IServer server, + TServerClient client, + uint commandID, + object data, + uint responseID) + where TServerClient : IServerClient; /// /// Handler, called when the server received client data. /// - /// Socket|EndPoint. /// Type of the server client. /// The server. /// The client. @@ -40,10 +37,9 @@ public delegate void ClientCommandDataReceivedHandler(IServer< /// /// true if you want to handle more data; false otherwise. /// - public delegate bool ClientDataReceivedHandler(IServer server, - TServerClient client, - object data, - uint responseID) - where T : class - where TServerClient : ServerClientBase; + public delegate bool ClientDataReceivedHandler(IServer server, + TServerClient client, + object data, + uint responseID) + where TServerClient : IServerClient; } \ No newline at end of file diff --git a/Exomia.Network/ClientDisconnectHandler.cs b/Exomia.Network/ClientDisconnectHandler.cs index de1ffa7..14b4cc7 100644 --- a/Exomia.Network/ClientDisconnectHandler.cs +++ b/Exomia.Network/ClientDisconnectHandler.cs @@ -13,14 +13,12 @@ namespace Exomia.Network /// /// Called than a client disconnects from the server. /// - /// Socket|EndPoint. /// Type of the server client. /// The server. /// The client. /// The reason. - public delegate void ClientDisconnectHandler(IServer server, - TServerClient client, - DisconnectReason reason) - where T : class - where TServerClient : ServerClientBase; + public delegate void ClientDisconnectHandler(IServer server, + TServerClient client, + DisconnectReason reason) + where TServerClient : IServerClient; } \ No newline at end of file diff --git a/Exomia.Network/Exomia.Network.csproj b/Exomia.Network/Exomia.Network.csproj index a273678..c15868f 100644 --- a/Exomia.Network/Exomia.Network.csproj +++ b/Exomia.Network/Exomia.Network.csproj @@ -4,7 +4,7 @@ exomia tcp / udp client and server Copyright © $([System.DateTime]::Now.Year) exomia - 1.4.2.0 + 1.4.3.0 https://raw.githubusercontent.com/exomia/network/master/LICENSE https://github.com/exomia/network true diff --git a/Exomia.Network/IServer.cs b/Exomia.Network/IServer.cs index ca246c6..ab85a46 100644 --- a/Exomia.Network/IServer.cs +++ b/Exomia.Network/IServer.cs @@ -16,7 +16,6 @@ namespace Exomia.Network /// /// Interface for server. /// - /// Generic type parameter. /// Type of the server client. public interface IServer : IDisposable where TServerClient : IServerClient diff --git a/Exomia.Network/IServerClient.cs b/Exomia.Network/IServerClient.cs new file mode 100644 index 0000000..fe01683 --- /dev/null +++ b/Exomia.Network/IServerClient.cs @@ -0,0 +1,37 @@ +#region License + +// Copyright (c) 2018-2019, exomia +// All rights reserved. +// +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. + +#endregion + +using System; +using System.Net; + +namespace Exomia.Network +{ + /// + /// Interface for server client. + /// + public interface IServerClient + { + /// + /// Gets the Date/Time of the last received packet time stamp. + /// + /// + /// The last received packet time stamp. + /// + DateTime LastReceivedPacketTimeStamp { get; } + + /// + /// Gets the IP address. + /// + /// + /// The IP address. + /// + IPAddress IPAddress { get; } + } +} \ No newline at end of file diff --git a/Exomia.Network/Lib/ServerClientEventEntry.cs b/Exomia.Network/Lib/ServerClientEventEntry.cs index d66dfb7..0472d4c 100644 --- a/Exomia.Network/Lib/ServerClientEventEntry.cs +++ b/Exomia.Network/Lib/ServerClientEventEntry.cs @@ -13,11 +13,9 @@ namespace Exomia.Network.Lib /// /// A server client event entry. This class cannot be inherited. /// - /// Generic type parameter. /// Type of the server client. - sealed class ServerClientEventEntry - where T : class - where TServerClient : ServerClientBase + sealed class ServerClientEventEntry + where TServerClient : IServerClient { /// /// The deserialize. @@ -27,15 +25,15 @@ sealed class ServerClientEventEntry /// /// The data received. /// - private readonly Event> _dataReceived; + private readonly Event> _dataReceived; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The deserialize. public ServerClientEventEntry(DeserializePacketHandler deserialize) { - _dataReceived = new Event>(); + _dataReceived = new Event>(); _deserialize = deserialize; } @@ -43,7 +41,7 @@ public ServerClientEventEntry(DeserializePacketHandler deserialize) /// Adds callback. /// /// The callback to remove. - public void Add(ClientDataReceivedHandler callback) + public void Add(ClientDataReceivedHandler callback) { _dataReceived.Add(callback); } @@ -52,7 +50,7 @@ public void Add(ClientDataReceivedHandler callback) /// Removes the given callback. /// /// The callback to remove. - public void Remove(ClientDataReceivedHandler callback) + public void Remove(ClientDataReceivedHandler callback) { _dataReceived.Remove(callback); } diff --git a/Exomia.Network/ServerBase.cs b/Exomia.Network/ServerBase.cs index 8568031..5cad1a9 100644 --- a/Exomia.Network/ServerBase.cs +++ b/Exomia.Network/ServerBase.cs @@ -57,17 +57,17 @@ public abstract class ServerBase : IServer /// /// Called than a client is connected. /// - public event ClientActionHandler ClientConnected; + public event ClientActionHandler ClientConnected; /// /// Called than a client is disconnected. /// - public event ClientDisconnectHandler ClientDisconnected; + public event ClientDisconnectHandler ClientDisconnected; /// /// Occurs when data from a client is received. /// - public event ClientCommandDataReceivedHandler ClientDataReceived + public event ClientCommandDataReceivedHandler ClientDataReceived { add { _clientDataReceived.Add(value); } remove { _clientDataReceived.Remove(value); } @@ -96,12 +96,12 @@ public event ClientCommandDataReceivedHandler ClientDataReceiv /// /// The data received callbacks. /// - private readonly Dictionary> _dataReceivedCallbacks; + private readonly Dictionary> _dataReceivedCallbacks; /// /// The client data received event handler. /// - private readonly Event> _clientDataReceived; + private readonly Event> _clientDataReceived; /// /// The clients lock. @@ -134,13 +134,13 @@ public int Port /// private protected ServerBase() { - _dataReceivedCallbacks = new Dictionary>(INITIAL_QUEUE_SIZE); + _dataReceivedCallbacks = new Dictionary>(INITIAL_QUEUE_SIZE); _clients = new Dictionary(INITIAL_CLIENT_QUEUE_SIZE); _clientsLock = new SpinLock(Debugger.IsAttached); _dataReceivedCallbacksLock = new SpinLock(Debugger.IsAttached); - _clientDataReceived = new Event>(); + _clientDataReceived = new Event>(); } /// @@ -231,7 +231,7 @@ private protected void DeserializeData(T arg0, { if (commandID <= Constants.USER_COMMAND_LIMIT && _dataReceivedCallbacks.TryGetValue( - commandID, out ServerClientEventEntry scee)) + commandID, out ServerClientEventEntry scee)) { sClient.SetLastReceivedPacketTimeStamp(); @@ -363,14 +363,10 @@ private void InvokeClientConnected(T arg0) /// /// The deserialize handler. /// A variable-length parameters list containing command ids. - /// - /// Thrown when one or more arguments are outside - /// the required range. - /// - /// - /// Thrown when one or more required arguments - /// are null. - /// + /// Thrown when one or more required arguments + /// are null. + /// Thrown when one or more arguments are outside + /// the required range. public void AddCommand(DeserializePacketHandler deserialize, params uint[] commandIDs) { if (commandIDs == null) { throw new ArgumentNullException(nameof(commandIDs)); } @@ -389,9 +385,9 @@ public void AddCommand(DeserializePacketHandler deserialize, params uint $"{nameof(commandID)} is restricted to 0 - {Constants.USER_COMMAND_LIMIT}"); } if (!_dataReceivedCallbacks.TryGetValue( - commandID, out ServerClientEventEntry buffer)) + commandID, out ServerClientEventEntry buffer)) { - buffer = new ServerClientEventEntry(deserialize); + buffer = new ServerClientEventEntry(deserialize); _dataReceivedCallbacks.Add(commandID, buffer); } } @@ -409,10 +405,8 @@ public void AddCommand(DeserializePacketHandler deserialize, params uint /// /// True if at least one command is removed, false otherwise. /// - /// - /// Thrown when one or more arguments are outside - /// the required range. - /// + /// Thrown when one or more arguments are outside + /// the required range. public bool RemoveCommands(params uint[] commandIDs) { bool removed = false; @@ -442,19 +436,13 @@ public bool RemoveCommands(params uint[] commandIDs) /// /// Identifier for the command. /// ClientDataReceivedHandler{Socket|Endpoint} - /// - /// Thrown when one or more arguments are outside - /// the required range. - /// - /// - /// Thrown when one or more required arguments - /// are null. - /// - /// - /// Thrown when an exception error condition - /// occurs. - /// - public void AddDataReceivedCallback(uint commandID, ClientDataReceivedHandler callback) + /// Thrown when one or more arguments are outside + /// the required range. + /// Thrown when one or more required arguments + /// are null. + /// Thrown when an exception error condition + /// occurs. + public void AddDataReceivedCallback(uint commandID, ClientDataReceivedHandler callback) { if (commandID > Constants.USER_COMMAND_LIMIT) { @@ -468,7 +456,7 @@ public void AddDataReceivedCallback(uint commandID, ClientDataReceivedHandler buffer)) + if (!_dataReceivedCallbacks.TryGetValue(commandID, out ServerClientEventEntry buffer)) { throw new Exception( $"Invalid parameter '{nameof(commandID)}'! Use 'AddCommand(DeserializeData, params uint[])' first."); @@ -487,15 +475,11 @@ public void AddDataReceivedCallback(uint commandID, ClientDataReceivedHandler /// Identifier for the command. /// ClientDataReceivedHandler{Socket|Endpoint} - /// - /// Thrown when one or more arguments are outside - /// the required range. - /// - /// - /// Thrown when one or more required arguments - /// are null. - /// - public void RemoveDataReceivedCallback(uint commandID, ClientDataReceivedHandler callback) + /// Thrown when one or more arguments are outside + /// the required range. + /// Thrown when one or more required arguments + /// are null. + public void RemoveDataReceivedCallback(uint commandID, ClientDataReceivedHandler callback) { if (commandID > Constants.USER_COMMAND_LIMIT) { @@ -505,7 +489,7 @@ public void RemoveDataReceivedCallback(uint commandID, ClientDataReceivedHandler if (callback == null) { throw new ArgumentNullException(nameof(callback)); } - if (_dataReceivedCallbacks.TryGetValue(commandID, out ServerClientEventEntry buffer)) + if (_dataReceivedCallbacks.TryGetValue(commandID, out ServerClientEventEntry buffer)) { buffer.Remove(callback); } diff --git a/Exomia.Network/ServerClientBase.cs b/Exomia.Network/ServerClientBase.cs index 32e90d6..5a5dc54 100644 --- a/Exomia.Network/ServerClientBase.cs +++ b/Exomia.Network/ServerClientBase.cs @@ -13,22 +13,6 @@ namespace Exomia.Network { - /// - /// Interface for server client. - /// - public interface IServerClient - { - /// - /// Gets the Date/Time of the last received packet time stamp. - /// - /// - /// The last received packet time stamp. - /// - DateTime LastReceivedPacketTimeStamp { get; } - - IPAddress IPAddress { get; } - } - /// /// A server client base. /// diff --git a/network.wiki b/network.wiki index 25e6177..334f7d7 160000 --- a/network.wiki +++ b/network.wiki @@ -1 +1 @@ -Subproject commit 25e6177c0baefc5085397ecb773e5e93815cc988 +Subproject commit 334f7d7fe7ca5f77975b7ecf08e445b241537b3b