Skip to content

Commit

Permalink
Merge branch '1.21.0' into 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Nov 11, 2024
2 parents 2abb4c9 + a8411c4 commit f85bb42
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public CommandUsage commandUsage() {
"ping maxPlayers <int>",
"ping lanBroadcast on/off",
"ping log on/off",
"enforceMatchingConnectingAddress on/off",
"timeout on/off",
"timeout <seconds>",
"autoConnectOnLogin on/off"
Expand Down Expand Up @@ -117,6 +118,13 @@ public LiteralArgumentBuilder<CommandContext> register() {
.title("Ping Log " + toggleStrCaps(CONFIG.server.ping.logPings));
return 1;
}))))
.then(literal("enforceMatchingConnectingAddress")
.then(argument("toggle", toggle()).executes(c -> {
CONFIG.server.enforceMatchingConnectingAddress = getToggle(c, "toggle");
c.getSource().getEmbed()
.title("Enforce Connecting Address " + toggleStrCaps(CONFIG.server.enforceMatchingConnectingAddress));
return 1;
})))
.then(literal("timeout")
.then(argument("toggle", toggle()).executes(c -> {
CONFIG.server.extra.timeout.enable = getToggle(c, "toggle");
Expand Down Expand Up @@ -162,6 +170,7 @@ public void postPopulate(final Embed builder) {
.addField("Ping Max Players", CONFIG.server.ping.maxPlayers, false)
.addField("Ping LAN Broadcast", toggleStr(CONFIG.server.ping.lanBroadcast), false)
.addField("Ping Log", toggleStr(CONFIG.server.ping.logPings), false)
.addField("Enforce Matching Connecting Address", toggleStr(CONFIG.server.enforceMatchingConnectingAddress), false)
.addField("Timeout", CONFIG.server.extra.timeout.enable ? CONFIG.server.extra.timeout.seconds : toggleStr(false), false)
.addField("Auto Connect On Login", toggleStr(CONFIG.client.extra.autoConnectOnLogin), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public ClientboundLoginPacket apply(@NonNull ClientboundLoginPacket packet, @Non
chatSession.getPlayerCertificates().getPublicKey(),
chatSession.getPlayerCertificates().getPublicKeySignature()
));
CLIENT_LOG.info("Server enforces secure chat, zenith chat signing enabled");
} else {
CLIENT_LOG.warn("Server enforces secure chat, but we cannot sign chat messages");
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/zenith/network/server/ServerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class ServerSession extends TcpServerSession {
// as requested by the player during login. may not be the same as what mojang api returns
private @Nullable UUID loginProfileUUID;
private int protocolVersion; // as reported by the client when they connected
private String connectingServerAddress; // as reported by the client when they connected
private int connectingServerPort; // as reported by the client when they connected
protected boolean isTransferring = false;
protected final CookieCache cookieCache = new CookieCache();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zenith.network.server.handler.shared.incoming;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.zenith.feature.ratelimiter.RateLimiter;
import com.zenith.network.registry.PacketHandler;
import com.zenith.network.server.ServerSession;
Expand All @@ -16,10 +17,33 @@ public class IntentionHandler implements PacketHandler<ClientIntentionPacket, Se
@Override
public ClientIntentionPacket apply(final ClientIntentionPacket packet, final ServerSession session) {
MinecraftProtocol protocol = session.getPacketProtocol();
session.setProtocolVersion(packet.getProtocolVersion());
session.setConnectingServerAddress(packet.getHostname());
session.setConnectingServerPort(packet.getPort());
if (CONFIG.server.enforceMatchingConnectingAddress) {
var addressWithPort = packet.getHostname() + ":" + packet.getPort();
var addressWithoutPort = packet.getHostname();
// if proxyIP is set to a DNS name, config address won't have port present and the port can mismatch due to SRV record
var expectedAddress = CONFIG.server.getProxyAddress();
if (!(expectedAddress.equals(addressWithPort) || expectedAddress.equals(addressWithoutPort))) {
SERVER_LOG.info(
"Disconnecting {} [{}] with intent: {} due to mismatched connecting server address. Expected: {} Actual: {}",
session.getRemoteAddress(),
ProtocolVersion.getProtocol(session.getProtocolVersion()).getName(),
packet.getIntent(),
expectedAddress,
addressWithPort);
session.disconnect("bye");
return null;
}
}
switch (packet.getIntent()) {
case STATUS -> {
protocol.setOutboundState(ProtocolState.STATUS);
session.switchInboundState(ProtocolState.STATUS);
if (!CONFIG.server.ping.enabled) {
session.disconnect("bye");
}
}
case LOGIN -> {
if (handleLogin(packet, session, protocol)) return null;
Expand All @@ -35,7 +59,6 @@ public ClientIntentionPacket apply(final ClientIntentionPacket packet, final Ser
}
default -> session.disconnect("Invalid client intention: " + packet.getIntent());
}
session.setProtocolVersion(packet.getProtocolVersion());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public class StatusRequestHandler implements PacketHandler<ServerboundStatusRequ
@Override
public ServerboundStatusRequestPacket apply(final ServerboundStatusRequestPacket packet, final ServerSession session) {
if (CONFIG.server.ping.logPings)
SERVER_LOG.info("[Ping] Request from: {} [{}]", session.getRemoteAddress(), ProtocolVersion.getProtocol(session.getProtocolVersion()).getName());
SERVER_LOG.info("[Ping] Request from: {} [{}] to: {}:{}",
session.getRemoteAddress(),
ProtocolVersion.getProtocol(session.getProtocolVersion()).getName(),
session.getConnectingServerAddress(),
session.getConnectingServerPort());
ServerInfoBuilder builder = session.getFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY);
if (builder == null) {
session.disconnect("bye");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/zenith/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ public static final class Server {
public final Ping ping = new Ping();
public final ServerViaVersion viaversion = new ServerViaVersion();
public boolean verifyUsers = true;
public boolean enforceMatchingConnectingAddress = false;
public boolean acceptTransfers = true;
public boolean onlyZenithTransfers = true;
public String proxyIP = "localhost";
Expand Down

0 comments on commit f85bb42

Please sign in to comment.