Example #1
0
        /// <summary>
        /// Try to establish a connection with the specified remote destination.
        /// </summary>

        public void Connect(IPEndPoint externalIP, IPEndPoint internalIP = null)
        {
#if !MODDING
            Disconnect();

            lock (mIn) Buffer.Recycle(mIn);
            lock (mOut) Buffer.Recycle(mOut);

#if W2 && !STANDALONE
            if (externalIP != null && externalIP.Port != 5181 && Game.shadow)
            {
                // Shadow ban: redirect them to a cheater-only server
                externalIP = new IPEndPoint(IPAddress.Parse("54.158.239.111"), 5146);
                internalIP = null;
            }
#endif
            if (externalIP != null)
            {
                // Some routers, like Asus RT-N66U don't support NAT Loopback, and connecting to an external IP
                // will connect to the router instead. So if it's a local IP, connect to it first.
                if (internalIP != null && Tools.GetSubnet(Tools.localAddress) == Tools.GetSubnet(internalIP.Address))
                {
                    tcpEndPoint = internalIP;
                    mFallback   = externalIP;
                }
                else
                {
                    tcpEndPoint = externalIP;
                    mFallback   = internalIP;
                }
                ConnectToTcpEndPoint();
            }
#endif
        }
Example #2
0
        /// <summary>
        /// Try to establish a connection with the specified remote destination.
        /// </summary>

        public void Connect(IPEndPoint externalIP, IPEndPoint internalIP)
        {
            Disconnect();

            // Some routers, like Asus RT-N66U don't support NAT Loopback, and connecting to an external IP
            // will connect to the router instead. So if it's a local IP, connect to it first.
            if (internalIP != null && Tools.GetSubnet(Tools.localAddress) == Tools.GetSubnet(internalIP.Address))
            {
                tcpEndPoint = internalIP;
                mFallback   = externalIP;
            }
            else
            {
                tcpEndPoint = externalIP;
                mFallback   = internalIP;
            }
            ConnectToTcpEndPoint();
        }