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
c434b59f
Commit
c434b59f
authored
Feb 15, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cache, close #46
parent
5d629fe6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
31 deletions
+62
-31
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+14
-0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt
.../mirai/qqandroid/network/protocol/packet/PacketFactory.kt
+48
-31
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
c434b59f
...
...
@@ -162,6 +162,11 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
StatSvc
.
Register
(
bot
.
client
).
sendAndExpect
<
StatSvc
.
Register
.
Response
>()
}
// caches
private
val
_pendingEnabled
=
atomic
(
true
)
internal
val
pendingEnabled
get
()
=
_pendingEnabled
.
value
internal
var
pendingIncomingPackets
:
LockFreeLinkedList
<
KnownPacketFactories
.
IncomingPacket
<
*
>>?
=
LockFreeLinkedList
()
@UseExperimental
(
MiraiExperimentalAPI
::
class
,
ExperimentalTime
::
class
)
override
suspend
fun
init
():
Unit
=
coroutineScope
{
MessageSvc
.
PbGetMsg
(
bot
.
client
,
MsgSvc
.
SyncFlag
.
START
,
currentTimeSeconds
).
sendWithoutExpect
()
...
...
@@ -265,6 +270,15 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
}
bot
.
firstLoginSucceed
=
true
_pendingEnabled
.
value
=
false
pendingIncomingPackets
?.
forEach
{
@Suppress
(
"UNCHECKED_CAST"
)
KnownPacketFactories
.
handleIncomingPacket
(
it
as
KnownPacketFactories
.
IncomingPacket
<
Packet
>,
bot
,
it
.
flag2
,
it
.
consumer
)
}
pendingIncomingPackets
=
null
// release
Unit
}
suspend
fun
doHeartBeat
():
Exception
?
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt
View file @
c434b59f
...
...
@@ -211,6 +211,25 @@ internal object KnownPacketFactories {
else
->
error
(
"unknown flag1: ${flag1.toByte().toUHexString()}"
)
}
}
?.
let
{
it
as
IncomingPacket
<
T
>
if
(
it
.
packetFactory
is
IncomingPacketFactory
<
T
>
&&
bot
.
network
.
pendingEnabled
)
{
bot
.
network
.
pendingIncomingPackets
?.
addLast
(
it
.
also
{
it
.
consumer
=
consumer
it
.
flag2
=
flag2
})
?:
handleIncomingPacket
(
it
,
bot
,
flag2
,
consumer
)
}
else
{
handleIncomingPacket
(
it
,
bot
,
flag2
,
consumer
)
}
}
?:
inline
{
PacketLogger
.
error
{
"任何key都无法解密: ${data.take(size).toUHexString()}"
}
return
}
}
}
@UseExperimental
(
MiraiInternalAPI
::
class
)
internal
suspend
fun
<
T
:
Packet
>
handleIncomingPacket
(
it
:
IncomingPacket
<
T
>,
bot
:
QQAndroidBot
,
flag2
:
Int
,
consumer
:
PacketConsumer
<
T
>)
{
if
(
it
.
packetFactory
==
null
)
{
bot
.
network
.
logger
.
debug
(
"Received commandName: ${it.commandName}"
)
PacketLogger
.
warning
{
"找不到 PacketFactory"
}
...
...
@@ -240,27 +259,25 @@ internal object KnownPacketFactories {
else
->
error
(
"unknown flag2: $flag2. Body to be parsed for inner packet=${it.data.readBytes().toUHexString()}"
)
}
}
}
?:
inline
{
PacketLogger
.
error
{
"任何key都无法解密: ${data.take(size).toUHexString()}"
}
return
}
}
}
private
inline
fun
<
R
>
inline
(
block
:
()
->
R
):
R
=
block
()
class
IncomingPacket
(
val
packetFactory
:
PacketFactory
<
*
>?,
class
IncomingPacket
<
T
:
Packet
>
(
val
packetFactory
:
PacketFactory
<
T
>?,
val
sequenceId
:
Int
,
val
data
:
ByteReadPacket
,
val
commandName
:
String
)
)
{
var
flag2
:
Int
=
-
1
lateinit
var
consumer
:
PacketConsumer
<
T
>
}
/**
* 解析 SSO 层包装
*/
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
,
MiraiInternalAPI
::
class
)
private
fun
parseSsoFrame
(
bot
:
QQAndroidBot
,
input
:
ByteReadPacket
):
IncomingPacket
{
private
fun
parseSsoFrame
(
bot
:
QQAndroidBot
,
input
:
ByteReadPacket
):
IncomingPacket
<
*
>
{
val
commandName
:
String
val
ssoSequenceId
:
Int
val
dataCompressed
:
Int
...
...
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