diff --git a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt index 87003c842..4b8951683 100644 --- a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt +++ b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt @@ -559,7 +559,12 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { } } // bot.network.logger.error(rep) - return bot.json.decodeFromString(GroupAnnouncementList.serializer(), rep) + return json.decodeFromString(GroupAnnouncementList.serializer(), rep) + } + + private val json = Json { + ignoreUnknownKeys = true + isLenient = true } @LowLevelApi diff --git a/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt b/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt index 4738ff6b3..8b181661f 100644 --- a/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt +++ b/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt @@ -81,7 +81,7 @@ internal class QQAndroidBot constructor( // TODO: 2021/4/14 bdhSyncer.loadFromCache() when login - private val components: ConcurrentComponentStorage by lazy { + internal val components: ConcurrentComponentStorage by lazy { ConcurrentComponentStorage().apply { set( SsoProcessor, diff --git a/mirai-core/src/commonMain/kotlin/network/highway/Highway.kt b/mirai-core/src/commonMain/kotlin/network/highway/Highway.kt index e3d285032..3ab53299c 100644 --- a/mirai-core/src/commonMain/kotlin/network/highway/Highway.kt +++ b/mirai-core/src/commonMain/kotlin/network/highway/Highway.kt @@ -21,7 +21,9 @@ import kotlinx.io.core.buildPacket import kotlinx.io.core.discardExact import kotlinx.io.core.writeFully import net.mamoe.mirai.internal.QQAndroidBot +import net.mamoe.mirai.internal.asQQAndroidBot import net.mamoe.mirai.internal.network.QQAndroidClient +import net.mamoe.mirai.internal.network.handler.components.BdhSessionSyncer import net.mamoe.mirai.internal.network.handler.context.BdhSession import net.mamoe.mirai.internal.network.handler.logger import net.mamoe.mirai.internal.network.protocol.data.proto.CSDataHighwayHead @@ -71,7 +73,7 @@ internal object Highway { localeId: Int = 2052, ): BdhUploadResponse { val bdhSession = kotlin.runCatching { - val deferred = bot.bdhSyncer.bdhSession + val deferred = bot.asQQAndroidBot().components[BdhSessionSyncer].bdhSession // no need to care about timeout. proceed by bot init @OptIn(ExperimentalCoroutinesApi::class) if (noBdhAwait) deferred.getCompleted() else deferred.await() diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/ConfigPushSvc.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/ConfigPushSvc.kt index 9c0e5520c..b1e9a5066 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/ConfigPushSvc.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/ConfigPushSvc.kt @@ -19,7 +19,9 @@ import net.mamoe.mirai.event.events.BotOfflineEvent import net.mamoe.mirai.internal.QQAndroidBot import net.mamoe.mirai.internal.message.contextualBugReportException import net.mamoe.mirai.internal.network.Packet +import net.mamoe.mirai.internal.network.handler.components.BdhSessionSyncer import net.mamoe.mirai.internal.network.handler.components.ServerAddress +import net.mamoe.mirai.internal.network.handler.components.ServerList import net.mamoe.mirai.internal.network.handler.context.BdhSession import net.mamoe.mirai.internal.network.handler.logger import net.mamoe.mirai.internal.network.networkType @@ -87,6 +89,8 @@ internal class ConfigPushSvc { } override suspend fun QQAndroidBot.handle(packet: PushReqResponse, sequenceId: Int): OutgoingPacket? { + val bdhSyncer = bot.components[BdhSessionSyncer] + fun handleConfigPush(packet: PushReqResponse.ConfigPush) { val pushReq = packet.struct @@ -94,9 +98,10 @@ internal class ConfigPushSvc { val fileStoragePushFSSvcList = pushReq.jcebuf.loadAs(FileStoragePushFSSvcList.serializer()) bot.client.fileStoragePushFSSvcList = fileStoragePushFSSvcList + val bigDataChannel = fileStoragePushFSSvcList.bigDataChannel if (bigDataChannel?.vBigdataPbBuf == null) { - bot.bdhSyncer.bdhSession.completeExceptionally(IllegalStateException("BdhSession not received.")) + bdhSyncer.bdhSession.completeExceptionally(IllegalStateException("BdhSession not received.")) return } @@ -149,10 +154,11 @@ internal class ConfigPushSvc { bot.network.logger.info { "Server list: ${pushServerList.joinToString()}." } if (pushServerList.isNotEmpty()) { - bot.serverListNew.setPreferred(pushServerList.shuffled().map { ServerAddress(it.host, it.port) }) + bot.components[ServerList].setPreferred( + pushServerList.shuffled().map { ServerAddress(it.host, it.port) }) } - bot.bdhSyncer.saveToCache() - bot.bdhSyncer.saveServerListToCache() + bdhSyncer.saveToCache() + bdhSyncer.saveServerListToCache() if (serverListPush.reconnectNeeded == 1) { bot.logger.info { "Server request to change server." } bot.launch { diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/StatSvc.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/StatSvc.kt index 9cba72d90..ab8812b7d 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/StatSvc.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/StatSvc.kt @@ -28,6 +28,7 @@ import net.mamoe.mirai.internal.contact.appId import net.mamoe.mirai.internal.createOtherClient import net.mamoe.mirai.internal.message.contextualBugReportException import net.mamoe.mirai.internal.network.* +import net.mamoe.mirai.internal.network.handler.components.ContactCacheService import net.mamoe.mirai.internal.network.protocol.data.jce.* import net.mamoe.mirai.internal.network.protocol.data.proto.Oidb0x769 import net.mamoe.mirai.internal.network.protocol.data.proto.StatSvcGetOnline @@ -136,7 +137,7 @@ internal class StatSvc { client: QQAndroidClient, regPushReason: RegPushReason = RegPushReason.appRegister ) = impl(client, 1 or 2 or 4, client.onlineStatus, regPushReason) { - client.bot.friendListCache?.let { friendListCache: FriendListCache -> + client.bot.components[ContactCacheService].friendListCache?.let { friendListCache: FriendListCache -> iLargeSeq = friendListCache.friendListSeq // timeStamp = friendListCache.timeStamp }