Skip to content

Commit d0d1d70

Browse files
Revert the merges from upstream.
1 parent 72ed9c8 commit d0d1d70

File tree

3 files changed

+158
-61
lines changed

3 files changed

+158
-61
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2018-2023 Velocity Contributors
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.velocitypowered.proxy.config;
19+
20+
/**
21+
* Legacy modes for ping passthrough.
22+
*/
23+
public enum LegacyPingPassthroughMode {
24+
DISABLED,
25+
MODS,
26+
DESCRIPTION,
27+
ALL
28+
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public class VelocityConfiguration implements ProxyConfig {
7777
private boolean onlineModeKickExistingPlayers = false;
7878
@Expose
7979
private PingPassthroughMode pingPassthrough = new PingPassthroughMode(false, false, false, false, false);
80+
@Expose
81+
private LegacyPingPassthroughMode legacyPingPassthrough = LegacyPingPassthroughMode.DISABLED;
8082
private final Servers servers;
8183
private final ForcedHosts forcedHosts;
8284
@Expose
@@ -104,8 +106,9 @@ private VelocityConfiguration(String bind, String motd, int showMaxPlayers, bool
104106
boolean preventClientProxyConnections, boolean announceForge,
105107
PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret,
106108
boolean onlineModeKickExistingPlayers, PingPassthroughMode pingPassthrough,
107-
boolean enablePlayerAddressLogging, Servers servers, ForcedHosts forcedHosts,
108-
Advanced advanced, Query query, Metrics metrics, boolean forceKeyAuthentication) {
109+
LegacyPingPassthroughMode legacyPingPassthrough, boolean enablePlayerAddressLogging,
110+
Servers servers, ForcedHosts forcedHosts, Advanced advanced, Query query,
111+
Metrics metrics, boolean forceKeyAuthentication) {
109112
this.bind = bind;
110113
this.motd = motd;
111114
this.showMaxPlayers = showMaxPlayers;
@@ -116,6 +119,7 @@ private VelocityConfiguration(String bind, String motd, int showMaxPlayers, bool
116119
this.forwardingSecret = forwardingSecret;
117120
this.onlineModeKickExistingPlayers = onlineModeKickExistingPlayers;
118121
this.pingPassthrough = pingPassthrough;
122+
this.legacyPingPassthrough = legacyPingPassthrough;
119123
this.enablePlayerAddressLogging = enablePlayerAddressLogging;
120124
this.servers = servers;
121125
this.forcedHosts = forcedHosts;
@@ -370,6 +374,10 @@ public PingPassthroughMode getPingPassthrough() {
370374
return pingPassthrough;
371375
}
372376

377+
public LegacyPingPassthroughMode getLegacyPingPassthrough() {
378+
return legacyPingPassthrough;
379+
}
380+
373381
public boolean isPlayerAddressLoggingEnabled() {
374382
return enablePlayerAddressLogging;
375383
}
@@ -494,8 +502,8 @@ public static VelocityConfiguration read(Path path) throws IOException {
494502
final CommentedConfig metricsConfig = config.get("metrics");
495503
final PlayerInfoForwarding forwardingMode = config.getEnumOrElse(
496504
"player-info-forwarding-mode", PlayerInfoForwarding.NONE);
497-
// final PingPassthroughMode pingPassthroughMode = config.getEnumOrElse("ping-passthrough",
498-
// PingPassthroughMode.DISABLED);
505+
final LegacyPingPassthroughMode legacyPingPassthrough = config.getEnumOrElse("ping-passthrough",
506+
LegacyPingPassthroughMode.DISABLED);
499507
final PingPassthroughMode pingPassthrough = new PingPassthroughMode(
500508
config.getOrElse("ping-passthrough-version", false),
501509
config.getOrElse("ping-passthrough-players", false),
@@ -532,6 +540,7 @@ public static VelocityConfiguration read(Path path) throws IOException {
532540
forwardingSecret,
533541
kickExisting,
534542
pingPassthrough,
543+
legacyPingPassthrough,
535544
enablePlayerAddressLogging,
536545
new Servers(serversConfig),
537546
new ForcedHosts(forcedHostsConfig),

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

Lines changed: 117 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.velocitypowered.api.util.Favicon;
2727
import com.velocitypowered.api.util.ModInfo;
2828
import com.velocitypowered.proxy.VelocityServer;
29+
import com.velocitypowered.proxy.config.LegacyPingPassthroughMode;
2930
import com.velocitypowered.proxy.config.PingPassthroughMode;
3031
import com.velocitypowered.proxy.config.VelocityConfiguration;
3132
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
@@ -64,7 +65,8 @@ private ServerPing constructLocalPing(ProtocolVersion version) {
6465
}
6566

6667
private CompletableFuture<ServerPing> attemptPingPassthrough(VelocityInboundConnection connection,
67-
PingPassthroughMode mode, List<String> servers, ProtocolVersion responseProtocolVersion) {
68+
PingPassthroughMode mode, LegacyPingPassthroughMode legacyMode,
69+
List<String> servers, ProtocolVersion responseProtocolVersion) {
6870
ServerPing fallback = constructLocalPing(connection.getProtocolVersion());
6971
List<CompletableFuture<ServerPing>> pings = new ArrayList<>();
7072
for (String s : servers) {
@@ -82,62 +84,119 @@ private CompletableFuture<ServerPing> attemptPingPassthrough(VelocityInboundConn
8284

8385
CompletableFuture<List<ServerPing>> pingResponses = CompletableFutures.successfulAsList(pings,
8486
(ex) -> fallback);
85-
return pingResponses.thenApply(responses -> {
86-
// Find the first non-fallback. If it includes a modlist, add it too.
87-
for (ServerPing response : responses) {
88-
if (response == fallback) {
89-
continue;
87+
// Use the new ping passthrough mode if enabled.
88+
if (mode.enabled()) {
89+
return pingResponses.thenApply(responses -> {
90+
// Find the first non-fallback. If it includes a modlist, add it too.
91+
for (ServerPing response : responses) {
92+
if (response == fallback) {
93+
continue;
94+
}
95+
96+
if (response.getDescriptionComponent() == null) {
97+
continue;
98+
}
99+
100+
ServerPing.Version version;
101+
if (mode.version) {
102+
version = response.getVersion();
103+
} else {
104+
version = fallback.getVersion();
105+
}
106+
107+
ServerPing.Players players;
108+
if (mode.players) {
109+
players = response.getPlayers().orElse(null);
110+
} else {
111+
players = fallback.getPlayers().orElse(null);
112+
}
113+
114+
net.kyori.adventure.text.Component description;
115+
if (mode.description) {
116+
description = response.getDescriptionComponent();
117+
} else {
118+
description = fallback.getDescriptionComponent();
119+
}
120+
121+
Favicon favicon;
122+
if (mode.favicon) {
123+
favicon = response.getFavicon().orElse(null);
124+
} else {
125+
favicon = fallback.getFavicon().orElse(null);
126+
}
127+
128+
ModInfo modinfo;
129+
if (mode.modinfo) {
130+
modinfo = response.getModinfo().orElse(null);
131+
} else {
132+
modinfo = fallback.getModinfo().orElse(null);
133+
}
134+
135+
return new ServerPing(
136+
version,
137+
players,
138+
description,
139+
favicon,
140+
modinfo
141+
);
90142
}
91-
92-
if (response.getDescriptionComponent() == null) {
93-
continue;
94-
}
95-
96-
ServerPing.Version version;
97-
if (mode.version) {
98-
version = response.getVersion();
99-
} else {
100-
version = fallback.getVersion();
101-
}
102-
103-
ServerPing.Players players;
104-
if (mode.players) {
105-
players = response.getPlayers().orElse(null);
106-
} else {
107-
players = fallback.getPlayers().orElse(null);
108-
}
109-
110-
net.kyori.adventure.text.Component description;
111-
if (mode.description) {
112-
description = response.getDescriptionComponent();
113-
} else {
114-
description = fallback.getDescriptionComponent();
115-
}
116-
117-
Favicon favicon;
118-
if (mode.favicon) {
119-
favicon = response.getFavicon().orElse(null);
120-
} else {
121-
favicon = fallback.getFavicon().orElse(null);
122-
}
123-
124-
ModInfo modinfo;
125-
if (mode.modinfo) {
126-
modinfo = response.getModinfo().orElse(null);
127-
} else {
128-
modinfo = fallback.getModinfo().orElse(null);
129-
}
130-
131-
return new ServerPing(
132-
version,
133-
players,
134-
description,
135-
favicon,
136-
modinfo
137-
);
143+
return fallback;
144+
});
145+
} else {
146+
// Otherwise, use the legacy ping passthrough mode.
147+
switch (legacyMode) {
148+
case ALL:
149+
return pingResponses.thenApply(responses -> {
150+
// Find the first non-fallback
151+
for (ServerPing response : responses) {
152+
if (response == fallback) {
153+
continue;
154+
}
155+
return response;
156+
}
157+
return fallback;
158+
});
159+
case MODS:
160+
return pingResponses.thenApply(responses -> {
161+
// Find the first non-fallback that contains a mod list
162+
for (ServerPing response : responses) {
163+
if (response == fallback) {
164+
continue;
165+
}
166+
Optional<ModInfo> modInfo = response.getModinfo();
167+
if (modInfo.isPresent()) {
168+
return fallback.asBuilder().mods(modInfo.get()).build();
169+
}
170+
}
171+
return fallback;
172+
});
173+
case DESCRIPTION:
174+
return pingResponses.thenApply(responses -> {
175+
// Find the first non-fallback. If it includes a modlist, add it too.
176+
for (ServerPing response : responses) {
177+
if (response == fallback) {
178+
continue;
179+
}
180+
181+
if (response.getDescriptionComponent() == null) {
182+
continue;
183+
}
184+
185+
return new ServerPing(
186+
fallback.getVersion(),
187+
fallback.getPlayers().orElse(null),
188+
response.getDescriptionComponent(),
189+
fallback.getFavicon().orElse(null),
190+
response.getModinfo().orElse(null)
191+
);
192+
}
193+
return fallback;
194+
});
195+
// Not possible, but covered for completeness.
196+
default:
197+
return CompletableFuture.completedFuture(fallback);
138198
}
139-
return fallback;
140-
});
199+
}
141200
}
142201

143202
/**
@@ -151,16 +210,17 @@ public CompletableFuture<ServerPing> getInitialPing(VelocityInboundConnection co
151210
ProtocolVersion shownVersion = connection.getProtocolVersion().isSupported()
152211
? connection.getProtocolVersion() : ProtocolVersion.MAXIMUM_VERSION;
153212
PingPassthroughMode passthroughMode = configuration.getPingPassthrough();
213+
LegacyPingPassthroughMode legacyPassthroughMode = configuration.getLegacyPingPassthrough();
154214

155-
if (!passthroughMode.enabled()) {
215+
if (!passthroughMode.enabled() && legacyPassthroughMode == LegacyPingPassthroughMode.DISABLED) {
156216
return CompletableFuture.completedFuture(constructLocalPing(shownVersion));
157217
} else {
158218
String virtualHostStr = connection.getVirtualHost().map(InetSocketAddress::getHostString)
159219
.map(str -> str.toLowerCase(Locale.ROOT))
160220
.orElse("");
161221
List<String> serversToTry = server.getConfiguration().getForcedHosts().getOrDefault(
162222
virtualHostStr, server.getConfiguration().getAttemptConnectionOrder());
163-
return attemptPingPassthrough(connection, passthroughMode, serversToTry, shownVersion);
223+
return attemptPingPassthrough(connection, passthroughMode, legacyPassthroughMode, serversToTry, shownVersion);
164224
}
165225
}
166226
}

0 commit comments

Comments
 (0)