This commit is contained in:
Him188moe 2019-08-17 14:39:00 +08:00
parent bbc1f717a6
commit 52857fad71
6 changed files with 50 additions and 10 deletions

View File

@ -0,0 +1,6 @@
module mirai_core {
requires kotlin.stdlib;
requires lombok;
exports net.mamoe.mirai;
}

View File

@ -22,20 +22,21 @@ import java.net.InetSocketAddress
* @author Him188moe @ Mirai Project * @author Him188moe @ Mirai Project
*/ */
class Robot(val number: Long) { class Robot(val number: Long) {
private lateinit var ctx: ChannelHandlerContext;
internal fun onPacketReceived(packet: Packet) { internal fun onPacketReceived(packet: Packet) {
if (packet !is ServerPacket) { if (packet !is ServerPacket) {
return; return
} }
packet.decode() packet.decode()
if (packet is Server0825Packet) {//todo 检查是否需要修改 UDP 连接??? if (packet is Server0825Packet) {//todo 检查是否需要修改 UDP 连接???
sendPacket(Client0825ResponsePacket(packet.serverIP, number)); sendPacket(Client0825ResponsePacket(packet.serverIP, number))
} }
} }
private fun sendPacket(packet: Packet) { private fun sendPacket(packet: Packet) {
TODO()
} }
@Throws(InterruptedException::class) @Throws(InterruptedException::class)
@ -53,8 +54,9 @@ class Robot(val number: Long) {
ch.pipeline().addLast(ByteArrayEncoder()) ch.pipeline().addLast(ByteArrayEncoder())
ch.pipeline().addLast(ByteArrayDecoder()) ch.pipeline().addLast(ByteArrayDecoder())
ch.pipeline().addLast(object : SimpleChannelInboundHandler<ByteArray>() { ch.pipeline().addLast(object : SimpleChannelInboundHandler<ByteArray>() {
override fun channelRead0(ctx: ChannelHandlerContext?, bytes: ByteArray) { override fun channelRead0(ctx: ChannelHandlerContext, bytes: ByteArray) {
try { try {
this@Robot.ctx = ctx;
/*val remaining = Reader.read(bytes); /*val remaining = Reader.read(bytes);
if (Reader.isPacketAvailable()) { if (Reader.isPacketAvailable()) {
robot.onPacketReceived(Reader.toServerPacket()) robot.onPacketReceived(Reader.toServerPacket())

View File

@ -3,6 +3,7 @@ package net.mamoe.mirai.network.packet.client
import net.mamoe.mirai.network.Protocol import net.mamoe.mirai.network.Protocol
import net.mamoe.mirai.network.packet.PacketId import net.mamoe.mirai.network.packet.PacketId
import net.mamoe.mirai.util.TEAEncryption import net.mamoe.mirai.util.TEAEncryption
import net.mamoe.mirai.util.hexToBytes
import java.io.IOException import java.io.IOException
/** /**
@ -27,6 +28,6 @@ class Client0825ResponsePacket(private val serverIP: String, private val qq: Lon
this.writeHex("01 6F A1 58 22 01 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 03 00 19") this.writeHex("01 6F A1 58 22 01 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 03 00 19")
this.writeHex(Protocol.publicKey) this.writeHex(Protocol.publicKey)
} }
}.encodeToByteArray(), Protocol.hexToBytes(Protocol.redirectionKey))) }.encodeToByteArray(), Protocol.redirectionKey.hexToBytes()))
} }
} }

View File

@ -5,8 +5,10 @@ import lombok.EqualsAndHashCode;
import net.mamoe.mirai.network.Protocol; import net.mamoe.mirai.network.Protocol;
import net.mamoe.mirai.network.packet.PacketId; import net.mamoe.mirai.network.packet.PacketId;
import net.mamoe.mirai.util.TEAEncryption; import net.mamoe.mirai.util.TEAEncryption;
import net.mamoe.mirai.util.Utils;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
/** /**
* @author Him188moe @ Mirai Project * @author Him188moe @ Mirai Project
@ -32,10 +34,25 @@ public class ClientLoginPacket extends ClientPacket {
this.writeHex(Protocol._0825data2); this.writeHex(Protocol._0825data2);
this.writeQQ(qq); this.writeQQ(qq);
this.writeHex("00 00 00 00 03 09 00 08 00 01"); this.writeHex("00 00 00 00 03 09 00 08 00 01");
this.writeIp(Protocol.SERVER_IP.get(2)); //this.writeIp(Protocol.SERVER_IP.get(2));
this.writeIp("123456789");
this.writeHex("00 02 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 02 00 19"); this.writeHex("00 02 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 02 00 19");
this.writeHex(Protocol.publicKey); this.writeHex(Protocol.publicKey);
} }
}.encodeToByteArray(), Protocol.hexToBytes(Protocol._0825key))); }.encodeToByteArray(), Protocol.hexToBytes(Protocol._0825key)));
} }
public static void main(String[] args) throws IOException {
try {
var pk = new ClientLoginPacket();
pk.qq = 1994701021;
pk.encode();
pk.writeHex(Protocol.tail);
System.out.println("pk.toByteArray() = " + Arrays.toString(pk.toByteArray()));
System.out.println(Utils.INSTANCE.toHexString(pk.toByteArray()));
} catch (Throwable e) {
e.printStackTrace();
}
}
} }

View File

@ -13,14 +13,12 @@ import java.io.IOException;
* @author Him188moe @ Mirai Project * @author Him188moe @ Mirai Project
*/ */
public abstract class ClientPacket extends DataOutputStream implements Packet { public abstract class ClientPacket extends DataOutputStream implements Packet {
public ClientPacket() {
super(new ByteArrayOutputStream());
}
@Getter @Getter
private final int packageId; private final int packageId;
{ public ClientPacket() {
super(new ByteArrayOutputStream());
var annotation = this.getClass().getAnnotation(PacketId.class); var annotation = this.getClass().getAnnotation(PacketId.class);
packageId = annotation.value(); packageId = annotation.value();

View File

@ -0,0 +1,16 @@
package net.mamoe.mirai.util
import net.mamoe.mirai.network.Protocol
/**
* @author Him188moe @ Mirai Project
*/
object Utils {
fun toHexString(byteArray: ByteArray): String = byteArray.joinToString(" ") { it.toString(16) }
}
fun ByteArray.toHexString(): String = Utils.toHexString(this)
fun Byte.toHexString(): String = this.toString(16)
fun String.hexToBytes(): ByteArray = Protocol.hexToBytes(this)