mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 18:00:33 +08:00
Fix #178
This commit is contained in:
parent
03d477ab16
commit
1f7bc4e50f
@ -291,10 +291,14 @@ internal class JceDecoder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun decodeTaggedInt(tag: JceTag): Int =
|
override fun decodeTaggedInt(tag: JceTag): Int =
|
||||||
jce.skipToHeadAndUseIfPossibleOrFail(tag.id) { jce.readJceIntValue(it) }
|
kotlin.runCatching { jce.skipToHeadAndUseIfPossibleOrFail(tag.id) { jce.readJceIntValue(it) } }.getOrElse {
|
||||||
|
throw IllegalStateException("$tag", it)
|
||||||
|
}
|
||||||
|
|
||||||
override fun decodeTaggedByte(tag: JceTag): Byte =
|
override fun decodeTaggedByte(tag: JceTag): Byte =
|
||||||
jce.skipToHeadAndUseIfPossibleOrFail(tag.id) { jce.readJceByteValue(it) }
|
kotlin.runCatching { jce.skipToHeadAndUseIfPossibleOrFail(tag.id) { jce.readJceByteValue(it) } }.getOrElse {
|
||||||
|
throw IllegalStateException("$tag", it)
|
||||||
|
}
|
||||||
|
|
||||||
override fun decodeTaggedBoolean(tag: JceTag): Boolean =
|
override fun decodeTaggedBoolean(tag: JceTag): Boolean =
|
||||||
jce.skipToHeadAndUseIfPossibleOrFail(tag.id) { jce.readJceBooleanValue(it) }
|
jce.skipToHeadAndUseIfPossibleOrFail(tag.id) { jce.readJceBooleanValue(it) }
|
||||||
|
@ -121,7 +121,7 @@ internal class JceInput(
|
|||||||
when (type) {
|
when (type) {
|
||||||
Jce.BYTE -> this.input.discardExact(1)
|
Jce.BYTE -> this.input.discardExact(1)
|
||||||
Jce.SHORT -> this.input.discardExact(2)
|
Jce.SHORT -> this.input.discardExact(2)
|
||||||
Jce.INT -> println("readInt=" + this.input.readInt())
|
Jce.INT -> this.input.discardExact(4)
|
||||||
Jce.LONG -> this.input.discardExact(8)
|
Jce.LONG -> this.input.discardExact(8)
|
||||||
Jce.FLOAT -> this.input.discardExact(4)
|
Jce.FLOAT -> this.input.discardExact(4)
|
||||||
Jce.DOUBLE -> this.input.discardExact(8)
|
Jce.DOUBLE -> this.input.discardExact(8)
|
||||||
|
@ -27,6 +27,7 @@ import net.mamoe.mirai.utils.firstValue
|
|||||||
import net.mamoe.mirai.utils.io.read
|
import net.mamoe.mirai.utils.io.read
|
||||||
import net.mamoe.mirai.qqandroid.utils.io.readPacketExact
|
import net.mamoe.mirai.qqandroid.utils.io.readPacketExact
|
||||||
import net.mamoe.mirai.utils.io.toReadPacket
|
import net.mamoe.mirai.utils.io.toReadPacket
|
||||||
|
import net.mamoe.mirai.utils.io.toUHexString
|
||||||
import kotlin.jvm.JvmMultifileClass
|
import kotlin.jvm.JvmMultifileClass
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
|
|
||||||
|
@ -36,11 +36,11 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.list.FriendList
|
|||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.Heartbeat
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.Heartbeat
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.StatSvc
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.StatSvc
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.WtLogin
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.WtLogin
|
||||||
|
import net.mamoe.mirai.qqandroid.utils.io.readPacketExact
|
||||||
|
import net.mamoe.mirai.qqandroid.utils.io.useBytes
|
||||||
import net.mamoe.mirai.utils.*
|
import net.mamoe.mirai.utils.*
|
||||||
import net.mamoe.mirai.utils.io.ByteArrayPool
|
import net.mamoe.mirai.utils.io.ByteArrayPool
|
||||||
import net.mamoe.mirai.utils.io.PlatformSocket
|
import net.mamoe.mirai.utils.io.PlatformSocket
|
||||||
import net.mamoe.mirai.qqandroid.utils.io.readPacketExact
|
|
||||||
import net.mamoe.mirai.qqandroid.utils.io.useBytes
|
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import kotlin.jvm.Volatile
|
import kotlin.jvm.Volatile
|
||||||
import kotlin.time.ExperimentalTime
|
import kotlin.time.ExperimentalTime
|
||||||
@ -117,9 +117,9 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
|||||||
channel = PlatformSocket()
|
channel = PlatformSocket()
|
||||||
// TODO: 2020/2/14 连接多个服务器, #52
|
// TODO: 2020/2/14 连接多个服务器, #52
|
||||||
withTimeoutOrNull(3000) {
|
withTimeoutOrNull(3000) {
|
||||||
channel.connect("113.96.13.208", 8080)
|
channel.connect("114.221.144.22", 8080)
|
||||||
} ?: error("timeout connecting server")
|
} ?: error("timeout connecting server")
|
||||||
logger.info("Connected to server 113.96.13.208:8080")
|
logger.info("Connected to server 114.221.144.22:8080")
|
||||||
startPacketReceiverJobOrKill(CancellationException("relogin", cause))
|
startPacketReceiverJobOrKill(CancellationException("relogin", cause))
|
||||||
|
|
||||||
var response: WtLogin.Login.LoginPacketResponse = WtLogin.Login.SubCommand9(bot.client).sendAndExpect()
|
var response: WtLogin.Login.LoginPacketResponse = WtLogin.Login.SubCommand9(bot.client).sendAndExpect()
|
||||||
|
@ -397,7 +397,6 @@ internal class TroopManagement {
|
|||||||
sServantName = "mqq.IMService.FriendListServiceServantObj",
|
sServantName = "mqq.IMService.FriendListServiceServantObj",
|
||||||
iVersion = 3,
|
iVersion = 3,
|
||||||
cPacketType = 0x00,
|
cPacketType = 0x00,
|
||||||
iMessageType = 0x00000,
|
|
||||||
iRequestId = client.nextRequestPacketRequestId(),
|
iRequestId = client.nextRequestPacketRequestId(),
|
||||||
sBuffer = jceRequestSBuffer(
|
sBuffer = jceRequestSBuffer(
|
||||||
"MGCREQ",
|
"MGCREQ",
|
||||||
|
@ -101,7 +101,6 @@ internal class FriendList {
|
|||||||
sServantName = "mqq.IMService.FriendListServiceServantObj",
|
sServantName = "mqq.IMService.FriendListServiceServantObj",
|
||||||
iVersion = 3,
|
iVersion = 3,
|
||||||
cPacketType = 0x00,
|
cPacketType = 0x00,
|
||||||
iMessageType = 0x00000,
|
|
||||||
iRequestId = client.nextRequestPacketRequestId(),
|
iRequestId = client.nextRequestPacketRequestId(),
|
||||||
sBuffer = jceRequestSBuffer(
|
sBuffer = jceRequestSBuffer(
|
||||||
"GetTroopListReqV2Simplify",
|
"GetTroopListReqV2Simplify",
|
||||||
@ -156,7 +155,6 @@ internal class FriendList {
|
|||||||
sServantName = "mqq.IMService.FriendListServiceServantObj",
|
sServantName = "mqq.IMService.FriendListServiceServantObj",
|
||||||
iVersion = 3,
|
iVersion = 3,
|
||||||
cPacketType = 0x003,
|
cPacketType = 0x003,
|
||||||
iMessageType = 0x00000,
|
|
||||||
iRequestId = 1921334514,
|
iRequestId = 1921334514,
|
||||||
sBuffer = jceRequestSBuffer(
|
sBuffer = jceRequestSBuffer(
|
||||||
"FL",
|
"FL",
|
||||||
|
File diff suppressed because one or more lines are too long
@ -191,7 +191,11 @@ open class LockFreeLinkedList<E> {
|
|||||||
return current.nodeValue
|
return current.nodeValue
|
||||||
|
|
||||||
if (current.nextNode === tail) {
|
if (current.nextNode === tail) {
|
||||||
if (current.compareAndSetNextNodeRef(tail, node)) { // ensure only one attempt can put the lazyNode in
|
if (current.compareAndSetNextNodeRef(
|
||||||
|
tail,
|
||||||
|
node
|
||||||
|
)
|
||||||
|
) { // ensure only one attempt can put the lazyNode in
|
||||||
return node.nodeValue
|
return node.nodeValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,7 +206,10 @@ open class LockFreeLinkedList<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PublishedApi // limitation by atomicfu
|
@PublishedApi // limitation by atomicfu
|
||||||
internal fun <E> LockFreeLinkedListNode<E>.compareAndSetNextNodeRef(expect: LockFreeLinkedListNode<E>, update: LockFreeLinkedListNode<E>) =
|
internal fun <E> LockFreeLinkedListNode<E>.compareAndSetNextNodeRef(
|
||||||
|
expect: LockFreeLinkedListNode<E>,
|
||||||
|
update: LockFreeLinkedListNode<E>
|
||||||
|
) =
|
||||||
this.nextNodeRef.compareAndSet(expect, update)
|
this.nextNodeRef.compareAndSet(expect, update)
|
||||||
|
|
||||||
override fun toString(): String = "[" + asSequence().joinToString() + "]"
|
override fun toString(): String = "[" + asSequence().joinToString() + "]"
|
||||||
@ -277,7 +284,10 @@ open class LockFreeLinkedList<E> {
|
|||||||
/**
|
/**
|
||||||
* 动态计算的大小
|
* 动态计算的大小
|
||||||
*/
|
*/
|
||||||
val size: Int get() = head.countChildIterate<LockFreeLinkedListNode<E>>({ it.nextNode }, { it !is Tail }) - 1 // empty head is always included
|
val size: Int
|
||||||
|
get() = head.countChildIterate<LockFreeLinkedListNode<E>>(
|
||||||
|
{ it.nextNode },
|
||||||
|
{ it !is Tail }) - 1 // empty head is always included
|
||||||
|
|
||||||
open operator fun contains(element: E): Boolean {
|
open operator fun contains(element: E): Boolean {
|
||||||
forEach { if (it == element) return true }
|
forEach { if (it == element) return true }
|
||||||
@ -312,10 +322,13 @@ open class LockFreeLinkedList<E> {
|
|||||||
open fun clear(onEach: ((E) -> Unit)? = null) {
|
open fun clear(onEach: ((E) -> Unit)? = null) {
|
||||||
val first = head.nextNode
|
val first = head.nextNode
|
||||||
head.nextNode = tail
|
head.nextNode = tail
|
||||||
first.childIterateReturnFirstUnsatisfying({
|
first.childIterateReturnFirstUnsatisfying(lambda@{
|
||||||
val n = it.nextNode
|
val n = it.nextNode
|
||||||
it.nextNode = tail
|
it.nextNode = tail
|
||||||
it.removed.value = true
|
it.removed.value = true
|
||||||
|
if (n === tail) {
|
||||||
|
return@lambda n
|
||||||
|
}
|
||||||
onEach?.invoke(n.nodeValue)
|
onEach?.invoke(n.nodeValue)
|
||||||
n
|
n
|
||||||
}, { it !== tail }) // clear the link structure, help GC.
|
}, { it !== tail }) // clear the link structure, help GC.
|
||||||
@ -644,14 +657,18 @@ open class LockFreeLinkedList<E> {
|
|||||||
// region internal
|
// region internal
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
private inline fun <E> E.asNode(nextNode: LockFreeLinkedListNode<E>): LockFreeLinkedListNode<E> = LockFreeLinkedListNode(nextNode, this)
|
private inline fun <E> E.asNode(nextNode: LockFreeLinkedListNode<E>): LockFreeLinkedListNode<E> =
|
||||||
|
LockFreeLinkedListNode(nextNode, this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Self-iterate using the [iterator], until [mustBeTrue] returns `false`.
|
* Self-iterate using the [iterator], until [mustBeTrue] returns `false`.
|
||||||
* Returns the element at the last time when the [mustBeTrue] returns `true`
|
* Returns the element at the last time when the [mustBeTrue] returns `true`
|
||||||
*/
|
*/
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal inline fun <N : LockFreeLinkedListNode<*>> N.childIterateReturnsLastSatisfying(iterator: (N) -> N, mustBeTrue: (N) -> Boolean): N {
|
internal inline fun <N : LockFreeLinkedListNode<*>> N.childIterateReturnsLastSatisfying(
|
||||||
|
iterator: (N) -> N,
|
||||||
|
mustBeTrue: (N) -> Boolean
|
||||||
|
): N {
|
||||||
if (!mustBeTrue(this)) return this
|
if (!mustBeTrue(this)) return this
|
||||||
var value: N = this
|
var value: N = this
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user