Ejemplo n.º 1
0
        private void OnExit(object sender, EventArgs e)
        {
            if (_proxyManager.LastProxyState == ProxyState.AutomaticallySetWithAutoconfigScript)
            {
                HostsFileManager.Remove(_proxyManager.GetAutoConfigUri().Host);
            }

            Application.Exit();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// "Validate cell" event handler.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void HE_ModelView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            // Skip validation of the new rows...
            if (((DataGridView)sender).Rows[e.RowIndex].IsNewRow)
            {
                return;
            }

            switch (e.ColumnIndex)
            {
            case 0:     // Validating IP-address...
                ((DataGridView)sender).Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = HostsFileManager.ValidateIPAddress((string)e.FormattedValue) ? null : AppStrings.AHE_IncorrectIPAddress;
                break;

            case 1:     // Validating Hostname...
                ((DataGridView)sender).Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = HostsFileManager.ValidateHostname((string)e.FormattedValue) ? null : AppStrings.AHE_IncorrectHostname;
                break;

            default:     // Reporting an error...
                Logger.Warn(DebugStrings.AppDbgModelViewColumnIndexOutOfRange);
                break;
            }
        }
Ejemplo n.º 3
0
        internal void InitializeFakeHostsForMultiSubnetFailover()
        {
            // initialize fake hosts for MultiSubnetFailover
            string originalHost, protocol, instance;
            int? port;
            NetUtils.ParseDataSource(this.Source.DataSource, out protocol, out originalHost, out instance, out port);

            // get the IPv4 addresses
            IPAddress[] ipV4 = NetUtils.EnumerateIPv4Addresses(originalHost).ToArray();
            if (ipV4 == null || ipV4.Length == 0)
            {
                // consider supporting IPv6 when it becomes relevant (not a goal right now)
                throw new ArgumentException("The target server " + originalHost + " has no IPv4 addresses associated with it in DNS");
            }

            // construct different host names for MSF with valid server IP located in a different place each time
            List<HostsFileManager.HostEntry> allEntries = new List<HostsFileManager.HostEntry>();

            int nextValidIp = 0;
            int nextInvalidIp = 0;
            _multiSubnetFailoverHostNames = new List<string>();

            // construct some interesting cases for MultiSubnetFailover stress

            // for integrated security to work properly, the server name in connection string must match the target server host name.
            // thus, create one entry in the hosts with the true server name: either FQDN or the short name
            Task<IPHostEntry> task = Dns.GetHostEntryAsync(ipV4[0]);
            string nameToUse = task.Result.HostName;
            if (originalHost.Contains('.'))
            {
                // if the original hosts is FQDN, put short name in the hosts instead
                // otherwise, put FQDN in hosts
                int shortNameEnd = nameToUse.IndexOf('.');
                if (shortNameEnd > 0)
                    nameToUse = nameToUse.Substring(0, shortNameEnd);
            }
            // since true server name is being re-mapped, keep the valid IP first in the list
            AddEntryHelper(allEntries, _multiSubnetFailoverHostNames, nameToUse,
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount));
            this.MultiSubnetFailoverHostNameForIntegratedSecurity = nameToUse;

            // single valid IP
            AddEntryHelper(allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_V",
                ipV4[(nextValidIp++) % ipV4.Length]);

            // valid + invalid
            AddEntryHelper(
                allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_VI",
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount));

            // invalid + valid + invalid
            AddEntryHelper(
                allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_IVI",
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount));

            // Using more than one active IP associated with the virtual name (VNN) is not a supported scenario with MultiSubnetFailover.
            // But, this can definitly happen in reality - add special cases here to cover two valid IPs.
            AddEntryHelper(
                allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_IVI",
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                ipV4[(nextValidIp++) % ipV4.Length]);

            // big boom with 7 IPs - for stress purposes only
            AddEntryHelper(
                allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_BIGBOOM",
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount)
                );

            // list of fake hosts is ready, initialize hosts file manager and update the file
            _hostsFile = new HostsFileManager();
            _hostsFile.AddRange(allEntries);
        }
Ejemplo n.º 4
0
        internal void InitializeFakeHostsForMultiSubnetFailover()
        {
            // initialize fake hosts for MultiSubnetFailover
            string originalHost, protocol, instance;
            int?   port;

            NetUtils.ParseDataSource(this.Source.DataSource, out protocol, out originalHost, out instance, out port);

            // get the IPv4 addresses
            IPAddress[] ipV4 = NetUtils.EnumerateIPv4Addresses(originalHost).ToArray();
            if (ipV4 == null || ipV4.Length == 0)
            {
                // consider supporting IPv6 when it becomes relevant (not a goal right now)
                throw new ArgumentException("The target server " + originalHost + " has no IPv4 addresses associated with it in DNS");
            }

            // construct different host names for MSF with valid server IP located in a different place each time
            List <HostsFileManager.HostEntry> allEntries = new List <HostsFileManager.HostEntry>();

            int nextValidIp   = 0;
            int nextInvalidIp = 0;

            _multiSubnetFailoverHostNames = new List <string>();

            // construct some interesting cases for MultiSubnetFailover stress

            // for integrated security to work properly, the server name in connection string must match the target server host name.
            // thus, create one entry in the hosts with the true server name: either FQDN or the short name
            Task <IPHostEntry> task      = Dns.GetHostEntryAsync(ipV4[0]);
            string             nameToUse = task.Result.HostName;

            if (originalHost.Contains('.'))
            {
                // if the original hosts is FQDN, put short name in the hosts instead
                // otherwise, put FQDN in hosts
                int shortNameEnd = nameToUse.IndexOf('.');
                if (shortNameEnd > 0)
                {
                    nameToUse = nameToUse.Substring(0, shortNameEnd);
                }
            }
            // since true server name is being re-mapped, keep the valid IP first in the list
            AddEntryHelper(allEntries, _multiSubnetFailoverHostNames, nameToUse,
                           ipV4[(nextValidIp++) % ipV4.Length],
                           NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount));
            this.MultiSubnetFailoverHostNameForIntegratedSecurity = nameToUse;

            // single valid IP
            AddEntryHelper(allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_V",
                           ipV4[(nextValidIp++) % ipV4.Length]);

            // valid + invalid
            AddEntryHelper(
                allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_VI",
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount));

            // invalid + valid + invalid
            AddEntryHelper(
                allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_IVI",
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount));

            // Using more than one active IP associated with the virtual name (VNN) is not a supported scenario with MultiSubnetFailover.
            // But, this can definitly happen in reality - add special cases here to cover two valid IPs.
            AddEntryHelper(
                allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_IVI",
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                ipV4[(nextValidIp++) % ipV4.Length]);

            // big boom with 7 IPs - for stress purposes only
            AddEntryHelper(
                allEntries, _multiSubnetFailoverHostNames, "MSF_MP_Stress_BIGBOOM",
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount),
                ipV4[(nextValidIp++) % ipV4.Length],
                NetUtils.GetNonExistingIPv4((nextInvalidIp++) % NetUtils.NonExistingIPv4AddressCount)
                );

            // list of fake hosts is ready, initialize hosts file manager and update the file
            _hostsFile = new HostsFileManager();
            _hostsFile.AddRange(allEntries);
        }
Ejemplo n.º 5
0
        static ServerInstance StartServer(Region region, HostsFileManager hosts)
        {
            _log.Basic("{0} proxy server starting...", region);

            var sls     = ServerListParameters.Uris[region];
            var slsPort = Configuration.ServerListPort;

            if (slsPort == 0)
            {
                slsPort = sls.Port;
            }

            var slsHost    = sls.Host;
            var slsAddress = Configuration.ServerListBaseAddress;

            hosts?.RemoveEntry(slsHost, slsAddress);

            var real = Dns.GetHostEntry(slsHost).AddressList[0];

            _log.Info("Resolved {0} server list address: {1} -> {2}", region, slsHost, real);

            hosts?.AddEntry(slsHost, slsAddress);

            var slsProxy = new ServerListProxy(new ServerListParameters(real,
                                                                        Configuration.ServerListBaseAddress, slsPort, Configuration.GameBaseAddress,
                                                                        Configuration.GameBasePort, region, Configuration.ServerListTimeout,
                                                                        Configuration.ServerListRetries));

            var pool = new ObjectPool <SocketAsyncEventArgs>(() => new SocketAsyncEventArgs(),
                                                             x => x.Reset(), Configuration.PoolLimit != 0 ? (int?)Configuration.PoolLimit : null);
            var version    = DataCenter.ClientVersions[region];
            var serializer = new CompilerPacketSerializer(region, new GameMessageTable(version),
                                                          new SystemMessageTable(version));
            var proxies = slsProxy.Servers.Select(x => new GameProxy(x, pool, serializer,
                                                                     Configuration.GameBacklog, Configuration.GameMaxClients, Configuration.GameTimeout))
                          .ToArray();

            var path = Path.ChangeExtension(Path.Combine(Configuration.AssetDirectory,
                                                         DataCenter.FileNames[region]), DataCenter.UnpackedExtension);

            using var file = File.Exists(path) ? File.OpenRead(path) : null;
            var dc = file == null ? new DataCenter(version) : new DataCenter(file,
                                                                             Configuration.DataCenterMode, Configuration.DataCenterStringOptions);
            var loader = new PluginLoader(new PluginContext(region, dc, proxies),
                                          Configuration.PluginDirectory, Configuration.PluginPattern, Configuration.DisablePlugins);

            loader.Start();

            if (Configuration.ServerListEnabled)
            {
                slsProxy.Start();
            }

            foreach (var proxy in proxies)
            {
                proxy.Start();
            }

            _log.Basic("{0} proxy server started", region);

            return(new ServerInstance(slsProxy, loader, proxies));
        }