This commit is contained in:
Him188 2020-03-31 11:57:19 +08:00
parent 03d477ab16
commit 1f7bc4e50f
8 changed files with 73 additions and 21 deletions

View File

@ -291,10 +291,14 @@ internal class JceDecoder(
}
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 =
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 =
jce.skipToHeadAndUseIfPossibleOrFail(tag.id) { jce.readJceBooleanValue(it) }

View File

@ -121,7 +121,7 @@ internal class JceInput(
when (type) {
Jce.BYTE -> this.input.discardExact(1)
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.FLOAT -> this.input.discardExact(4)
Jce.DOUBLE -> this.input.discardExact(8)

View File

@ -27,6 +27,7 @@ import net.mamoe.mirai.utils.firstValue
import net.mamoe.mirai.utils.io.read
import net.mamoe.mirai.qqandroid.utils.io.readPacketExact
import net.mamoe.mirai.utils.io.toReadPacket
import net.mamoe.mirai.utils.io.toUHexString
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

View File

@ -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.StatSvc
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.io.ByteArrayPool
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.jvm.Volatile
import kotlin.time.ExperimentalTime
@ -117,9 +117,9 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
channel = PlatformSocket()
// TODO: 2020/2/14 连接多个服务器, #52
withTimeoutOrNull(3000) {
channel.connect("113.96.13.208", 8080)
channel.connect("114.221.144.22", 8080)
} ?: 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))
var response: WtLogin.Login.LoginPacketResponse = WtLogin.Login.SubCommand9(bot.client).sendAndExpect()

View File

@ -397,7 +397,6 @@ internal class TroopManagement {
sServantName = "mqq.IMService.FriendListServiceServantObj",
iVersion = 3,
cPacketType = 0x00,
iMessageType = 0x00000,
iRequestId = client.nextRequestPacketRequestId(),
sBuffer = jceRequestSBuffer(
"MGCREQ",

View File

@ -101,7 +101,6 @@ internal class FriendList {
sServantName = "mqq.IMService.FriendListServiceServantObj",
iVersion = 3,
cPacketType = 0x00,
iMessageType = 0x00000,
iRequestId = client.nextRequestPacketRequestId(),
sBuffer = jceRequestSBuffer(
"GetTroopListReqV2Simplify",
@ -156,7 +155,6 @@ internal class FriendList {
sServantName = "mqq.IMService.FriendListServiceServantObj",
iVersion = 3,
cPacketType = 0x003,
iMessageType = 0x00000,
iRequestId = 1921334514,
sBuffer = jceRequestSBuffer(
"FL",

View File

@ -191,7 +191,11 @@ open class LockFreeLinkedList<E> {
return current.nodeValue
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
}
}
@ -202,7 +206,10 @@ open class LockFreeLinkedList<E> {
}
@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)
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 {
forEach { if (it == element) return true }
@ -312,10 +322,13 @@ open class LockFreeLinkedList<E> {
open fun clear(onEach: ((E) -> Unit)? = null) {
val first = head.nextNode
head.nextNode = tail
first.childIterateReturnFirstUnsatisfying({
first.childIterateReturnFirstUnsatisfying(lambda@{
val n = it.nextNode
it.nextNode = tail
it.removed.value = true
if (n === tail) {
return@lambda n
}
onEach?.invoke(n.nodeValue)
n
}, { it !== tail }) // clear the link structure, help GC.
@ -644,14 +657,18 @@ open class LockFreeLinkedList<E> {
// region internal
@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`.
* Returns the element at the last time when the [mustBeTrue] returns `true`
*/
@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
var value: N = this