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