private void processSocket(Socket socket) { try { string ip = (socket.RemoteEndPoint as IPEndPoint).Address.ToString(); string Localip = (socket.LocalEndPoint as IPEndPoint).Address.ToString(); int ipHash = ip.GetHashCode(); int time = Time32.Now.GetHashCode(); int oldValue; if (!BruteforceProtection.TryGetValue(ipHash, out oldValue)) { BruteforceProtection[ipHash] = time; } else { if (time - oldValue < TimeLimit) { if (PrintoutIPs) { Console.WriteLine("Dropped connection: " + ip); } socket.Disconnect(false); socket.Close(); return; } else { BruteforceProtection[ipHash] = time; if (PrintoutIPs) { Console.WriteLine("Allowed connection: " + ip); } } } ClientWrapper wrapper = new ClientWrapper(); wrapper.Create(socket, this, OnClientReceive); wrapper.Alive = true; wrapper.IP = ip; wrapper.LocalIp = Localip; if (this.OnClientConnect != null) { this.OnClientConnect(wrapper); } } catch (Exception es) { Console.WriteLine(es); } }
private void Accept_Callback(IAsyncResult asyncResult) { try { Socket accepted = Connection.EndAccept(asyncResult); if (accepted.Connected) { string ip = (accepted.RemoteEndPoint as IPEndPoint).Address.ToString(); string Localip = (accepted.LocalEndPoint as IPEndPoint).Address.ToString(); int ipHash = ip.GetHashCode(); ClientWrapper wrapper = new ClientWrapper(); wrapper.Create(accepted, this, OnClientReceive); wrapper.Alive = true; wrapper.IP = ip; wrapper.LocalIp = Localip; if (this.OnClientConnect != null) { this.OnClientConnect(wrapper); } } } catch (Exception ex) { Console.WriteLine(ex); } Accept(); }