Exemplo n.º 1
0
        static void Main(/*string[] args*/)
        {
            Console.Title = "BAOO-SecureProxy";
            var Config = Preparation.FindAndSaveBAOPAth();
            var Proxy  = new TcpProxyServer();

            Proxy.Start("ozzypc-wbid.live.ws.fireteam.net", 443, "127.0.0.1", 0, Config).Wait();
        }
Exemplo n.º 2
0
        public async System.Threading.Tasks.Task Start(string RemoteServerDNS, ushort RemoteServerPort, string LocalIp, ushort LocalPort, AppConfig AppConfig)
        {
            System.Net.Sockets.TcpListener ProxyServer = null;
            var Connections = new System.Collections.Concurrent.ConcurrentBag <TcpProxyClient>();

            try
            {
                System.Net.IPAddress LocalIpAddress = string.IsNullOrEmpty(LocalIp) ? System.Net.IPAddress.Parse("127.0.0.1") : System.Net.IPAddress.Parse(LocalIp);
                ProxyServer = new System.Net.Sockets.TcpListener(new System.Net.IPEndPoint(LocalIpAddress, LocalPort));
                ProxyServer.Server.SetSocketOption(System.Net.Sockets.SocketOptionLevel.IPv6, System.Net.Sockets.SocketOptionName.IPv6Only, false);
                ProxyServer.Start();

                var ProxyEndPoint = ProxyServer.Server.LocalEndPoint;
                Preparation.RerouteBAOOToProxy(AppConfig, ProxyEndPoint);
                Console.WriteLine($"TCP proxy started {ProxyEndPoint} -> {RemoteServerDNS}:{RemoteServerPort}");
                Console.WriteLine("You can now start the game.");

                var _ = System.Threading.Tasks.Task.Run(async() =>
                {
                    while (true)
                    {
                        await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(10)).ConfigureAwait(false);

                        var tempConnections = new System.Collections.Generic.List <TcpProxyClient>(Connections.Count);
                        while (Connections.TryTake(out var connection))
                        {
                            tempConnections.Add(connection);
                        }

                        foreach (var tcpConnection in tempConnections)
                        {
                            if (tcpConnection.LastActivity + ConnectionTimeout < Environment.TickCount64)
                            {
                                tcpConnection.Stop();
                            }
                            else
                            {
                                Connections.Add(tcpConnection);
                            }
                        }
                    }
                });

                while (true)
                {
                    try
                    {
                        var GameConnection = await TcpProxyClient.AcceptTcpClientAsync(ProxyServer, RemoteServerDNS, RemoteServerPort, AppConfig).ConfigureAwait(false);

                        GameConnection.Run();
                        Connections.Add(GameConnection);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex);
                        Console.ResetColor();
                    }
                }
            }
            catch (System.Net.Sockets.SocketException e)
            {
                Console.WriteLine("Error Code: {0}", e.ErrorCode);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                ProxyServer.Stop();
            }

            Console.WriteLine("Press ENTER to exit.");
            Console.Read();
        }