fix Handshake and State
This commit is contained in:
@@ -6,7 +6,6 @@ package mc.core.netty;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.netty.util.AttributeKey;
|
||||
import lombok.Getter;
|
||||
import mc.core.Packet;
|
||||
@@ -14,15 +13,15 @@ import mc.core.netty.packets.HandshakeRequestPacket;
|
||||
import mc.core.netty.packets.PingPacket;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum State {
|
||||
Unknown(0, ImmutableBiMap.of()),
|
||||
Handshaking(1, ImmutableBiMap.of(
|
||||
0, HandshakeRequestPacket.class,
|
||||
1, PingPacket.class
|
||||
)),
|
||||
Status(0, ImmutableBiMap.of(1, PingPacket.class));
|
||||
));
|
||||
//Login(2, ...)
|
||||
|
||||
public static final AttributeKey<State> ATTR_STATE = AttributeKey.newInstance("ATTR_STATE");
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ package mc.core.netty.packets;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.NetStream;
|
||||
import mc.core.NotSupportException;
|
||||
import mc.core.Packet;
|
||||
@@ -14,6 +15,7 @@ import mc.core.netty.UnknowState;
|
||||
|
||||
import static mc.core.netty.Utils.*;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
@ToString
|
||||
public class HandshakeRequestPacket implements Packet {
|
||||
@@ -22,6 +24,7 @@ public class HandshakeRequestPacket implements Packet {
|
||||
private String serverAddress;
|
||||
private int serverPort;
|
||||
private State nextState;
|
||||
private String nickname;
|
||||
private int size;
|
||||
|
||||
@Override
|
||||
@@ -40,8 +43,11 @@ public class HandshakeRequestPacket implements Packet {
|
||||
serverAddress = netStream.readString();
|
||||
serverPort = netStream.readUnsignedShort();
|
||||
final int nextStateInt = netStream.readVarInt();
|
||||
nextState = State.getById(nextStateInt).orElseThrow(() -> new UnknowState(nextStateInt));
|
||||
netStream.skipBytes(2); //TODO magic
|
||||
nextState = State.getById(nextStateInt).orElseGet(() -> {
|
||||
log.warn("Unknown state: {}", nextStateInt);
|
||||
return State.Unknown;
|
||||
});
|
||||
nickname = netStream.readString();
|
||||
|
||||
size = lengthVarInt(id)
|
||||
+ lengthVarInt(protocolVersion)
|
||||
|
||||
Reference in New Issue
Block a user