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
aa0bf81a
Commit
aa0bf81a
authored
Jan 31, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add init retry
parent
4c1b25d4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
15 deletions
+24
-15
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+0
-3
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
...ndroid/network/protocol/packet/chat/receive/MessageSvc.kt
+4
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
+15
-10
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt
...nMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt
+5
-0
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
aa0bf81a
...
...
@@ -312,19 +312,16 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
val
rawInput
=
try
{
channel
.
read
()
}
catch
(
e
:
ClosedChannelException
)
{
close
()
bot
.
tryReinitializeNetworkHandler
(
e
)
return
}
catch
(
e
:
ReadPacketInternalException
)
{
bot
.
logger
.
error
(
"Socket channel read failed: ${e.message}"
)
close
()
bot
.
tryReinitializeNetworkHandler
(
e
)
return
}
catch
(
e
:
CancellationException
)
{
return
}
catch
(
e
:
Throwable
)
{
bot
.
logger
.
error
(
"Caught unexpected exceptions"
,
e
)
close
()
bot
.
tryReinitializeNetworkHandler
(
e
)
return
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
aa0bf81a
...
...
@@ -25,6 +25,7 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket
import
net.mamoe.mirai.qqandroid.utils.toMessageChain
import
net.mamoe.mirai.qqandroid.utils.toRichTextElems
import
net.mamoe.mirai.utils.cryptor.contentToString
import
net.mamoe.mirai.utils.currentTimeSeconds
import
net.mamoe.mirai.utils.io.hexToBytes
import
net.mamoe.mirai.utils.io.toReadPacket
import
kotlin.math.absoluteValue
...
...
@@ -162,8 +163,9 @@ internal class MessageSvc {
)
),
msgSeq
=
client
.
atomicNextMessageSequenceId
(),
msgRand
=
Random
.
nextInt
().
absoluteValue
// syncCookie = client.c2cMessageSync.syncCookie.takeIf { it.isNotEmpty() } ?: "08 92 C2 C4 F1 05 10 92 C2 C4 F1 05 18 E6 ED B9 C3 02 20 89 FE BE A4 06 28 89 84 F9 A2 06 48 DE 8C EA E5 0E 58 D9 BD BB A0 09 60 1D 68 92 C2 C4 F1 05 70 00".hexToBytes(),
msgRand
=
Random
.
nextInt
().
absoluteValue
,
syncCookie
=
client
.
c2cMessageSync
.
syncCookie
?.
takeIf
{
it
.
isNotEmpty
()
}
?:
SyncCookie
(
currentTimeSeconds
).
toByteArray
(
SyncCookie
.
serializer
())
// msgVia = 1
)
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
View file @
aa0bf81a
...
...
@@ -6,6 +6,7 @@ import kotlinx.coroutines.*
import
net.mamoe.mirai.event.broadcast
import
net.mamoe.mirai.event.events.BotOfflineEvent
import
net.mamoe.mirai.network.BotNetworkHandler
import
net.mamoe.mirai.network.closeAndJoin
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.io.logStacktrace
import
kotlin.coroutines.CoroutineContext
...
...
@@ -92,7 +93,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
try
{
if
(
::
_network
.
isInitialized
)
{
BotOfflineEvent
(
this
).
broadcast
()
_network
.
close
(
cause
)
_network
.
close
AndJoin
(
cause
)
}
}
catch
(
e
:
Exception
)
{
logger
.
error
(
"Cannot close network handler"
,
e
)
...
...
@@ -105,22 +106,26 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
break
@
loginLoop
}
catch
(
e
:
Exception
)
{
e
.
logStacktrace
()
_network
.
close
(
e
)
_network
.
close
AndJoin
(
e
)
}
logger
.
warning
(
"Login failed. Retrying in 3s..."
)
delay
(
3000
)
}
while
(
true
)
{
try
{
return
_network
.
init
()
}
catch
(
e
:
Exception
)
{
e
.
logStacktrace
()
_network
.
close
(
e
)
repeat
(
1
)
block
@
{
repeat
(
2
)
{
try
{
_network
.
init
()
return
@
block
}
catch
(
e
:
Exception
)
{
e
.
logStacktrace
()
}
logger
.
warning
(
"Init failed. Retrying in 3s..."
)
delay
(
3000
)
}
logger
.
warning
(
"Init failed. Retrying in 3s..."
)
delay
(
3000
)
logger
.
error
(
"cannot init. some features may be affected"
)
}
}
protected
abstract
fun
createNetworkHandler
(
coroutineContext
:
CoroutineContext
):
N
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt
View file @
aa0bf81a
...
...
@@ -73,4 +73,9 @@ abstract class BotNetworkHandler : CoroutineScope {
}
}
}
}
suspend
fun
BotNetworkHandler
.
closeAndJoin
(
cause
:
Throwable
?
=
null
){
this
.
close
(
cause
)
this
.
supervisor
.
join
()
}
\ No newline at end of file
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