избавляемся от странного кода
This commit is contained in:
@@ -54,6 +54,8 @@ subprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compile (group: 'org.jetbrains', name: 'annotations', version: '16.0.3')
|
||||||
|
|
||||||
/* Logger */
|
/* Logger */
|
||||||
compile (group: 'org.slf4j', name: 'slf4j-api', version: slf4j_version)
|
compile (group: 'org.slf4j', name: 'slf4j-api', version: slf4j_version)
|
||||||
compile (group: 'org.slf4j', name: 'jcl-over-slf4j', version: slf4j_version)
|
compile (group: 'org.slf4j', name: 'jcl-over-slf4j', version: slf4j_version)
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package mc.core.network;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public abstract class NetInputStream extends InputStream {
|
public abstract class NetInputStream extends InputStream {
|
||||||
@Getter
|
@Getter
|
||||||
@@ -23,7 +24,7 @@ public abstract class NetInputStream extends InputStream {
|
|||||||
public abstract short readShort();
|
public abstract short readShort();
|
||||||
public abstract int readInt();
|
public abstract int readInt();
|
||||||
public abstract int readVarInt();
|
public abstract int readVarInt();
|
||||||
public abstract int readVarInt(int[] countReadBytes);
|
public abstract int readVarInt(AtomicInteger countReadBytes);
|
||||||
public abstract long readLong();
|
public abstract long readLong();
|
||||||
public abstract float readFloat();
|
public abstract float readFloat();
|
||||||
public abstract double readDouble();
|
public abstract double readDouble();
|
||||||
@@ -33,22 +34,22 @@ public abstract class NetInputStream extends InputStream {
|
|||||||
public abstract void skipBytes(int count);
|
public abstract void skipBytes(int count);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() {
|
||||||
return readByte();
|
return readByte();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read(byte[] b) throws IOException {
|
public int read(@NotNull byte[] b) {
|
||||||
return readBytes(b);
|
return readBytes(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
public int read(@NotNull byte[] b, int off, int len) {
|
||||||
return readBytes(b, off, len);
|
return readBytes(b, off, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long skip(long n) throws IOException {
|
public long skip(long n) {
|
||||||
skipBytes((int) n);
|
skipBytes((int) n);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,12 @@ import mc.core.network.NetInputStream;
|
|||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class NetInputStream_p340 extends NetInputStream {
|
public abstract class NetInputStream_p340 extends NetInputStream {
|
||||||
@Override
|
@Override
|
||||||
public int readVarInt(int[] countReadBytes) {
|
public int readVarInt(AtomicInteger countReadBytes) {
|
||||||
int numRead = 0;
|
int numRead = 0;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
byte read;
|
byte read;
|
||||||
@@ -29,7 +30,10 @@ public abstract class NetInputStream_p340 extends NetInputStream {
|
|||||||
numRead++;
|
numRead++;
|
||||||
} while ((read & 0b10000000) != 0);
|
} while ((read & 0b10000000) != 0);
|
||||||
|
|
||||||
if (countReadBytes != null && countReadBytes.length == 1) countReadBytes[0] = numRead;
|
if (countReadBytes != null) {
|
||||||
|
countReadBytes.set(numRead);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,21 +10,21 @@ import mc.core.network.proto_1_12_2.State;
|
|||||||
import mc.core.network.proto_1_12_2.netty.wrappers.WrapperNetInputStream;
|
import mc.core.network.proto_1_12_2.netty.wrappers.WrapperNetInputStream;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_STATE;
|
import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_STATE;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PacketDecoder extends ReplayingDecoder<CSPacket> {
|
public class PacketDecoder extends ReplayingDecoder<CSPacket> {
|
||||||
private int[] countReadBytes = new int[]{0};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
public void channelActive(ChannelHandlerContext ctx) {
|
||||||
ctx.channel().attr(ATTR_STATE).set(State.HANDSHAKE);
|
ctx.channel().attr(ATTR_STATE).set(State.HANDSHAKE);
|
||||||
ctx.fireChannelActive();
|
ctx.fireChannelActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
public void channelInactive(ChannelHandlerContext ctx) {
|
||||||
ctx.channel().attr(ATTR_STATE).set(null);
|
ctx.channel().attr(ATTR_STATE).set(null);
|
||||||
ctx.fireChannelInactive();
|
ctx.fireChannelInactive();
|
||||||
}
|
}
|
||||||
@@ -38,11 +38,12 @@ public class PacketDecoder extends ReplayingDecoder<CSPacket> {
|
|||||||
log.debug("Packet size: {}", packetSize);
|
log.debug("Packet size: {}", packetSize);
|
||||||
int leftDataPacket = packetSize;
|
int leftDataPacket = packetSize;
|
||||||
|
|
||||||
|
final AtomicInteger countReadBytes = new AtomicInteger(0);
|
||||||
int packetId = netStream.readVarInt(countReadBytes);
|
int packetId = netStream.readVarInt(countReadBytes);
|
||||||
String hexPacketId = Integer.toHexString(packetId).toUpperCase();
|
String hexPacketId = Integer.toHexString(packetId).toUpperCase();
|
||||||
if (hexPacketId.length() == 1) hexPacketId = "0" + hexPacketId;
|
if (hexPacketId.length() == 1) hexPacketId = "0" + hexPacketId;
|
||||||
log.debug("Packet id: 0x{}", hexPacketId);
|
log.debug("Packet id: 0x{}", hexPacketId);
|
||||||
leftDataPacket = leftDataPacket - countReadBytes[0];
|
leftDataPacket = leftDataPacket - countReadBytes.get();
|
||||||
|
|
||||||
Class<? extends CSPacket> packetClass = state.getClientSidePacket(packetId);
|
Class<? extends CSPacket> packetClass = state.getClientSidePacket(packetId);
|
||||||
if (packetClass == null) {
|
if (packetClass == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user