using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using System.Threading; using System.IO; namespace Blizzard.Connections { class DataRouter { private TcpListener Listener; private static int mMaxConnections = 50000; private AsyncCallback OnReceiveConection; private static string[] mConnectionCounter; public DataRouter(int Port) { BlizzardSystem.WriteLine("Starting listening connections on " + Port + "..."); Listener = new TcpListener(Port); Listener.Start(); OnReceiveConection = new AsyncCallback(ConnectionRequest); Task Thread = new Task(WaitforNextConnection); Thread.Start(); mConnectionCounter = new string[mMaxConnections]; BlizzardSystem.WriteLine("Succeful started Game Socket system"); } private void WaitforNextConnection() { Listener.BeginAcceptSocket(OnReceiveConection, null); GC.Collect(); } private void ConnectionRequest(IAsyncResult iAr) { try { Socket ClientSock = Listener.EndAcceptSocket(iAr); BlizzardSystem.Net.AddConnection(ClientSock); // ConsoleWritter.WriteError("[DDOS] IP blocked: " + ClientSock.RemoteEndPoint.ToString().Split(':')[0]); } catch (Exception e) { BlizzardSystem.WriteLine("Error on sockets system: " + e.ToString()); } finally { WaitforNextConnection(); } } } }