mirror of https://github.com/quasar/Quasar.git
Merge pull request #241 from yankejustin/Documentation
Documentation additions for Client/Server objects
This commit is contained in:
commit
ec40c47b26
|
@ -17,10 +17,24 @@ namespace xClient.Core
|
|||
{
|
||||
public class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Occurs as a result of an unrecoverable issue with the client.
|
||||
/// </summary>
|
||||
public event ClientFailEventHandler ClientFail;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a method that will handle failure of the client.
|
||||
/// </summary>
|
||||
/// <param name="s">The client that has failed.</param>
|
||||
/// <param name="ex">The exception containing information about the cause
|
||||
/// of the client's failure.</param>
|
||||
public delegate void ClientFailEventHandler(Client s, Exception ex);
|
||||
|
||||
/// <summary>
|
||||
/// Fires an event that informs subscribers that the client has failed.
|
||||
/// </summary>
|
||||
/// <param name="ex">The exception containing information about the cause
|
||||
/// of the client's failure.</param>
|
||||
private void OnClientFail(Exception ex)
|
||||
{
|
||||
if (ClientFail != null)
|
||||
|
@ -29,10 +43,24 @@ namespace xClient.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the state of the client has changed.
|
||||
/// </summary>
|
||||
public event ClientStateEventHandler ClientState;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a method that handles when the state of the client has changed.
|
||||
/// </summary>
|
||||
/// <param name="s">The client to update the state of.</param>
|
||||
/// <param name="connected">True if the client is connected; False if the client
|
||||
/// is not connected.</param>
|
||||
public delegate void ClientStateEventHandler(Client s, bool connected);
|
||||
|
||||
/// <summary>
|
||||
/// Fires an event that informs subscribers that the state of the client has changed.
|
||||
/// </summary>
|
||||
/// <param name="connected">True if the client is connected; False if the client is
|
||||
/// not connected.</param>
|
||||
private void OnClientState(bool connected)
|
||||
{
|
||||
if (Connected == connected) return;
|
||||
|
@ -44,10 +72,23 @@ namespace xClient.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a packet is received from the server.
|
||||
/// </summary>
|
||||
public event ClientReadEventHandler ClientRead;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a method that will handle a packet from the server to the client.
|
||||
/// </summary>
|
||||
/// <param name="s">The client that is receiving the packet (from the server).</param>
|
||||
/// <param name="packet">The packet that has been received by the client from the server.</param>
|
||||
public delegate void ClientReadEventHandler(Client s, IPacket packet);
|
||||
|
||||
/// <summary>
|
||||
/// Fires an event that informs subscribers that the a packet has been
|
||||
/// received from the server to the client.
|
||||
/// </summary>
|
||||
/// <param name="packet"></param>
|
||||
private void OnClientRead(IPacket packet)
|
||||
{
|
||||
if (ClientRead != null)
|
||||
|
@ -68,14 +109,23 @@ namespace xClient.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The type of the packet received.
|
||||
/// </summary>
|
||||
public enum ReceiveType
|
||||
{
|
||||
Header,
|
||||
Payload
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A list of all the connected proxy clients that this client holds.
|
||||
/// </summary>
|
||||
private List<ReverseProxyClient> _proxyClients;
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array containing all of the proxy clients of this client.
|
||||
/// </summary>
|
||||
public ReverseProxyClient[] ProxyClients
|
||||
{
|
||||
get { return _proxyClients.ToArray(); }
|
||||
|
@ -89,6 +139,9 @@ namespace xClient.Core
|
|||
private Socket _handle;
|
||||
private int _typeIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer for the client's incoming and outgoing packets.
|
||||
/// </summary>
|
||||
private byte[] _buffer = new byte[MAX_PACKET_SIZE];
|
||||
|
||||
//receive info
|
||||
|
@ -98,7 +151,9 @@ namespace xClient.Core
|
|||
private int _payloadLen;
|
||||
private ReceiveType _receiveState = ReceiveType.Header;
|
||||
|
||||
//Connection info
|
||||
/// <summary>
|
||||
/// Gets if the client is currently connected to a server.
|
||||
/// </summary>
|
||||
public bool Connected { get; private set; }
|
||||
|
||||
private const bool encryptionEnabled = true;
|
||||
|
@ -108,6 +163,11 @@ namespace xClient.Core
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to connect to the specified host on the specified port.
|
||||
/// </summary>
|
||||
/// <param name="host">The host (or server) to connect to.</param>
|
||||
/// <param name="port">The port of the host.</param>
|
||||
public void Connect(string host, ushort port)
|
||||
{
|
||||
try
|
||||
|
@ -307,6 +367,11 @@ namespace xClient.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect the client from the server, disconnect all proxies that
|
||||
/// are held by this client, and dispose of other resources associated
|
||||
/// with this client.
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
OnClientState(false);
|
||||
|
|
|
@ -15,10 +15,24 @@ namespace xServer.Core
|
|||
{
|
||||
public class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Occurs when the state of the client changes.
|
||||
/// </summary>
|
||||
public event ClientStateEventHandler ClientState;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the method that will handle a change in a client's state.
|
||||
/// </summary>
|
||||
/// <param name="s">The client to update the state of.</param>
|
||||
/// <param name="connected">True if the client is connected; False if the client
|
||||
/// is not connected.</param>
|
||||
public delegate void ClientStateEventHandler(Client s, bool connected);
|
||||
|
||||
/// <summary>
|
||||
/// Fires an event that informs subscribers that the state of the client has changed.
|
||||
/// </summary>
|
||||
/// <param name="connected">True if the client is connected; False if the client is
|
||||
/// not connected.</param>
|
||||
private void OnClientState(bool connected)
|
||||
{
|
||||
if (Connected == connected) return;
|
||||
|
@ -30,10 +44,23 @@ namespace xServer.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a packet is received from the client.
|
||||
/// </summary>
|
||||
public event ClientReadEventHandler ClientRead;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the method that will handle a packet from a client.
|
||||
/// </summary>
|
||||
/// <param name="s">The client that has sent the packet.</param>
|
||||
/// <param name="packet">The packet that has been received from the client.</param>
|
||||
public delegate void ClientReadEventHandler(Client s, IPacket packet);
|
||||
|
||||
/// <summary>
|
||||
/// Fires an event that informs subscribers that the a packet has been
|
||||
/// received from the client.
|
||||
/// </summary>
|
||||
/// <param name="packet"></param>
|
||||
private void OnClientRead(IPacket packet)
|
||||
{
|
||||
if (ClientRead != null)
|
||||
|
@ -59,6 +86,9 @@ namespace xServer.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The type of the packet received.
|
||||
/// </summary>
|
||||
public enum ReceiveType
|
||||
{
|
||||
Header,
|
||||
|
@ -73,6 +103,9 @@ namespace xServer.Core
|
|||
private Socket _handle;
|
||||
private int _typeIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer for the client's incoming and outgoing packets.
|
||||
/// </summary>
|
||||
private byte[] _buffer = new byte[MAX_PACKET_SIZE];
|
||||
|
||||
//receive info
|
||||
|
@ -294,6 +327,10 @@ namespace xServer.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect the client from the server and dispose of
|
||||
/// resources associated with the client.
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
OnClientState(false);
|
||||
|
|
|
@ -11,10 +11,24 @@ namespace xServer.Core
|
|||
public long BytesReceived { get; set; }
|
||||
public long BytesSent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the state of the server changes.
|
||||
/// </summary>
|
||||
public event ServerStateEventHandler ServerState;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a method that will handle a change in the server's state.
|
||||
/// </summary>
|
||||
/// <param name="s">The server to update the state of.</param>
|
||||
/// <param name="listening">True if the server is listening; False if the server
|
||||
/// is not listening.</param>
|
||||
public delegate void ServerStateEventHandler(Server s, bool listening);
|
||||
|
||||
/// <summary>
|
||||
/// Fires an event that informs subscribers that the server has changed state.
|
||||
/// </summary>
|
||||
/// <param name="listening">True if the server is listening; False if the server
|
||||
/// is not listening.</param>
|
||||
private void OnServerState(bool listening)
|
||||
{
|
||||
if (ServerState != null)
|
||||
|
@ -23,10 +37,25 @@ namespace xServer.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the state of a client changes.
|
||||
/// </summary>
|
||||
public event ClientStateEventHandler ClientState;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a method that will handle a change in a client's state.
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <param name="c"></param>
|
||||
/// <param name="connected"></param>
|
||||
public delegate void ClientStateEventHandler(Server s, Client c, bool connected);
|
||||
|
||||
/// <summary>
|
||||
/// Fires an event that informs subscribers that a client has changed state.
|
||||
/// </summary>
|
||||
/// <param name="c"></param>
|
||||
/// <param name="connected">True if the client is connected; False if the client
|
||||
/// is not connected.</param>
|
||||
private void OnClientState(Client c, bool connected)
|
||||
{
|
||||
if (ClientState != null)
|
||||
|
@ -35,10 +64,25 @@ namespace xServer.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a packet is received by a client.
|
||||
/// </summary>
|
||||
public event ClientReadEventHandler ClientRead;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a method that will handle a packet received from a client.
|
||||
/// </summary>
|
||||
/// <param name="s">The destination server of the packet; also where the client specified
|
||||
/// should reside</param>
|
||||
/// <param name="c">The client that has sent the packet.</param>
|
||||
/// <param name="packet">The packet that was sent to the server.</param>
|
||||
public delegate void ClientReadEventHandler(Server s, Client c, IPacket packet);
|
||||
|
||||
/// <summary>
|
||||
/// Fires an event that informs subscribers that the a packet has been
|
||||
/// received from the client.
|
||||
/// </summary>
|
||||
/// <param name="packet">The packet that has been received by the server from the client.</param>
|
||||
private void OnClientRead(Client c, IPacket packet)
|
||||
{
|
||||
if (ClientRead != null)
|
||||
|
@ -63,18 +107,36 @@ namespace xServer.Core
|
|||
private Socket _handle;
|
||||
private SocketAsyncEventArgs _item;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the server is currently processing data that
|
||||
/// should prevent disconnection.
|
||||
/// </summary>
|
||||
private bool Processing { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status of the server. True if the server is currently
|
||||
/// listening; False if the server is not currently listening.
|
||||
/// </summary>
|
||||
public bool Listening { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The internal list of the clients connected to the server.
|
||||
/// </summary>
|
||||
private List<Client> _clients;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the clients currently connected to the server, or an empty array of
|
||||
/// clients if the server is currently not listening.
|
||||
/// </summary>
|
||||
public Client[] Clients
|
||||
{
|
||||
get { return Listening ? _clients.ToArray() : new Client[0]; }
|
||||
}
|
||||
|
||||
public int ConnectedClients { get; set; }
|
||||
/// <summary>
|
||||
/// A collection containing all of the clients that have connected to the server.
|
||||
/// </summary>
|
||||
public Dictionary<string, DateTime> AllTimeConnectedClients { get; set; }
|
||||
|
||||
private List<Type> PacketTypes { get; set; }
|
||||
|
@ -85,6 +147,10 @@ namespace xServer.Core
|
|||
AllTimeConnectedClients = new Dictionary<string, DateTime>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins listening for clients.
|
||||
/// </summary>
|
||||
/// <param name="port">Port to listen for clients on.</param>
|
||||
public void Listen(ushort port)
|
||||
{
|
||||
try
|
||||
|
@ -146,6 +212,12 @@ namespace xServer.Core
|
|||
AddTypeToSerializer(parent, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes an incoming client; adding the client to the list of clients,
|
||||
/// hooking up the client's events, and finally accepts the client.
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Process(object s, SocketAsyncEventArgs e)
|
||||
{
|
||||
try
|
||||
|
@ -177,6 +249,10 @@ namespace xServer.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect the server from all of the clients and discontinue
|
||||
/// listening (placing the server in an "off" state).
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
if (Processing)
|
||||
|
|
Loading…
Reference in New Issue