This commit is contained in:
Him188moe 2019-08-09 00:19:12 +08:00
parent 9e21ebcb6f
commit 43595db045
3 changed files with 23 additions and 5 deletions

View File

@ -1,16 +1,28 @@
package net.mamoe.mirai.network.packet.client;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.mamoe.mirai.network.Protocol;
import net.mamoe.mirai.network.packet.PacketId;
import net.mamoe.mirai.util.TEAEncryption;
import java.io.IOException;
/**
* @author Him188moe @ Mirai Project
*/
@PacketId(0x0058)
@EqualsAndHashCode(callSuper = true)
@Data
@PacketId(0x00_58)
public class ClientHeartbeatPacket extends ClientPacket {
public long qq;
public byte[] sessionKey;//登录后获得
@Override
public void encode() throws IOException {
this.writeRandom(2);
this.writeQQ(qq);
this.writeHex(Protocol.fixVer);
this.write(TEAEncryption.encrypt(new byte[]{0x00, 0x01, 0x00, 0x01}, sessionKey));
}
}

View File

@ -39,6 +39,6 @@ public class ClientLoginPacket extends ClientPacket {
};
data.encode();
TEAEncryption.encrypt(data.toByteArray(), Protocol.hexToBytes(Protocol._0825key));
this.write(TEAEncryption.encrypt(data.toByteArray(), Protocol.hexToBytes(Protocol._0825key)));
}
}

View File

@ -53,6 +53,12 @@ public abstract class ClientPacket extends DataOutputStream implements Packet {
}
}
protected void writeRandom(int length) throws IOException {
for (int i = 0; i < length; i++) {
this.writeByte((byte) (int) (Math.random() * 255));
}
}
protected void writeQQ(long qq) throws IOException {
this.writeLong(qq);
}
@ -60,9 +66,9 @@ public abstract class ClientPacket extends DataOutputStream implements Packet {
/**
* Encode this packet.
*
* <p>
* Before sending the packet, an {@linkplain Protocol#tail tail} will be added.
*/
*/// TODO: 2019/8/9 添加 tail
public abstract void encode() throws IOException;
public byte[] toByteArray() {