diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..884330be --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:17-alpine3.14 + +ENV JAVA_HEAP_SIZE="1G" +ENV JAVA_ARGS="" + +WORKDIR /app + +COPY build/libs/NanoLimbo-*-all.jar server.jar + +ENTRYPOINT java $JAVA_ARGS -Xmx$JAVA_HEAP_SIZE -Xms$JAVA_HEAP_SIZE -jar server.jar \ No newline at end of file diff --git a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java index aac08c6b..9c0bf0ce 100644 --- a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java +++ b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java @@ -51,11 +51,17 @@ public final class LimboConfig { private boolean useBossBar; private boolean useTitle; private boolean usePlayerList; + private boolean useHeaderAndFooter; + private String brandName; private String joinMessage; private BossBar bossBar; private Title title; + private String playerListUsername; + private String playerListHeader; + private String playerListFooter; + private InfoForwarding infoForwarding; private long readTimeout; private int debugLevel = 3; @@ -87,7 +93,8 @@ public void load() throws Exception { useJoinMessage = conf.node("joinMessage", "enable").getBoolean(); useBossBar = conf.node("bossBar", "enable").getBoolean(); useTitle = conf.node("title", "enable").getBoolean(); - usePlayerList = conf.node("playerList").getBoolean(); + usePlayerList = conf.node("playerList", "enable").getBoolean(); + useHeaderAndFooter = conf.node("headerAndFooter", "enable").getBoolean(); if (useBrandName) brandName = conf.node("brandName", "content").getString(); @@ -101,6 +108,14 @@ public void load() throws Exception { if (useTitle) title = conf.node("title").get(Title.class); + if (usePlayerList) + playerListUsername = conf.node("playerList", "username").getString(); + + if (useHeaderAndFooter) { + playerListHeader = conf.node("headerAndFooter", "header").getString(); + playerListFooter = conf.node("headerAndFooter", "footer").getString(); + } + infoForwarding = conf.node("infoForwarding").get(InfoForwarding.class); readTimeout = conf.node("readTimeout").getLong(); debugLevel = conf.node("debugLevel").getInt(); @@ -193,6 +208,10 @@ public boolean isUsePlayerList() { return usePlayerList; } + public boolean isUseHeaderAndFooter() { + return useHeaderAndFooter; + } + public String getBrandName() { return brandName; } @@ -209,6 +228,18 @@ public Title getTitle() { return title; } + public String getPlayerListUsername() { + return playerListUsername; + } + + public String getPlayerListHeader() { + return playerListHeader; + } + + public String getPlayerListFooter() { + return playerListFooter; + } + public boolean isUseEpoll() { return useEpoll; } diff --git a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java index affc76c5..33cf9c4d 100644 --- a/src/main/java/ru/nanit/limbo/connection/ClientConnection.java +++ b/src/main/java/ru/nanit/limbo/connection/ClientConnection.java @@ -65,6 +65,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter { private static PacketSnapshot PACKET_PLAYER_POS; private static PacketSnapshot PACKET_JOIN_MESSAGE; private static PacketSnapshot PACKET_BOSS_BAR; + private static PacketSnapshot PACKET_HEADER_AND_FOOTER; private static PacketSnapshot PACKET_TITLE_TITLE; private static PacketSnapshot PACKET_TITLE_SUBTITLE; @@ -240,19 +241,12 @@ private void fireLoginSuccess() { writePacket(PACKET_PLAYER_ABILITIES); writePacket(PACKET_PLAYER_POS); - if (clientVersion.moreOrEqual(Version.V1_17)) { - if (server.getConfig().isUsePlayerList()) { - writePacket(PACKET_PLAYER_INFO); - } - } - else { + if (PACKET_PLAYER_INFO != null && !clientVersion.equals(Version.V1_16_4)) writePacket(PACKET_PLAYER_INFO); - } if (clientVersion.moreOrEqual(Version.V1_13)){ writePacket(PACKET_DECLARE_COMMANDS); - if (PACKET_PLUGIN_MESSAGE != null) writePacket(PACKET_PLUGIN_MESSAGE); } @@ -266,6 +260,9 @@ private void fireLoginSuccess() { if (PACKET_TITLE_TITLE != null) writeTitle(); + if (PACKET_HEADER_AND_FOOTER != null) + writePacket(PACKET_HEADER_AND_FOOTER); + sendKeepAlive(); } @@ -430,11 +427,6 @@ public static void initPackets(LimboServer server) { positionAndLook.setPitch(server.getConfig().getSpawnPosition().getPitch()); positionAndLook.setTeleportId(ThreadLocalRandom.current().nextInt()); - PacketPlayerInfo info = new PacketPlayerInfo(); - info.setUsername(username); - info.setGameMode(server.getConfig().getGameMode()); - info.setUuid(uuid); - PacketDeclareCommands declareCommands = new PacketDeclareCommands(); declareCommands.setCommands(Collections.emptyList()); @@ -443,10 +435,23 @@ public static void initPackets(LimboServer server) { PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities); PACKET_PLAYER_POS = PacketSnapshot.of(positionAndLook); - PACKET_PLAYER_INFO = PacketSnapshot.of(info); - PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands); + if (server.getConfig().isUsePlayerList()) { + PacketPlayerInfo info = new PacketPlayerInfo(); + info.setUsername(server.getConfig().getPlayerListUsername()); + info.setGameMode(server.getConfig().getGameMode()); + info.setUuid(uuid); + PACKET_PLAYER_INFO = PacketSnapshot.of(info); + + if (server.getConfig().isUseHeaderAndFooter()) { + PacketPlayerListHeader header = new PacketPlayerListHeader(); + header.setHeader(server.getConfig().getPlayerListHeader()); + header.setFooter(server.getConfig().getPlayerListFooter()); + PACKET_HEADER_AND_FOOTER = PacketSnapshot.of(header); + } + } + if (server.getConfig().isUseBrandName()){ PacketPluginMessage pluginMessage = new PacketPluginMessage(); pluginMessage.setChannel(LimboConstants.BRAND_CHANNEL); diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerListHeader.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerListHeader.java new file mode 100644 index 00000000..c4e4cb61 --- /dev/null +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPlayerListHeader.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2020 Nan1t + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package ru.nanit.limbo.protocol.packets.play; + +import ru.nanit.limbo.protocol.ByteMessage; +import ru.nanit.limbo.protocol.PacketOut; +import ru.nanit.limbo.protocol.registry.Version; + +public class PacketPlayerListHeader implements PacketOut { + + private String header; + private String footer; + + public void setHeader(String header) { + this.header = header; + } + + public void setFooter(String footer) { + this.footer = footer; + } + + @Override + public void encode(ByteMessage msg, Version version) { + msg.writeString(header); + msg.writeString(footer); + } +} diff --git a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPluginMessage.java b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPluginMessage.java index e11c4523..1563775d 100644 --- a/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPluginMessage.java +++ b/src/main/java/ru/nanit/limbo/protocol/packets/play/PacketPluginMessage.java @@ -26,10 +26,11 @@ public class PacketPluginMessage implements PacketOut { private String channel; private String message; - public void setChannel(String channel){ + public void setChannel(String channel) { this.channel = channel; } - public void setMessage(String message){ + + public void setMessage(String message) { this.message = message; } diff --git a/src/main/java/ru/nanit/limbo/protocol/registry/State.java b/src/main/java/ru/nanit/limbo/protocol/registry/State.java index 65ab4649..ae72454b 100644 --- a/src/main/java/ru/nanit/limbo/protocol/registry/State.java +++ b/src/main/java/ru/nanit/limbo/protocol/registry/State.java @@ -189,6 +189,19 @@ public enum State { map(0x5A, V1_17, V1_17_1), map(0x5B, V1_18, V1_18) ); + clientBound.register(PacketPlayerListHeader::new, + map(0x47, V1_8, V1_8), + map(0x48, V1_9, V1_9_2), + map(0x47, V1_9_4, V1_11_1), + map(0x49, V1_12, V1_12), + map(0x4A, V1_12_1, V1_12_2), + map(0x4E, V1_13, V1_13_2), + map(0x53, V1_14, V1_14_4), + map(0x54, V1_15, V1_15_2), + map(0x53, V1_16, V1_16_4), + map(0x5E, V1_17, V1_17_1), + map(0x5F, V1_18, V1_18) + ); } }; diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index 4ef7cb86..b0d56fbb 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -20,7 +20,16 @@ ping: dimension: THE_END # Whether to display the player in the player list -playerList: true +playerList: + enable: false + username: 'NanoLimbo' + +# Whether to display header and footer in player list +# Enable it only if you enabled playerList +headerAndFooter: + enable: false + header: '{"text": "&eWelcome!"}' + footer: '{"text": "&9NanoLimbo"}' # Spawn position in the world spawnPosition: