Commit 15de6f31 authored by Him188moe's avatar Him188moe

Updated

parent ece200d4
...@@ -54,10 +54,11 @@ Network部分使用 Kotlin 完成(因为kt有对 unsigned byte 的支持). ...@@ -54,10 +54,11 @@ Network部分使用 Kotlin 完成(因为kt有对 unsigned byte 的支持).
- [X] Network - Verification Code - [X] Network - Verification Code
- [X] Network - Message Receiving - [X] Network - Message Receiving
- [X] Network - Message Sending - [X] Network - Message Sending
- [ ] Network - Events **(Working on)** - [ ] Network - Events
- [ ] Bot - Friend/group list - [ ] Bot - Friend/group list
- [ ] Bot - Actions(joining group, adding friend, etc.) - [ ] Bot - Actions(joining group, adding friend, etc.)
- [ ] Message Section **(Working on)** - [ ] Message Section **(Working on)**
- [ ] Image uploading **(Working on)**
- [ ] Contact - [ ] Contact
- [ ] UI - [ ] UI
......
...@@ -65,7 +65,8 @@ object Protocol { ...@@ -65,7 +65,8 @@ object Protocol {
const val key0836 = "EF 4A 36 6A 16 A8 E6 3D 2E EA BD 1F 98 C1 3C DA" const val key0836 = "EF 4A 36 6A 16 A8 E6 3D 2E EA BD 1F 98 C1 3C DA"
/** /**
* 发送/接受消息中的一个const * 发送/接受消息中的一个const (?)
* length=15
*/ */
const val friendMessageConst1 = "00 00 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91" const val friendMessageConst1 = "00 00 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91"
......
...@@ -55,10 +55,11 @@ class ServerCanAddFriendResponsePacket(input: DataInputStream) : ServerPacket(in ...@@ -55,10 +55,11 @@ class ServerCanAddFriendResponsePacket(input: DataInputStream) : ServerPacket(in
return return
} }
state = when (data[data.size - 1].toUInt()) { state = when (data[data.size - 1].toUInt()) {
0u -> State.NOT_REQUIRE_VERIFICATION 0x00u -> State.NOT_REQUIRE_VERIFICATION
1u -> State.REQUIRE_VERIFICATION 0x01u -> State.REQUIRE_VERIFICATION
99u -> State.ALREADY_ADDED 0x99u -> State.ALREADY_ADDED
3u, 4u -> State.FAILED 0x03u,
0x04u -> State.FAILED
else -> throw IllegalArgumentException(Arrays.toString(data)) else -> throw IllegalArgumentException(Arrays.toString(data))
} }
} }
......
package net.mamoe.mirai.utils
import java.io.DataOutputStream
/**
* Google ProtocolBuff 的一些算法实现
*
* @author Him188moe
*/
/**
* 128(10000000) -> 0x7F (10000000_10000001)
*
* TODO improve
*/
@ExperimentalUnsignedTypes
fun DataOutputStream.writeProtoFixedInt(int: Int) {
if (int == 128) {
this.writeShort(0x80_01)//unsigned//1000000010000001
return
}
this.writeByte(int.rem(128) + 128)
this.writeByte(int / 128)
}
/**
* 127(1111111(7)) -> 0x7F (11111111(8))
*
* TODO improve
*/
@ExperimentalUnsignedTypes
fun DataOutputStream.writeProtoInt(int: Int) {
if (int < 128) {
this.writeByte(int and 0xFF)//10000000
return
}
this.writeProtoFixedInt(int)
}
@ExperimentalUnsignedTypes
fun main() {
println()
println(lazyEncode {
it.writeProtoInt(128)
}.toUHexString())
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment