mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2025-07-15 13:40:14 +02:00
Added 1.7.x support
This commit is contained in:
parent
b19fa9db37
commit
4c8668f222
@ -46,6 +46,7 @@ import java.security.InvalidKeyException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ClientConnection extends ChannelInboundHandlerAdapter {
|
||||
|
||||
@ -123,38 +124,45 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
writePacket(PacketSnapshots.PACKET_LOGIN_SUCCESS);
|
||||
sendPacket(PacketSnapshots.PACKET_LOGIN_SUCCESS);
|
||||
updateState(State.PLAY);
|
||||
|
||||
server.getConnections().addConnection(this);
|
||||
|
||||
writePacket(PacketSnapshots.PACKET_JOIN_GAME);
|
||||
writePacket(PacketSnapshots.PACKET_PLAYER_ABILITIES);
|
||||
writePacket(PacketSnapshots.PACKET_PLAYER_POS);
|
||||
Runnable sendPlayPackets = () -> {
|
||||
writePacket(PacketSnapshots.PACKET_JOIN_GAME);
|
||||
writePacket(PacketSnapshots.PACKET_PLAYER_ABILITIES);
|
||||
writePacket(PacketSnapshots.PACKET_PLAYER_POS);
|
||||
|
||||
if (server.getConfig().isUsePlayerList() || clientVersion.equals(Version.V1_16_4))
|
||||
writePacket(PacketSnapshots.PACKET_PLAYER_INFO);
|
||||
if (server.getConfig().isUsePlayerList() || clientVersion.equals(Version.V1_16_4))
|
||||
writePacket(PacketSnapshots.PACKET_PLAYER_INFO);
|
||||
|
||||
if (clientVersion.moreOrEqual(Version.V1_13)) {
|
||||
writePacket(PacketSnapshots.PACKET_DECLARE_COMMANDS);
|
||||
if (clientVersion.moreOrEqual(Version.V1_13)) {
|
||||
writePacket(PacketSnapshots.PACKET_DECLARE_COMMANDS);
|
||||
|
||||
if (PacketSnapshots.PACKET_PLUGIN_MESSAGE != null)
|
||||
writePacket(PacketSnapshots.PACKET_PLUGIN_MESSAGE);
|
||||
if (PacketSnapshots.PACKET_PLUGIN_MESSAGE != null)
|
||||
writePacket(PacketSnapshots.PACKET_PLUGIN_MESSAGE);
|
||||
}
|
||||
|
||||
if (PacketSnapshots.PACKET_BOSS_BAR != null && clientVersion.moreOrEqual(Version.V1_9))
|
||||
writePacket(PacketSnapshots.PACKET_BOSS_BAR);
|
||||
|
||||
if (PacketSnapshots.PACKET_JOIN_MESSAGE != null)
|
||||
writePacket(PacketSnapshots.PACKET_JOIN_MESSAGE);
|
||||
|
||||
if (PacketSnapshots.PACKET_TITLE_TITLE != null && clientVersion.moreOrEqual(Version.V1_8))
|
||||
writeTitle();
|
||||
|
||||
if (PacketSnapshots.PACKET_HEADER_AND_FOOTER != null && clientVersion.moreOrEqual(Version.V1_8))
|
||||
writePacket(PacketSnapshots.PACKET_HEADER_AND_FOOTER);
|
||||
|
||||
sendKeepAlive();
|
||||
};
|
||||
|
||||
if (clientVersion.lessOrEqual(Version.V1_7_6)) {
|
||||
this.channel.eventLoop().schedule(sendPlayPackets, 100, TimeUnit.MILLISECONDS);
|
||||
} else {
|
||||
sendPlayPackets.run();
|
||||
}
|
||||
|
||||
if (PacketSnapshots.PACKET_BOSS_BAR != null && clientVersion.moreOrEqual(Version.V1_9))
|
||||
writePacket(PacketSnapshots.PACKET_BOSS_BAR);
|
||||
|
||||
if (PacketSnapshots.PACKET_JOIN_MESSAGE != null)
|
||||
writePacket(PacketSnapshots.PACKET_JOIN_MESSAGE);
|
||||
|
||||
if (PacketSnapshots.PACKET_TITLE_TITLE != null)
|
||||
writeTitle();
|
||||
|
||||
if (PacketSnapshots.PACKET_HEADER_AND_FOOTER != null)
|
||||
writePacket(PacketSnapshots.PACKET_HEADER_AND_FOOTER);
|
||||
|
||||
sendKeepAlive();
|
||||
}
|
||||
|
||||
public void disconnectLogin(String reason) {
|
||||
|
@ -40,8 +40,10 @@ public class PacketLoginSuccess implements PacketOut {
|
||||
public void encode(ByteMessage msg, Version version) {
|
||||
if (version.moreOrEqual(Version.V1_16)) {
|
||||
msg.writeUuid(uuid);
|
||||
} else {
|
||||
} else if (version.moreOrEqual(Version.V1_7_6)) {
|
||||
msg.writeString(uuid.toString());
|
||||
} else {
|
||||
msg.writeString(uuid.toString().replace("-", ""));
|
||||
}
|
||||
msg.writeString(username);
|
||||
if (version.moreOrEqual(Version.V1_19)) {
|
||||
|
@ -46,11 +46,9 @@ public class PacketChatMessage implements PacketOut {
|
||||
msg.writeString(jsonData);
|
||||
if (version.moreOrEqual(Version.V1_19_1)) {
|
||||
msg.writeBoolean(position.index == PositionLegacy.ACTION_BAR.index);
|
||||
}
|
||||
else if (version.moreOrEqual(Version.V1_19)) {
|
||||
} else if (version.moreOrEqual(Version.V1_19)) {
|
||||
msg.writeVarInt(position.index);
|
||||
}
|
||||
else {
|
||||
} else if (version.moreOrEqual(Version.V1_8)) {
|
||||
msg.writeByte(position.index);
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,14 @@ public class PacketJoinGame implements PacketOut {
|
||||
public void encode(ByteMessage msg, Version version) {
|
||||
msg.writeInt(entityId);
|
||||
|
||||
if (version.fromTo(Version.V1_7_2, Version.V1_7_6)) {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(dimensionRegistry.getDefaultDimension_1_16().getId());
|
||||
msg.writeByte(0); // Difficulty
|
||||
msg.writeByte(maxPlayers);
|
||||
msg.writeString("flat"); // Level type
|
||||
}
|
||||
|
||||
if (version.fromTo(Version.V1_8, Version.V1_9)) {
|
||||
msg.writeByte(gameMode);
|
||||
msg.writeByte(dimensionRegistry.getDefaultDimension_1_16().getId());
|
||||
|
@ -37,8 +37,10 @@ public class PacketKeepAlive implements Packet {
|
||||
public void encode(ByteMessage msg, Version version) {
|
||||
if (version.moreOrEqual(Version.V1_12_2)) {
|
||||
msg.writeLong(id);
|
||||
} else {
|
||||
} else if (version.moreOrEqual(Version.V1_8)) {
|
||||
msg.writeVarInt((int) id);
|
||||
} else {
|
||||
msg.writeInt((int) id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,8 +48,10 @@ public class PacketKeepAlive implements Packet {
|
||||
public void decode(ByteMessage msg, Version version) {
|
||||
if (version.moreOrEqual(Version.V1_12_2)) {
|
||||
this.id = msg.readLong();
|
||||
} else {
|
||||
} else if (version.moreOrEqual(Version.V1_8)) {
|
||||
this.id = msg.readVarInt();
|
||||
} else {
|
||||
this.id = msg.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,16 +46,22 @@ public class PacketPlayerInfo implements PacketOut {
|
||||
|
||||
@Override
|
||||
public void encode(ByteMessage msg, Version version) {
|
||||
msg.writeVarInt(0); // Add player action
|
||||
msg.writeVarInt(1);
|
||||
msg.writeUuid(uuid);
|
||||
msg.writeString(username);
|
||||
msg.writeVarInt(0);
|
||||
msg.writeVarInt(gameMode);
|
||||
msg.writeVarInt(60);
|
||||
msg.writeBoolean(false);
|
||||
if (version.moreOrEqual(Version.V1_19)) {
|
||||
if (version.less(Version.V1_8)) {
|
||||
msg.writeString(username);
|
||||
msg.writeBoolean(true); // Is online
|
||||
msg.writeShort(0);
|
||||
} else {
|
||||
msg.writeVarInt(0); // Add player action
|
||||
msg.writeVarInt(1);
|
||||
msg.writeUuid(uuid);
|
||||
msg.writeString(username);
|
||||
msg.writeVarInt(0);
|
||||
msg.writeVarInt(gameMode);
|
||||
msg.writeVarInt(60);
|
||||
msg.writeBoolean(false);
|
||||
if (version.moreOrEqual(Version.V1_19)) {
|
||||
msg.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,15 +62,18 @@ public class PacketPlayerPositionAndLook implements PacketOut {
|
||||
@Override
|
||||
public void encode(ByteMessage msg, Version version) {
|
||||
msg.writeDouble(x);
|
||||
msg.writeDouble(y);
|
||||
msg.writeDouble(y + (version.less(Version.V1_8) ? 1.62F : 0));
|
||||
msg.writeDouble(z);
|
||||
msg.writeFloat(yaw);
|
||||
msg.writeFloat(pitch);
|
||||
|
||||
if (version.less(Version.V1_9)) {
|
||||
msg.writeBoolean(true); // On ground
|
||||
} else {
|
||||
if (version.moreOrEqual(Version.V1_8)) {
|
||||
msg.writeByte(flags);
|
||||
} else {
|
||||
msg.writeBoolean(true);
|
||||
}
|
||||
|
||||
if (version.moreOrEqual(Version.V1_9)) {
|
||||
msg.writeVarInt(teleportId);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public enum State {
|
||||
PLAY(3) {
|
||||
{
|
||||
serverBound.register(PacketKeepAlive::new,
|
||||
map(0x00, V1_8, V1_8),
|
||||
map(0x00, V1_7_2, V1_8),
|
||||
map(0x0B, V1_9, V1_11_1),
|
||||
map(0x0C, V1_12, V1_12),
|
||||
map(0x0B, V1_12_1, V1_12_2),
|
||||
@ -98,7 +98,7 @@ public enum State {
|
||||
map(0x0F, V1_19, V1_19_1)
|
||||
);
|
||||
clientBound.register(PacketJoinGame::new,
|
||||
map(0x01, V1_8, V1_8),
|
||||
map(0x01, V1_7_2, V1_8),
|
||||
map(0x23, V1_9, V1_12_2),
|
||||
map(0x25, V1_13, V1_14_4),
|
||||
map(0x26, V1_15, V1_15_2),
|
||||
@ -119,7 +119,7 @@ public enum State {
|
||||
map(0x16, V1_19_1, V1_19_1)
|
||||
);
|
||||
clientBound.register(PacketPlayerAbilities::new,
|
||||
map(0x39, V1_8, V1_8),
|
||||
map(0x39, V1_7_2, V1_8),
|
||||
map(0x2B, V1_9, V1_12),
|
||||
map(0x2C, V1_12_1, V1_12_2),
|
||||
map(0x2E, V1_13, V1_13_2),
|
||||
@ -132,7 +132,7 @@ public enum State {
|
||||
map(0x31, V1_19_1, V1_19_1)
|
||||
);
|
||||
clientBound.register(PacketPlayerPositionAndLook::new,
|
||||
map(0x08, V1_8, V1_8),
|
||||
map(0x08, V1_7_2, V1_8),
|
||||
map(0x2E, V1_9, V1_12),
|
||||
map(0x2F, V1_12_1, V1_12_2),
|
||||
map(0x32, V1_13, V1_13_2),
|
||||
@ -145,7 +145,7 @@ public enum State {
|
||||
map(0x39, V1_19_1, V1_19_1)
|
||||
);
|
||||
clientBound.register(PacketKeepAlive::new,
|
||||
map(0x00, V1_8, V1_8),
|
||||
map(0x00, V1_7_2, V1_8),
|
||||
map(0x1F, V1_9, V1_12_2),
|
||||
map(0x21, V1_13, V1_13_2),
|
||||
map(0x20, V1_14, V1_14_4),
|
||||
@ -157,7 +157,7 @@ public enum State {
|
||||
map(0x20, V1_19_1, V1_19_1)
|
||||
);
|
||||
clientBound.register(PacketChatMessage::new,
|
||||
map(0x02, V1_8, V1_8),
|
||||
map(0x02, V1_7_2, V1_8),
|
||||
map(0x0F, V1_9, V1_12_2),
|
||||
map(0x0E, V1_13, V1_14_4),
|
||||
map(0x0F, V1_15, V1_15_2),
|
||||
@ -174,7 +174,7 @@ public enum State {
|
||||
map(0x0A, V1_19, V1_19_1)
|
||||
);
|
||||
clientBound.register(PacketPlayerInfo::new,
|
||||
map(0x38, V1_8, V1_8),
|
||||
map(0x38, V1_7_2, V1_8),
|
||||
map(0x2D, V1_9, V1_12),
|
||||
map(0x2E, V1_12_1, V1_12_2),
|
||||
map(0x30, V1_13, V1_13_2),
|
||||
|
@ -23,6 +23,10 @@ import java.util.Map;
|
||||
public enum Version {
|
||||
|
||||
UNDEFINED(-1),
|
||||
V1_7_2(4),
|
||||
// 1.7.2-1.7.5 has same protocol numbers
|
||||
V1_7_6(5),
|
||||
// 1.7.6-1.7.10 has same protocol numbers
|
||||
V1_8(47),
|
||||
// 1.8-1.8.8 has same protocol numbers
|
||||
V1_9(107),
|
||||
@ -119,7 +123,7 @@ public enum Version {
|
||||
}
|
||||
|
||||
public static Version getMin() {
|
||||
return V1_8;
|
||||
return V1_7_2;
|
||||
}
|
||||
|
||||
public static Version getMax() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user