private void ProtocolClient_ConnectionError(ProtocolClient sender, Exception exception) { lock (syncLock) { connectedClients.Remove(sender); ConnectionError?.Invoke(sender, exception); } }
private void ProtocolClient_ConnectionEstablished(ProtocolClient sender) { lock (syncLock) { connectedClients.Add(sender); ConnectionEstablished?.Invoke(sender); } }
private void AcceptCallBack(IAsyncResult iar) { try { Socket accepted = listeningSocket.EndAccept(iar); if (blockedHosts.Contains((accepted.RemoteEndPoint as IPEndPoint).Address.ToString())) { accepted.Disconnect(false); return; } accepted.NoDelay = true; ProtocolClient protocolClient = new ProtocolClient(accepted, ServerOptions.ClientOptions); protocolClient.ConnectionError += ProtocolClient_ConnectionError; protocolClient.ConnectionEstablished += ProtocolClient_ConnectionEstablished; protocolClient.PacketReceived += ProtocolClient_PacketReceived; protocolClient.ReceiveProgressChanged += ProtocolClient_ReceiveProgressChanged; protocolClient.PacketSend += ProtocolClient_PacketSend; protocolClient.DOSDetected += ProtocolClient_DOSDetected; protocolClient.PingUpdated += ProtocolClient_PingUpdated; protocolClient.Start(); listeningSocket.BeginAccept(AcceptCallBack, null); } catch { //MessageBox.Show(ex.Message + " \n\n [" + ex.StackTrace + "]"); } }
public void Broadcast(byte[] packet, ProtocolClient exception = null) { lock (syncLock) { for (int i = 0; i > connectedClients.Count; i++) { var client = connectedClients[i]; if (client != exception) { try { client.Send(packet); } catch { } } } } }
private void ProtocolClient_PacketReceived(ProtocolClient sender, PacketReceivedEventArgs PacketReceivedEventArgs) { PacketReceived?.Invoke(sender, PacketReceivedEventArgs); }
private void ProtocolClient_ReceiveProgressChanged(ProtocolClient sender, int bytesReceived, int bytesToReceive) { ReceiveProgressChanged?.Invoke(sender, bytesReceived, bytesToReceive); }
private void ProtocolClient_DOSDetected(ProtocolClient sender) { DOSDetected?.Invoke(sender); }
private void ProtocolClient_PacketSend(ProtocolClient sender, int Send) { PacketSend?.Invoke(sender, Send); }
private void ProtocolClient_PingUpdated(ProtocolClient sender, double ping) { PingUpdated?.Invoke(sender, ping); }