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

📄 loginframework.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace Imps.Client.Core
{
    using Imps.Client;
    using Imps.Client.Core.Login;
    using Imps.Client.Resource;
    using Imps.Client.Utils;
    using Imps.Common;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Threading;

    public sealed class LoginFramework
    {
        private readonly ILoginListner _listener;
        private readonly Imps.Client.Core.User _user;
        private List<LoginAction> actions = new List<LoginAction>();
        private SipCTunnelAction sipcTunnelAction;

        internal LoginFramework(Imps.Client.Core.User user)
        {
            if (user == null)
            {
                throw new NullReferenceException("user should not be null!");
            }
            this._user = user;
            this._user.IsRetryPreLoggin = false;
            this._listener = new ImpsLogListner(this._user);
            this._user.LoginListner = this._listener;
        }

        private void CheckConnectionState()
        {
            if ((this.GetCurrentLoginPresence() != MainPresence.OfflineLogin) && ((this.sipcTunnelAction == null) || this.sipcTunnelAction.ConnectionBroken))
            {
                throw new Exception("SipC连接已断开");
            }
        }

        private void ClearActions()
        {
            if (this.actions != null)
            {
                List<LoginAction>.Enumerator enumerator = this.actions.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        LoginAction action = enumerator.get_Current();
                        if (action != null)
                        {
                            action.Clear();
                        }
                    }
                }
                finally
                {
                    enumerator.Dispose();
                }
            }
        }

        private void DoLogin()
        {
            this.InitActions();
            List<LoginAction> actions = new List<LoginAction>();
            this._listener.SuspendNotify();
            for (int i = 0; i < this.actions.get_Count(); i++)
            {
                if (this.actions.get_Item(i).LocalCacheHit)
                {
                    actions.Add(this.actions.get_Item(i));
                }
                else
                {
                    if (!this.actions.get_Item(i).Execute())
                    {
                        break;
                    }
                    this.CheckConnectionState();
                }
            }
            Thread.Sleep(0x3e8);
            this._listener.ResumeNotify();
            if (this._user.Status != UserAccountStatus.Logon)
            {
                this._listener.NotifyMessage(LoginStage.Unknown, "首次登录失败,开始执行重试。");
                this._user.Status = UserAccountStatus.Loginning;
                this._user.IsRetryPreLoggin = true;
                this.InitActions();
                if (this._user.Status != UserAccountStatus.Logon)
                {
                    for (int j = 0; j < this.actions.get_Count(); j++)
                    {
                        if (!this.actions.get_Item(j).Execute())
                        {
                            break;
                        }
                        this.CheckConnectionState();
                    }
                }
            }
            if (this._user.Status == UserAccountStatus.Logon)
            {
                actions.Sort();
                for (int k = 0; k < actions.get_Count(); k++)
                {
                    if (this._user.Status != UserAccountStatus.Logon)
                    {
                        break;
                    }
                    actions.get_Item(k).PostLoginExecute();
                }
            }
            this._user.Configuration.SaveAll();
            try
            {
                GC.Collect();
            }
            catch
            {
            }
            try
            {
                if (this._user.Status == UserAccountStatus.Logon)
                {
                    new RetryAction(this._listener, actions).Run();
                }
            }
            catch
            {
            }
        }

        private void DoOfflineLogin()
        {
            this.InitActions();
            this._listener.ResumeNotify();
            long sid = this._user.Sid;
            if ((sid <= 0) && !string.IsNullOrEmpty(this._user.MobileNo))
            {
                sid = UserAccounts.GetMappedSid(this._user.MobileNo);
            }
            for (int i = 0; i < this.actions.get_Count(); i++)
            {
                this._user.Sid = sid;
                if (!this.actions.get_Item(i).LocalCacheHit)
                {
                    this._listener.NotifyLoginFailed(LoginStage.Unknown, string.Format("离线登录失败, {0}", this.actions.get_Item(i).LoginStage), new LoginException("离线登录失败"));
                }
            }
            this._user.Status = UserAccountStatus.OfflineLogon;
            this._user.Presence.RealValue = -100;
            UserAccounts.TrySaveLastestAccount(true);
        }

        private LoginAction GetAction(LoginStage stage)
        {
            LoginAction action = null;
            LoginStage stage2 = stage;
            if (stage2 <= LoginStage.GetContactsInfo)
            {
                switch (stage2)
                {
                    case LoginStage.RetriveSystemConfig:
                        return new NavAction(this._user, this._listener);

                    case LoginStage.LoginToSSIPortal:
                        return new SSIAuthAction(this._user, this._listener);

                    case LoginStage.RetriveUri:
                        return new GetUriAction(this._user, this._listener);

                    case LoginStage.ConnectToSipc:
                        return new SipCTunnelAction(this._user, this._listener);

                    case LoginStage.SipcRegister:
                        return new SipCRegAction(this._user, this._listener);

                    case LoginStage.SipcAuth:
                    case ((LoginStage) 0x3ee):
                    case ((LoginStage) 0x3ef):
                    case ((LoginStage) 0x3f0):
                    case ((LoginStage) 0x3f1):
                    case ((LoginStage) 0x3f3):
                    case ((LoginStage) 0x3f4):
                    case ((LoginStage) 0x3f8):
                    case ((LoginStage) 0x3fa):
                    case ((LoginStage) 0x3fb):
                        return action;

                    case LoginStage.RetrivePersonalInfo:
                        return new PersonalInfoAction(this._user, this._listener);

                    case LoginStage.GetScore:
                        return new GetScoreAction(this._user, this._listener);

                    case LoginStage.GetMobilEmailInfo:
                        return new GetMobilMailInfoAction(this._user, this._listener);

                    case LoginStage.GetContactsList:
                        return new ContactListAction(this._user, this._listener);

                    case LoginStage.GetPermission:
                        return new PermissionAction(this._user, this._listener);

                    case LoginStage.SubscribePresence:
                        return new SubscribePresenceAction(this._user, this._listener);

                    case LoginStage.GetContactsInfo:
                        return new ContactInfoCardAction(this._user, this._listener);
                }
                return action;
            }
            if (stage2 != LoginStage.ChangePresence)
            {
                if (stage2 == LoginStage.GetOfflineMessage)
                {
                    return new GetOfflineMessageAction(this._user, this._listener);
                }
                if (stage2 != LoginStage.DownloadPortrait)
                {
                    return action;
                }
            }
            else
            {
                return new ChangePresenceAction(this._user, this._listener);
            }
            return new PortraitAction(this._user, this._listener);
        }

        private MainPresence GetCurrentLoginPresence()
        {
            return GetCurrentLoginPresence(this._user);
        }

        public static MainPresence GetCurrentLoginPresence(Imps.Client.Core.User user)
        {
            MainPresence initPresence = user.InitPresence;
            if ((user._lastPresence != null) && user._lastPresence.IsForCurrentUser(user))
            {
                initPresence = user._lastPresence._presence;
            }
            return initPresence;
        }

        private void InitActions()
        {
            this.actions.Clear();
            this.actions.Add(this.GetAction(LoginStage.RetriveSystemConfig));
            if (this.GetCurrentLoginPresence() != MainPresence.OfflineLogin)
            {
                this.actions.Add(this.GetAction(LoginStage.LoginToSSIPortal));
                this.sipcTunnelAction = this.GetAction(LoginStage.ConnectToSipc);
                this.actions.Add(this.sipcTunnelAction);
            }
            if (this.GetCurrentLoginPresence() == MainPresence.OfflineLogin)
            {
                this.actions.Add(this.GetAction(LoginStage.RetriveUri));
            }
            this.actions.Add(this.GetAction(LoginStage.RetrivePersonalInfo));
            this.actions.Add(this.GetAction(LoginStage.GetScore));
            this.actions.Add(this.GetAction(LoginStage.GetMobilEmailInfo));
            this.actions.Add(this.GetAction(LoginStage.GetContactsList));
            this.actions.Add(this.GetAction(LoginStage.GetPermission));
            if (this.GetCurrentLoginPresence() != MainPresence.OfflineLogin)
            {
                this.actions.Add(this.GetAction(LoginStage.ChangePresence));
            }
            this.actions.Add(this.GetAction(LoginStage.SubscribePresence));
            this.actions.Add(this.GetAction(LoginStage.GetContactsInfo));
            this.actions.Add(this.GetAction(LoginStage.GetOfflineMessage));
            this.actions.Add(this.GetAction(LoginStage.DownloadPortrait));
            this.ClearActions();
            this.RestoreUserAccountInfo();
        }

        public void Login()
        {
            this._user.LoginStep = StringTable.User.StepSigning;
            try
            {
                if (this.GetCurrentLoginPresence() == MainPresence.OfflineLogin)
                {
                    Trace.WriteLine("Offline login.");
                    this.DoOfflineLogin();
                }
                else
                {
                    Trace.WriteLine("Normal login.");
                    this.DoLogin();
                }
            }
            catch (ThreadAbortException exception)
            {
                ClientLogger.WriteGeneral("登录线程被终止", exception.ToString(), 10);
            }
            catch (Exception exception2)
            {
                this._listener.NotifyException(LoginStage.Unknown, "执行登录操作过程中出现错误", exception2);
            }
        }

        private void RestoreUserAccountInfo()
        {
            switch (this._user.CurrentAccount.AccountType)
            {
                case UserAccounts.AccountType.SID:
                    long num;
                    if (!long.TryParse(this._user.CurrentAccount.Id, ref num))
                    {
                        break;
                    }
                    this._user.Sid = num;
                    return;

                case UserAccounts.AccountType.MobileNo:
                    this._user.PersonalInfo.MobileNo = this._user.CurrentAccount.Id;
                    break;

                default:
                    return;
            }
        }
    }
}

⌨️ 快捷键说明

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