mirai/mirai-core
StageGuard 78d0b4fd54
QRCode login support & Introduce new authorization factory (#2502)
* [core] process `wtlogin.trans_emp` to support qrcode login

* [core] fix `wtlogin.trans_emp` protocol

* [core] optimize QRCodeLoginProcessor logic

* [core] fix `wtlogin.trans_emp` outgoing packet

* [core] cancel login when logging a bot which is inconsistent from bot factory

* [core] ignore `flag3` check on ANDROID_WATCH & name `flag1` and `flag2`

* [core] provide default `QRCodeLoginListener` for jvm

* [core] don't catch IllegalStateException in QRCodeLoginProcessor

* [core] Use `LoginSolver.createQRCodeLoginListener()` instead of property; Rename configuration name

* [core] Code improvement

* [core] remove qrcode state lock

* [core] ignore `flag3` when command is `wtlogin.trans_emp` in packet codec

* [core] enable qrcode login for macos

* [core] remove debug property in log

* [core] reformat code

* [core] rename `TransEmpResponse` to `Response`

* [core] assert `flag3Exception` not null first

* [core] remove arg client

* [core] update qrcode login notes

* [core] set custom qrcode size

* [core] Draft BotAuthorization

* [core] make SecretsProtection mpp

* [core] BotAuthorization.byXXX

* [core] Move QRCodeLoginListener to `.auth`

* [core] Protect data of BotAccount

* [core] Add SelectorRequireReconnectException

* [core] Implementation of BotAuthorization

* Revert changes of BotConfiguration

* api dump

* [core] remove passwordMd5 in `BotAccount`

* [mock] Add new bot factory function to mock bot factory

* Delete LoginCommandTest

* [core] Improve QRCode render

* [core] Introduce UnsupportedCaptchaMethodException & UnsupportedQRCodeCaptchaException

* api dump

* update docs

* [core] update `DebugRunHelper`

* [core] add simple block for BotAuthorization

* api dump

* Rename `canDoQRLogin` to `supportsQRLogin`, and specify argument names for MiraiProtocolInternal

* Remove `phoneNumber` parameter from BotAccount

* Make `BotAccount.<init>` with String password parameter TestOnly

* Rename `InconsistentBotException` to `InconsistentBotIdException`

* Rename `QRCodeLoginListener.onStatusChanged` to `QRCodeLoginListener.onStateChanged`

* Rename `BotAuthorizationResult` to `BotAuthResult`

* Rename BotAuthComponent, move internal APIs to internal module

* Logic fixup

* doc update

* QRCodeLoginListener.qrCodeStateUpdateInterval & onIntervalLoop

* console login with BotAuthorization

* update testing

* Update mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.jvm.kt

* Move AuthControl outside SsoProcessor

* Redesign auth

* Add initialTicket to producerCoroutine

* Revert protocol changes of MACOS

* Fix latch death locking

* Fix CoroutineOnDemandValueScope.receiveOrNull exceptional finish

* Fix exception collecting

* Fix DefaultBotAuthorizationFactory loading

* [core] qrcode login for IPAD protocol

* Revert "[core] qrcode login for IPAD protocol"

This reverts commit c1136a8798.

---------

Co-authored-by: Karlatemp <kar@kasukusakura.com>
Co-authored-by: Him188 <Him188@mamoe.net>
2023-03-18 13:52:31 +00:00
..
compatibility-validation Fix project structure for Dokka 2022-01-06 20:26:52 +00:00
src QRCode login support & Introduce new authorization factory (#2502) 2023-03-18 13:52:31 +00:00
.gitignore Implement mirai-core for native 2022-07-20 00:30:16 +08:00
build.gradle.kts Update login protocol (#2433) 2023-01-18 17:41:21 +08:00
README.md Update docs and improve source code readability 2021-05-09 15:31:50 +08:00

mirai-core

mirai 核心实现模块。首先阅读 mirai-core-api/README.md

本文仅介绍重要部分。

架构

包名 描述
net.mamoe.mirai.internal mirai 核心 API 的实现
.contact 联系人实现
.message 消息系统的实现
.network 网络层实现
.utils 工具类

net.mamoe.mirai.internal.contact

AbstractContact

AbstractContact.kt

所有 Contact 实现的基类. 实现生命周期等.

SendMessageHandler

SendMessageHandler.kt

处理 mirai 消息系统 Message 到协议数据结构的转换, 并处理长消息上传, 音乐转发上传等.

net.mamoe.mirai.internal.message

ReceiveMessageTransformer

ReceiveMessageHandler.kt

处理协议数据结构到 Message 的转换. 设有 RefinableMessage 处理长消息下载, 合并转发下载并展开等.

RefinableMessage

RefinableMessage.kt

支持处理长消息下载, 合并转发下载并展开等.

Image 实现

imagesImpl.kt

图片的实现的基类为 AbstractImage.

在底层协议, 群图片与私聊图片很不同. 因此图片实现可以是 GroupImageFriendImage.

图片又细分了 OnlineImageOfflineImage. 故有 OnlineGroupImage 等四个类型, 及他们分别的 Impl.

OnlineImage 为通过 Contact.uploadImage 上传得到的, 或刚刚从服务器接收的图片对象. OfflineImage 则为反序列化得到的对象.

MessageSource 实现

MessageSourceInternal.kt

MessageSource 在协议底层十分复杂,