using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Timers; using KaduhServer; namespace PatcherServer.FileCheck { public sealed class Listener { public Dictionary Sessions = new Dictionary(); public Socket sListener; public string LinkIP = ""; public ushort ListenPort; public ushort SendPort; public Listener(ushort pListenPort, ushort pSendPort, string pIP) { this.LinkIP = pIP; ListenPort = pListenPort; SendPort = pSendPort; try { sListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sListener.Bind(new IPEndPoint(IPAddress.Any, pListenPort)); sListener.Listen(100); sListener.BeginAccept(new AsyncCallback(OnConnect), sListener); } catch (SocketException ex) { throw ex; } Timer timeOuts = new Timer(10000); timeOuts.Elapsed += new ElapsedEventHandler(timeOuts_Elapsed); timeOuts.Start(); } private List toDelete = new List(); void timeOuts_Elapsed(object sender, ElapsedEventArgs e) { lock (Sessions) { foreach (var x in Sessions) { if ((DateTime.Now - x.Value).TotalMinutes > 2) toDelete.Add(x.Key); } toDelete.ForEach(d => Sessions.Remove(d)); toDelete.Clear(); } } private void OnConnect(IAsyncResult ar) { try { Socket client = sListener.EndAccept(ar); string IP = client.RemoteEndPoint.ToString().Split(':')[0]; sListener.BeginAccept(new AsyncCallback(OnConnect), sListener); /* if (!Program.Server.Sessions.ContainsKey(IP)) { client.Shutdown(SocketShutdown.Both); DatabaseManager.Instance.InsertHackAttempt(IP, "Bypassing HackProtect."); return; } if (!Program.Server.Sessions[IP].didFileCheck) { client.Shutdown(SocketShutdown.Both); DatabaseManager.Instance.InsertHackAttempt(IP, "Bypassing filechecks."); return; } if ((DateTime.Now - Program.Server.Sessions[IP].Authenciated).TotalMinutes > 2) { client.Shutdown(SocketShutdown.Both); DatabaseManager.Instance.InsertHackAttempt(IP, "Suspicious client start."); return; }*/ //not so secure, but yea, there's the guid check NormalProxy proxy = new NormalProxy(client, SendPort, LinkIP); Sessions.Add(proxy, DateTime.Now); } catch (SocketException ex) { // srsly. WTF? throw ex; } } } }