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