private void Server_TCP_ClientState_Changed(AssaultBird2454.VPTU.Networking.Server.TCP.TCP_ClientNode Client, AssaultBird2454.VPTU.Networking.Data.Client_ConnectionStatus Client_State) { if (Client_State == AssaultBird2454.VPTU.Networking.Data.Client_ConnectionStatus.Connected) { this.Dispatcher.Invoke(new Action(() => { this.ClientList.Add(Client); })); } else if (Client_State == AssaultBird2454.VPTU.Networking.Data.Client_ConnectionStatus.Disconnected) { this.Dispatcher.Invoke(new Action(() => { try { this.ClientList.Remove(Client); } catch { } })); } else if (Client_State == AssaultBird2454.VPTU.Networking.Data.Client_ConnectionStatus.Rejected) { this.Dispatcher.Invoke(new Action(() => { try { this.ClientList.Remove(Client); } catch { } })); } //Clients.Dispatcher.Invoke(new Action(() => Clients.Items.Refresh())); }
/// <summary> /// Disconnects a client /// </summary> /// <param name="node">The client being disconected</param> public void Disconnect_Client(TCP_ClientNode node) { Fire_TCP_ClientState_Changed(node, Data.Client_ConnectionStatus.Disconnected); // Sends Client Disconnect Event node.Disconnect(); // Disconnects the client from the server lock (ClientNodes) { ClientNodes.Remove(node);// Removes from list } }
/// <summary> /// /// </summary> public void Client_SendData(object Data, TCP_ClientNode node = null) { if (node == null) { foreach (TCP_ClientNode cn in ClientNodes) { cn.Send(Data);// Send the data to everybody } } else { node.Send(Data);// Send the data to a single client } }
/// <summary> /// Handels Network Commands /// </summary> /// <param name="_Data">The Data that needs to be handeled</param> /// <param name="node">The client that sent it</param> internal void Server_Commands(object _Data, TCP_ClientNode node) { Data.InternalNetworkCommand Data = (Data.InternalNetworkCommand)_Data; if (Data.CommandType == Networking.Data.Commands.SSL_Enable) { node.EnableSSL(Data.Response); } else if (Data.CommandType == Networking.Data.Commands.SSL_Dissable) { node.DissableSSL(); } else if (Data.CommandType == Networking.Data.Commands.SSL_Active) { } else if (Data.CommandType == Networking.Data.Commands.SetBufferSize) { //Command Not Implemented node.Send(new Data.InternalNetworkCommand(Networking.Data.Commands.SetBufferSize, Networking.Data.ResponseCode.Not_Implemented)); } }
private void Client_Connected(IAsyncResult ar) { TcpListener tcpl = (TcpListener)ar.AsyncState; // The Listener TcpClient tclient = null; // The Connecting clients TCPClient Object TCP_ClientNode node = null; // The Connecting clients Node Object try { if (AcceptClients && ClientNodes.Count <= MaxConnections) { tclient = Listener.EndAcceptTcpClient(ar); // Creates a client object to handel remote connection tcpl.BeginAcceptTcpClient(Client_Connected, Listener); // Starts listening for another connection lock (ClientNodes) { node = new TCP_ClientNode(tclient, tclient.Client.RemoteEndPoint.ToString(), this); // Creates a new client node object ClientNodes.Add(node); // Adds the client node to the list } Fire_TCP_ClientState_Changed(node, Data.Client_ConnectionStatus.Connected);// Sends the client connected event } else { tclient = Listener.EndAcceptTcpClient(ar); // Creates a client object to handel remote connection tclient.Close(); // Closes the connection (if full or not accepting, this will change latter) tcpl.BeginAcceptTcpClient(Client_Connected, Listener); // Starts listening for another connection Fire_TCP_ClientState_Changed(null, Data.Client_ConnectionStatus.Rejected); // Sends the client rejected event } } catch (Exception ex) { /* Error occured when connecting a client */ } }
protected void Fire_TCP_Data_Event(string Data, TCP_ClientNode Client, DataDirection Direction) { TCP_Data_Event?.Invoke(Data, Client, Direction); }
protected void Fire_TCP_ClientState_Changed(TCP_ClientNode Client, Data.Client_ConnectionStatus Client_State) { TCP_ClientState_Changed?.Invoke(Client, Client_State); }