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
a4ea0772
Commit
a4ea0772
authored
Nov 08, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate to data class
parent
70ae02f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
37 deletions
+56
-37
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
....mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
+23
-23
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/Touch.kt
...et.mamoe.mirai/network/protocol/tim/packet/login/Touch.kt
+33
-14
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
View file @
a4ea0772
...
@@ -357,31 +357,31 @@ internal class TIMBotNetworkHandler internal constructor(override inline val bot
...
@@ -357,31 +357,31 @@ internal class TIMBotNetworkHandler internal constructor(override inline val bot
suspend
fun
onPacketReceived
(
packet
:
Any
)
{
//complex function, but it doesn't matter
suspend
fun
onPacketReceived
(
packet
:
Any
)
{
//complex function, but it doesn't matter
when
(
packet
)
{
when
(
packet
)
{
is
TouchPacket
.
TouchResponse
->
{
is
TouchPacket
.
TouchResponse
.
OK
->
{
if
(
packet
.
serverIP
!=
null
)
{
//redirection
loginIP
=
packet
.
loginIP
withContext
(
userContext
)
{
loginTime
=
packet
.
loginTime
socket
.
close
()
token0825
=
packet
.
token0825
socket
=
BotSocketAdapter
(
packet
.
serverIP
!!
,
socket
.
configuration
)
bot
.
logger
.
info
(
"Redirecting to ${packet.serverIP}"
)
loginResult
.
complete
(
socket
.
resendTouch
())
}
}
else
{
//password submission
this
.
loginIP
=
packet
.
loginIP
this
.
loginTime
=
packet
.
loginTime
this
.
token0825
=
packet
.
token0825
socket
.
sendPacket
(
socket
.
sendPacket
(
SubmitPasswordPacket
(
SubmitPasswordPacket
(
bot
=
bot
.
qqAccount
,
bot
=
bot
.
qqAccount
,
password
=
bot
.
account
.
password
,
password
=
bot
.
account
.
password
,
loginTime
=
loginTime
,
loginTime
=
loginTime
,
loginIP
=
loginIP
,
loginIP
=
loginIP
,
privateKey
=
privateKey
,
privateKey
=
privateKey
,
token0825
=
token0825
,
token0825
=
token0825
,
token00BA
=
null
,
token00BA
=
null
,
randomDeviceName
=
socket
.
configuration
.
randomDeviceName
randomDeviceName
=
socket
.
configuration
.
randomDeviceName
)
)
)
)
}
is
TouchPacket
.
TouchResponse
.
Redirection
->
{
withContext
(
userContext
)
{
socket
.
close
()
socket
=
BotSocketAdapter
(
packet
.
serverIP
!!
,
socket
.
configuration
)
bot
.
logger
.
info
(
"Redirecting to ${packet.serverIP}"
)
loginResult
.
complete
(
socket
.
resendTouch
())
}
}
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/Touch.kt
View file @
a4ea0772
...
@@ -44,31 +44,50 @@ object TouchPacket : PacketFactory<TouchPacket.TouchResponse, TouchKey>(TouchKey
...
@@ -44,31 +44,50 @@ object TouchPacket : PacketFactory<TouchPacket.TouchResponse, TouchKey>(TouchKey
}
}
}
}
class
TouchResponse
:
Packet
{
sealed
class
TouchResponse
:
Packet
{
var
serverIP
:
String
?
=
null
data class
OK
(
internal
set
var
loginTime
:
Int
,
var
loginTime
:
Int
=
0
val
loginIP
:
String
,
internal
set
val
token0825
:
ByteArray
)
:
TouchResponse
()
{
override
fun
equals
(
other
:
Any
?):
Boolean
{
if
(
this
===
other
)
return
true
if
(
other
!
is
OK
)
return
false
lateinit
var
loginIP
:
String
if
(
loginTime
!=
other
.
loginTime
)
return
false
internal
set
if
(
loginIP
!=
other
.
loginIP
)
return
false
lateinit
var
token0825
:
ByteArray
if
(!
token0825
.
contentEquals
(
other
.
token0825
))
return
false
internal
set
return
true
}
override
fun
hashCode
():
Int
{
var
result
=
loginTime
result
=
31
*
result
+
loginIP
.
hashCode
()
result
=
31
*
result
+
token0825
.
contentHashCode
()
return
result
}
}
data class
Redirection
(
val
serverIP
:
String
?
=
null
)
:
TouchResponse
()
}
}
override
suspend
fun
ByteReadPacket
.
decode
(
id
:
PacketId
,
sequenceId
:
UShort
,
handler
:
BotNetworkHandler
<
*
>):
TouchResponse
=
TouchResponse
().
apply
{
override
suspend
fun
ByteReadPacket
.
decode
(
id
:
PacketId
,
sequenceId
:
UShort
,
handler
:
BotNetworkHandler
<
*
>):
TouchResponse
{
when
(
val
flag
=
readByte
().
toUByte
().
toInt
())
{
when
(
val
flag
=
readByte
().
toUByte
().
toInt
())
{
0
xFE
->
{
0
xFE
->
{
discardExact
(
94
)
discardExact
(
94
)
serverIP
=
readIP
(
)
return
TouchResponse
.
Redirection
(
readIP
()
)
}
}
0
x00
->
{
0
x00
->
{
discardExact
(
4
)
discardExact
(
4
)
token0825
=
readBytes
(
56
)
val
token0825
=
readBytes
(
56
)
discardExact
(
6
)
discardExact
(
6
)
loginTime
=
readInt
()
val
loginTime
=
readInt
()
loginIP
=
readIP
()
val
loginIP
=
readIP
()
return
TouchResponse
.
OK
(
loginTime
,
loginIP
,
token0825
)
}
}
else
->
throw
IllegalStateException
(
flag
.
toByte
().
toUHexString
())
else
->
throw
IllegalStateException
(
flag
.
toByte
().
toUHexString
())
...
...
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