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
df561360
Commit
df561360
authored
Jan 22, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
image protocol
parent
2f1114d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
14 deletions
+33
-14
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+32
-13
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt
.../mirai/qqandroid/network/protocol/packet/PacketFactory.kt
+1
-1
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
df561360
...
@@ -2,6 +2,7 @@ package net.mamoe.mirai.qqandroid.network
...
@@ -2,6 +2,7 @@ package net.mamoe.mirai.qqandroid.network
import
kotlinx.coroutines.*
import
kotlinx.coroutines.*
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.readBytes
import
kotlinx.io.core.use
import
kotlinx.io.core.use
import
net.mamoe.mirai.data.Packet
import
net.mamoe.mirai.data.Packet
import
net.mamoe.mirai.event.broadcast
import
net.mamoe.mirai.event.broadcast
...
@@ -42,24 +43,42 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -42,24 +43,42 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
SvcReqRegisterPacket
(
bot
.
client
,
RegPushReason
.
setOnlineStatus
).
sendAndExpect
<
SvcReqRegisterPacket
.
Response
>()
SvcReqRegisterPacket
(
bot
.
client
,
RegPushReason
.
setOnlineStatus
).
sendAndExpect
<
SvcReqRegisterPacket
.
Response
>()
}
}
internal
fun
launchPacketProcessor
(
rawInput
:
ByteReadPacket
):
Job
=
launch
(
CoroutineName
(
"Incoming Packet handler"
))
{
rawInput
.
debugPrint
(
"Received"
).
use
{
input
->
var
lastPacket
:
ByteArray
?
=
null
if
(
input
.
remaining
==
0L
)
{
internal
fun
launchPacketProcessor
(
rawInput
:
ByteReadPacket
):
Job
=
bot
.
logger
.
error
(
"Empty packet received. Consider if bad packet was sent."
)
launch
(
CoroutineName
(
"Incoming Packet handler"
))
{
return
@
launch
rawInput
.
debugPrint
(
"Received"
).
use
{
input
->
}
if
(
input
.
remaining
==
0L
)
{
KnownPacketFactories
.
parseIncomingPacket
(
bot
,
input
)
{
packet
:
Packet
,
packetId
:
PacketId
,
sequenceId
:
Int
->
bot
.
logger
.
error
(
"Empty packet received. Consider if bad packet was sent."
)
if
(
PacketReceivedEvent
(
packet
).
broadcast
().
cancelled
)
{
return
@
launch
return
@
parseIncomingPacket
}
val
fixedInput
=
if
(
lastPacket
==
null
)
{
input
}
else
{
ByteReadPacket
((
lastPacket
?:
ByteArray
(
0
))
+
input
.
readBytes
(
input
.
remaining
.
toInt
()))
}
}
packetListeners
.
forEach
{
listener
->
while
(
true
)
{
if
(
listener
.
filter
(
packetId
,
sequenceId
)
&&
packetListeners
.
remove
(
listener
))
{
val
pk1Length
=
fixedInput
.
readInt
()
-
4
listener
.
complete
(
packet
)
if
(
pk1Length
>
fixedInput
.
remaining
)
{
lastPacket
=
pk1Length
.
toByteArray
().
plus
(
fixedInput
.
readBytes
(
fixedInput
.
remaining
.
toInt
()))
break
}
KnownPacketFactories
.
parseIncomingPacket
(
bot
,
fixedInput
.
readBytes
(
pk1Length
).
toReadPacket
()
)
{
packet
:
Packet
,
packetId
:
PacketId
,
sequenceId
:
Int
->
if
(
PacketReceivedEvent
(
packet
).
broadcast
().
cancelled
)
{
return
@
parseIncomingPacket
}
packetListeners
.
forEach
{
listener
->
if
(
listener
.
filter
(
packetId
,
sequenceId
)
&&
packetListeners
.
remove
(
listener
))
{
listener
.
complete
(
packet
)
}
}
}
}
}
}
}
}
}
}
}
private
suspend
fun
processReceive
()
{
private
suspend
fun
processReceive
()
{
while
(
channel
.
isOpen
)
{
while
(
channel
.
isOpen
)
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt
View file @
df561360
...
@@ -82,7 +82,7 @@ internal object KnownPacketFactories : List<PacketFactory<*>> by mutableListOf(
...
@@ -82,7 +82,7 @@ internal object KnownPacketFactories : List<PacketFactory<*>> by mutableListOf(
else
->
error
(
"Illegal flag2. Expected 0x02, got $flag2"
)
else
->
error
(
"Illegal flag2. Expected 0x02, got $flag2"
)
}
}
// 00 00 00 60 00 00 00 0B 02 00 00 00 00 0E 31 39 39 34 37 30 31 30 32 31 CE 35 53 19 84 A8 1A B8 5B 48 E3 7C D0 A6 BA 58 6A EB CE 50 B9 A0 98 D5 B9 D0 1C 72 E2 86 24 FC 55 44 6C 6E E3 F9 15 6C EC 6C 6B 94 40 F7 B4 45 CF B4 D0 79 84 FE 30 EA 98 84 44 84 02 32 70 DD D7 07 07 72 DE 87 59 AC
// 00 00 00 60 00 00 00 0B 02 00 00 00 00 0E 31 39 39 34 37 30 31 30 32 31 CE 35 53 19 84 A8 1A B8 5B 48 E3 7C D0 A6 BA 58 6A EB CE 50 B9 A0 98 D5 B9 D0 1C 72 E2 86 24 FC 55 44 6C 6E E3 F9 15 6C EC 6C 6B 94 40 F7 B4 45 CF B4 D0 79 84 FE 30 EA 98 84 44 84 02 32 70 DD D7 07 07 72 DE 87 59 AC
0
x0B
->
0
x0B
->
TODO
(
"TO FOX"
)
else
->
error
(
"Illegal flag1. Expected 0x0A or 0x0B, got $flag1"
)
else
->
error
(
"Illegal flag1. Expected 0x0A or 0x0B, got $flag1"
)
}
}
}
}
...
...
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