예제 #1
0
            internal static void RefreshDirectConnectButton()
            {
                if (!GameObject.Find("RegionMenu"))
                {
                    return;
                }

                if (DirectConnect)
                {
                    DirectConnect.gameObject.Destroy();
                }

                RegionMenu     regionMenu     = DestroyableSingleton <RegionMenu> .Instance;
                JoinGameButton joinGameButton = DestroyableSingleton <JoinGameButton> .Instance;

                DirectConnect = Object.Instantiate(joinGameButton.GameIdText, regionMenu.transform);
                DirectConnect.GetComponentInChildren <TextTranslatorTMP>().Destroy();
                DirectConnect.GetComponent <JoinGameButton>().Destroy();
                DirectConnect.outputText.text = "Enter IP";
                DirectConnect.IpMode          = true;
                DirectConnect.characterLimit  = 15;
                DirectConnect.ClearOnFocus    = false;

                DirectConnect.OnEnter = new Button.ButtonClickedEvent();
                DirectConnect.OnEnter.AddListener((Action)UpdateRegion);

                int offset = NewRegions.Length + ModRegions.Count;

                DirectConnect.transform.localPosition = new Vector3(0, 1f - (offset / 2f), -100f);
            }
예제 #2
0
        protected void StartConnect(EndPoint target)
        {
            try
            {
                _destEndPoint = target;

                CreateRemote();

                // Setting up proxy
                IForwardProxy remote;
                EndPoint      proxyEP;
                if (Config.proxy.useProxy)
                {
                    switch (Config.proxy.proxyType)
                    {
                    case ProxyConfig.PROXY_SOCKS5:
                        remote = new Socks5Proxy();
                        break;

                    case ProxyConfig.PROXY_HTTP:
                        remote = new HttpProxy();
                        break;

                    default:
                        throw new NotSupportedException("Unknown forward proxy.");
                    }
                    proxyEP = SocketUtil.GetEndPoint(Config.proxy.proxyServer, Config.proxy.proxyPort);
                }
                else
                {
                    remote  = new DirectConnect();
                    proxyEP = null;
                }

                var session = new AsyncSession(remote);
                _currentRemoteSession = session;

                ProxyTimer proxyTimer = new ProxyTimer(_proxyTimeout);
                proxyTimer.AutoReset = false;
                proxyTimer.Elapsed  += proxyConnectTimer_Elapsed;
                proxyTimer.Enabled   = true;

                proxyTimer.Session      = session;
                proxyTimer.DestEndPoint = SocketUtil.GetEndPoint(_server.server, _server.server_port);
                proxyTimer.Server       = _server;

                _proxyConnected = false;

                // Connect to the proxy server.
                remote.BeginConnectProxy(proxyEP, ProxyConnectCallback, new AsyncSession <ProxyTimer>(remote, proxyTimer));
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                Close();
            }
        }
        private void ok_Click(object sender, RoutedEventArgs e)
        {
            if (serverList.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a server!", "Select", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            DC = serverList.SelectedItem as DirectConnect;

            DialogResult = true;
        }
예제 #4
0
        private void StartConnect()
        {
            try
            {
                CreateRemote();

                // Setting up proxy
                IProxy   remote;
                EndPoint proxyEP;
                if (_config.useProxy)
                {
                    remote  = new Socks5Proxy();
                    proxyEP = SocketUtil.GetEndPoint(_config.proxyServer, _config.proxyPort);
                }
                else
                {
                    remote  = new DirectConnect();
                    proxyEP = null;
                }

                var session = new AsyncSession(remote);
                _currentRemoteSession = session;

                ProxyTimer proxyTimer = new ProxyTimer(3000);
                proxyTimer.AutoReset = false;
                proxyTimer.Elapsed  += proxyConnectTimer_Elapsed;
                proxyTimer.Enabled   = true;

                proxyTimer.Session      = session;
                proxyTimer.DestEndPoint = SocketUtil.GetEndPoint(server.server, server.server_port);
                proxyTimer.Server       = server;

                _proxyConnected = false;

                // Connect to the proxy server.
                remote.BeginConnectProxy(proxyEP, new AsyncCallback(ProxyConnectCallback), new AsyncSession <ProxyTimer>(remote, proxyTimer));
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                Close();
            }
        }
예제 #5
0
        private void StartConnect()
        {
            try
            {
                CreateRemote();

                // Setting up proxy
                IProxy   remote;
                EndPoint proxyEP  = null;
                EndPoint serverEP = SocketUtil.GetEndPoint(_server.server, _server.server_port);
                EndPoint pluginEP = _controller.GetPluginLocalEndPointIfConfigured(_server);

                if (pluginEP != null)
                {
                    serverEP = pluginEP;
                    remote   = new DirectConnect();
                }
                else if (_config.proxy.useProxy)
                {
                    switch (_config.proxy.proxyType)
                    {
                    case ProxyConfig.PROXY_SOCKS5:
                        remote = new Socks5Proxy();
                        break;

                    case ProxyConfig.PROXY_HTTP:
                        remote = new HttpProxy();
                        break;

                    default:
                        throw new NotSupportedException("Unknown forward proxy.");
                    }
                    proxyEP = SocketUtil.GetEndPoint(_config.proxy.proxyServer, _config.proxy.proxyPort);
                }
                else
                {
                    remote = new DirectConnect();
                }

                var session = new AsyncSession(remote);
                lock (_closeConnLock)
                {
                    if (_closed)
                    {
                        remote.Close();
                        return;
                    }

                    _currentRemoteSession = session;
                }

                ProxyTimer proxyTimer = new ProxyTimer(_proxyTimeout)
                {
                    AutoReset = false
                };
                proxyTimer.Elapsed += ProxyConnectTimer_Elapsed;
                proxyTimer.Enabled  = true;

                proxyTimer.Session      = session;
                proxyTimer.DestEndPoint = serverEP;
                proxyTimer.Server       = _server;

                _proxyConnected = false;

                // Connect to the proxy server.
                remote.BeginConnectProxy(proxyEP, ProxyConnectCallback,
                                         new AsyncSession <ProxyTimer>(remote, proxyTimer));
            }
            catch (Exception e)
            {
                Logger.LogUsefulException(e);
                Close();
            }
        }
예제 #6
0
        /// <summary>
        /// 测试速度
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="millisecondsTimeout">超时时间</param>
        /// <returns></returns>
        public int StartTest(Server server, int millisecondsTimeout = 1000)
        {
            _closed = false;
            try
            {
                CreateRemote(server);
                // Setting up proxy
                IProxy   remote;
                EndPoint proxyEP  = null;
                EndPoint serverEP = SocketUtil.GetEndPoint(_server.server, _server.server_port);
                EndPoint pluginEP = _controller.GetPluginLocalEndPointIfConfigured(_server);

                if (pluginEP != null)
                {
                    serverEP = pluginEP;
                    remote   = new DirectConnect();
                }
                else if (_config.proxy.useProxy)
                {
                    switch (_config.proxy.proxyType)
                    {
                    case ProxyConfig.PROXY_SOCKS5:
                        remote = new Socks5Proxy();
                        break;

                    case ProxyConfig.PROXY_HTTP:
                        remote = new HttpProxy();
                        break;

                    default:
                        throw new NotSupportedException("Unknown forward proxy.");
                    }
                    proxyEP = SocketUtil.GetEndPoint(_config.proxy.proxyServer, _config.proxy.proxyPort);
                }
                else
                {
                    remote = new DirectConnect();
                }

                var session = new AsyncSession(remote);
                lock (_closeConnLock)
                {
                    if (_closed)
                    {
                        remote.Close();
                        return(0);
                    }

                    _currentRemoteSession = session;
                }

                _destEndPoint = serverEP;

                _proxyConnected  = false;
                _received        = false;
                manualResetEvent = new ManualResetEventSlim(false);
                Stopwatch sw = new Stopwatch();
                sw.Start();
                remote.BeginConnectProxy(proxyEP, ProxyConnectCallback,
                                         new AsyncSession(remote));
                manualResetEvent.Wait(millisecondsTimeout);
                sw.Stop();
                Close();
                if (_received)
                {
                    return((int)sw.ElapsedMilliseconds);
                }
                return(0);
            }
            catch (Exception e)
            {
                Close();
            }
            finally
            {
                manualResetEvent?.Dispose();
                manualResetEvent = null;
            }
            return(0);
        }