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
1e4893c7
Commit
1e4893c7
authored
Nov 08, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename to handlePacket
parent
34627b67
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
22 additions
and
28 deletions
+22
-28
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt
...nMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
....mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/OutgoingPacket.kt
...mamoe.mirai/network/protocol/tim/packet/OutgoingPacket.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/PacketFactory.kt
....mamoe.mirai/network/protocol/tim/packet/PacketFactory.kt
+3
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/PacketId.kt
...n/net.mamoe.mirai/network/protocol/tim/packet/PacketId.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/AddContact.kt
...oe.mirai/network/protocol/tim/packet/action/AddContact.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Unknown.kt
....mamoe.mirai/network/protocol/tim/packet/event/Unknown.kt
+1
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/TypeConvertion.kt
...monMain/kotlin/net.mamoe.mirai/utils/io/TypeConvertion.kt
+9
-4
mirai-debug/src/main/kotlin/PacketDebuger.kt
mirai-debug/src/main/kotlin/PacketDebuger.kt
+4
-14
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt
View file @
1e4893c7
...
@@ -8,9 +8,9 @@ import net.mamoe.mirai.Bot
...
@@ -8,9 +8,9 @@ import net.mamoe.mirai.Bot
import
net.mamoe.mirai.network.protocol.tim.TIMBotNetworkHandler.BotSocketAdapter
import
net.mamoe.mirai.network.protocol.tim.TIMBotNetworkHandler.BotSocketAdapter
import
net.mamoe.mirai.network.protocol.tim.TIMBotNetworkHandler.LoginHandler
import
net.mamoe.mirai.network.protocol.tim.TIMBotNetworkHandler.LoginHandler
import
net.mamoe.mirai.network.protocol.tim.handler.*
import
net.mamoe.mirai.network.protocol.tim.handler.*
import
net.mamoe.mirai.network.protocol.tim.packet.HeartbeatPacket
import
net.mamoe.mirai.network.protocol.tim.packet.OutgoingPacket
import
net.mamoe.mirai.network.protocol.tim.packet.OutgoingPacket
import
net.mamoe.mirai.network.protocol.tim.packet.Packet
import
net.mamoe.mirai.network.protocol.tim.packet.Packet
import
net.mamoe.mirai.network.protocol.tim.packet.login.HeartbeatPacket
import
net.mamoe.mirai.network.protocol.tim.packet.login.LoginResult
import
net.mamoe.mirai.network.protocol.tim.packet.login.LoginResult
import
net.mamoe.mirai.network.protocol.tim.packet.login.RequestSKeyPacket
import
net.mamoe.mirai.network.protocol.tim.packet.login.RequestSKeyPacket
import
net.mamoe.mirai.utils.BotConfiguration
import
net.mamoe.mirai.utils.BotConfiguration
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
View file @
1e4893c7
...
@@ -255,7 +255,7 @@ internal class TIMBotNetworkHandler internal constructor(override inline val bot
...
@@ -255,7 +255,7 @@ internal class TIMBotNetworkHandler internal constructor(override inline val bot
if
(
factory
is
SessionPacketFactory
<
*
>)
{
if
(
factory
is
SessionPacketFactory
<
*
>)
{
with
(
factory
as
SessionPacketFactory
<
TPacket
>)
{
with
(
factory
as
SessionPacketFactory
<
TPacket
>)
{
process
Packet
(
packet
)
handle
Packet
(
packet
)
}
}
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/OutgoingPacket.kt
View file @
1e4893c7
...
@@ -37,7 +37,7 @@ abstract class SessionPacketFactory<TPacket : Packet> : PacketFactory<TPacket, S
...
@@ -37,7 +37,7 @@ abstract class SessionPacketFactory<TPacket : Packet> : PacketFactory<TPacket, S
/**
/**
* 在 [BotNetworkHandler] 下处理这个包. 广播事件等.
* 在 [BotNetworkHandler] 下处理这个包. 广播事件等.
*/
*/
open
suspend
fun
BotNetworkHandler
<*>.
process
Packet
(
packet
:
TPacket
)
{}
open
suspend
fun
BotNetworkHandler
<*>.
handle
Packet
(
packet
:
TPacket
)
{}
}
}
/**
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/PacketFactory.kt
View file @
1e4893c7
...
@@ -52,10 +52,10 @@ abstract class PacketFactory<out TPacket : Packet, TDecrypter : Decrypter>(val d
...
@@ -52,10 +52,10 @@ abstract class PacketFactory<out TPacket : Packet, TDecrypter : Decrypter>(val d
}
}
object
UnknownPacketFactory
:
SessionPacketFactory
<
UnknownPacket
>()
{
object
UnknownPacketFactory
:
SessionPacketFactory
<
UnknownPacket
>()
{
override
suspend
fun
BotNetworkHandler
<*>.
process
Packet
(
packet
:
UnknownPacket
)
{
override
suspend
fun
BotNetworkHandler
<*>.
handle
Packet
(
packet
:
UnknownPacket
)
{
ByteArrayPool
.
useInstance
{
ByteArrayPool
.
useInstance
{
packet
.
body
.
readAvailable
(
it
)
packet
.
body
.
readAvailable
(
it
)
bot
.
logger
.
debug
(
"Unknown
packet(${packet.id.value}) body
= "
+
it
.
toUHexString
())
bot
.
logger
.
debug
(
"Unknown
Packet(${packet.id.value.toUHexString()})
= "
+
it
.
toUHexString
())
}
}
packet
.
body
.
close
()
packet
.
body
.
close
()
}
}
...
@@ -66,7 +66,7 @@ object UnknownPacketFactory : SessionPacketFactory<UnknownPacket>() {
...
@@ -66,7 +66,7 @@ object UnknownPacketFactory : SessionPacketFactory<UnknownPacket>() {
}
}
object
IgnoredPacketFactory
:
SessionPacketFactory
<
IgnoredPacket
>()
{
object
IgnoredPacketFactory
:
SessionPacketFactory
<
IgnoredPacket
>()
{
override
suspend
fun
BotNetworkHandler
<*>.
process
Packet
(
packet
:
IgnoredPacket
)
{
override
suspend
fun
BotNetworkHandler
<*>.
handle
Packet
(
packet
:
IgnoredPacket
)
{
}
}
override
suspend
fun
ByteReadPacket
.
decode
(
id
:
PacketId
,
sequenceId
:
UShort
,
handler
:
BotNetworkHandler
<
*
>):
IgnoredPacket
=
IgnoredPacket
override
suspend
fun
ByteReadPacket
.
decode
(
id
:
PacketId
,
sequenceId
:
UShort
,
handler
:
BotNetworkHandler
<
*
>):
IgnoredPacket
=
IgnoredPacket
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/PacketId.kt
View file @
1e4893c7
...
@@ -82,5 +82,5 @@ enum class KnownPacketId(override inline val value: UShort, override inline val
...
@@ -82,5 +82,5 @@ enum class KnownPacketId(override inline val value: UShort, override inline val
;
;
override
fun
toString
():
String
=
factory
::
class
.
simpleName
?:
this
.
name
override
fun
toString
():
String
=
(
factory
::
class
.
simpleName
?:
this
.
name
)
+
"(${value.toUHexString()})"
}
}
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/AddContact.kt
View file @
1e4893c7
...
@@ -162,7 +162,7 @@ object AddFriendPacket : SessionPacketFactory<AddFriendPacket.AddFriendResponse>
...
@@ -162,7 +162,7 @@ object AddFriendPacket : SessionPacketFactory<AddFriendPacket.AddFriendResponse>
}
}
}
}
override
suspend
fun
BotNetworkHandler
<*>.
process
Packet
(
packet
:
AddFriendResponse
)
{
override
suspend
fun
BotNetworkHandler
<*>.
handle
Packet
(
packet
:
AddFriendResponse
)
{
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Unknown.kt
View file @
1e4893c7
...
@@ -22,8 +22,7 @@ data class UnknownEventPacket(
...
@@ -22,8 +22,7 @@ data class UnknownEventPacket(
class
UnknownEventParserAndHandler
(
override
val
id
:
UShort
)
:
EventParserAndHandler
<
UnknownEventPacket
>
{
class
UnknownEventParserAndHandler
(
override
val
id
:
UShort
)
:
EventParserAndHandler
<
UnknownEventPacket
>
{
override
suspend
fun
ByteReadPacket
.
parse
(
bot
:
Bot
,
identity
:
EventPacketIdentity
):
UnknownEventPacket
{
override
suspend
fun
ByteReadPacket
.
parse
(
bot
:
Bot
,
identity
:
EventPacketIdentity
):
UnknownEventPacket
{
MiraiLogger
.
debug
(
"UnknownEventPacket type = ${id.toUHexString()}"
)
MiraiLogger
.
debug
(
"UnknownEventPacket(${id.toUHexString()}) = ${readBytes().toUHexString()}"
)
MiraiLogger
.
debug
(
"UnknownEventPacket data = ${readBytes().toUHexString()}"
)
return
UnknownEventPacket
(
id
,
this
)
//TODO the cause is that `this` reference.
return
UnknownEventPacket
(
id
,
this
)
//TODO the cause is that `this` reference.
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/TypeConvertion.kt
View file @
1e4893c7
...
@@ -41,9 +41,12 @@ fun UShort.toByteArray(): ByteArray = with(toUInt()) {
...
@@ -41,9 +41,12 @@ fun UShort.toByteArray(): ByteArray = with(toUInt()) {
}
}
/**
/**
* 转 [ByteArray] 后再转 hex
* 转 [ByteArray] 后再转 hex.
*
* @return 2 位 Unsigned Hex
*/
*/
fun
UShort
.
toUHexString
(
separator
:
String
=
" "
):
String
=
this
.
toByteArray
().
toUHexString
(
separator
)
fun
UShort
.
toUHexString
(
separator
:
String
=
" "
):
String
=
(
this
.
toInt
().
shr
(
8
).
toUShort
()
and
255
u
).
toByte
().
toUHexString
()
+
separator
+
(
this
and
255
u
).
toByte
().
toUHexString
()
/**
/**
* 255u -> 00 00 00 FF
* 255u -> 00 00 00 FF
...
@@ -108,7 +111,8 @@ fun getRandomString(length: Int, charRange: CharRange): String = String(CharArra
...
@@ -108,7 +111,8 @@ fun getRandomString(length: Int, charRange: CharRange): String = String(CharArra
/**
/**
* 根据所给 [charRanges] 随机生成长度为 [length] 的 [String].
* 根据所给 [charRanges] 随机生成长度为 [length] 的 [String].
*/
*/
fun
getRandomString
(
length
:
Int
,
vararg
charRanges
:
CharRange
):
String
=
String
(
CharArray
(
length
)
{
charRanges
[
Random
.
Default
.
nextInt
(
0
..
charRanges
.
lastIndex
)].
random
()
})
fun
getRandomString
(
length
:
Int
,
vararg
charRanges
:
CharRange
):
String
=
String
(
CharArray
(
length
)
{
charRanges
[
Random
.
Default
.
nextInt
(
0
..
charRanges
.
lastIndex
)].
random
()
})
/**
/**
* 将 [this] 前 4 个 [Byte] 的 bits 合并为一个 [Int]
* 将 [this] 前 4 个 [Byte] 的 bits 合并为一个 [Int]
...
@@ -118,7 +122,8 @@ fun getRandomString(length: Int, vararg charRanges: CharRange): String = String(
...
@@ -118,7 +122,8 @@ fun getRandomString(length: Int, vararg charRanges: CharRange): String = String(
* 一个 [Int] 有 32 bits
* 一个 [Int] 有 32 bits
* 本函数将 4 个 [Byte] 的 bits 连接得到 [Int]
* 本函数将 4 个 [Byte] 的 bits 连接得到 [Int]
*/
*/
fun
ByteArray
.
toUInt
():
UInt
=
this
[
0
].
toUInt
().
and
(
255
u
).
shl
(
24
)
+
this
[
1
].
toUInt
().
and
(
255
u
).
shl
(
16
)
+
this
[
2
].
toUInt
().
and
(
255
u
).
shl
(
8
)
+
this
[
3
].
toUInt
().
and
(
255
u
).
shl
(
0
)
fun
ByteArray
.
toUInt
():
UInt
=
this
[
0
].
toUInt
().
and
(
255
u
).
shl
(
24
)
+
this
[
1
].
toUInt
().
and
(
255
u
).
shl
(
16
)
+
this
[
2
].
toUInt
().
and
(
255
u
).
shl
(
8
)
+
this
[
3
].
toUInt
().
and
(
255
u
).
shl
(
0
)
/**
/**
* 从 [IoBuffer.Pool] [borrow][ObjectPool.borrow] 一个 [IoBuffer] 然后将 [this] 写入.
* 从 [IoBuffer.Pool] [borrow][ObjectPool.borrow] 一个 [IoBuffer] 然后将 [this] 写入.
...
...
mirai-debug/src/main/kotlin/PacketDebuger.kt
View file @
1e4893c7
...
@@ -93,30 +93,20 @@ object Main {
...
@@ -93,30 +93,20 @@ object Main {
//println("raw = " + data.toUHexString())
//println("raw = " + data.toUHexString())
data
.
read
{
data
.
read
{
discardExact
(
3
)
discardExact
(
3
)
val
idHex
=
readInt
().
toUHexString
(
" "
)
val
id
=
matchPacketId
(
readUShort
())
if
(
idHex
.
startsWith
(
"00 81"
))
{
val
sequenceId
=
readUShort
()
if
(
id
==
KnownPacketId
.
HEARTBEAT
||
readUInt
()
!=
qq
)
return
@
read
return
@
read
}
if
(
readUInt
()
!=
qq
)
{
return
@
read
}
println
(
"--------------"
)
println
(
"--------------"
)
println
(
"接收数据包"
)
println
(
"接收数据包"
)
discardExact
(
3
)
//0x00 0x00 0x00. 但更可能是应该 discard 8
discardExact
(
3
)
//0x00 0x00 0x00. 但更可能是应该 discard 8
println
(
"id=$id
Hex
"
)
println
(
"id=$id
, sequence=${sequenceId.toUHexString()}
"
)
val
remaining
=
this
.
readRemainingBytes
().
cutTail
(
1
)
val
remaining
=
this
.
readRemainingBytes
().
cutTail
(
1
)
try
{
try
{
val
decrypted
=
remaining
.
decryptBy
(
sessionKey
)
val
decrypted
=
remaining
.
decryptBy
(
sessionKey
)
println
(
"解密body=${decrypted.toUHexString()}"
)
println
(
"解密body=${decrypted.toUHexString()}"
)
discardExact
(
3
)
val
id
=
matchPacketId
(
readUShort
())
val
sequenceId
=
readUShort
()
discardExact
(
7
)
//4 for qq number, 3 for 0x00 0x00 0x00
val
packet
=
use
{
val
packet
=
use
{
with
(
id
.
factory
)
{
with
(
id
.
factory
)
{
provideDecrypter
(
id
.
factory
)
provideDecrypter
(
id
.
factory
)
...
...
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