/// <summary> /// 轮询新消息,发送心跳包,也就是挂qq /// </summary> public void DoPollMsg() { Context.Logger.LogInformation("begin to poll..."); var login = Context.GetModule <LoginModule>(QQModuleType.LOGIN); _pollFuture = login.PollMsg((sender, Event) => { // 回调通知事件函数 if (Event.Type == QQActionEventType.EvtOK) { var events = (List <QQNotifyEvent>)Event.Target; foreach (var evt in events) { Context.FireNotify(evt); } // 准备提交下次poll请求 var session = Context.Session; if (session.State == QQSessionState.Online) { DoPollMsg(); return; } else if (session.State != QQSessionState.Kicked) { Relogin(); return; } } else if (Event.Type == QQActionEventType.EvtError) { var ex = (QQException)Event.Target; var code = ex.ErrorCode; if (code == QQErrorCode.IOTimeout) { DoPollMsg(); return; // 心跳超时是正常的 } //因为自带了错误重试机制,如果出现了错误回调,表明已经超时多次均失败,这里直接返回网络错误的异常 var session = Context.Session; var account = Context.Account; session.State = QQSessionState.Offline; switch (code) { case QQErrorCode.NeedToLogin: { DoGetVFWebqq(new ProcActionFuture(null, true)); return; } case QQErrorCode.InvalidLoginAuth: { Relogin(); return; } case QQErrorCode.IOError: case QQErrorCode.IOTimeout: case QQErrorCode.InvalidResponse: { account.Status = QQStatus.OFFLINE; //粗线了IO异常,直接报网络错误 Context.FireNotify(new QQNotifyEvent(QQNotifyEventType.NetError, ex)); return; } default: { Context.Logger.LogInformation("poll msg unexpected error, ignore it ...", ex); Relogin(); return; } } } else if (Event.Type == QQActionEventType.EvtRetry) { // System.err.println("Poll Retry:" + this); Context.Logger.LogInformation("poll msg error, retrying....", (QQException)Event.Target); } }); }
/// <summary> /// 轮询新消息,发送心跳包,也就是挂qq /// </summary> public void DoPollMsg() { Context.Logger.LogInformation("begin to poll..."); var login = Context.GetModule<LoginModule>(QQModuleType.LOGIN); _pollFuture = login.PollMsg((sender, Event) => { // 回调通知事件函数 if (Event.Type == QQActionEventType.EvtOK) { var events = (List<QQNotifyEvent>)Event.Target; foreach (var evt in events) { Context.FireNotify(evt); } // 准备提交下次poll请求 var session = Context.Session; if (session.State == QQSessionState.Online) { DoPollMsg(); return; } else if (session.State != QQSessionState.Kicked) { Relogin(); return; } } else if (Event.Type == QQActionEventType.EvtError) { var ex = (QQException)Event.Target; var code = ex.ErrorCode; if (code == QQErrorCode.IOTimeout) { DoPollMsg(); return; // 心跳超时是正常的 } //因为自带了错误重试机制,如果出现了错误回调,表明已经超时多次均失败,这里直接返回网络错误的异常 var session = Context.Session; var account = Context.Account; session.State = QQSessionState.Offline; switch (code) { case QQErrorCode.NeedToLogin: { DoGetVFWebqq(new ProcActionFuture(null, true)); return; } case QQErrorCode.InvalidLoginAuth: { Relogin(); return; } case QQErrorCode.IOError: case QQErrorCode.IOTimeout: case QQErrorCode.InvalidResponse: { account.Status = QQStatus.OFFLINE; //粗线了IO异常,直接报网络错误 Context.FireNotify(new QQNotifyEvent(QQNotifyEventType.NetError, ex)); return; } default: { Context.Logger.LogInformation("poll msg unexpected error, ignore it ...", ex); Relogin(); return; } } } else if (Event.Type == QQActionEventType.EvtRetry) { // System.err.println("Poll Retry:" + this); Context.Logger.LogInformation("poll msg error, retrying....", (QQException)Event.Target); } }); }