Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
a63c925c
Commit
a63c925c
authored
Jan 06, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid using UShort for sequenceId
parent
c3ccb0b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
10 deletions
+13
-10
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/OutgoingPacketAndroid.kt
...qandroid/network/protocol/packet/OutgoingPacketAndroid.kt
+4
-5
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt
.../mirai/qqandroid/network/protocol/packet/PacketFactory.kt
+7
-3
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/LoginPacket.kt
...ai/qqandroid/network/protocol/packet/login/LoginPacket.kt
+2
-2
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/OutgoingPacketAndroid.kt
View file @
a63c925c
...
...
@@ -22,7 +22,7 @@ import net.mamoe.mirai.utils.io.*
internal
class
OutgoingPacket
constructor
(
name
:
String
?,
val
packetId
:
PacketId
,
val
sequenceId
:
U
Short
,
val
sequenceId
:
Short
,
val
delegate
:
ByteReadPacket
)
:
Packet
{
val
name
:
String
by
lazy
{
...
...
@@ -48,13 +48,12 @@ private val EMPTY_BYTE_ARRAY = ByteArray(0)
*
* byte[] body encrypted by 16 zero
*/
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
internal
inline
fun
PacketFactory
<*,
*>.
buildLoginOutgoingPacket
(
uinAccount
:
String
,
extraData
:
ByteArray
=
EMPTY_BYTE_ARRAY
,
name
:
String
?
=
null
,
id
:
PacketId
=
this
.
id
,
sequenceId
:
U
Short
=
PacketFactory
.
atomicNextSequenceId
(),
sequenceId
:
Short
=
PacketFactory
.
atomicNextSequenceId
(),
body
:
BytePacketBuilder
.()
->
Unit
):
OutgoingPacket
=
OutgoingPacket
(
name
,
id
,
sequenceId
,
buildPacket
{
writeIntLVPacket
(
lengthOffset
=
{
it
+
4
})
{
...
...
@@ -259,7 +258,7 @@ internal inline fun BytePacketBuilder.writeRequestPacket(
client
:
QQAndroidClient
,
encryptMethod
:
EncryptMethod
,
commandId
:
CommandId
,
sequenceId
:
U
Short
=
PacketFactory
.
atomicNextSequenceId
(),
sequenceId
:
Short
=
PacketFactory
.
atomicNextSequenceId
(),
bodyBlock
:
BytePacketBuilder
.()
->
Unit
)
{
val
body
=
encryptMethod
.
run
{
...
...
@@ -270,7 +269,7 @@ internal inline fun BytePacketBuilder.writeRequestPacket(
writeByte
(
0
x02
)
// head
writeShort
((
27
+
2
+
body
.
remaining
).
toShort
())
// orthodox algorithm
writeShort
(
client
.
protocolVersion
)
writeShort
(
sequenceId
.
toShort
()
)
writeShort
(
sequenceId
)
writeShort
(
commandId
.
id
.
toShort
())
writeQQ
(
client
.
account
.
id
)
writeByte
(
3
)
// originally const
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt
View file @
a63c925c
...
...
@@ -7,6 +7,7 @@ import net.mamoe.mirai.data.Packet
import
net.mamoe.mirai.network.BotNetworkHandler
import
net.mamoe.mirai.qqandroid.network.protocol.packet.login.NullPacketId
import
net.mamoe.mirai.qqandroid.network.protocol.packet.login.PacketId
import
net.mamoe.mirai.utils.LockFreeLinkedList
import
net.mamoe.mirai.utils.cryptor.Decrypter
import
net.mamoe.mirai.utils.cryptor.DecrypterType
...
...
@@ -31,18 +32,21 @@ internal abstract class PacketFactory<out TPacket : Packet, TDecrypter : Decrypt
/**
* **解码**服务器的回复数据包
*/
abstract
suspend
fun
ByteReadPacket
.
decode
(
id
:
PacketId
,
sequenceId
:
U
Short
,
handler
:
BotNetworkHandler
):
TPacket
abstract
suspend
fun
ByteReadPacket
.
decode
(
id
:
PacketId
,
sequenceId
:
Short
,
handler
:
BotNetworkHandler
):
TPacket
companion
object
{
private
val
sequenceId
:
AtomicInt
=
atomic
(
1
)
fun
atomicNextSequenceId
():
U
Short
{
fun
atomicNextSequenceId
():
Short
{
val
id
=
sequenceId
.
getAndAdd
(
1
)
if
(
id
>
Short
.
MAX_VALUE
.
toInt
()
*
2
)
{
sequenceId
.
value
=
0
return
atomicNextSequenceId
()
}
return
id
.
to
U
Short
()
return
id
.
toShort
()
}
}
}
internal
class
KnownPacketFactories
:
LockFreeLinkedList
<
PacketFactory
<
*
,
*
>>()
{
}
\ No newline at end of file
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/LoginPacket.kt
View file @
a63c925c
...
...
@@ -19,7 +19,6 @@ class LoginPacketDecrypter(override val value: ByteArray) : DecrypterByteArray {
companion
object
:
DecrypterType
<
LoginPacketDecrypter
>
}
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
internal
object
LoginPacket
:
PacketFactory
<
LoginPacket
.
LoginPacketResponse
,
LoginPacketDecrypter
>(
LoginPacketDecrypter
)
{
init
{
this
.
_id
=
PacketId
(
CommandId
(
"wtlogin.login"
,
0
x0810
),
9
)
...
...
@@ -164,7 +163,8 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse, Log
class
LoginPacketResponse
:
Packet
override
suspend
fun
ByteReadPacket
.
decode
(
id
:
PacketId
,
sequenceId
:
UShort
,
handler
:
BotNetworkHandler
):
LoginPacketResponse
{
@ExperimentalUnsignedTypes
override
suspend
fun
ByteReadPacket
.
decode
(
id
:
PacketId
,
sequenceId
:
Short
,
handler
:
BotNetworkHandler
):
LoginPacketResponse
{
TODO
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment