1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-25 04:50:26 +08:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
liujiahua123123 2019-08-08 22:47:38 +08:00
commit 0e032cf9b7
6 changed files with 81 additions and 32 deletions

View File

@ -6,24 +6,6 @@
<artifactId>mirai-core</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>net.mamoe</groupId>
<artifactId>jpre</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<packaging>jar</packaging>
@ -95,7 +77,7 @@
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>

View File

@ -4,7 +4,6 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import java.io.IOException;
import java.net.InetSocketAddress;
/**
* 网络数据包接收器. 该类属于网络层, 插件一般不需要使用
@ -31,7 +30,7 @@ public class NetworkPacketHandler extends SimpleChannelInboundHandler<byte[]> {
* Synchronized by {@code synchronized (this)} in {@link #channelRead0}
*/
private void handlePacket(ChannelHandlerContext ctx, byte[] data) {
try {
/*try {
temp = Utils.arrayAppend(temp, data);
while (temp.length != 0) {
int position = Utils.arraySearch(temp, Protocol.SIGNATURE);
@ -46,7 +45,7 @@ public class NetworkPacketHandler extends SimpleChannelInboundHandler<byte[]> {
}
} catch (Exception e) {
e.printStackTrace();
}
}*/
}
//TODO 改为 public, 并将 ctx 改为插件可扩展的消息源以实现多源化
@ -54,12 +53,12 @@ public class NetworkPacketHandler extends SimpleChannelInboundHandler<byte[]> {
if (data.length == 0) {
return;
}
processPacket(ctx, new BinaryStream(data));
processPacket(ctx, new BinaryStream());
}
private void processPacket(ChannelHandlerContext ctx, BinaryStream stream) {
//System.out.println(stream);
for (MPQClient client : clients) {
/*for (MPQClient client : clients) {
if (client.is((InetSocketAddress) ctx.channel().remoteAddress())) {
client.getFrame().getScheduler().addTask(() -> {
try {
@ -70,7 +69,7 @@ public class NetworkPacketHandler extends SimpleChannelInboundHandler<byte[]> {
});
return;
}
}
}*/
}
@Override
@ -86,6 +85,7 @@ public class NetworkPacketHandler extends SimpleChannelInboundHandler<byte[]> {
public void channelActive(ChannelHandlerContext ctx) throws Exception {
super.channelActive(ctx);
/*
FrameConnectionEvent event = null;
for (MPQClient client : clients) {
if (client.is((InetSocketAddress) ctx.channel().remoteAddress())) {
@ -103,13 +103,13 @@ public class NetworkPacketHandler extends SimpleChannelInboundHandler<byte[]> {
event = new FrameConnectionEvent(frame);
}
event.getFrame().getPluginManager().callEvent(event);
event.getFrame().getPluginManager().callEvent(event);*/
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
System.out.println("[Network] RemoteClient: " + ctx.channel().remoteAddress() + " disconnected.");
/*
for (MPQClient client : clients) {
if (client.is((InetSocketAddress) ctx.channel().remoteAddress())) {
FrameDisconnectionEvent event = new FrameDisconnectionEvent(client.getFrame());
@ -117,7 +117,7 @@ public class NetworkPacketHandler extends SimpleChannelInboundHandler<byte[]> {
break;
}
}
*/
super.channelInactive(ctx);
}
}

View File

@ -0,0 +1,20 @@
package net.mamoe.mirai.network.packet;
/**
* @author Him188moe @ Mirai Project
*/
public final class PacketUtil {
/**
* 易语言返回的 string(valueof
*/
public static int getGTK(String sKey) {
int init = 5381;
int i = 0;
int length = sKey.length();
while (i++ < length) {
init += init << 5 + sKey.charAt(i);
}
return init & 2147483647;
}
}

View File

@ -0,0 +1,13 @@
package net.mamoe.mirai.network.packet.client;
import java.io.IOException;
/**
* @author Him188moe @ Mirai Project
*/
public class ClientHeartbeatPacket extends ClientPacket {
@Override
public void encode() throws IOException {
}
}

View File

@ -4,6 +4,8 @@ import net.mamoe.mirai.network.packet.Packet;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
/**
* @author Him188moe @ Mirai Project
@ -13,12 +15,42 @@ public abstract class ClientPacket extends DataOutputStream implements Packet {
super(new ByteArrayOutputStream());
}
protected void writeQQHex(long qq) {
this.write
private final byte packageId;
{
packageId = 0x0058;
}
protected void writeHead() throws IOException {
this.writeByte(0x02);
}
public static void main(String[] args) throws IOException {
var pk = new ClientPacket() {
@Override
public void encode() throws IOException {
writeHead();
}
};
pk.encode();
System.out.println(Arrays.toString(((ByteArrayOutputStream) pk.out).toByteArray()));
}
protected void writeVersion() throws IOException {
this.writeByte(0x37_13);
}
protected void writePacketId() {
}
protected void writeQQ(long qq) throws IOException {
this.writeLong(qq);
}
/**
* Encode this packet
*/
public abstract void encode();
public abstract void encode() throws IOException;
}

View File

@ -4,7 +4,9 @@
public class NetworkTest {
public static void main(String[] args) {
System.out.println(Short.valueOf("37 13", 16));
Long.valueOf("", 16);
System.out.println(1040400290L & 0x0FFFFFFFF);
System.out.println(Long.valueOf("3E033FA2", 16));
}
}