Skip to content

Commit

Permalink
Added HeaderAndFooter packet. Modified config file. Take username for…
Browse files Browse the repository at this point in the history
… playerlist not from version string
  • Loading branch information
Nan1t committed Jan 31, 2022
1 parent 416878d commit 647997a
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 19 deletions.
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
33 changes: 32 additions & 1 deletion src/main/java/ru/nanit/limbo/configuration/LimboConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -193,6 +208,10 @@ public boolean isUsePlayerList() {
return usePlayerList;
}

public boolean isUseHeaderAndFooter() {
return useHeaderAndFooter;
}

public String getBrandName() {
return brandName;
}
Expand All @@ -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;
}
Expand Down
35 changes: 20 additions & 15 deletions src/main/java/ru/nanit/limbo/connection/ClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}

Expand Down Expand Up @@ -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());

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/ru/nanit/limbo/protocol/registry/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
};

Expand Down
11 changes: 10 additions & 1 deletion src/main/resources/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 647997a

Please sign in to comment.