Example #1
0
        public static string Whois(string user, Server server, FormatStyle style)
        {
            WhoisResult whois = XML.GetWhois(user, server);

            if (whois == null || !whois.Success)
            {
                return(UppercaseFirst(user));
            }
            else
            {
                return(Whois(whois, style));
            }
        }
Example #2
0
        private static WhoisResult GetCachedWhois(string character, Server server, bool ignoreDate)
        {
            character = character.ToLower();
            WhoisResult result = null;

            try
            {
                string path = XmlCachePath + Path.DirectorySeparatorChar + WhoisPath;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string file = path + Path.DirectorySeparatorChar + (int)server + "." + character + ".xml";
                if (File.Exists(file))
                {
                    TimeSpan time = DateTime.Now - File.GetLastWriteTime(file);
                    if (time.TotalHours > CacheDuration && ignoreDate == false)
                    {
                        return(null);
                    }

                    FileStream   stream = null;
                    StreamReader reader = null;
                    try
                    {
                        stream = File.OpenRead(file);
                        reader = new StreamReader((Stream)stream);
                        string xml = reader.ReadToEnd();
                        result = ParseWhois(xml);
                    }
                    catch { }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                            reader.Dispose();
                        }
                        if (stream != null)
                        {
                            stream.Close();
                            stream.Dispose();
                        }
                    }
                }
            }
            catch { }
            return(result);
        }
Example #3
0
        private static string WhoisToXml(WhoisResult whois)
        {
            string       xml    = null;
            MemoryStream stream = null;

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(WhoisResult));
                stream = new MemoryStream();
                serializer.Serialize(stream, whois);
                xml = Encoding.UTF8.GetString(stream.ToArray());
            }
            catch { }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
            }
            return(xml);
        }
Example #4
0
        public static string Whois(WhoisResult whois, FormatStyle style)
        {
            if (whois == null || !whois.Success)
            {
                return(null);
            }

            string result = whois.Name.Nickname;

            switch (style)
            {
            case FormatStyle.Small:
                result += string.Format(" (L {0}/{1} {2})", whois.Stats.Level, whois.Stats.DefenderLevel, whois.Stats.Profession);
                break;

            case FormatStyle.Compact:
                result += string.Format(" (L {0}/{1} {2} {3})", whois.Stats.Level, whois.Stats.DefenderLevel, whois.Stats.Faction, whois.Stats.Profession);
                break;

            case FormatStyle.Medium:
                result += string.Format(" (Level {0}/{1} {2} {3})", whois.Stats.Level, whois.Stats.DefenderLevel, whois.Stats.Faction, whois.Stats.Profession);
                if (whois.InOrganization)
                {
                    result += string.Format(" {0} of {1}", whois.Organization.Rank, whois.Organization.Name);
                }
                break;

            case FormatStyle.Large:
                result += string.Format(" (Level {0} / Defender Rank {1}) {2} {3} {4}", whois.Stats.Level, whois.Stats.DefenderLevel, whois.Stats.Faction, whois.Stats.Breed, whois.Stats.Profession);
                if (whois.InOrganization)
                {
                    result += string.Format(", {0} of {1}", whois.Organization.Rank, whois.Organization.Name);
                }
                break;
            }
            return(result);
        }
Example #5
0
        public static WhoisResult ParseWhois(string xml)
        {
            MemoryStream stream = null;

            try
            {
                stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
                XmlSerializer serializer = new XmlSerializer(typeof(WhoisResult));
                WhoisResult   result     = (WhoisResult)serializer.Deserialize(stream);
                stream.Close();
                stream.Dispose();
                return(result);
            }
            catch { }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
            }
            return(null);
        }
Example #6
0
        private static void SetCachedOrganization(OrganizationResult organization, Server server)
        {
            if (organization.ID < 1)
            {
                return;
            }
            if (organization.Name == null || organization.Name == string.Empty)
            {
                return;
            }
            if (organization.Members == null || organization.Members.Items == null || organization.Members.Items.Length == 0)
            {
                return;
            }

            OrganizationCache cache = new OrganizationCache();

            cache.FromOrganizationResult(organization);
            string xml = OrganizationCacheToXml(cache);

            if (xml == null || xml == String.Empty)
            {
                return;
            }

            FileStream   stream = null;
            StreamWriter writer = null;

            try
            {
                string path = XmlCachePath + Path.DirectorySeparatorChar + OrganizationPath;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string file = path + Path.DirectorySeparatorChar + (int)server + "." + organization.ID + ".xml";
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                stream = File.Create(file);
                writer = new StreamWriter((Stream)stream);
                writer.Write(xml);

                foreach (OrganizationMember member in organization.Members.Items)
                {
                    WhoisResult whois = member.ToWhoisResult(organization);
                    SetCachedWhois(whois, server);
                }
            }
            catch { }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                    writer.Dispose();
                }
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
            }
        }
Example #7
0
        internal static WhoisResult GetWhois(string character, Server server, bool readCache, bool writeCache, bool shutup)
        {
            if (server == Server.Test)
            {
                return(null);
            }

            WhoisResult result = null;

            character = character.ToLower();
            if (readCache)
            {
                result = GetCachedWhois(character, server, false);
                if (result != null)
                {
                    if (!shutup)
                    {
                        Output("Retrieved {0}@{1} from whois cache", character, server.ToString());
                    }
                    return(result);
                }
            }

            result = GetWhois(String.Format(URL_OfficialWhois, character, (int)server), 15000);
            if (result != null)
            {
                if (writeCache)
                {
                    SetCachedWhois(result, server);
                }
                if (!shutup)
                {
                    Output("Retrieved {0}@{1} from funcom's whois server", character, server.ToString());
                }
                return(result);
            }

            result = GetWhois(String.Format(URL_AunoWhois, character, (int)server), 35000);
            if (result != null)
            {
                if (writeCache)
                {
                    SetCachedWhois(result, server);
                }
                if (!shutup)
                {
                    Output("Retrieved {0}@{1} from auno's whois server", character, server.ToString());
                }
                return(result);
            }

            if (readCache)
            {
                result = GetCachedWhois(character, server, true);
                if (!shutup && result != null && result.Success)
                {
                    Output("Retrieved {0}@{1} from old whois cache", character, server.ToString());
                }
                else
                {
                    Output("Unable to retrieve whois data for {0}@{1}", character, server.ToString());
                }
                return(result);
            }
            else
            {
                if (!shutup)
                {
                    Output("Unable to retrieve whois data for {0}@{1}", character, server.ToString());
                }
                return(null);
            }
        }
Example #8
0
        private static void SetCachedWhois(WhoisResult whois, Server server)
        {
            if (whois == null)
            {
                return;
            }
            if (whois.Name == null)
            {
                return;
            }
            if (whois.Name.Nickname == null)
            {
                return;
            }
            if (whois.Stats == null)
            {
                return;
            }
            if (whois.Stats.Level == 0)
            {
                return;
            }
            if (whois.Stats.Profession == null)
            {
                return;
            }

            string xml = WhoisToXml(whois);

            if (xml == null || xml == String.Empty)
            {
                return;
            }

            FileStream   stream = null;
            StreamWriter writer = null;

            try
            {
                string path = XmlCachePath + Path.DirectorySeparatorChar + WhoisPath;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string file = path + Path.DirectorySeparatorChar + (int)server + "." + whois.Name.Nickname.ToLower() + ".xml";
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                stream = File.Create(file);
                writer = new StreamWriter((Stream)stream);
                writer.Write(xml);
            }
            catch { }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                    writer.Dispose();
                }
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
            }
        }