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
d5587bb3
Commit
d5587bb3
authored
Oct 18, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Name and permission analyzing is now available
parent
7e90737c
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
406 additions
and
389 deletions
+406
-389
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/GroupEvents.kt
...onMain/kotlin/net.mamoe.mirai/event/events/GroupEvents.kt
+9
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt
...n/net.mamoe.mirai/message/internal/MessageDataInternal.kt
+63
-56
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/EventPacketHandler.kt
....mirai/network/protocol/tim/handler/EventPacketHandler.kt
+13
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/FriendOnlineStatusChanged.kt
.../network/protocol/tim/packet/FriendOnlineStatusChanged.kt
+2
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/ServerEvent.kt
...et.mamoe.mirai/network/protocol/tim/packet/ServerEvent.kt
+0
-325
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/AndroidOnlineEventPackets.kt
...rk/protocol/tim/packet/event/AndroidOnlineEventPackets.kt
+16
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/GroupEventPackets.kt
...ai/network/protocol/tim/packet/event/GroupEventPackets.kt
+32
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MessageEventPackets.kt
.../network/protocol/tim/packet/event/MessageEventPackets.kt
+122
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/ServerEventPackets.kt
...i/network/protocol/tim/packet/event/ServerEventPackets.kt
+126
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/TypingEventPackets.kt
...i/network/protocol/tim/packet/event/TypingEventPackets.kt
+21
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ByteReadPacketUtil.kt
...onMain/kotlin/net.mamoe.mirai/utils/ByteReadPacketUtil.kt
+1
-1
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
+1
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/GroupEvents.kt
View file @
d5587bb3
...
...
@@ -5,12 +5,20 @@ import net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.contact.QQ
import
net.mamoe.mirai.message.Message
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.network.protocol.tim.packet.SenderPermission
abstract
class
GroupEvent
(
bot
:
Bot
,
val
group
:
Group
)
:
BotEvent
(
bot
)
class
GroupMessageEvent
(
bot
:
Bot
,
group
:
Group
,
val
sender
:
QQ
,
val
message
:
MessageChain
)
:
GroupEvent
(
bot
,
group
)
{
class
GroupMessageEvent
(
bot
:
Bot
,
group
:
Group
,
val
sender
:
QQ
,
val
message
:
MessageChain
,
val
senderPermission
:
SenderPermission
,
val
senderName
:
String
//若他有群名片就是群名片, 没有就是昵称
)
:
GroupEvent
(
bot
,
group
)
{
suspend
inline
fun
reply
(
message
:
Message
)
=
group
.
sendMessage
(
message
)
suspend
inline
fun
reply
(
message
:
String
)
=
group
.
sendMessage
(
message
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt
View file @
d5587bb3
...
...
@@ -29,30 +29,31 @@ internal fun IoBuffer.parseMessageImage0x06(): Image {
//MiraiLogger.logDebug(this.toUHexString())
val
filenameLength
=
readShort
()
val
suffix
=
readString
(
filenameLength
).
substringAfter
(
"."
)
discardExact
(
this
.
readRemaining
-
37
-
1
-
filenameLength
-
2
-
8
-
4
)
val
imageId
=
readString
(
36
)
MiraiLogger
.
logDebug
(
"imageId=$imageId"
)
//todo ID似乎错了??
discardExact
(
1
)
//0x41
return
Image
(
"{$imageId}.$suffix"
)
discardExact
(
8
)
//03 00 04 00 00 02 9C 04
val
length
=
readShort
()
//27
discardExact
(
1
)
return
Image
(
"{${readString(length - 2/*去掉首尾各一个*/)}}.$suffix"
)
}
}
//00 1B filenameLength
// 43 37 46 29 5F 34 32 34 4E 33 55 37 7B 4C 47 36 7D 4F 25 5A 51 58 51 2E 6A 70 67 get suffix
// 03 00 04 00 00 02 9C 04
// 00 25 2F 32 65 37 61 65 33 36 66 2D 61 39 31 63 2D 34 31 32 39 2D 62 61 34 32 2D 37 65 30 31 32 39 37 37 35 63 63 38 14
// 00 04 03 00 00 00 18
// 00 25 2F 32 65 37 61 65 33 36 66 2D 61 39 31 63 2D 34 31 32 39 2D 62 61 34 32 2D 37 65 30 31 32 39 37 37 35 63 63 38 19
// 00 04 00 00 00 2E 1A 00 04 00 00 00 2E FF
// 00 63 16 20 20 39 39 31 30 20 38 38 31 43 42 20 20 20 20 20 20 20 36 36 38 65 35 43 36 38 45 36 42 44 32 46 35 38 34 31 42 30 39 37 39 45 37 46 32 35 34 33 38 38 31 33 43 33 2E 6A 70 67 66 2F 32 65 37 61 65 33 36 66 2D 61 39 31 63 2D 34 31 32 39 2D 62 61 34 32 2D 37 65 30 31 32 39 37 37 35 63 63 38 41
fun
main
()
{
println
(
"f/"
.
toByteArray
().
toUHexString
())
println
(
"16 20 20 39 39 31 30 20 38 38 31 43 42 20 20 20 20 20 20 20 36 36 38 65 35 43 36 38 45 36 42 44 32 46 35 38 34 31 42 30 39 37 39 45 37 46 32 35 34 33 38 38 31 33 43 33 2E 6A 70 67 66 2F 32 65 37 61 65 33 36 66 2D 61 39 31 63 2D 34 31 32 39 2D 62 61 34 32 2D 37 65 30 31 32 39 37 37 35 63 63 38 41"
.
hexToBytes
().
stringOf
())
}
internal
fun
IoBuffer
.
parseMessageImage0x03
():
Image
{
discardExact
(
1
)
return
Image
(
String
(
readLVByteArray
()))
/*
println(String(readLVByteArray()))
readTLVMap()
return Image(String(readLVByteArray().cutTail(5).getRight(42)))
/
discardExact(data.size - 47)
val imageId = String(readBytes(42))
discardExact(1)//0x41
discardExact(1)//0x42
discardExact(1)//0x43
discardExact(1)//0x41
return Image(imageId)*/
}
internal
fun
ByteReadPacket
.
parseMessageChain
():
MessageChain
{
...
...
@@ -63,50 +64,56 @@ internal fun ByteReadPacket.readMessage(): Message? {
val
messageType
=
this
.
readByte
().
toInt
()
val
sectionLength
=
this
.
readShort
().
toLong
()
//sectionLength: short
val
sectionData
=
this
.
readIoBuffer
(
sectionLength
.
toInt
())
//use buffer instead
return
when
(
messageType
)
{
0
x01
->
sectionData
.
parsePlainText
()
0
x02
->
sectionData
.
parseMessageFace
()
0
x03
->
sectionData
.
parseMessageImage0x03
()
0
x06
->
sectionData
.
parseMessageImage0x06
()
0
x19
->
{
//未知, 可能是长文本?
//bot手机自己跟自己发消息会出这个
//似乎手机发消息就会有这个?
//sectionData: 01 00 1C AA 02 19 08 00 88 01 00 9A 01 11 78 00 C8 01 00 F0 01 00 F8 01 00 90 02 00 C8 02 00
// 01 00 1C AA 02 19 08 00 88 01 00 9A 01 11 78 00 C8 01 00 F0 01 00 F8 01 00 90 02 00 C8 02 00
return
null
sectionData
.
readBytes
().
debugPrint
(
"sectionData"
)
return
PlainText
(
"[UNKNOWN(${this.readBytes().toUHexString()})]"
)
println
()
val
value
=
readLVByteArray
()
//todo 未知压缩算法
PlainText
(
String
(
value
))
// PlainText(String(GZip.uncompress( value)))
}
return
try
{
when
(
messageType
)
{
0
x01
->
sectionData
.
parsePlainText
()
0
x02
->
sectionData
.
parseMessageFace
()
0
x03
->
sectionData
.
parseMessageImage0x03
()
0
x06
->
sectionData
.
parseMessageImage0x06
()
0
x19
->
{
//未知, 可能是长文本?
//bot手机自己跟自己发消息会出这个
//似乎手机发消息就会有这个?
//sectionData: 01 00 1C AA 02 19 08 00 88 01 00 9A 01 11 78 00 C8 01 00 F0 01 00 F8 01 00 90 02 00 C8 02 00
// 01 00 1C AA 02 19 08 00 88 01 00 9A 01 11 78 00 C8 01 00 F0 01 00 F8 01 00 90 02 00 C8 02 00
return
null
sectionData
.
readBytes
().
debugPrint
(
"sectionData"
)
return
PlainText
(
"[UNKNOWN(${this.readBytes().toUHexString()})]"
)
println
()
val
value
=
readLVByteArray
()
//todo 未知压缩算法
PlainText
(
String
(
value
))
// PlainText(String(GZip.uncompress( value)))
}
0
x14
->
{
//长文本
val
value
=
readLVByteArray
()
println
(
value
.
size
)
println
(
value
.
toUHexString
())
//todo 未知压缩算法
this
.
discardExact
(
7
)
//几个TLV
return
PlainText
(
String
(
value
))
}
0
x0E
->
{
null
}
0
x14
->
{
//长文本
else
->
{
println
(
"未知的messageType=0x${messageType.toByte().toUHexString()}"
)
println
(
"后文=${this.readBytes().toUHexString()}"
)
null
//是否要用 sectionData.read?
val
value
=
readLVByteArray
()
println
(
value
.
size
)
println
(
value
.
toUHexString
())
//todo 未知压缩算法
this
.
discardExact
(
7
)
//几个TLV
return
PlainText
(
String
(
value
))
}
0
x0E
->
{
null
}
else
->
{
println
(
"未知的messageType=0x${messageType.toByte().toUHexString()}"
)
println
(
"后文=${this.readBytes().toUHexString()}"
)
null
}
}
}
finally
{
sectionData
.
release
(
IoBuffer
.
Pool
)
}
}
fun
ByteReadPacket
.
readMessageChain
():
MessageChain
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/EventPacketHandler.kt
View file @
d5587bb3
...
...
@@ -10,7 +10,9 @@ import net.mamoe.mirai.getQQ
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.network.BotSession
import
net.mamoe.mirai.network.distributePacket
import
net.mamoe.mirai.network.protocol.tim.packet.*
import
net.mamoe.mirai.network.protocol.tim.packet.IgnoredServerEventPacket
import
net.mamoe.mirai.network.protocol.tim.packet.ServerFriendOnlineStatusChangedPacket
import
net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
import
net.mamoe.mirai.network.protocol.tim.packet.action.ClientSendFriendMessagePacket
import
net.mamoe.mirai.network.protocol.tim.packet.action.ClientSendGroupMessagePacket
import
net.mamoe.mirai.network.protocol.tim.packet.action.ServerSendFriendMessageResponsePacket
...
...
@@ -41,7 +43,14 @@ class EventPacketHandler(session: BotSession) : PacketHandler(session) {
is
ServerGroupMessageEventPacket
->
{
if
(
packet
.
qq
.
toLong
()
==
bot
.
account
.
account
)
return
GroupMessageEvent
(
bot
,
bot
.
getGroupByNumber
(
packet
.
groupNumber
),
bot
.
getQQ
(
packet
.
qq
),
packet
.
message
).
broadcast
()
GroupMessageEvent
(
bot
,
group
=
bot
.
getGroupByNumber
(
packet
.
groupNumber
),
sender
=
bot
.
getQQ
(
packet
.
qq
),
message
=
packet
.
message
,
senderName
=
packet
.
senderName
,
senderPermission
=
packet
.
senderPermission
).
broadcast
()
}
is
ServerSendFriendMessageResponsePacket
,
...
...
@@ -49,8 +58,8 @@ class EventPacketHandler(session: BotSession) : PacketHandler(session) {
//ignored
}
is
ServerF
iel
dOnlineStatusChangedPacket
.
Encrypted
->
distributePacket
(
packet
.
decrypt
(
sessionKey
))
is
ServerF
iel
dOnlineStatusChangedPacket
->
{
is
ServerF
rien
dOnlineStatusChangedPacket
.
Encrypted
->
distributePacket
(
packet
.
decrypt
(
sessionKey
))
is
ServerF
rien
dOnlineStatusChangedPacket
->
{
MiraiLogger
.
logInfo
(
"${packet.qq.toLong()} 登录状态改变为 ${packet.status}"
)
//TODO
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/FriendOnlineStatusChanged.kt
View file @
d5587bb3
...
...
@@ -13,7 +13,7 @@ import kotlin.properties.Delegates
* 好友在线状态改变
*/
@PacketId
(
0
x00_81u
)
class
ServerF
iel
dOnlineStatusChangedPacket
(
input
:
ByteReadPacket
)
:
ServerPacket
(
input
)
{
class
ServerF
rien
dOnlineStatusChangedPacket
(
input
:
ByteReadPacket
)
:
ServerPacket
(
input
)
{
var
qq
:
UInt
by
Delegates
.
notNull
()
lateinit
var
status
:
OnlineStatus
...
...
@@ -28,6 +28,6 @@ class ServerFieldOnlineStatusChangedPacket(input: ByteReadPacket) : ServerPacket
@PacketId
(
0
x00_81u
)
class
Encrypted
(
input
:
ByteReadPacket
)
:
ServerPacket
(
input
)
{
fun
decrypt
(
sessionKey
:
ByteArray
):
ServerF
ieldOnlineStatusChangedPacket
=
ServerFiel
dOnlineStatusChangedPacket
(
this
.
decryptBy
(
sessionKey
)).
applySequence
(
sequenceId
)
fun
decrypt
(
sessionKey
:
ByteArray
):
ServerF
riendOnlineStatusChangedPacket
=
ServerFrien
dOnlineStatusChangedPacket
(
this
.
decryptBy
(
sessionKey
)).
applySequence
(
sequenceId
)
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/ServerEvent.kt
deleted
100644 → 0
View file @
7e90737c
This diff is collapsed.
Click to expand it.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/AndroidOnlineEventPackets.kt
0 → 100644
View file @
d5587bb3
package
net.mamoe.mirai.network.protocol.tim.packet.event
import
kotlinx.io.core.ByteReadPacket
import
net.mamoe.mirai.network.protocol.tim.packet.EventPacketIdentity
import
net.mamoe.mirai.network.protocol.tim.packet.ServerEventPacket
/**
* Android 客户端上线
*/
class
ServerAndroidOnlineEventPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerEventPacket
(
input
,
eventIdentity
)
/**
* Android 客户端下线
*/
class
ServerAndroidOfflineEventPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerEventPacket
(
input
,
eventIdentity
)
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/GroupEventPackets.kt
0 → 100644
View file @
d5587bb3
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
)
package
net.mamoe.mirai.network.protocol.tim.packet.event
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.discardExact
import
net.mamoe.mirai.network.protocol.tim.packet.EventPacketIdentity
import
net.mamoe.mirai.network.protocol.tim.packet.ServerEventPacket
import
net.mamoe.mirai.utils.readString
/**
* 群文件上传
*/
class
ServerGroupUploadFileEventPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerEventPacket
(
input
,
eventIdentity
)
{
private
lateinit
var
xmlMessage
:
String
override
fun
decode
()
{
this
.
input
.
discardExact
(
60
)
val
size
=
this
.
input
.
readShort
().
toInt
()
this
.
input
.
discardExact
(
3
)
xmlMessage
=
this
.
input
.
readString
(
size
)
}
//todo test
}
class
ServerGroupUnknownChangedEventPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerEventPacket
(
input
,
eventIdentity
)
{
override
fun
decode
()
=
with
(
input
)
{
//00 00 00 08 00 0A 00 04 01 00 00 00 22 96 29 7B 01 01 00 00 F3 55 00 00 00 05 00 00 00 E9 00 00 00 05
//00 00 00 08 00 0A 00 04 01 00 00 00 22 96 29 7B 01 01 00 00 F3 56 00 00 00 05 00 00 00 EA 00 00 00 05
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MessageEventPackets.kt
0 → 100644
View file @
d5587bb3
@
file
:
Suppress
(
"EXPERIMENTAL_UNSIGNED_LITERALS"
,
"EXPERIMENTAL_API_USAGE"
)
package
net.mamoe.mirai.network.protocol.tim.packet.event
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.discardExact
import
kotlinx.io.core.readUInt
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.message.internal.readMessageChain
import
net.mamoe.mirai.network.protocol.tim.packet.EventPacketIdentity
import
net.mamoe.mirai.network.protocol.tim.packet.ServerEventPacket
import
net.mamoe.mirai.utils.printTLVMap
import
net.mamoe.mirai.utils.read
import
net.mamoe.mirai.utils.readLVByteArray
import
net.mamoe.mirai.utils.readTLVMap
import
kotlin.properties.Delegates
enum
class
SenderPermission
{
OWNER
,
OPERATOR
,
MEMBER
;
}
@Suppress
(
"EXPERIMENTAL_API_USAGE"
)
class
ServerGroupMessageEventPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerEventPacket
(
input
,
eventIdentity
)
{
var
groupNumber
:
UInt
by
Delegates
.
notNull
()
var
qq
:
UInt
by
Delegates
.
notNull
()
lateinit
var
senderName
:
String
/**
* 发送方权限.
*/
lateinit
var
senderPermission
:
SenderPermission
lateinit
var
message
:
MessageChain
override
fun
decode
()
=
with
(
input
)
{
discardExact
(
31
)
groupNumber
=
readUInt
()
discardExact
(
1
)
qq
=
readUInt
()
discardExact
(
48
)
readLVByteArray
()
discardExact
(
2
)
//2个0x00
message
=
readMessageChain
()
val
map
=
readTLVMap
(
true
).
withDefault
{
byteArrayOf
(
0
,
0
,
0
,
0
)
}
//map.printTLVMap("父map")
if
(
map
.
containsKey
(
18
))
{
senderName
=
map
.
getValue
(
18
).
read
{
val
tlv
=
readTLVMap
(
true
)
//tlv.printTLVMap("子map")
////群主的18: 05 00 04 00 00 00 03 08 00 04 00 00 00 04 01 00 09 48 69 6D 31 38 38 6D 6F 65 03 00 01 04 04 00 04 00 00 00 08
//群主的 子map= {5=00 00 00 03, 8=00 00 00 04, 1=48 69 6D 31 38 38 6D 6F 65, 3=04, 4=00 00 00 08}
//管理员 子map= {5=00 00 00 03, 8=00 00 00 04, 2=65 6F 6D 38 38 31 6D 69 48, 3=02, 4=00 00 00 10}
//群成员 子map= {5=00 00 00 03, 8=00 00 00 04, 2=65 6F 6D 38 38 31 6D 69 48, 3=02}
senderPermission
=
when
(
val
value0x03
=
tlv
.
getValue
(
0
x03
)[
0
].
toUInt
())
{
0
x04u
->
SenderPermission
.
OWNER
0
x03u
->
{
when
(
val
value0x04
=
tlv
.
getValue
(
0
x04
)[
3
].
toUInt
())
{
0
x08u
->
SenderPermission
.
OPERATOR
0
x10u
->
SenderPermission
.
MEMBER
else
->
error
(
"Could not determine member permission, unknown tlv(key=0x04,value=$value0x04)"
)
}
}
else
->
error
(
"Could not determine member permission, unknown tlv(key=0x03,value=$value0x03)"
)
}
when
{
tlv
.
containsKey
(
0
x01
)
->
kotlinx
.
io
.
core
.
String
(
tlv
.
getValue
(
0
x01
))
//这个人的qq昵称
tlv
.
containsKey
(
0
x02
)
->
kotlinx
.
io
.
core
.
String
(
tlv
.
getValue
(
0
x02
))
//这个人的群名片
else
->
"null"
}
}
}
}
}
//
//以前的消息: 00 00 00 25 00 08 00 02 00 01 00 09 00 06 00 01 00 00 00 01 00 0A 00 04 01 00 00 00 00 01 00 04 00 00 00 00 00 03 00 01 01 38 03 3E 03 3F A2 76 E4 B8 DD 58 2C 60 86 35 3A 30 B3 C7 63 4A 80 E7 CD 5B 64 00 0B 78 16 5D A3 0A FD 01 1D 00 00 00 00 01 00 00 00 01 4D 53 47 00 00 00 00 00 5D A3 0A FD AB 77 16 02 00 00 00 00 0C 00 86 22 00 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91 00 00 01 00 04 01 00 01 36 0E 00 07 01 00 04 00 00 00 09 19 00 18 01 00 15 AA 02 12 9A 01 0F 80 01 01 C8 01 00 F0 01 00 F8 01 00 90 02 00
//刚刚的消息: 00 00 00 2D 00 05 00 02 00 01 00 06 00 04 00 01 2E 01 00 09 00 06 00 01 00 00 00 01 00 0A 00 04 01 00 00 00 00 01 00 04 00 00 00 00 00 03 00 01 01 38 03 3E 03 3F A2 76 E4 B8 DD 11 F4 B2 F2 1A E7 1F C4 F1 3F 23 FB 74 80 42 64 00 0B 78 1A 5D A3 26 C1 01 1D 00 00 00 00 01 00 00 00 01 4D 53 47 00 00 00 00 00 5D A3 26 C1 AA 34 08 42 00 00 00 00 0C 00 86 22 00 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91 00 00 01 00 09 01 00 06 E4 BD A0 E5 A5 BD 0E 00 07 01 00 04 00 00 00 09 19 00 18 01 00 15 AA 02 12 9A 01 0F 80 01 01 C8 01 00 F0 01 00 F8 01 00 90 02 00
class
ServerFriendMessageEventPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerEventPacket
(
input
,
eventIdentity
)
{
val
qq
:
UInt
get
()
=
eventIdentity
.
from
/**
* 是否是在这次登录之前的消息, 即消息记录
*/
var
isPrevious
:
Boolean
=
false
lateinit
var
message
:
MessageChain
//来自自己发送给自己
//00 00 00 20 00 05 00 02 00 06 00 06 00 04 00 01 01 07 00 09 00 06 03 E9 20 02 EB 94 00 0A 00 04 01 00 00 00 0C 17 76 E4 B8 DD 76 E4 B8 DD 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0B A6 D2 5D A3 2A 3F 00 00 5D A3 2A 3F 01 00 00 00 00 4D 53 47 00 00 00 00 00 5D A3 2A 3F 0C 8A 59 3D 00 00 00 00 0A 00 86 02 00 06 E5 AE 8B E4 BD 93 00 00 01 00 06 01 00 03 31 32 33 19 00 1F 01 00 1C AA 02 19 08 00 88 01 00 9A 01 11 78 00 C8 01 00 F0 01 00 F8 01 00 90 02 00 C8 02 00 0E 00 0E 01 00 04 00 00 00 00 0A 00 04 00 00 00 00
override
fun
decode
()
=
with
(
input
)
{
input
.
discardExact
(
2
)
val
l1
=
readShort
()
discardExact
(
1
)
//0x00
isPrevious
=
readByte
().
toInt
()
==
0
x08
discardExact
(
l1
.
toInt
()
-
2
)
discardExact
(
69
)
readLVByteArray
()
//font
discardExact
(
2
)
//2个0x00
message
=
readMessageChain
()
val
map
:
Map
<
Int
,
ByteArray
>
=
readTLVMap
(
true
).
withDefault
{
byteArrayOf
()
}
map
.
printTLVMap
(
"readTLVMap"
)
//println("map.getValue(18)=" + map.getValue(18).toUHexString())
//19 00 38 01 00 35 AA 02 32 50 03 60 00 68 00 9A 01 29 08 09 20 BF 02 80 01 01 C8 01 00 F0 01 00 F8 01 00 90 02 00 98 03 00 A0 03 20 B0 03 00 B8 03 00 C0 03 00 D0 03 00 E8 03 00 12 00 25 01 00 09 48 69 6D 31 38 38 6D 6F 65 03 00 01 04 04 00 04 00 00 00 08 05 00 04 00 00 00 01 08 00 04 00 00 00 01
/*
val offset = unknownLength0 + fontLength//57
event = MessageChain(PlainText(let {
val length = input.readShortAt(101 + offset)//
input.goto(103 + offset).readString(length.toInt())
}))*/
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/ServerEventPackets.kt
0 → 100644
View file @
d5587bb3
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"EXPERIMENTAL_UNSIGNED_LITERALS"
)
package
net.mamoe.mirai.network.protocol.tim.packet
import
kotlinx.io.core.*
import
net.mamoe.mirai.network.protocol.tim.TIMProtocol
import
net.mamoe.mirai.network.protocol.tim.packet.event.*
import
net.mamoe.mirai.utils.*
/**
* 事件的识别 ID. 在 [事件确认包][ServerEventPacket.ResponsePacket] 中被使用.
*/
data class
EventPacketIdentity
(
val
from
:
UInt
,
//对于好友消息, 这个是发送人
val
to
:
UInt
,
//对于好友消息, 这个是bot
internal
val
uniqueId
:
IoBuffer
//8
)
{
override
fun
toString
():
String
=
"(from=$from, to=$to)"
}
fun
BytePacketBuilder
.
writeEventPacketIdentity
(
identity
:
EventPacketIdentity
)
=
with
(
identity
)
{
writeUInt
(
from
)
writeUInt
(
to
)
writeFully
(
uniqueId
)
}
fun
<
S
:
ServerEventPacket
>
S
.
applyId
(
id
:
UShort
):
S
{
this
.
id
=
id
return
this
}
/**
* Packet id: `00 CE` or `00 17`
*
* @author Him188moe
*/
abstract
class
ServerEventPacket
(
input
:
ByteReadPacket
,
val
eventIdentity
:
EventPacketIdentity
)
:
ServerPacket
(
input
)
{
override
var
id
:
UShort
=
0
u
class
Raw
(
input
:
ByteReadPacket
,
override
val
id
:
UShort
)
:
ServerPacket
(
input
)
{
fun
distribute
():
ServerEventPacket
=
with
(
input
)
{
val
eventIdentity
=
EventPacketIdentity
(
from
=
readUInt
(),
to
=
readUInt
(),
uniqueId
=
readIoBuffer
(
8
)
)
discardExact
(
2
)
val
type
=
readUShort
()
//DebugLogger.logPurple("unknown2Byte+byte = ${unknown2Byte.toUHexString()} ${type.toUHexString()}")
return
when
(
type
.
toUInt
())
{
0
x00C4u
->
{
discardExact
(
13
)
if
(
readBoolean
())
{
ServerAndroidOfflineEventPacket
(
input
,
eventIdentity
)
}
else
{
ServerAndroidOnlineEventPacket
(
input
,
eventIdentity
)
}
}
0
x002Du
->
ServerGroupUploadFileEventPacket
(
input
,
eventIdentity
)
0
x0052u
->
ServerGroupMessageEventPacket
(
input
,
eventIdentity
)
0
x00A6u
->
ServerFriendMessageEventPacket
(
input
.
debugPrint
(
"好友消息事件"
),
eventIdentity
)
//00 00 00 08 00 0A 00 04 01 00 00 00 00 00 00 16 00 00 00 37 08 02 1A 12 08 95 02 10 90 04 40 98 E1 8C ED 05 48 AF 96 C3 A4 03 08 A2 FF 8C F0 03 10 DD F1 92 B7 07 1A 29 08 00 10 05 18 98 E1 8C ED 05 20 01 28 FF FF FF FF 0F 32 15 E5 AF B9 E6 96 B9 E6 AD A3 E5 9C A8 E8 BE 93 E5 85 A5 2E 2E 2E
//00 00 00 08 00 0A 00 04 01 00 00 00 00 00 00 07 00 00 00
0
x0210u
->
{
discardExact
(
19
)
println
(
"type事件"
+
readUByte
().
toUInt
())
//todo 错了. 可能是 00 79 才是.
ServerFriendTypingCanceledPacket
(
input
,
eventIdentity
)
/*
if (readUByte().toUInt() == 0x37u) ServerFriendTypingStartedPacket(input, eventIdentity)
else /*0x22*/ ServerFriendTypingCanceledPacket(input, eventIdentity)*/
}
0
x0079u
->
IgnoredServerEventPacket
(
type
,
input
,
eventIdentity
)
//"02 10", "00 12" -> ServerUnknownEventPacket(input, eventIdentity)
else
->
{
MiraiLogger
.
logDebug
(
"UnknownEvent type = ${type.toInt().toByteArray().toUHexString()}"
)
UnknownServerEventPacket
(
input
,
eventIdentity
)
}
}.
applyId
(
id
).
applySequence
(
sequenceId
)
}
class
Encrypted
(
input
:
ByteReadPacket
,
override
var
id
:
UShort
,
override
var
sequenceId
:
UShort
)
:
ServerPacket
(
input
)
{
fun
decrypt
(
sessionKey
:
ByteArray
):
Raw
=
Raw
(
this
.
decryptBy
(
sessionKey
),
id
).
applySequence
(
sequenceId
)
}
}
inner
class
ResponsePacket
(
val
bot
:
Long
,
val
sessionKey
:
ByteArray
)
:
ClientPacket
()
{
override
val
id
:
UShort
get
()
=
this
@ServerEventPacket
.
id
override
val
sequenceId
:
UShort
get
()
=
this
@ServerEventPacket
.
sequenceId
override
fun
encode
(
builder
:
BytePacketBuilder
)
=
with
(
builder
)
{
this
.
writeQQ
(
bot
)
this
.
writeHex
(
TIMProtocol
.
fixVer2
)
this
.
encryptAndWrite
(
sessionKey
)
{
writeEventPacketIdentity
(
eventIdentity
)
}
}
}
}
/**
* 忽略的事件.
* 如 00 79: 总是与 01 12 一起发生, 但 00 79 却没多大意义
*/
@Suppress
(
"unused"
)
class
IgnoredServerEventPacket
(
val
eventId
:
UShort
,
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerEventPacket
(
input
,
eventIdentity
)
/**
* Unknown event
*/
class
UnknownServerEventPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerEventPacket
(
input
,
eventIdentity
)
{
override
fun
decode
()
{
MiraiLogger
.
logDebug
(
"UnknownServerEventPacket data: "
+
this
.
input
.
readBytes
().
toUHexString
())
}
}
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/TypingEventPackets.kt
0 → 100644
View file @
d5587bb3
package
net.mamoe.mirai.network.protocol.tim.packet.event
import
kotlinx.io.core.ByteReadPacket
import
net.mamoe.mirai.network.protocol.tim.packet.EventPacketIdentity
import
net.mamoe.mirai.network.protocol.tim.packet.ServerEventPacket
sealed
class
ServerFriendTypingPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerEventPacket
(
input
,
eventIdentity
)
{
val
qq
get
()
=
eventIdentity
.
from
}
/**
* 对方正在输入
*/
class
ServerFriendTypingStartedPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerFriendTypingPacket
(
input
,
eventIdentity
)
/**
* 对方取消了输入
*/
class
ServerFriendTypingCanceledPacket
(
input
:
ByteReadPacket
,
eventIdentity
:
EventPacketIdentity
)
:
ServerFriendTypingPacket
(
input
,
eventIdentity
)
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ByteReadPacketUtil.kt
View file @
d5587bb3
...
...
@@ -75,7 +75,7 @@ fun ByteReadPacket.parseServerPacket(size: Int): ServerPacket {
0
x00_58_u
->
ServerHeartbeatResponsePacket
(
this
)
0
x00_BA_u
->
ServerCaptchaPacket
.
Encrypted
(
this
)
0
x00_CE_u
,
0
x00_17_u
->
ServerEventPacket
.
Raw
.
Encrypted
(
this
,
id
,
sequenceId
)
0
x00_81_u
->
ServerF
iel
dOnlineStatusChangedPacket
.
Encrypted
(
this
)
0
x00_81_u
->
ServerF
rien
dOnlineStatusChangedPacket
.
Encrypted
(
this
)
0
x00_CD_u
->
ServerSendFriendMessageResponsePacket
(
this
)
0
x00_02_u
->
ServerSendGroupMessageResponsePacket
(
this
)
0
x00_A7_u
->
ServerCanAddFriendResponsePacket
(
this
)
...
...
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
View file @
d5587bb3
...
...
@@ -17,6 +17,7 @@ import net.mamoe.mirai.utils.BotAccount
import
net.mamoe.mirai.utils.Console
import
net.mamoe.mirai.utils.MiraiLogger
@Suppress
(
"UNUSED_VARIABLE"
)
suspend
fun
main
()
{
val
bot
=
Bot
(
BotAccount
(
//填写你的账号
account
=
1994701021
,
...
...
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