mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-03 23:22:29 +08:00
Working on new network
This commit is contained in:
parent
c23a48ebb0
commit
87ccf60dcd
@ -24,7 +24,7 @@ class ClientLoginVerificationCodePacket(
|
||||
this.writeQQ(qq)
|
||||
this.writeHex(Protocol.fixVer)
|
||||
this.writeHex(Protocol._00BaKey)
|
||||
this.write(TEACryptor.CRYPTOR_0825KEY.encrypt(object : ByteArrayDataOutputStream() {
|
||||
this.write(TEACryptor.CRYPTOR_00BAKEY.encrypt(object : ByteArrayDataOutputStream() {
|
||||
override fun toByteArray(): ByteArray {
|
||||
this.writeHex("00 02 00 00 08 04 01 E0")
|
||||
this.writeHex(Protocol._0825data2)
|
||||
|
@ -9,23 +9,17 @@ import java.io.DataInputStream
|
||||
/**
|
||||
* @author Him188moe
|
||||
*/
|
||||
class ServerLoginResponseVerificationCodePacket(input: DataInputStream, val packetLength: Int) : ServerPacket(input) {
|
||||
var verifyCodeLength: Short = 0
|
||||
class ServerLoginResponseVerificationCodePacket(input: DataInputStream, private val packetLength: Int) : ServerPacket(input) {
|
||||
|
||||
lateinit var verifyCode: ByteArray
|
||||
lateinit var token00BA: ByteArray
|
||||
var unknownBoolean: Boolean? = null
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
override fun decode() {//todo decode 注释的内容
|
||||
/*
|
||||
verifyCodeLength = HexToDec(取文本中间(data, 235, 5))
|
||||
verifyCode = 取文本中间(data, 241, verifyCodeLength * 3 - 1)
|
||||
unknownBoolean = 取文本中间(data, 245 + verifyCodeLength * 3 - 1, 2) == "01"
|
||||
token00BA = 取文本中间(data, 取文本长度(data) - 178, 119)
|
||||
*/
|
||||
this.verifyCodeLength = this.input.goto(78).readShort()
|
||||
this.verifyCode = this.input.readNBytes(this.verifyCodeLength.toInt())
|
||||
override fun decode() {
|
||||
val verifyCodeLength = this.input.goto(78).readShort()//2bytes
|
||||
this.verifyCode = this.input.readNBytes(verifyCodeLength.toInt())
|
||||
|
||||
this.input.skip(1)
|
||||
|
||||
|
@ -240,7 +240,7 @@ public class TEACryptor {
|
||||
|
||||
public byte[] encrypt(byte[] plaintext) {
|
||||
DebugLoggerKt.encryptionDebugLogging(plaintext);
|
||||
System.out.println("TEA加密, 原文=" + UtilsKt.toUHexString(plaintext));
|
||||
//System.out.println("TEA加密, 原文=" + Utils.INSTANCE.toHexString(plaintext, ""));
|
||||
return encrypt(plaintext, 0, plaintext.length);
|
||||
}
|
||||
|
||||
|
5
mirai-core/src/test/java/netty/LogEventEncoder.java
Normal file
5
mirai-core/src/test/java/netty/LogEventEncoder.java
Normal file
@ -0,0 +1,5 @@
|
||||
package netty;
|
||||
|
||||
/**
|
||||
* Created by XiuYin.Cui on 2018/9/10.
|
||||
*/
|
55
mirai-core/src/test/java/netty/UDPPacketSender.java
Normal file
55
mirai-core/src/test/java/netty/UDPPacketSender.java
Normal file
@ -0,0 +1,55 @@
|
||||
package netty;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import io.netty.channel.socket.nio.NioDatagramChannel;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import net.mamoe.mirai.network.packet.client.ClientPacket;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
|
||||
public class UDPPacketSender {
|
||||
private final EventLoopGroup group;
|
||||
|
||||
private final Channel channel;
|
||||
|
||||
public UDPPacketSender(InetSocketAddress address) throws InterruptedException {
|
||||
group = new NioEventLoopGroup();
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(group)
|
||||
.channel(NioDatagramChannel.class)
|
||||
.option(ChannelOption.SO_BROADCAST, true)
|
||||
.handler(new LogEventEncoder(address));
|
||||
channel = bootstrap.bind(0).sync().channel();
|
||||
}
|
||||
|
||||
private static final class LogEventEncoder extends MessageToMessageEncoder<ClientPacket> {
|
||||
private final InetSocketAddress remoteAddress;
|
||||
|
||||
private LogEventEncoder(InetSocketAddress remoteAddress) {
|
||||
this.remoteAddress = remoteAddress;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ClientPacket packet, List<Object> out) {
|
||||
var buffer = ctx.alloc().buffer();
|
||||
buffer.writeBytes(packet.toByteArray());
|
||||
out.add(new DatagramPacket(buffer, remoteAddress));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(ClientPacket packet) {
|
||||
channel.writeAndFlush(packet);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
group.shutdownGracefully();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user