Commit e129719d authored by Him188moe's avatar Him188moe

Updated robot & network structure

parent c353e8e8
...@@ -10,7 +10,7 @@ class Group(robot: Robot, number: Long) : Contact(robot, number), Closeable { ...@@ -10,7 +10,7 @@ class Group(robot: Robot, number: Long) : Contact(robot, number), Closeable {
val members = ContactList<QQ>() val members = ContactList<QQ>()
override fun sendMessage(message: Message) { override fun sendMessage(message: Message) {
robot.network.packetSystem.sendGroupMessage(this, message) robot.network.messageHandler.sendGroupMessage(this, message)
} }
override fun sendXMLMessage(message: String) { override fun sendXMLMessage(message: String) {
......
...@@ -12,7 +12,7 @@ import net.mamoe.mirai.message.defaults.At ...@@ -12,7 +12,7 @@ import net.mamoe.mirai.message.defaults.At
*/ */
class QQ(robot: Robot, number: Long) : Contact(robot, number) { class QQ(robot: Robot, number: Long) : Contact(robot, number) {
override fun sendMessage(message: Message) { override fun sendMessage(message: Message) {
robot.network.packetSystem.sendFriendMessage(this, message) robot.network.messageHandler.sendFriendMessage(this, message)
} }
override fun sendXMLMessage(message: String) { override fun sendXMLMessage(message: String) {
......
...@@ -7,9 +7,8 @@ import java.util.stream.Collectors ...@@ -7,9 +7,8 @@ import java.util.stream.Collectors
/** /**
* @author Him188moe * @author Him188moe
*/ */
interface Protocol { object Protocol {
companion object { val SERVER_IP: List<String> = object : ArrayList<String>() {
val SERVER_IP: ArrayList<String> = object : ArrayList<String>() {
init { init {
add("183.60.56.29") add("183.60.56.29")
...@@ -25,7 +24,7 @@ interface Protocol { ...@@ -25,7 +24,7 @@ interface Protocol {
} }
} }
get() = Collections.unmodifiableList(field)
const val head = "02" const val head = "02"
const val ver = "37 13" const val ver = "37 13"
...@@ -90,5 +89,4 @@ interface Protocol { ...@@ -90,5 +89,4 @@ interface Protocol {
.map { s -> s.toUByte(16) } .map { s -> s.toUByte(16) }
.collect(Collectors.toList()).toUByteArray() .collect(Collectors.toList()).toUByteArray()
}
} }
...@@ -17,6 +17,7 @@ class ClientAccountInfoRequestPacket( ...@@ -17,6 +17,7 @@ class ClientAccountInfoRequestPacket(
) : ClientPacket() { ) : ClientPacket() {
override fun encode() { override fun encode() {
this.writeRandom(2)//part of packet id this.writeRandom(2)//part of packet id
this.writeQQ(qq) this.writeQQ(qq)
this.writeHex(Protocol.fixVer2) this.writeHex(Protocol.fixVer2)
this.encryptAndWrite(sessionKey) { this.encryptAndWrite(sessionKey) {
......
...@@ -53,11 +53,13 @@ abstract class ServerPacket(val input: DataInputStream) : Packet { ...@@ -53,11 +53,13 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
551, 487 -> LoginState.DEVICE_LOCK 551, 487 -> LoginState.DEVICE_LOCK
359 -> LoginState.TAKEN_BACK 359 -> LoginState.TAKEN_BACK
else -> LoginState.UNKNOWN
/*
//unknown //unknown
63 -> throw IllegalArgumentException(bytes.size.toString() + " (Unknown error)") 63 -> throw IllegalArgumentException(bytes.size.toString() + " (Unknown error)")
351 -> throw IllegalArgumentException(bytes.size.toString() + " (Illegal package data or Unknown error)")//包数据有误 351 -> throw IllegalArgumentException(bytes.size.toString() + " (Illegal package data or Unknown error)")//包数据有误
else -> throw IllegalArgumentException(bytes.size.toString()) else -> throw IllegalArgumentException(bytes.size.toString())*/
}, stream) }, stream)
} }
...@@ -112,17 +114,6 @@ abstract class ServerPacket(val input: DataInputStream) : Packet { ...@@ -112,17 +114,6 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
} }
fun DataInputStream.readUntil(byte: Byte): ByteArray {
var buff = byteArrayOf()
var b: Byte
b = readByte()
while (b != byte) {
buff += b
b = readByte()
}
return buff
}
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
fun DataInputStream.readIP(): String { fun DataInputStream.readIP(): String {
var buff = "" var buff = ""
......
...@@ -14,5 +14,7 @@ enum class LoginState { ...@@ -14,5 +14,7 @@ enum class LoginState {
DEVICE_LOCK,//设备锁 DEVICE_LOCK,//设备锁
TAKEN_BACK,//被回收 TAKEN_BACK,//被回收
// VERIFICATION_CODE,//需要验证码 // VERIFICATION_CODE,//需要验证码
// SUCCEED,
UNKNOWN,
} }
\ No newline at end of file
...@@ -11,9 +11,8 @@ import java.util.Random; ...@@ -11,9 +11,8 @@ import java.util.Random;
* @author iweiz https://github.com/iweizime/StepChanger/blob/master/app/src/main/java/me/iweizi/stepchanger/qq/Cryptor.java * @author iweiz https://github.com/iweizime/StepChanger/blob/master/app/src/main/java/me/iweizi/stepchanger/qq/Cryptor.java
*/ */
public final class TEA { public final class TEA {
public static final TEA CRYPTOR_SHARE_KEY = new TEA(Protocol.Companion.hexToBytes(Protocol.shareKey)); public static final TEA CRYPTOR_SHARE_KEY = new TEA(Protocol.INSTANCE.hexToBytes(Protocol.shareKey));
public static final TEA CRYPTOR_0825KEY = new TEA(Protocol.Companion.hexToBytes(Protocol.key0825)); public static final TEA CRYPTOR_0825KEY = new TEA(Protocol.INSTANCE.hexToBytes(Protocol.key0825));
public static final TEA CRYPTOR_00BAKEY = new TEA(Protocol.Companion.hexToBytes(Protocol.key00BA));
private static final long UINT32_MASK = 0xffffffffL; private static final long UINT32_MASK = 0xffffffffL;
private final long[] mKey; private final long[] mKey;
......
...@@ -79,7 +79,7 @@ operator fun File.plus(child: String): File = File(this, child) ...@@ -79,7 +79,7 @@ operator fun File.plus(child: String): File = File(this, child)
private const val GTK_BASE_VALUE: Int = 5381 private const val GTK_BASE_VALUE: Int = 5381
fun getGTK(sKey: String): Int { internal fun getGTK(sKey: String): Int {
var value = GTK_BASE_VALUE var value = GTK_BASE_VALUE
for (c in sKey.toCharArray()) { for (c in sKey.toCharArray()) {
value += (value shl 5) + c.toInt() value += (value shl 5) + c.toInt()
...@@ -89,7 +89,7 @@ fun getGTK(sKey: String): Int { ...@@ -89,7 +89,7 @@ fun getGTK(sKey: String): Int {
return value return value
} }
fun getCrc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.toInt() } internal fun getCrc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.toInt() }
/** /**
...@@ -122,3 +122,13 @@ fun Any.getAllDeclaredFields(): List<Field> { ...@@ -122,3 +122,13 @@ fun Any.getAllDeclaredFields(): List<Field> {
return list return list
} }
private const val ZERO_BYTE: Byte = 0
fun ByteArray.removeZeroTail(): ByteArray {
var i = this.size - 1
while (this[i] == ZERO_BYTE) {
--i
}
return this.copyOfRange(0, i + 1)
}
\ 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