Added HeaderAndFooter packet. Modified config file. Take username for playerlist not from version string

This commit is contained in:
Nanit 2022-01-31 21:11:43 +02:00
parent 416878d160
commit 647997aa5e
7 changed files with 130 additions and 19 deletions

10
Dockerfile Normal file
View File

@ -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

View File

@ -51,11 +51,17 @@ public final class LimboConfig {
private boolean useBossBar; private boolean useBossBar;
private boolean useTitle; private boolean useTitle;
private boolean usePlayerList; private boolean usePlayerList;
private boolean useHeaderAndFooter;
private String brandName; private String brandName;
private String joinMessage; private String joinMessage;
private BossBar bossBar; private BossBar bossBar;
private Title title; private Title title;
private String playerListUsername;
private String playerListHeader;
private String playerListFooter;
private InfoForwarding infoForwarding; private InfoForwarding infoForwarding;
private long readTimeout; private long readTimeout;
private int debugLevel = 3; private int debugLevel = 3;
@ -87,7 +93,8 @@ public final class LimboConfig {
useJoinMessage = conf.node("joinMessage", "enable").getBoolean(); useJoinMessage = conf.node("joinMessage", "enable").getBoolean();
useBossBar = conf.node("bossBar", "enable").getBoolean(); useBossBar = conf.node("bossBar", "enable").getBoolean();
useTitle = conf.node("title", "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) if (useBrandName)
brandName = conf.node("brandName", "content").getString(); brandName = conf.node("brandName", "content").getString();
@ -101,6 +108,14 @@ public final class LimboConfig {
if (useTitle) if (useTitle)
title = conf.node("title").get(Title.class); 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); infoForwarding = conf.node("infoForwarding").get(InfoForwarding.class);
readTimeout = conf.node("readTimeout").getLong(); readTimeout = conf.node("readTimeout").getLong();
debugLevel = conf.node("debugLevel").getInt(); debugLevel = conf.node("debugLevel").getInt();
@ -193,6 +208,10 @@ public final class LimboConfig {
return usePlayerList; return usePlayerList;
} }
public boolean isUseHeaderAndFooter() {
return useHeaderAndFooter;
}
public String getBrandName() { public String getBrandName() {
return brandName; return brandName;
} }
@ -209,6 +228,18 @@ public final class LimboConfig {
return title; return title;
} }
public String getPlayerListUsername() {
return playerListUsername;
}
public String getPlayerListHeader() {
return playerListHeader;
}
public String getPlayerListFooter() {
return playerListFooter;
}
public boolean isUseEpoll() { public boolean isUseEpoll() {
return useEpoll; return useEpoll;
} }

View File

@ -65,6 +65,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
private static PacketSnapshot PACKET_PLAYER_POS; private static PacketSnapshot PACKET_PLAYER_POS;
private static PacketSnapshot PACKET_JOIN_MESSAGE; private static PacketSnapshot PACKET_JOIN_MESSAGE;
private static PacketSnapshot PACKET_BOSS_BAR; private static PacketSnapshot PACKET_BOSS_BAR;
private static PacketSnapshot PACKET_HEADER_AND_FOOTER;
private static PacketSnapshot PACKET_TITLE_TITLE; private static PacketSnapshot PACKET_TITLE_TITLE;
private static PacketSnapshot PACKET_TITLE_SUBTITLE; private static PacketSnapshot PACKET_TITLE_SUBTITLE;
@ -240,19 +241,12 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
writePacket(PACKET_PLAYER_ABILITIES); writePacket(PACKET_PLAYER_ABILITIES);
writePacket(PACKET_PLAYER_POS); writePacket(PACKET_PLAYER_POS);
if (clientVersion.moreOrEqual(Version.V1_17)) { if (PACKET_PLAYER_INFO != null && !clientVersion.equals(Version.V1_16_4))
if (server.getConfig().isUsePlayerList()) {
writePacket(PACKET_PLAYER_INFO); writePacket(PACKET_PLAYER_INFO);
}
}
else {
writePacket(PACKET_PLAYER_INFO);
}
if (clientVersion.moreOrEqual(Version.V1_13)){ if (clientVersion.moreOrEqual(Version.V1_13)){
writePacket(PACKET_DECLARE_COMMANDS); writePacket(PACKET_DECLARE_COMMANDS);
if (PACKET_PLUGIN_MESSAGE != null) if (PACKET_PLUGIN_MESSAGE != null)
writePacket(PACKET_PLUGIN_MESSAGE); writePacket(PACKET_PLUGIN_MESSAGE);
} }
@ -266,6 +260,9 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
if (PACKET_TITLE_TITLE != null) if (PACKET_TITLE_TITLE != null)
writeTitle(); writeTitle();
if (PACKET_HEADER_AND_FOOTER != null)
writePacket(PACKET_HEADER_AND_FOOTER);
sendKeepAlive(); sendKeepAlive();
} }
@ -430,11 +427,6 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
positionAndLook.setPitch(server.getConfig().getSpawnPosition().getPitch()); positionAndLook.setPitch(server.getConfig().getSpawnPosition().getPitch());
positionAndLook.setTeleportId(ThreadLocalRandom.current().nextInt()); positionAndLook.setTeleportId(ThreadLocalRandom.current().nextInt());
PacketPlayerInfo info = new PacketPlayerInfo();
info.setUsername(username);
info.setGameMode(server.getConfig().getGameMode());
info.setUuid(uuid);
PacketDeclareCommands declareCommands = new PacketDeclareCommands(); PacketDeclareCommands declareCommands = new PacketDeclareCommands();
declareCommands.setCommands(Collections.emptyList()); declareCommands.setCommands(Collections.emptyList());
@ -443,9 +435,22 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities); PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities);
PACKET_PLAYER_POS = PacketSnapshot.of(positionAndLook); PACKET_PLAYER_POS = PacketSnapshot.of(positionAndLook);
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); PACKET_PLAYER_INFO = PacketSnapshot.of(info);
PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands); 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()){ if (server.getConfig().isUseBrandName()){
PacketPluginMessage pluginMessage = new PacketPluginMessage(); PacketPluginMessage pluginMessage = new PacketPluginMessage();

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

View File

@ -26,10 +26,11 @@ public class PacketPluginMessage implements PacketOut {
private String channel; private String channel;
private String message; private String message;
public void setChannel(String channel){ public void setChannel(String channel) {
this.channel = channel; this.channel = channel;
} }
public void setMessage(String message){
public void setMessage(String message) {
this.message = message; this.message = message;
} }

View File

@ -189,6 +189,19 @@ public enum State {
map(0x5A, V1_17, V1_17_1), map(0x5A, V1_17, V1_17_1),
map(0x5B, V1_18, V1_18) 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)
);
} }
}; };

View File

@ -20,7 +20,16 @@ ping:
dimension: THE_END dimension: THE_END
# Whether to display the player in the player list # 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 # Spawn position in the world
spawnPosition: spawnPosition: