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
d7ac5fa1
Commit
d7ac5fa1
authored
Jan 30, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add atomic message sequence id
parent
f0d8bbcc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
10 deletions
+57
-10
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt
...tlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt
+2
-0
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
+55
-10
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt
View file @
d7ac5fa1
...
@@ -96,6 +96,8 @@ internal open class QQAndroidClient(
...
@@ -96,6 +96,8 @@ internal open class QQAndroidClient(
val
apkVersionName
:
ByteArray
=
"8.2.0"
.
toByteArray
()
val
apkVersionName
:
ByteArray
=
"8.2.0"
.
toByteArray
()
private
val
messageSequenceId
:
AtomicInt
=
atomic
(
0
)
internal
fun
atomicNextMessageSequenceId
():
Int
=
messageSequenceId
.
getAndIncrement
()
val
appClientVersion
:
Int
=
0
val
appClientVersion
:
Int
=
0
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
d7ac5fa1
...
@@ -25,8 +25,10 @@ import net.mamoe.mirai.qqandroid.utils.toRichTextElems
...
@@ -25,8 +25,10 @@ import net.mamoe.mirai.qqandroid.utils.toRichTextElems
import
net.mamoe.mirai.utils.cryptor.contentToString
import
net.mamoe.mirai.utils.cryptor.contentToString
import
net.mamoe.mirai.utils.io.hexToBytes
import
net.mamoe.mirai.utils.io.hexToBytes
import
net.mamoe.mirai.utils.io.toReadPacket
import
net.mamoe.mirai.utils.io.toReadPacket
import
kotlin.math.absoluteValue
import
kotlin.random.Random
class
MessageSvc
{
internal
class
MessageSvc
{
/**
/**
* 告知要刷新好友消息
* 告知要刷新好友消息
*/
*/
...
@@ -119,8 +121,16 @@ class MessageSvc {
...
@@ -119,8 +121,16 @@ class MessageSvc {
}
}
}
}
internal
object
PbSendMsg
:
PacketFactory
<
MsgSvc
.
PbSendMsgResp
>(
"MessageSvc.PbSendMsg"
)
{
internal
object
PbSendMsg
:
PacketFactory
<
PbSendMsg
.
Response
>(
"MessageSvc.PbSendMsg"
)
{
object
Response
:
Packet
sealed
class
Response
:
Packet
{
object
SUCCESS
:
Response
()
{
override
fun
toString
():
String
=
"MessageSvc.PbSendMsg.Response.SUCCESS"
}
data class
Failed
(
val
errorCode
:
Int
,
val
errorMessage
:
String
)
:
Response
()
{
override
fun
toString
():
String
=
"MessageSvc.PbSendMsg.Response.FAILED(errorCode=$errorCode, errorMessage=$errorMessage"
}
}
/**
/**
* 发送好友消息
* 发送好友消息
...
@@ -142,18 +152,53 @@ class MessageSvc {
...
@@ -142,18 +152,53 @@ class MessageSvc {
richText
=
ImMsgBody
.
RichText
(
richText
=
ImMsgBody
.
RichText
(
elems
=
message
.
toRichTextElems
()
elems
=
message
.
toRichTextElems
()
)
)
)
),
// msgSeq = 17041,
msgSeq
=
client
.
atomicNextMessageSequenceId
(),
// msgRand = Random.nextInt().absoluteValue,
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(),
// 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(),
// msgVia = 1
// msgVia = 1
)
)
}
/**
* 发送群消息
*/
fun
ToGroup
(
client
:
QQAndroidClient
,
groupId
:
Long
,
message
:
MessageChain
):
OutgoingPacket
=
buildOutgoingUniPacket
(
client
)
{
///writeFully("0A 08 0A 06 08 89 FC A6 8C 0B 12 06 08 01 10 00 18 00 1A 1F 0A 1D 12 08 0A 06 0A 04 F0 9F 92 A9 12 11 AA 02 0E 88 01 00 9A 01 08 78 00 F8 01 00 C8 02 00 20 9B 7A 28 F4 CA 9B B8 03 32 34 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 40 01".hexToBytes())
///return@buildOutgoingUniPacket
writeProtoBuf
(
MsgSvc
.
PbSendMsgReq
.
serializer
(),
MsgSvc
.
PbSendMsgReq
(
routingHead
=
MsgSvc
.
RoutingHead
(
grp
=
MsgSvc
.
Grp
(
groupCode
=
groupId
)),
// TODO: 2020/1/30 确认这里是 id 还是 internalId
contentHead
=
MsgComm
.
ContentHead
(
pkgNum
=
1
),
msgBody
=
ImMsgBody
.
MsgBody
(
richText
=
ImMsgBody
.
RichText
(
elems
=
message
.
toRichTextElems
()
)
),
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(),
// msgVia = 1
)
)
)
)
}
}
override
suspend
fun
ByteReadPacket
.
decode
(
bot
:
QQAndroidBot
):
MsgSvc
.
PbSendMsgResp
{
override
suspend
fun
ByteReadPacket
.
decode
(
bot
:
QQAndroidBot
):
Response
{
discardExact
(
4
)
discardExact
(
4
)
return
readRemainingAsProtoBuf
(
MsgSvc
.
PbSendMsgResp
.
serializer
())
val
response
=
readRemainingAsProtoBuf
(
MsgSvc
.
PbSendMsgResp
.
serializer
())
return
if
(
response
.
result
==
0
)
{
Response
.
SUCCESS
}
else
{
Response
.
Failed
(
response
.
errtype
,
response
.
errmsg
)
}
}
}
}
}
}
}
...
...
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