/// <summary> /// Trasform the line of data sent into a Message structure and raise /// the event linked. /// </summary> /// <param name="server">Server raising the event.</param> /// <param name="receiver">Client that will receive the Message.</param> /// <param name="Data">Line of data sent.</param> void BaseMessageServer_OnDataSent(Server server, ClientS receiver, Data Data) { TCPMessage msg = null; try { msg = TCPMessage.FromByteArray(Data.Message); } catch (Exception) { } if (msg != null) if (OnClientAfterMessageSent != null) OnClientAfterMessageSent(this, (BaseMessageClientS)receiver, msg); }
/// <summary> /// Trasform the line of data received into a Message structure and raise /// the event linked. /// </summary> /// <param name="server">Server raising the event.</param> /// <param name="sender">Client sending the data.</param> /// <param name="Data">Line of data received.</param> void BaseMessageServer_OnDataReceived(Server server, ClientS sender, Data Data) { TCPMessage msg = null; try { msg = TCPMessage.FromByteArray(Data.Message); } catch (Exception) { } if (msg != null) if (OnClientMessageReceived != null) OnClientMessageReceived(this, (BaseMessageClientS)sender, msg); }
/// <summary> /// Base constructor of the class. /// </summary> /// <param name="server">Server to which this client is linked to.</param> /// <param name="client">Socket of the client.</param> protected internal BaseMessageClientS(Server server, TcpClient client) : base(server, client) { }
/// <summary> /// Kick the client if the server reached the maximum allowed number of clients. /// </summary> /// <param name="server">Server raising the event.</param> /// <param name="client">Client connecting to the server.</param> /// <param name="args">Specify if the client should be accepted into the server.</param> void BaseMessageServer_OnClientBeforeConnect(Server server, ClientS client, CancelArgs args) { if ((Clients.Count >= UserLimit) && (UserLimit != 0)) { TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.MaxUsers; ((BaseMessageClientS)client).Send(msg); args.Cancel = true; } }
/// <summary> /// Base class constructor. /// </summary> /// <param name="server">Server to which this client is linked to.</param> /// <param name="client">Socket of the client.</param> protected internal ClientS(Server server, TcpClient client) { _lock = new object(); _active = true; _server = server; _client = client; _ipaddress = _client.Client.RemoteEndPoint.ToString(); NetworkStream ns = _client.GetStream(); tr = new BinaryReader(ns); tw = new BinaryWriter(ns); }