Skip to content

Commit

Permalink
Merge pull request #7 from bivashy/feature/6-1-20-6-support
Browse files Browse the repository at this point in the history
[Feature] 1.20.6 support
  • Loading branch information
bivashy authored May 19, 2024
2 parents 90f58e1 + d22a21e commit 2cd41c4
Show file tree
Hide file tree
Showing 36 changed files with 456 additions and 219 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ The main goal of this project is maximum simplicity with a minimum number of sen
The limbo is empty; there is no ability to set a schematic building since this is not necessary.
You can send useful information via chat or boss bar.

No plugins, no logs. The server is fully clear. It is only able keep a lot of players while the main server is down.
The server is fully clear. It is only able to keep a lot of players while the main server is down.

General features:
* High performance. The server doesn't save or cache any useless (for limbo) data.
* Doesn't spawn threads per player. Uses a fixed thread pool.
* Doesn't spawn threads per player. Use a fixed thread pool.
* Support for **BungeeCord** and **Velocity** info forwarding.
* Support for [BungeeGuard](https://www.spigotmc.org/resources/79601/) handshake format.
* Multiple versions support.
* Fully configurable.
* Lightweight. App size around **2MB**.
* Lightweight. App size around **3MB**.

![](https://i.imgur.com/sT8p1Gz.png)

Expand All @@ -147,7 +147,7 @@ Symbol `X` means all minor versions.
- [x] 1.17.X
- [x] 1.18.X
- [x] 1.19.X
- [x] 1.20-1.20.4
- [x] 1.20-1.20.6

The server **doesn't** support snapshot versions.

Expand All @@ -162,14 +162,16 @@ Note that the server also will be closed correctly if you just press `Ctrl+C`.

### Installation

Required software: JRE 11+

The installation process is simple.

1. Download the latest version of the program [**here**](https://github.com/Nan1t/NanoLimbo/releases).
2. Put the jar file in the folder you want.
3. Create a start script as you did for Bukkit or BungeeCord, with a command like this:
`java -jar NanoLimbo-<version>.jar`
5. The server will create `settings.yml` file, which is the server configuration.
6. Configure it as you want and restart the server.
4. The server will create `settings.yml` file, which is the server configuration.
5. Configure it as you want and restart the server.

### Player info forwarding

Expand All @@ -187,14 +189,14 @@ Then add your tokens to `tokens` list.

### Contributing

Feel free to create a pull request if you found some bug or optimization opportunity, or if you want
Feel free to create a pull request if you find some bug or optimization opportunity, or if you want
to add some functionality that is suitable for a limbo server and won't significantly load the server.

### Building

Required software:

* JDK 1.8+
* JDK 11+
* Gradle 7+ (optional)

To build a minimized jar, go to the project root directory and run in the terminal:
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/ua/nanit/limbo/NanoLimbo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import ua.nanit.limbo.configuration.YamlLimboConfig;
import ua.nanit.limbo.server.ConsoleCommandHandler;
import ua.nanit.limbo.server.LimboServer;
import ua.nanit.limbo.server.Logger;
import ua.nanit.limbo.server.Log;

public final class NanoLimbo {

Expand All @@ -35,7 +35,7 @@ public static void main(String[] args) {
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(server::stop, "NanoLimbo shutdown thread"));
} catch(Exception e) {
Logger.error("Cannot start server: ", e);
Log.error("Cannot start server: ", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ default int getMaxBytesPerSec() {
return -1;
}

double getInterval();

double getMaxPacketRate();

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public final class YamlLimboConfig implements LimboConfig {

private boolean useTrafficLimits;
private int maxPacketSize;
private int maxPacketsPerSec;
private int maxBytesPerSec;
private double interval;
private double maxPacketRate;

public YamlLimboConfig(Path root,ClassLoader classLoader) {
this.root = root;
Expand Down Expand Up @@ -137,9 +137,9 @@ public YamlLimboConfig load() throws Exception {
workerGroupSize = conf.node("netty", "threads", "workerGroup").getInt(4);

useTrafficLimits = conf.node("traffic", "enable").getBoolean(false);
maxPacketSize = conf.node("traffic", "packetSize").getInt(-1);
maxPacketsPerSec = conf.node("traffic", "packets").getInt(-1);
maxBytesPerSec = conf.node("traffic", "bytes").getInt(-1);
maxPacketSize = conf.node("traffic", "maxPacketSize").getInt(-1);
interval = conf.node("traffic", "interval").getDouble(-1.0);
maxPacketRate = conf.node("traffic", "maxPacketRate").getDouble(-1.0);
return this;
}

Expand Down Expand Up @@ -300,13 +300,13 @@ public int getMaxPacketSize() {
}

@Override
public int getMaxPacketsPerSec() {
return maxPacketsPerSec;
public double getInterval() {
return interval;
}

@Override
public int getMaxBytesPerSec() {
return maxBytesPerSec;
public double getMaxPacketRate() {
return maxPacketRate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ protected void initChannel(Channel channel) {
if (server.getConfig().isUseTrafficLimits()) {
pipeline.addLast("traffic_limit", new ChannelTrafficHandler(
server.getConfig().getMaxPacketSize(),
server.getConfig().getMaxPacketsPerSec(),
server.getConfig().getMaxBytesPerSec()
server.getConfig().getInterval(),
server.getConfig().getMaxPacketRate()
));
}

Expand Down
23 changes: 13 additions & 10 deletions api/src/main/java/ua/nanit/limbo/connection/ClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
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.server.Log;
import ua.nanit.limbo.util.UuidUtil;

public class ClientConnection extends ChannelInboundHandlerAdapter {
Expand Down Expand Up @@ -107,7 +107,7 @@ public void channelInactive(@NotNull ChannelHandlerContext ctx) throws Exception
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
if (channel.isActive()) {
Logger.error("Unhandled exception: ", cause);
Log.error("Unhandled exception: ", cause);
}
}

Expand Down Expand Up @@ -179,9 +179,9 @@ public void spawnPlayer() {
writePacket(server.getPacketSnapshots().getPacketHeaderAndFooter());

if (clientVersion.moreOrEqual(Version.V1_20_3)) {
writePacket(PacketSnapshots.PACKET_START_WAITING_CHUNKS);
writePacket(server.getPacketSnapshots().getPacketStartWaitingChunks());

for (PacketSnapshot chunk : PacketSnapshots.PACKETS_EMPTY_CHUNKS) {
for (PacketSnapshot chunk : server.getPacketSnapshots().getPacketsEmptyChunks()) {
writePacket(chunk);
}
}
Expand All @@ -201,7 +201,14 @@ public void onLoginAcknowledgedReceived() {

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

if (clientVersion.moreOrEqual(Version.V1_20_5)) {
for (PacketSnapshot packet : server.getPacketSnapshots().getPacketsRegistryData()) {
writePacket(packet);
}
} else {
writePacket(server.getPacketSnapshots().getPacketRegistryData());
}

sendPacket(server.getPacketSnapshots().getPacketFinishConfiguration());
}
Expand Down Expand Up @@ -259,10 +266,6 @@ public void updateState(State state) {
encoder.updateState(state);
}

public void updateDecoderState(State state) {
decoder.updateState(state);
}

public void updateEncoderState(State state) {
encoder.updateState(state);
}
Expand Down Expand Up @@ -307,7 +310,7 @@ boolean checkBungeeGuardHandshake(String handshake) {
setAddress(socketAddressHostname);
gameProfile.setUuid(uuid);

Logger.debug("Successfully verified BungeeGuard token");
Log.debug("Successfully verified BungeeGuard token");

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import ua.nanit.limbo.protocol.packets.status.PacketStatusRequest;
import ua.nanit.limbo.protocol.packets.status.PacketStatusResponse;
import ua.nanit.limbo.server.LimboServer;
import ua.nanit.limbo.server.Logger;
import ua.nanit.limbo.server.Log;
import ua.nanit.limbo.util.UuidUtil;

import java.util.concurrent.ThreadLocalRandom;
Expand All @@ -46,7 +46,7 @@ public void handle(ClientConnection conn, PacketHandshake packet) {
conn.updateVersion(packet.getVersion());
conn.updateState(packet.getNextState());

Logger.debug("Pinged from %s [%s]", conn.getAddress(),
Log.debug("Pinged from %s [%s]", conn.getAddress(),
conn.getClientVersion().toString());

if (server.getConfig().getInfoForwarding().isLegacy()) {
Expand Down
51 changes: 46 additions & 5 deletions api/src/main/java/ua/nanit/limbo/connection/PacketSnapshots.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package ua.nanit.limbo.connection;

import net.kyori.adventure.nbt.BinaryTag;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.nbt.ListBinaryTag;
import ua.nanit.limbo.LimboConstants;
import ua.nanit.limbo.protocol.PacketSnapshot;
import ua.nanit.limbo.protocol.packets.configuration.PacketFinishConfiguration;
Expand All @@ -40,6 +43,7 @@
import ua.nanit.limbo.protocol.packets.play.PacketTitleSetSubTitle;
import ua.nanit.limbo.protocol.packets.play.PacketTitleSetTitle;
import ua.nanit.limbo.protocol.packets.play.PacketTitleTimes;
import ua.nanit.limbo.world.Dimension;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -61,7 +65,7 @@ public final class PacketSnapshots {
private PacketSnapshot packetHeaderAndFooter;

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

private PacketSnapshot packetTitleTitle;
Expand All @@ -73,6 +77,7 @@ public final class PacketSnapshots {
private PacketSnapshot packetTitleLegacyTimes;

private PacketSnapshot packetRegistryData;
private List<PacketSnapshot> packetsRegistryData;
private PacketSnapshot packetFinishConfiguration;

private List<PacketSnapshot> packetsEmptyChunks;
Expand Down Expand Up @@ -200,10 +205,42 @@ public PacketSnapshots(LimboServer server) {
packetTitleLegacyTimes = PacketSnapshot.of(legacyTimes);
}

PacketRegistryData packetRegistryData = new PacketRegistryData();
packetRegistryData.setDimensionRegistry(server.getDimensionRegistry());
PacketRegistryData registryData = new PacketRegistryData();
registryData.setDimensionRegistry(server.getDimensionRegistry());

packetRegistryData = PacketSnapshot.of(registryData);

Dimension dimension1_20_5 = server.getDimensionRegistry().getDimension_1_20_5();
List<PacketSnapshot> packetRegistries = new ArrayList<>();
CompoundBinaryTag dimensionTag = dimension1_20_5.getData();
for (String registryType : dimensionTag.keySet()) {
CompoundBinaryTag compundRegistryType = dimensionTag.getCompound(registryType);

registryData = new PacketRegistryData();
registryData.setDimensionRegistry(server.getDimensionRegistry());

ListBinaryTag values = compundRegistryType.getList("value");
registryData.setMetadataWriter((message, version) -> {
message.writeString(registryType);

message.writeVarInt(values.size());
for (BinaryTag entry : values) {
CompoundBinaryTag entryTag = (CompoundBinaryTag) entry;

String name = entryTag.getString("name");
CompoundBinaryTag element = entryTag.getCompound("element");

message.writeString(name);
message.writeBoolean(true);
message.writeNamelessCompoundTag(element);
}
});

packetRegistries.add(PacketSnapshot.of(registryData));
}

packetsRegistryData = packetRegistries;

this.packetRegistryData = PacketSnapshot.of(packetRegistryData);
packetFinishConfiguration = PacketSnapshot.of(new PacketFinishConfiguration());

PacketGameEvent packetGameEvent = new PacketGameEvent();
Expand Down Expand Up @@ -310,11 +347,15 @@ public PacketSnapshot getPacketFinishConfiguration() {
}

public List<PacketSnapshot> getPacketsEmptyChunks() {
return packetsEmptyChunks;
return Collections.unmodifiableList(packetsEmptyChunks);
}

public PacketSnapshot getPacketStartWaitingChunks() {
return packetStartWaitingChunks;
}

public List<PacketSnapshot> getPacketsRegistryData() {
return Collections.unmodifiableList(packetsRegistryData);
}

}
Loading

0 comments on commit 2cd41c4

Please sign in to comment.