예제 #1
0
        private void DoWebLogin(string verifyCode, ProcActionFuture future)
        {
            if (future.IsCanceled)
            {
                return;
            }

            var login = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            login.WebLogin(Context.Account.Username, Context.Account.Password, Context.Account.Uin,
                           verifyCode, ((sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EvtOK)
                {
                    DoCheckLoginSig((string)Event.Target, future);
                }
                else if (Event.Type == QQActionEventType.EvtError)
                {
                    var ex = (QQException)(Event.Target);
                    if (ex.ErrorCode == QQErrorCode.WrongCaptcha)
                    {
                        DoGetVerify(ex.Message, future);
                    }
                    else
                    {
                        future.NotifyActionEvent(QQActionEventType.EvtError, Event.Target);
                    }
                }
            }));
        }
예제 #2
0
        private void DoGetVerify(string reason, ProcActionFuture future)
        {
            if (future.IsCanceled)
            {
                return;
            }

            var account = Context.Account;
            var login   = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            login.GetCaptcha(account.Uin, (sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EvtOK)
                {
                    var verify = new ImageVerify()
                    {
                        Type   = ImageVerify.VerifyType.LOGIN,
                        Image  = (Image)Event.Target,
                        Reason = reason,
                        Future = future
                    };
                    Context.FireNotify(new QQNotifyEvent(QQNotifyEventType.CapachaVerify, verify));
                }
                else if (Event.Type == QQActionEventType.EvtError)
                {
                    future.NotifyActionEvent(QQActionEventType.EvtError, Event.Target);
                }
            });
        }
예제 #3
0
        private void DoCheckVerify(ProcActionFuture future)
        {
            if (future.IsCanceled)
            {
                return;
            }

            var login   = Context.GetModule <LoginModule>(QQModuleType.LOGIN);
            var account = Context.Account;

            login.CheckVerify(account.Username, (sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EvtOK)
                {
                    var args            = (CheckVerifyArgs)(Event.Target);
                    Context.Account.Uin = args.Uin;
                    if (args.Result == 0)
                    {
                        DoWebLogin(args.Code, future);
                    }
                    else
                    {
                        Context.Session.CapCd = args.Code;
                        DoGetVerify("为了保证您账号的安全,请输入验证码中字符继续登录。", future);
                    }
                }
                else if (Event.Type == QQActionEventType.EvtError)
                {
                    future.NotifyActionEvent(QQActionEventType.EvtError, Event.Target);
                }
            });
        }
예제 #4
0
        private void DoWebLogin(string verifyCode, ProcActionFuture future)
        {
            var login = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            login.WebLogin(Context.Account.Username, Context.Account.Password, Context.Account.Uin,
                           verifyCode, ((sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EVT_OK)
                {
                    DoCheckLoginSig((string)Event.Target, future);
                }
                else if (Event.Type == QQActionEventType.EVT_ERROR)
                {
                    var ex = (QQException)(Event.Target);
                    if (ex.ErrorCode == QQErrorCode.WRONG_CAPTCHA)
                    {
                        DoGetVerify(ex.Message, future);
                    }
                    else
                    {
                        future.NotifyActionEvent(QQActionEventType.EVT_ERROR, Event.Target);
                    }
                }
            }));
        }
예제 #5
0
        public IQQActionFuture Login(QQActionListener listener)
        {
            var future = new ProcActionFuture(listener, true);

            // DoGetLoginSig(future); // 这里可以直接替换成 DoCheckVerify(future);
            DoCheckVerify(future);
            return(future);
        }
예제 #6
0
        private void DoChannelLogin(ProcActionFuture future)
        {
            if (future.IsCanceled)
            {
                return;
            }

            var login = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            if (Context.Account.Status == QQStatus.OFFLINE)
            {
                Context.Account.Status = QQStatus.ONLINE;
            }

            login.ChannelLogin(Context.Account.Status, async(sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EvtOK)
                {
                    future.NotifyActionEvent(QQActionEventType.EvtOK, null);
                    Context.FireNotify(new QQNotifyEvent(QQNotifyEventType.LoginSuccess));
                    var task1 = Context.GetModule <GroupModule>(QQModuleType.GROUP).GetGroupList((s, e) =>
                    {
                        if (e.Type == QQActionEventType.EvtOK)
                        {
                            Context.Logger.LogInformation($"获取群列表成功,共{Context.Store.GroupCount}个群");
                        }
                    }).WhenFinalEvent();
                    var task2 = Context.GetModule <CategoryModule>(QQModuleType.CATEGORY).GetBuddyList((s, e) =>
                    {
                        if (e.Type == QQActionEventType.EvtOK)
                        {
                            Context.Logger.LogInformation($"获取好友列表成功,共{Context.Store.BuddyCount}个好友");
                        }
                    }).WhenFinalEvent();
                    var task3 = Context.GetModule <LoginModule>(QQModuleType.LOGIN).GetSelfInfo((s, e) =>
                    {
                        if (e.Type == QQActionEventType.EvtOK)
                        {
                            Context.Logger.LogInformation("获取个人信息成功");
                        }
                    }).WhenFinalEvent();
                    var task4 = Context.GetModule <BuddyModule>(QQModuleType.BUDDY).GetOnlineBuddy((s, e) =>
                    {
                        if (e.Type == QQActionEventType.EvtOK)
                        {
                            Context.Logger.LogInformation($"获取在线好友信息成功,共{Context.Store.GetOnlineBuddyList().Count()}个在线好友");
                        }
                    }).WhenFinalEvent();

                    await Task.WhenAll(task1, task2, task3, task4).ConfigureAwait(false);
                    DoPollMsg();
                }
                else if (Event.Type == QQActionEventType.EvtError)
                {
                    future.NotifyActionEvent(QQActionEventType.EvtError, Event.Target);
                }
            });
        }
예제 #7
0
 public QQActionFuture SendMsg(QQMsg msg, QQActionEventHandler listener)
 {
     if (msg.Type == QQMsgType.SESSION_MSG)
     {
         ProcActionFuture future   = new ProcActionFuture(listener, true);
         QQStranger       stranger = (QQStranger)msg.To;
         if (string.IsNullOrEmpty(stranger.GroupSig))
         {
             GetSessionMsgSig(stranger, new QQActionEventHandler((sender, Event) =>
             {
                 if (Event.Type == QQActionEventType.EVT_OK)
                 {
                     if (!future.IsCanceled)
                     {
                         DoSendMsg(msg, future.Listener);
                     }
                 }
                 else if (Event.Type == QQActionEventType.EVT_ERROR)
                 {
                     future.NotifyActionEvent(Event.Type, Event.Target);
                 }
             }));
         }
         return(future);
     }
     else if (msg.Type == QQMsgType.GROUP_MSG || msg.Type == QQMsgType.DISCUZ_MSG)
     {
         if (string.IsNullOrEmpty(this.Context.Session.CfaceKey))
         {
             ProcActionFuture future = new ProcActionFuture(listener, true);
             GetCFaceSig(new QQActionEventHandler((sender, Event) =>
             {
                 if (Event.Type == QQActionEventType.EVT_OK)
                 {
                     if (!future.IsCanceled)
                     {
                         DoSendMsg(msg, future.Listener);
                     }
                 }
                 else if (Event.Type == QQActionEventType.EVT_ERROR)
                 {
                     future.NotifyActionEvent(Event.Type, Event.Target);
                 }
             }));
             return(future);
         }
     }
     return(DoSendMsg(msg, listener));
 }
예제 #8
0
        private void DoGetLoginSig(ProcActionFuture future)
        {
            var login = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            login.GetLoginSig((sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EvtOK)
                {
                    DoCheckVerify(future);
                }
                else if (Event.Type == QQActionEventType.EvtError)
                {
                    future.NotifyActionEvent(QQActionEventType.EvtError, Event.Target);
                }
            });
        }
예제 #9
0
        private void DoChannelLogin(ProcActionFuture future)
        {
            var login = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            login.ChannelLogin(Context.Account.Status, (sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EVT_OK)
                {
                    future.NotifyActionEvent(QQActionEventType.EVT_OK, null);
                }
                else if (Event.Type == QQActionEventType.EVT_ERROR)
                {
                    future.NotifyActionEvent(QQActionEventType.EVT_ERROR, Event.Target);
                }
            });
        }
예제 #10
0
        private void DoCheckLoginSig(string checkSigUrl, ProcActionFuture future)
        {
            var login = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            login.CheckLoginSig(checkSigUrl, (sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EVT_OK)
                {
                    DoChannelLogin(future);
                }
                else if (Event.Type == QQActionEventType.EVT_ERROR)
                {
                    future.NotifyActionEvent(QQActionEventType.EVT_ERROR, Event.Target);
                }
            });
        }
예제 #11
0
        private void DoCheckQRCode(ProcActionFuture future)
        {
            if (future.IsCanceled)
            {
                return;
            }

            var login = Context.GetModule <LoginModule>(QQModuleType.LOGIN);
            QQActionListener handler = null;

            handler = (sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EvtOK)
                {
                    var eventArgs = (CheckQRCodeArgs)Event.Target;
                    switch (eventArgs.Status)
                    {
                    case QRCodeStatus.QRCODE_OK:
                        Context.FireNotify(new QQNotifyEvent(QQNotifyEventType.QrcodeSuccess));
                        DoCheckLoginSig(eventArgs.Msg, future);
                        break;

                    case QRCodeStatus.QRCODE_VALID:
                        Thread.Sleep(3000);
                        login.CheckQRCode(handler);
                        break;

                    case QRCodeStatus.QRCODE_AUTH:
                        Context.FireNotify(new QQNotifyEvent(QQNotifyEventType.QrcodeAuth, eventArgs.Msg));
                        login.CheckQRCode(handler);
                        break;

                    case QRCodeStatus.QRCODE_INVALID:
                        Context.FireNotify(new QQNotifyEvent(QQNotifyEventType.QrcodeInvalid, eventArgs.Msg));
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else if (Event.Type == QQActionEventType.EvtError)
                {
                    future.NotifyActionEvent(QQActionEventType.EvtError, Event.Target);
                }
            };
            login.CheckQRCode(handler);
        }
예제 #12
0
        public QQActionFuture CheckQRCode(QQActionEventHandler listener)
        {
            var future = new ProcActionFuture(listener, true);
            var login  = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            login.CheckQRCode((sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EVT_OK)
                {
                    DoCheckLoginSig(Event.Target as string, future);
                }
                else if (Event.Type == QQActionEventType.EVT_ERROR)
                {
                    future.NotifyActionEvent(QQActionEventType.EVT_ERROR, Event.Target);
                }
            });
            return(future);
        }
예제 #13
0
        private void DoGetVFWebqq(ProcActionFuture future)
        {
            if (future.IsCanceled)
            {
                return;
            }

            var login = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            login.GetVFWebqq((sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EvtOK)
                {
                    DoChannelLogin(future);
                }
                else if (Event.Type == QQActionEventType.EvtError)
                {
                    future.NotifyActionEvent(QQActionEventType.EvtError, Event.Target);
                }
            });
        }
예제 #14
0
        public IQQActionFuture LoginWithQRCode(QQActionListener listener)
        {
            var future = new ProcActionFuture(listener, true);
            var login  = Context.GetModule <LoginModule>(QQModuleType.LOGIN);

            login.GetQRCode((sender, @event) =>
            {
                if (@event.Type == QQActionEventType.EvtOK)
                {
                    var verify = (Image)@event.Target;
                    Context.FireNotify(new QQNotifyEvent(QQNotifyEventType.QrcodeReady, verify));
                    DoCheckQRCode(future);
                    // future.NotifyActionEvent(QQActionEventType.EvtOK, @event.Target);
                }
                else if (@event.Type == QQActionEventType.EvtError)
                {
                    future.NotifyActionEvent(QQActionEventType.EvtError, @event.Target);
                }
            });
            return(future);
        }
예제 #15
0
        public IQQActionFuture SendMsg(QQMsg msg, QQActionListener listener)
        {
            var future = new ProcActionFuture(listener, true);

            if (msg.Type == QQMsgType.SESSION_MSG)
            {
                var stranger = (QQStranger)msg.To;
                if (string.IsNullOrEmpty(stranger.GroupSig))
                {
                    GetSessionMsgSig(stranger, (sender, Event) =>
                    {
                        if (Event.Type == QQActionEventType.EvtOK)
                        {
                            DoSendMsg(msg, future.Listener);
                        }
                        else if (Event.Type == QQActionEventType.EvtError)
                        {
                            future.NotifyActionEvent(Event.Type, Event.Target);
                        }
                    });
                }
                return(future);
            }
            else if (msg.Type == QQMsgType.GROUP_MSG || msg.Type == QQMsgType.DISCUZ_MSG)
            {
                if (msg.Type == QQMsgType.GROUP_MSG)
                {
                    if (msg.Group.Gin == 0)
                    {
                        msg.Group = Context.Store.GetGroupByCode(msg.Group.Code);
                        return(future);
                    }
                }
            }
            return(DoSendMsg(msg, listener));
        }
예제 #16
0
 public IQQActionFuture LoginWithVerify(string verifyCode, ProcActionFuture future)
 {
     DoWebLogin(verifyCode, future);
     return(future);
 }