private void CheckListener() { int num1; Socket[] socketArray1; int num2; IPAddress address1; NetState state1; for (num1 = 0; (num1 < this.m_Listeners.Length); ++num1) { socketArray1 = this.m_Listeners[num1].Slice(); num2 = 0; while ((num2 < socketArray1.Length)) { try { address1 = ((IPEndPoint)socketArray1[num2].RemoteEndPoint).Address; if (!Firewall.IsBlocked(address1)) { goto Label_0064; } Console.WriteLine("Client: {0}: Firewall blocked connection attempt.", address1); try { socketArray1[num2].Shutdown(SocketShutdown.Both); } catch { } try { socketArray1[num2].Close(); goto Label_009A; } catch { goto Label_009A; } } catch { } goto Label_009A; Label_0064: state1 = new NetState(socketArray1[num2], this); state1.Start(); if (state1.Running) { Console.WriteLine("Client: {0}: Connected. [{1} Online]", state1, NetState.Instances.Count); } Label_009A: ++num2; } } }
private static void EndAcceptTcpClient(IAsyncResult r) { TcpClient client; try { client = Listener.EndAcceptTcpClient(r); } catch (Exception e) { CSOptions.ToConsole(e); return; } finally { ListenAsync(); } if (client.Connected && _ServerStarted) { var ip = ((IPEndPoint)client.Client.RemoteEndPoint).Address; var allow = !CSOptions.UseWhitelist; if (allow) { allow = !CSOptions.Blacklist.Any(l => Utility.IPMatch(l, ip)) && !Firewall.IsBlocked(ip); } if (!allow && CSOptions.UseWhitelist) { allow = CSOptions.Whitelist.Any(l => Utility.IPMatch(l, ip)); } if (allow) { Connect(new WebAPIClient(client)); return; } } client.Close(); }
public static void ListenAsync() { AcquireListener(); if (Listener == null) { return; } VitaNexCore.TryCatch( () => { Listener.BeginAcceptTcpClient( r => { var client = VitaNexCore.TryCatchGet(Listener.EndAcceptTcpClient, r, CSOptions.ToConsole); ListenAsync(); if (client != null && client.Connected) { //client.NoDelay = true; if (_ServerStarted) { var ip = ((IPEndPoint)client.Client.RemoteEndPoint).Address; var allow = !CSOptions.UseWhitelist; if (allow) { allow = !CSOptions.Blacklist.Any(l => Utility.IPMatch(l, ip)) && !Firewall.IsBlocked(ip); } if (!allow && CSOptions.UseWhitelist) { allow = CSOptions.Whitelist.Any(l => Utility.IPMatch(l, ip)); } if (allow) { Connect(new WebAPIClient(client)); return; } } client.Close(); } }, null); }, e => { if (!(e is SocketException) && !(e is ObjectDisposedException)) { CSOptions.ToConsole(e); } }); }