BF2Statistics.Gamespy.MasterServer.ValidateServer C# (CSharp) Method

ValidateServer() private method

When a server sends data initially, it needs to be validated with a validation code. Once that has happened, this method is called, and it allows the server to be seen in the Serverlist. This method also corrects local IP addresses by converting them to External IP addresses, so that external clients get a good IP to connect to.
private ValidateServer ( IPEndPoint remote ) : bool
remote System.Net.IPEndPoint The remote IP of the server
return bool
        private bool ValidateServer(IPEndPoint remote)
        {
            string key = String.Format("{0}:{1}", remote.Address, remote.Port);
            GameServer server;

            // try to fetch the existing server, if its not here... we have bigger problems
            if (!Servers.TryGetValue(key, out server))
            {
                Program.ErrorLog.Write("NOTICE: [MasterServer.ValidateServer] We encountered a strange error trying to fetch a connected server.");
                return false;
            }

            // Parse our External IP Address
            IPAddress ExtAddress = IPAddress.Loopback;
            IPAddress.TryParse(Program.Config.GamespyExtAddress, out ExtAddress);
            bool ExtAddressIsLocal = Networking.IsLanIP(ExtAddress);

            // Parse Server address and see if its external or LAN
            IPAddress serverAddress = server.AddressInfo.Address;
            bool isLocalServer = Networking.IsLanIP(server.AddressInfo.Address);

            // Check to make sure we allow external servers in our list
            if (!isLocalServer && !Program.Config.GamespyAllowExtServers)
            {
                DebugLog.Write("External Server not Allowed: " + key);
                return false;
            }
            else if (isLocalServer && !ExtAddressIsLocal)
                server.AddressInfo.Address = ExtAddress;

            // Server is valid
            server.IsValidated = true;
            server.LastRefreshed = DateTime.Now;
            server.LastPing = DateTime.Now;
            server.country = (serverAddress.AddressFamily == AddressFamily.InterNetwork)
                ? Ip2nation.GetCountryCode(serverAddress).ToUpperInvariant()
                : "??";

            // Update or add the new server
            DebugLog.Write("Adding Validated Server to Serverlist: " + key);
            Servers.AddOrUpdate(key, server, (k, old) => { return server; });

            // Fire the event
            if (OnServerlistUpdate != null)
                OnServerlistUpdate(null, EventArgs.Empty);

            return true;
        }