Пример #1
0
        /// <summary>
        /// Checks the HOSTS file on startup, detecting existing redirects to the bf2web.gamespy
        /// or gpcm/gpsp.gamespy urls
        /// </summary>
        private void DoHOSTSCheck()
        {
            // Make sure we can read and write
            if (!HostsFile.CanRead)
            {
                UpdateStatus("- Cannot open HOSTS file for reading!");
            }
            else if (!HostsFile.CanWrite)
            {
                UpdateStatus("- Cannot open HOSTS file for writing!");
            }
            else
            {
                bool MatchFound = false;

                // Login server redirect
                if (HostsFile.HasEntry("gpcm.gamespy.com"))
                {
                    MatchFound           = true;
                    GpcmCheckbox.Checked = true;
                    GpcmAddress.Text     = HostsFile.Get("gpcm.gamespy.com");
                }

                // Stat server redirect
                if (HostsFile.HasEntry("bf2web.gamespy.com"))
                {
                    MatchFound             = true;
                    Bf2webCheckbox.Checked = true;
                    Bf2webAddress.Text     = HostsFile.Get("bf2web.gamespy.com");
                }

                // Did we find any matches?
                if (MatchFound)
                {
                    UpdateStatus("- Found old redirect data in HOSTS file.");
                    RedirectsEnabled = true;
                    LockGroups();

                    RedirectButton.Enabled = true;
                    RedirectButton.Text    = "Remove HOSTS Redirect";

                    UpdateStatus("- Locking HOSTS file");
                    HostsFile.Lock();
                    UpdateStatus("- All Done!");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Preforms the pings required to fill the dns cache, and locks the HOSTS file.
        /// The reason we ping, is because once the HOSTS file is locked, any request
        /// made to a url (when the DNS cache is empty), will skip the hosts file, because
        /// it cant be read. If we ping first, then the DNS cache fills up with the IP
        /// addresses in the hosts file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RebuildDNSCache(object sender, DoWorkEventArgs e)
        {
            // Update status window
            UdpateStatus("- Rebuilding DNS Cache... ", false);
            foreach (KeyValuePair <String, String> IP in HostsFile.GetLines())
            {
                // Cancel if we have a cancelation request
                if (HostsWorker.CancellationPending)
                {
                    UpdateStatus("Cancelled!");
                    e.Cancel = true;
                    return;
                }

                Ping      p     = new Ping();
                PingReply reply = p.Send(IP.Key);
            }
            UpdateStatus("Done");

            // Lock the hosts file
            UpdateStatus("- Locking HOSTS file");
            HostsFile.Lock();
            UpdateStatus("- All Done!");
        }