Skip to content

Commit

Permalink
NanoLimbo 1.5 api support
Browse files Browse the repository at this point in the history
  • Loading branch information
bivashy committed Dec 11, 2022
2 parents e47b705 + 08165bb commit b9d25d7
Show file tree
Hide file tree
Showing 21 changed files with 378 additions and 382 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The general features:

Symbol `X` means all minor versions.

- [x] 1.7.X
- [x] 1.8.X
- [x] 1.9.X
- [x] 1.10.X
Expand All @@ -35,6 +36,8 @@ Symbol `X` means all minor versions.
- [x] 1.18.X
- [x] 1.19
- [x] 1.19.1
- [x] 1.19.2
- [x] 1.19.3

The server **doesn't** support snapshots.

Expand Down Expand Up @@ -87,7 +90,7 @@ Required software:
To build minimized .jar, go to project root and write in terminal:

```
gradlew shadowJar
./gradlew shadowJar
```

### Contacts
Expand Down
2 changes: 1 addition & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ dependencies {

shadowJar{
manifest {
attributes 'Main-Class': 'ru.nanit.limbo.NanoLimbo'
attributes 'Main-Class': 'ua.nanit.limbo.NanoLimbo'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ua.nanit.limbo.server.data.InfoForwarding;
import ua.nanit.limbo.server.data.PingData;
import ua.nanit.limbo.server.data.Title;
import ua.nanit.limbo.world.Location;

public interface LimboConfig {
SocketAddress getAddress();
Expand All @@ -17,8 +16,6 @@ public interface LimboConfig {

String getDimensionType();

Location getSpawnPosition();

int getGameMode();

InfoForwarding getInfoForwarding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import ua.nanit.limbo.server.data.PingData;
import ua.nanit.limbo.server.data.Title;
import ua.nanit.limbo.util.Colors;
import ua.nanit.limbo.world.Location;

public final class YamlLimboConfig implements LimboConfig {

Expand All @@ -48,7 +47,6 @@ public final class YamlLimboConfig implements LimboConfig {
private PingData pingData;

private String dimensionType;
private Location spawnPosition;
private int gameMode;

private boolean useBrandName;
Expand Down Expand Up @@ -99,7 +97,6 @@ public YamlLimboConfig load() throws Exception {
if (dimensionType.equalsIgnoreCase("end")) {
dimensionType = "the_end";
}
spawnPosition = conf.node("spawnPosition").get(Location.class);
gameMode = conf.node("gameMode").getInt();
useBrandName = conf.node("brandName", "enable").getBoolean();
useJoinMessage = conf.node("joinMessage", "enable").getBoolean();
Expand Down Expand Up @@ -159,7 +156,6 @@ private TypeSerializerCollection getSerializers() {
.register(PingData.class, new PingData.Serializer())
.register(BossBar.class, new BossBar.Serializer())
.register(Title.class, new Title.Serializer())
.register(Location.class, new Location.Serializer())
.build();
}

Expand All @@ -183,11 +179,6 @@ public String getDimensionType() {
return dimensionType;
}

@Override
public Location getSpawnPosition() {
return spawnPosition;
}

@Override
public int getGameMode() {
return gameMode;
Expand Down Expand Up @@ -287,4 +278,4 @@ public int getBossGroupSize() {
public int getWorkerGroupSize() {
return workerGroupSize;
}
}
}
89 changes: 51 additions & 38 deletions api/src/main/java/ua/nanit/limbo/connection/ClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@

package ua.nanit.limbo.connection;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import org.jetbrains.annotations.NotNull;

import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
Expand All @@ -26,32 +39,17 @@
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import org.jetbrains.annotations.NotNull;

import ua.nanit.limbo.connection.pipeline.PacketDecoder;
import ua.nanit.limbo.connection.pipeline.PacketEncoder;
import ua.nanit.limbo.protocol.ByteMessage;
import ua.nanit.limbo.protocol.Packet;
import ru.nanit.limbo.protocol.packets.login.*;
import ru.nanit.limbo.protocol.packets.play.*;
import ua.nanit.limbo.protocol.packets.login.PacketDisconnect;
import ua.nanit.limbo.protocol.packets.play.PacketKeepAlive;
import ua.nanit.limbo.protocol.registry.State;
import ua.nanit.limbo.protocol.registry.Version;
import ua.nanit.limbo.server.LimboServer;
import ua.nanit.limbo.server.Logger;
import ua.nanit.limbo.util.UuidUtil;
import ua.nanit.limbo.protocol.packets.login.PacketDisconnect;
import ua.nanit.limbo.protocol.packets.play.PacketKeepAlive;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public class ClientConnection extends ChannelInboundHandlerAdapter {

Expand Down Expand Up @@ -129,38 +127,53 @@ public void fireLoginSuccess() {
return;
}

writePacket(server.getPacketSnapshots().getPacketLoginSuccess());
sendPacket(server.getPacketSnapshots().getPacketLoginSuccess());
updateState(State.PLAY);

server.getConnections().addConnection(this);

writePacket(server.getPacketSnapshots().getPacketJoinGame());
writePacket(server.getPacketSnapshots().getPacketPlayerAbilities());
writePacket(server.getPacketSnapshots().getPacketPlayerPos());
Runnable sendPlayPackets = () -> {
writePacket(server.getPacketSnapshots().getPacketJoinGame());
writePacket(server.getPacketSnapshots().getPacketPlayerAbilities());

if (server.getConfig().isUsePlayerList() || clientVersion.equals(Version.V1_16_4))
writePacket(server.getPacketSnapshots().getPacketPlayerInfo());
if (clientVersion.less(Version.V1_9)) {
writePacket(server.getPacketSnapshots().getPacketPlayerPosAndLookLegacy());
} else {
writePacket(server.getPacketSnapshots().getPacketPlayerPosAndLook());
}

if (clientVersion.moreOrEqual(Version.V1_13)) {
writePacket(server.getPacketSnapshots().getPacketDeclareCommands());
if (clientVersion.moreOrEqual(Version.V1_19_3))
writePacket(server.getPacketSnapshots().getPacketSpawnPosition());

if (server.getPacketSnapshots().getPacketPluginMessage() != null)
writePacket(server.getPacketSnapshots().getPacketPluginMessage());
}
if (server.getConfig().isUsePlayerList() || clientVersion.equals(Version.V1_16_4))
writePacket(server.getPacketSnapshots().getPacketPlayerInfo());

if (server.getPacketSnapshots().getPacketBossBar() != null && clientVersion.moreOrEqual(Version.V1_9))
writePacket(server.getPacketSnapshots().getPacketBossBar());
if (clientVersion.moreOrEqual(Version.V1_13)) {
writePacket(server.getPacketSnapshots().getPacketDeclareCommands());

if (server.getPacketSnapshots().getPacketPluginMessage() != null)
writePacket(server.getPacketSnapshots().getPacketPluginMessage());
}

if (server.getPacketSnapshots().getPacketJoinMessage() != null)
writePacket(server.getPacketSnapshots().getPacketJoinMessage());
if (server.getPacketSnapshots().getPacketBossBar() != null && clientVersion.moreOrEqual(Version.V1_9))
writePacket(server.getPacketSnapshots().getPacketBossBar());

if (server.getPacketSnapshots().getPacketTitleTitle() != null)
writeTitle();
if (server.getPacketSnapshots().getPacketJoinMessage() != null)
writePacket(server.getPacketSnapshots().getPacketJoinMessage());

if (server.getPacketSnapshots().getPacketHeaderAndFooter() != null)
writePacket(server.getPacketSnapshots().getPacketHeaderAndFooter());
if (server.getPacketSnapshots().getPacketTitleTitle() != null && clientVersion.moreOrEqual(Version.V1_8))
writeTitle();

sendKeepAlive();
if (server.getPacketSnapshots().getPacketHeaderAndFooter() != null && clientVersion.moreOrEqual(Version.V1_8))
writePacket(server.getPacketSnapshots().getPacketHeaderAndFooter());

sendKeepAlive();
};

if (clientVersion.lessOrEqual(Version.V1_7_6)) {
this.channel.eventLoop().schedule(sendPlayPackets, 100, TimeUnit.MILLISECONDS);
} else {
sendPlayPackets.run();
}
}

public void disconnectLogin(String reason) {
Expand Down
46 changes: 31 additions & 15 deletions api/src/main/java/ua/nanit/limbo/connection/PacketSnapshots.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import ua.nanit.limbo.LimboConstants;
import ua.nanit.limbo.protocol.PacketSnapshot;
import ua.nanit.limbo.protocol.packets.login.PacketLoginSuccess;
import ru.nanit.limbo.protocol.packets.play.*;
import ua.nanit.limbo.protocol.packets.play.*;
import ua.nanit.limbo.server.LimboServer;
import ua.nanit.limbo.server.data.Title;
import ua.nanit.limbo.util.UuidUtil;
Expand All @@ -46,15 +46,19 @@ public final class PacketSnapshots {

private PacketSnapshot packetLoginSuccess;
private PacketSnapshot packetJoinGame;
private PacketSnapshot packetSpawnPosition;
private PacketSnapshot packetPluginMessage;
private PacketSnapshot packetPlayerAbilities;
private PacketSnapshot packetPlayerInfo;
private PacketSnapshot packetDeclareCommands;
private PacketSnapshot packetPlayerPos;
private PacketSnapshot packetJoinMessage;
private PacketSnapshot packetBossBar;
private PacketSnapshot packetHeaderAndFooter;

private PacketSnapshot packetPlayerPosAndLookLegacy;
// For 1.19 we need to spawn player outside world to avoid stuck in terrain loading
private PacketSnapshot packetPlayerPosAndLook;

private PacketSnapshot packetTitleTitle;
private PacketSnapshot packetTitleSubtitle;
private PacketSnapshot packetTitleTimes;
Expand All @@ -73,6 +77,7 @@ public PacketSnapshots(LimboServer server) {
loginSuccess.setUuid(uuid);

PacketJoinGame joinGame = new PacketJoinGame();
String worldName = "minecraft:" + server.getConfig().getDimensionType().toLowerCase();
joinGame.setEntityId(0);
joinGame.setEnableRespawnScreen(true);
joinGame.setFlat(false);
Expand All @@ -83,7 +88,6 @@ public PacketSnapshots(LimboServer server) {
joinGame.setReducedDebugInfo(true);
joinGame.setDebug(false);
joinGame.setViewDistance(0);
String worldName = "minecraft:" + server.getConfig().getDimensionType().toLowerCase();
joinGame.setWorldName(worldName);
joinGame.setWorldNames(worldName);
joinGame.setHashedSeed(0);
Expand All @@ -94,13 +98,15 @@ public PacketSnapshots(LimboServer server) {
playerAbilities.setFlags(0x02);
playerAbilities.setFieldOfView(0.1F);

PacketPlayerPositionAndLook positionAndLook = new PacketPlayerPositionAndLook();
positionAndLook.setX(server.getConfig().getSpawnPosition().getX());
positionAndLook.setY(server.getConfig().getSpawnPosition().getY());
positionAndLook.setZ(server.getConfig().getSpawnPosition().getZ());
positionAndLook.setYaw(server.getConfig().getSpawnPosition().getYaw());
positionAndLook.setPitch(server.getConfig().getSpawnPosition().getPitch());
positionAndLook.setTeleportId(ThreadLocalRandom.current().nextInt());
int teleportId = ThreadLocalRandom.current().nextInt();

PacketPlayerPositionAndLook positionAndLookLegacy
= new PacketPlayerPositionAndLook(0, 64, 0, 0, 0, teleportId);

PacketPlayerPositionAndLook positionAndLook
= new PacketPlayerPositionAndLook(0, 400, 0, 0, 0, teleportId);

PacketSpawnPosition spawnPosition = new PacketSpawnPosition(0, 400, 0);

PacketDeclareCommands declareCommands = new PacketDeclareCommands();
declareCommands.setCommands(Collections.emptyList());
Expand All @@ -112,8 +118,10 @@ public PacketSnapshots(LimboServer server) {

packetLoginSuccess = PacketSnapshot.of(loginSuccess);
packetJoinGame = PacketSnapshot.of(joinGame);
packetPlayerPosAndLookLegacy = PacketSnapshot.of(positionAndLookLegacy);
packetPlayerPosAndLook = PacketSnapshot.of(positionAndLook);
packetSpawnPosition = PacketSnapshot.of(spawnPosition);
packetPlayerAbilities = PacketSnapshot.of(playerAbilities);
packetPlayerPos = PacketSnapshot.of(positionAndLook);
packetPlayerInfo = PacketSnapshot.of(info);

packetDeclareCommands = PacketSnapshot.of(declareCommands);
Expand Down Expand Up @@ -191,6 +199,10 @@ public PacketSnapshot getPacketJoinGame() {
return packetJoinGame;
}

public PacketSnapshot getPacketSpawnPosition() {
return packetSpawnPosition;
}

public PacketSnapshot getPacketPluginMessage() {
return packetPluginMessage;
}
Expand All @@ -207,10 +219,6 @@ public PacketSnapshot getPacketDeclareCommands() {
return packetDeclareCommands;
}

public PacketSnapshot getPacketPlayerPos() {
return packetPlayerPos;
}

public PacketSnapshot getPacketJoinMessage() {
return packetJoinMessage;
}
Expand All @@ -223,6 +231,14 @@ public PacketSnapshot getPacketHeaderAndFooter() {
return packetHeaderAndFooter;
}

public PacketSnapshot getPacketPlayerPosAndLookLegacy() {
return packetPlayerPosAndLookLegacy;
}

public PacketSnapshot getPacketPlayerPosAndLook() {
return packetPlayerPosAndLook;
}

public PacketSnapshot getPacketTitleTitle() {
return packetTitleTitle;
}
Expand Down
21 changes: 21 additions & 0 deletions api/src/main/java/ua/nanit/limbo/protocol/ByteMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.BitSet;
import java.util.EnumSet;
import java.util.UUID;

public class ByteMessage extends ByteBuf {
Expand Down Expand Up @@ -190,6 +193,24 @@ public void writeCompoundTag(CompoundBinaryTag compoundTag) {
}
}

public <E extends Enum<E>> void writeEnumSet(EnumSet<E> enumset, Class<E> oclass) {
E[] enums = oclass.getEnumConstants();
BitSet bits = new BitSet(enums.length);

for (int i = 0; i < enums.length; ++i) {
bits.set(i, enumset.contains(enums[i]));
}

writeFixedBitSet(bits, enums.length, buf);
}

private static void writeFixedBitSet(BitSet bits, int size, ByteBuf buf) {
if (bits.length() > size) {
throw new StackOverflowError("BitSet too large (expected " + size + " got " + bits.size() + ")");
}
buf.writeBytes(Arrays.copyOf(bits.toByteArray(), (size + 8) >> 3));
}

/* Delegated methods */

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public void setUsername(String username) {
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)) {
Expand Down
Loading

0 comments on commit b9d25d7

Please sign in to comment.