⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 presence.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Imps.Client.Core
{
    using Imps.Client;
    using Imps.Client.Resource;
    using Imps.Common;
    using Imps.Utils;
    using System;
    using System.Collections.Generic;
    using System.Xml;

    public abstract class Presence : PropertyDictionary
    {
        private DateTime _crbtUpdateTime;
        private List<string> _deviceCapsList = new List<string>();
        protected static readonly int[] _knownValues;
        private int _lastValue;
        private int _realValue = -1;
        private int _smsTickCount;
        private object _syncObjSmsStatus = new object();
        private const int TIMESPAN = 600;

        static Presence()
        {
            List<int> list = new List<int>((int[]) Enum.GetValues(typeof(Imps.Common.MainPresence)));
            list.Remove(-1);
            list.Sort();
            _knownValues = list.ToArray();
        }

        protected Presence(Imps.Common.MainPresence presence, string moodPhrase)
        {
            this.Value = (int) new ProposedData<int>((int) presence);
            this.SmsStatus = new ProposedData<TimeSpan>(TimeSpan.Zero);
        }

        public static int AdjustContactPresence(int presenceValue)
        {
            int validPresence = (presenceValue > 0) ? presenceValue : 0;
            validPresence = GetValidPresence(validPresence);
            if ((validPresence != 0x383) && (validPresence != 1))
            {
                return validPresence;
            }
            return 0;
        }

        internal override void Clear()
        {
            base.SuspendUpdate();
            base.Clear();
            this._realValue = -1;
            this.Value = 1;
            this.SmsStatus = new ProposedData<TimeSpan>(TimeSpan.Zero);
            base.ResumeUpdate();
        }

        public static int GetServerPresence(int localPresence)
        {
            return AdjustContactPresence(localPresence);
        }

        protected static int GetValidPresence(int presenceValue)
        {
            int num = (presenceValue > 0) ? presenceValue : 0;
            int index = _knownValues.Length;
            while (index-- > 0)
            {
                if (_knownValues[index] <= num)
                {
                    return _knownValues[index];
                }
            }
            return num;
        }

        internal void LoadCrbtXmlNode(XmlNode crbtNode)
        {
            foreach (XmlNode node in crbtNode.ChildNodes)
            {
                if (node.Name == "tone")
                {
                    CrbtToBuddy buddy = new CrbtToBuddy();
                    buddy.TryLoadXmlNode(node);
                    this.CrbtToMe = buddy;
                }
            }
        }

        internal virtual void LoadXmlNode(XmlNode presenceNode)
        {
            if (presenceNode != null)
            {
                Suspender suspender = new Suspender(this);
                try
                {
                    XmlNode node = presenceNode.SelectSingleNode("basic");
                    if (node != null)
                    {
                        XmlAttribute attribute = node.Attributes["value"];
                        if (attribute != null)
                        {
                            this.RealValue = Convert.ToInt32(attribute.Value);
                        }
                        XmlAttribute attribute2 = node.Attributes["desc"];
                        if (attribute2 != null)
                        {
                            this.PresenceDesc = attribute2.Value;
                        }
                        else if (attribute != null)
                        {
                            this.PresenceDesc = string.Empty;
                        }
                        attribute2 = node.Attributes["device-id"];
                        if (attribute2 != null)
                        {
                            this.DeviceId = attribute2.Value;
                        }
                        attribute2 = node.Attributes["device-type"];
                        if (attribute2 != null)
                        {
                            this.ClientType = attribute2.Value;
                        }
                        attribute2 = node.Attributes["device-caps"];
                        if (attribute2 != null)
                        {
                            this.DeviceCaps = attribute2.Value;
                        }
                    }
                    foreach (XmlNode node2 in presenceNode.SelectNodes("extended"))
                    {
                        switch (XmlHelper.ReadXmlAttributeString(node2, "type"))
                        {
                            case "sms":
                            {
                                TimeSpan val;
                                if (TimeSpan.TryParse(node2.InnerText, ref val))
                                {
                                    this.SmsStatus = new ProposedData<TimeSpan>(val);
                                }
                                continue;
                            }
                            case "mobile-device-status":
                            {
                                XmlNode node3 = node2.SelectSingleNode("mobile-device-status");
                                if (node3 != null)
                                {
                                    this.PhoneStatus = XmlHelper.ReadXmlAttributeEnum<Imps.Common.PhoneStatus>(node3, "value", Imps.Common.PhoneStatus.Unknown);
                                }
                                continue;
                            }
                            case "listening":
                            {
                                this.Listening = new ProposedData<string>(node2.InnerXml);
                                continue;
                            }
                            case "location":
                            {
                                LocationPresence presence = new LocationPresence();
                                presence.LoadXmlNode(node2);
                                this.Location = presence;
                                continue;
                            }
                            case "ring-back-tone":
                                break;

                            default:
                            {
                                continue;
                            }
                        }
                        this.LoadCrbtXmlNode(node2);
                    }
                }
                finally
                {
                    suspender.Dispose();
                }
            }
        }

        internal void SetSmsOnline_Tick(object sender, EventArgs e)
        {
            int tickCount = Environment.TickCount;
            TimeSpan val = this.SmsStatus.OriginalValue.Subtract(new TimeSpan((tickCount - this._smsTickCount) * 0x2710));
            this.SmsStatus = new ProposedData<TimeSpan>(val);
            this._smsTickCount = tickCount;
        }

        internal virtual void UpdateValue()
        {
            this.Value = AdjustContactPresence(this.RealValue);
        }

        public string ClientType
        {
            get
            {
                return base.InnerGetPropertyValue<string>("device-type");
            }
            internal set
            {
                base.InnerSetPropertyValue<string>("device-type", value);
            }
        }

        public Crbt CrbtToMe
        {
            get
            {
                return base.InnerGetPropertyValue<Crbt>("crbt-to-me");
            }
            internal set
            {
                base.InnerSetPropertyValue<Crbt>("crbt-to-me", value);
            }
        }

        public DateTime CrbtUpdateTime
        {
            get
            {
                return this._crbtUpdateTime;
            }
            set
            {
                this._crbtUpdateTime = value;
            }
        }

        public string DeviceCaps
        {
            get
            {
                return base.InnerGetPropertyValue<string>("device-caps");
            }
            internal set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    this._deviceCapsList.Clear();
                    foreach (string text in value.Split(new char[] { ';', ',' }))
                    {
                        this._deviceCapsList.Add(text.ToLower());
                    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -