Skip to content

Commit

Permalink
add: protocol supported check
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Jun 24, 2023
1 parent 6497b3b commit f28c983
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
9 changes: 3 additions & 6 deletions mirai-core/src/commonMain/kotlin/network/QQAndroidClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import net.mamoe.mirai.internal.network.components.AccountSecrets
import net.mamoe.mirai.internal.network.components.SsoSession
import net.mamoe.mirai.internal.network.protocol.data.jce.FileStoragePushFSSvcList
import net.mamoe.mirai.internal.network.protocol.packet.Tlv
import net.mamoe.mirai.internal.spi.EncryptService
import net.mamoe.mirai.internal.utils.AtomicIntSeq
import net.mamoe.mirai.internal.utils.MiraiProtocolInternal
import net.mamoe.mirai.internal.utils.NetworkType
Expand Down Expand Up @@ -82,12 +83,8 @@ internal open class QQAndroidClient(
override var outgoingPacketSessionId: ByteArray = 0x02B05B8B.toByteArray()
override var loginState = 0

val useAndroid by lazy {
bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PHONE ||
bot.configuration.protocol == BotConfiguration.MiraiProtocol.ANDROID_PAD
}
val usePC by lazy {
bot.configuration.protocol == BotConfiguration.MiraiProtocol.MACOS
val supportedEncrypt by lazy {
EncryptService.instance?.supported(bot.configuration.protocol) ?: false
}
var onlineStatus: OnlineStatus = OnlineStatus.ONLINE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal object WtLogin10 : WtLoginExt {
t194(client.device.imsiMd5)
t511()
t202(client.device.wifiBSSID, client.device.wifiSSID)
if (client.useAndroid) {
if (client.supportedEncrypt) {
t544ForToken(
uin = client.uin,
protocol = client.bot.configuration.protocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ internal object WtLogin15 : WtLoginExt {

t521() // new
t525(client.loginExtraData) // new
if (client.useAndroid) {
if (client.supportedEncrypt) {
t544ForToken(
uin = client.uin,
protocol = client.bot.configuration.protocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal object WtLogin2 : WtLoginExt {
t104(client.t104)
t116(client.miscBitMap, client.subSigMap)
client.t547?.let { t547(it) }
if (client.useAndroid) {
if (client.supportedEncrypt) {
t544ForVerify(
uin = client.uin,
protocol = client.bot.configuration.protocol,
Expand Down Expand Up @@ -61,7 +61,7 @@ internal object WtLogin2 : WtLoginExt {
t104(client.t104)
t116(client.miscBitMap, client.subSigMap)
client.t547?.let { t547(it) }
if (client.useAndroid) {
if (client.supportedEncrypt) {
t544ForVerify(
uin = client.uin,
protocol = client.bot.configuration.protocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal object WtLogin7 : WtLoginExt {
t17c(code.encodeToByteArray())
t401(client.G)
t198()
if (client.useAndroid) {
if (client.supportedEncrypt) {
t544ForVerify(
uin = client.uin,
protocol = client.bot.configuration.protocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,7 @@ internal object WtLogin9 : WtLoginExt {
// this.build().debugPrint("傻逼")

// ignored t318 because not logging in by QR
if (client.useAndroid) {
t544ForToken(
uin = client.uin,
protocol = client.bot.configuration.protocol,
guid = client.device.guid,
sdkVersion = client.sdkVersion,
subCommandId = 9,
commandStr = "810_9"
)
}

if (client.usePC) {
if (client.supportedEncrypt) {
t544ForToken(
uin = client.uin,
protocol = client.bot.configuration.protocol,
Expand Down Expand Up @@ -210,7 +199,7 @@ internal object WtLogin9 : WtLoginExt {
t521(8)
t318(data.tgtQR)

if (client.usePC) {
if (client.supportedEncrypt) {
t544ForToken(
uin = client.uin,
protocol = client.bot.configuration.protocol,
Expand Down
8 changes: 8 additions & 0 deletions mirai-core/src/commonMain/kotlin/spi/EncryptService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public class EncryptServiceContext @MiraiInternalApi constructor(
* @since 2.15.0
*/
public interface EncryptService : BaseService {

/**
* @since 2.15
*/
public fun supported(protocol: BotConfiguration.MiraiProtocol) : Boolean {
return protocol != BotConfiguration.MiraiProtocol.ANDROID_WATCH
}

/**
* Returns `null` if not supported.
*/
Expand Down

0 comments on commit f28c983

Please sign in to comment.