Beispiel #1
0
 private void ProtocolClient_ConnectionError(ProtocolClient sender, Exception exception)
 {
     lock (syncLock) {
         connectedClients.Remove(sender);
         ConnectionError?.Invoke(sender, exception);
     }
 }
Beispiel #2
0
 private void ProtocolClient_ConnectionEstablished(ProtocolClient sender)
 {
     lock (syncLock) {
         connectedClients.Add(sender);
         ConnectionEstablished?.Invoke(sender);
     }
 }
Beispiel #3
0
        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 + "]");
            }
        }
Beispiel #4
0
 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 { }
             }
         }
     }
 }
Beispiel #5
0
 private void ProtocolClient_PacketReceived(ProtocolClient sender, PacketReceivedEventArgs PacketReceivedEventArgs)
 {
     PacketReceived?.Invoke(sender, PacketReceivedEventArgs);
 }
Beispiel #6
0
 private void ProtocolClient_ReceiveProgressChanged(ProtocolClient sender, int bytesReceived, int bytesToReceive)
 {
     ReceiveProgressChanged?.Invoke(sender, bytesReceived, bytesToReceive);
 }
Beispiel #7
0
 private void ProtocolClient_DOSDetected(ProtocolClient sender)
 {
     DOSDetected?.Invoke(sender);
 }
Beispiel #8
0
 private void ProtocolClient_PacketSend(ProtocolClient sender, int Send)
 {
     PacketSend?.Invoke(sender, Send);
 }
Beispiel #9
0
 private void ProtocolClient_PingUpdated(ProtocolClient sender, double ping)
 {
     PingUpdated?.Invoke(sender, ping);
 }