mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-08 18:25:15 +08:00
Reconnection is directed by `BotOfflineEvent`. ### Event Broadcasting - PacketFactory `MessageSvcPushForceOffline` closes network with `ForceOfflineException`. - `network.close(cause)` pass the cause to state observer from `QQAndroidBot.stateObserverChain`, the observer broadcasts as follows: - Nothing if `cause` is `ForceOfflineException` or `BotClosedByEvent`(which is broadcast by user) - `BotOfflineEvent.Dropped` if cause is NetworkException and is recoverable(which is from Netty handlers) - `BotOfflineEvent.Force` if cause is `ForceOfflineException` is from the factory mentioned above. - `BotOfflineEvent.Active` otherwise(any other unexpected exceptions considered as an error) ### Deciding whether to reconnect User can listen and change `BotOfflineEvent.reconnect` to decide. Default values are determined by `BotConfiguration`. ### Event listening - Component `BotOfflineEventMonitor` listens `BotOfflineEvent`, logs the event for users, and launches a coroutine to do `network.resumeConnection` to notify the selector to renew an instance. - `BotOnlineWatchdog` in `SelectorNetworkHandler` is removed. - Selector now handles `maxAttempts` correctly in such a way that `awaitResumeInstance` does not throw exception until maximum attempts reached. - On every attempt, new exceptions are logged to provide debugging information, and further duplications are ignored. |
||
---|---|---|
.. | ||
src | ||
build.gradle.kts | ||
README.md |
mirai-core
mirai 核心实现模块。首先阅读 mirai-core-api/README.md。
本文仅介绍重要部分。
架构
包名 | 描述 |
---|---|
net.mamoe.mirai.internal |
mirai 核心 API 的实现 |
.contact |
联系人实现 |
.message |
消息系统的实现 |
.network |
网络层实现 |
.utils |
工具类 |
net.mamoe.mirai.internal.contact
AbstractContact
所有 Contact
实现的基类. 实现生命周期等.
SendMessageHandler
处理 mirai 消息系统 Message
到协议数据结构的转换, 并处理长消息上传, 音乐转发上传等.
net.mamoe.mirai.internal.message
ReceiveMessageTransformer
处理协议数据结构到 Message
的转换. 设有 RefinableMessage
处理长消息下载, 合并转发下载并展开等.
RefinableMessage
支持处理长消息下载, 合并转发下载并展开等.
Image
实现
图片的实现的基类为 AbstractImage
.
在底层协议, 群图片与私聊图片很不同. 因此图片实现可以是 GroupImage
或 FriendImage
.
图片又细分了 OnlineImage
和 OfflineImage
. 故有 OnlineGroupImage
等四个类型, 及他们分别的 Impl
.
OnlineImage
为通过 Contact.uploadImage
上传得到的, 或刚刚从服务器接收的图片对象. OfflineImage
则为反序列化得到的对象.
MessageSource
实现
MessageSource
在协议底层十分复杂,