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
dcfe934a
Commit
dcfe934a
authored
Jul 02, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix missed BotOfflineEvent.Dropped. Close #376
parent
0741d484
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
14 deletions
+44
-14
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt
...rc/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt
+10
-3
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+6
-3
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt
.../mirai/qqandroid/network/protocol/packet/login/StatSvc.kt
+4
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/bot.kt
...src/commonMain/kotlin/net.mamoe.mirai/event/events/bot.kt
+24
-4
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt
View file @
dcfe934a
...
...
@@ -74,11 +74,13 @@ internal abstract class BotImpl<N : BotNetworkHandler> constructor(
// bot 还未登录就被 close
return
@
subscribeAlways
}
if
(
network
.
areYouOk
()
&&
event
!
is
BotOfflineEvent
.
Force
)
{
/*
if (network.areYouOk() && event !is BotOfflineEvent.Force && event !is BotOfflineEvent.MsfOffline) {
// network 运行正常
return@subscribeAlways
}
}
*/
when
(
event
)
{
is
BotOfflineEvent
.
MsfOffline
,
is
BotOfflineEvent
.
Dropped
,
is
BotOfflineEvent
.
RequireReconnect
->
{
...
...
@@ -105,7 +107,12 @@ internal abstract class BotImpl<N : BotNetworkHandler> constructor(
@OptIn
(
ThisApiMustBeUsedInWithConnectionLockBlock
::
class
)
relogin
((
event
as
?
BotOfflineEvent
.
Dropped
)
?.
cause
)
}
launch
{
BotReloginEvent
(
bot
,
(
event
as
?
BotOfflineEvent
.
Dropped
)
?.
cause
).
broadcast
()
}
launch
{
BotReloginEvent
(
bot
,
(
event
as
?
BotOfflineEvent
.
CauseAware
)
?.
cause
).
broadcast
()
}
return
}.
getOrElse
{
if
(
it
is
LoginFailedException
&&
!
it
.
killBot
)
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
dcfe934a
...
...
@@ -96,14 +96,17 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
private
fun
startHeartbeatJobOrKill
(
cancelCause
:
CancellationException
?
=
null
):
Job
{
heartbeatJob
?.
cancel
(
cancelCause
)
return
this
@QQAndroidBotNetworkHandler
.
launch
(
CoroutineName
(
"Heartbeat"
))
{
return
this
@QQAndroidBotNetworkHandler
.
launch
(
CoroutineName
(
"Heartbeat"
))
heartBeatJob
@
{
while
(
this
.
isActive
)
{
delay
(
bot
.
configuration
.
heartbeatPeriodMillis
)
val
failException
=
doHeartBeat
()
if
(
failException
!=
null
)
{
delay
(
bot
.
configuration
.
firstReconnectDelayMillis
)
bot
.
launch
{
BotOfflineEvent
.
Dropped
(
bot
,
failException
).
broadcast
()
}
return
@
launch
bot
.
launch
{
BotOfflineEvent
.
Dropped
(
bot
,
failException
).
broadcast
()
}
return
@
heartBeatJob
}
}
}.
also
{
heartbeatJob
=
it
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt
View file @
dcfe934a
...
...
@@ -182,7 +182,7 @@ internal class StatSvc {
}
internal
object
ReqMSFOffline
:
IncomingPacketFactory
<
BotOfflineEvent
.
Dropped
>(
"StatSvc.ReqMSFOffline"
,
"StatSvc.RspMSFForceOffline"
)
{
IncomingPacketFactory
<
BotOfflineEvent
.
MsfOffline
>(
"StatSvc.ReqMSFOffline"
,
"StatSvc.RspMSFForceOffline"
)
{
internal
data class
MsfOfflineToken
(
val
uin
:
Long
,
...
...
@@ -190,13 +190,13 @@ internal class StatSvc {
val
const
:
Byte
)
:
Packet
,
RuntimeException
(
"dropped by StatSvc.ReqMSFOffline"
)
override
suspend
fun
ByteReadPacket
.
decode
(
bot
:
QQAndroidBot
,
sequenceId
:
Int
):
BotOfflineEvent
.
Dropped
{
override
suspend
fun
ByteReadPacket
.
decode
(
bot
:
QQAndroidBot
,
sequenceId
:
Int
):
BotOfflineEvent
.
MsfOffline
{
val
decodeUniPacket
=
readUniPacket
(
RequestMSFForceOffline
.
serializer
())
@Suppress
(
"INVISIBLE_MEMBER"
)
return
BotOfflineEvent
.
Dropped
(
bot
,
MsfOfflineToken
(
decodeUniPacket
.
uin
,
decodeUniPacket
.
iSeqno
,
0
))
return
BotOfflineEvent
.
MsfOffline
(
bot
,
MsfOfflineToken
(
decodeUniPacket
.
uin
,
decodeUniPacket
.
iSeqno
,
0
))
}
override
suspend
fun
QQAndroidBot
.
handle
(
packet
:
BotOfflineEvent
.
Dropped
,
sequenceId
:
Int
):
OutgoingPacket
?
{
override
suspend
fun
QQAndroidBot
.
handle
(
packet
:
BotOfflineEvent
.
MsfOffline
,
sequenceId
:
Int
):
OutgoingPacket
?
{
val
cause
=
packet
.
cause
check
(
cause
is
MsfOfflineToken
)
{
"internal error: handling $packet in StatSvc.ReqMSFOffline"
}
return
buildResponseUniPacket
(
client
)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/bot.kt
View file @
dcfe934a
...
...
@@ -16,6 +16,9 @@ package net.mamoe.mirai.event.events
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.event.AbstractEvent
import
net.mamoe.mirai.qqandroid.network.Packet
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.SinceMirai
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
...
...
@@ -35,7 +38,8 @@ sealed class BotOfflineEvent : BotEvent, AbstractEvent() {
/**
* 主动离线. 主动广播这个事件也可以让 [Bot] 关闭.
*/
data class
Active
(
override
val
bot
:
Bot
,
val
cause
:
Throwable
?)
:
BotOfflineEvent
(),
BotActiveEvent
data class
Active
(
override
val
bot
:
Bot
,
override
val
cause
:
Throwable
?)
:
BotOfflineEvent
(),
BotActiveEvent
,
CauseAware
/**
* 被挤下线
...
...
@@ -45,15 +49,31 @@ sealed class BotOfflineEvent : BotEvent, AbstractEvent() {
BotPassiveEvent
/**
* 被服务器断开
或因网络问题而掉线
* 被服务器断开
*/
data class
Dropped
internal
constructor
(
override
val
bot
:
Bot
,
val
cause
:
Throwable
?)
:
BotOfflineEvent
(),
Packet
,
BotPassiveEvent
@SinceMirai
(
"1.1.0"
)
@MiraiInternalAPI
(
"This is very experimental and might be changed"
)
data class
MsfOffline
internal
constructor
(
override
val
bot
:
Bot
,
override
val
cause
:
Throwable
?)
:
BotOfflineEvent
(),
Packet
,
BotPassiveEvent
,
CauseAware
/**
* 因网络问题而掉线
*/
data class
Dropped
internal
constructor
(
override
val
bot
:
Bot
,
override
val
cause
:
Throwable
?)
:
BotOfflineEvent
(),
Packet
,
BotPassiveEvent
,
CauseAware
/**
* 服务器主动要求更换另一个服务器
*/
@MiraiInternalAPI
data class
RequireReconnect
internal
constructor
(
override
val
bot
:
Bot
)
:
BotOfflineEvent
(),
Packet
,
BotPassiveEvent
@MiraiExperimentalAPI
interface
CauseAware
{
val
cause
:
Throwable
?
}
}
/**
...
...
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