Skip to content

Commit 1218588

Browse files
Update file dates and cleanup/consolidate ping-passthrough code.
1 parent 1344650 commit 1218588

5 files changed

Lines changed: 40 additions & 25 deletions

File tree

proxy/src/main/java/com/velocitypowered/proxy/config/LegacyPingPassthroughMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2023 Velocity Contributors
2+
* Copyright (C) 2018-2026 Velocity Contributors
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -25,4 +25,4 @@ public enum LegacyPingPassthroughMode {
2525
MODS,
2626
DESCRIPTION,
2727
ALL
28-
}
28+
}

proxy/src/main/java/com/velocitypowered/proxy/config/PingPassthroughMode.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
package com.velocitypowered.proxy.config;
19+
import com.electronwill.nightconfig.core.CommentedConfig;
1920

2021
/**
2122
* Object to contain all the things that can be toggled for ping passthrough.
@@ -28,13 +29,36 @@
2829
*/
2930
public record PingPassthroughMode(boolean version, boolean players,
3031
boolean description, boolean favicon, boolean modinfo) {
32+
public static final PingPassthroughMode DEFAULT = new PingPassthroughMode();
33+
34+
/**
35+
* Creates a default PingPassthroughMode.
36+
*/
37+
PingPassthroughMode() {
38+
this(false, false, false, false, false);
39+
}
40+
41+
/**
42+
* Returns a PingPassthroughMode from a config section, or the default if the section is null.
43+
* Based on the code for PacketLimiterConfig.
44+
*
45+
* @param config The configuration object to parse.
46+
* @return The PingPassthroughMode, or the default if {@code config} is null.
47+
*/
48+
public static PingPassthroughMode fromConfig(CommentedConfig config) {
49+
if (config == null) {
50+
return DEFAULT;
51+
}
52+
return new PingPassthroughMode(
53+
config.getOrElse("version", DEFAULT.version()),
54+
config.getOrElse("players", DEFAULT.players()),
55+
config.getOrElse("description", DEFAULT.description()),
56+
config.getOrElse("favicon", DEFAULT.favicon()),
57+
config.getOrElse("modinfo", DEFAULT.modinfo()));
58+
}
3159

3260
public boolean enabled() {
3361
return this.version || this.players || this.description || this.favicon
3462
|| this.modinfo;
3563
}
36-
37-
// Not used, just here to state what the defaults are.
38-
public static final PingPassthroughMode DEFAULT = new PingPassthroughMode(
39-
false, false, false, false, false);
40-
}
64+
}

proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class VelocityConfiguration implements ProxyConfig {
8080
@Expose
8181
private boolean onlineModeKickExistingPlayers = false;
8282
@Expose
83-
private PingPassthroughMode pingPassthrough = new PingPassthroughMode(false, false, false, false, false);
83+
private PingPassthroughMode pingPassthrough = PingPassthroughMode.DEFAULT;
8484
@Expose
8585
private boolean samplePlayersInPing = false;
8686
private final Servers servers;
@@ -557,12 +557,7 @@ public static VelocityConfiguration read(Path path) throws IOException {
557557
final CommentedConfig metricsConfig = config.get("metrics");
558558
final PlayerInfoForwarding forwardingMode = config.getEnumOrElse(
559559
"player-info-forwarding-mode", PlayerInfoForwarding.NONE);
560-
final PingPassthroughMode pingPassthrough = new PingPassthroughMode(
561-
config.getOrElse("ping-passthrough.version", false),
562-
config.getOrElse("ping-passthrough.players", false),
563-
config.getOrElse("ping-passthrough.description", false),
564-
config.getOrElse("ping-passthrough.favicon", false),
565-
config.getOrElse("ping-passthrough.modinfo", false));
560+
final PingPassthroughMode pingPassthrough = PingPassthroughMode.fromConfig(config.get("ping-passthrough"));
566561
final boolean samplePlayersInPing = config.getOrElse("sample-players-in-ping", false);
567562

568563
final String bind = config.getOrElse("bind", "0.0.0.0:25565");

proxy/src/main/java/com/velocitypowered/proxy/config/migration/PingPassthroughMigration.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Velocity Contributors
2+
* Copyright (C) 2024-2026 Velocity Contributors
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -65,42 +65,36 @@ public void migrate(final CommentedFileConfig config, final Logger logger) {
6565
config.removeComment("ping-passthrough");
6666
config.remove("ping-passthrough");
6767

68-
// Create ping passthrough entry for the version
6968
config.set("ping-passthrough.version", version);
7069
config.setComment(
7170
"ping-passthrough.version",
7271
" Should Velocity pass the version number from the backend server when responding to server list ping requests?"
7372
);
7473

75-
// Create ping passthrough entry for the players
7674
config.set("ping-passthrough.players", players);
7775
config.setComment(
7876
"ping-passthrough.players",
7977
" Should Velocity pass the player count from the backend server when responding to server list ping requests?"
8078
);
8179

82-
// Create ping passthrough entry for the description
8380
config.set("ping-passthrough.description", description);
8481
config.setComment(
8582
"ping-passthrough.description",
8683
" Should Velocity pass the description from the backend server when responding to server list ping requests?"
8784
);
8885

89-
// Create ping passthrough entry for the favicon
9086
config.set("ping-passthrough.favicon", favicon);
9187
config.setComment(
9288
"ping-passthrough.favicon",
9389
" Should Velocity pass the favicon (also known as the server icon) from the backend server when responding to server list ping requests?"
9490
);
9591

96-
// Create ping passthrough entry for the mods info
9792
config.set("ping-passthrough.modinfo", modinfo);
9893
config.setComment(
9994
"ping-passthrough.modinfo",
10095
" Should Velocity pass the mod list from the backend server when responding to server list ping requests?"
10196
);
10297

103-
// Update config version
10498
config.set("config-version", "2.9");
10599
}
106100
}

proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@ private CompletableFuture<ServerPing> attemptPingPassthrough(VelocityInboundConn
128128
players = fallback.getPlayers().orElse(null);
129129
}
130130

131-
// Why the special handling of the description?
132-
// Why not just response.getDescriptionComponent.orElse(null)?
133131
Component description;
134-
if (mode.description() && response.getDescriptionComponent() != null) {
135-
description = response.getDescriptionComponent();
132+
if (mode.description()) {
133+
if (response.getDescriptionComponent() != null) {
134+
description = response.getDescriptionComponent();
135+
} else {
136+
description = Component.empty();
137+
}
136138
} else {
137139
description = fallback.getDescriptionComponent();
138140
}

0 commit comments

Comments
 (0)