Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
Clean up slightly, don't use streams
Dieser Commit ist enthalten in:
Ursprung
ca9a4492c4
Commit
d8fb7c11e7
@ -24,19 +24,18 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class StatusSessionHandler implements MinecraftSessionHandler {
|
public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||||
|
|
||||||
private final VelocityServer server;
|
private final VelocityServer server;
|
||||||
private final MinecraftConnection connection;
|
private final MinecraftConnection connection;
|
||||||
private final InboundConnection inboundWrapper;
|
private final InboundConnection inbound;
|
||||||
|
|
||||||
StatusSessionHandler(VelocityServer server, MinecraftConnection connection,
|
StatusSessionHandler(VelocityServer server, MinecraftConnection connection,
|
||||||
InboundConnection inboundWrapper) {
|
InboundConnection inbound) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.inboundWrapper = inboundWrapper;
|
this.inbound = inbound;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerPing constructLocalPing(ProtocolVersion version) {
|
private ServerPing constructLocalPing(ProtocolVersion version) {
|
||||||
@ -52,20 +51,6 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<ServerPing> createInitialPing() {
|
|
||||||
VelocityConfiguration configuration = server.getConfiguration();
|
|
||||||
ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion())
|
|
||||||
? connection.getProtocolVersion() : ProtocolVersion.MAXIMUM_VERSION;
|
|
||||||
|
|
||||||
PingPassthroughMode passthrough = configuration.getPingPassthrough();
|
|
||||||
if (passthrough == PingPassthroughMode.DISABLED) {
|
|
||||||
return CompletableFuture.completedFuture(constructLocalPing(shownVersion));
|
|
||||||
} else {
|
|
||||||
return attemptPingPassthrough(configuration.getPingPassthrough(),
|
|
||||||
configuration.getAttemptConnectionOrder(), shownVersion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private CompletableFuture<ServerPing> attemptPingPassthrough(PingPassthroughMode mode,
|
private CompletableFuture<ServerPing> attemptPingPassthrough(PingPassthroughMode mode,
|
||||||
List<String> servers, ProtocolVersion pingingVersion) {
|
List<String> servers, ProtocolVersion pingingVersion) {
|
||||||
ServerPing fallback = constructLocalPing(pingingVersion);
|
ServerPing fallback = constructLocalPing(pingingVersion);
|
||||||
@ -88,20 +73,27 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
|||||||
case ALL:
|
case ALL:
|
||||||
return pingResponses.thenApply(responses -> {
|
return pingResponses.thenApply(responses -> {
|
||||||
// Find the first non-fallback
|
// Find the first non-fallback
|
||||||
return responses.stream()
|
for (ServerPing response : responses) {
|
||||||
.filter(ping -> ping != fallback)
|
if (response == fallback) {
|
||||||
.findFirst()
|
continue;
|
||||||
.orElse(fallback);
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
return fallback;
|
||||||
});
|
});
|
||||||
case MODS:
|
case MODS:
|
||||||
return pingResponses.thenApply(responses -> {
|
return pingResponses.thenApply(responses -> {
|
||||||
// Find the first non-fallback that contains a non-empty mod list
|
// Find the first non-fallback that contains a mod list
|
||||||
Optional<ModInfo> modInfo = responses.stream()
|
for (ServerPing response : responses) {
|
||||||
.filter(ping -> ping != fallback)
|
if (response == fallback) {
|
||||||
.map(ServerPing::getModinfo)
|
continue;
|
||||||
.flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
|
}
|
||||||
.findFirst();
|
Optional<ModInfo> modInfo = response.getModinfo();
|
||||||
return modInfo.map(mi -> fallback.asBuilder().mods(mi).build()).orElse(fallback);
|
if (modInfo.isPresent()) {
|
||||||
|
return fallback.asBuilder().mods(modInfo.get()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fallback;
|
||||||
});
|
});
|
||||||
default:
|
default:
|
||||||
// Not possible, but covered for completeness.
|
// Not possible, but covered for completeness.
|
||||||
@ -109,11 +101,24 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CompletableFuture<ServerPing> getInitialPing() {
|
||||||
|
VelocityConfiguration configuration = server.getConfiguration();
|
||||||
|
ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion())
|
||||||
|
? connection.getProtocolVersion() : ProtocolVersion.MAXIMUM_VERSION;
|
||||||
|
PingPassthroughMode passthrough = configuration.getPingPassthrough();
|
||||||
|
|
||||||
|
if (passthrough == PingPassthroughMode.DISABLED) {
|
||||||
|
return CompletableFuture.completedFuture(constructLocalPing(shownVersion));
|
||||||
|
} else {
|
||||||
|
return attemptPingPassthrough(configuration.getPingPassthrough(),
|
||||||
|
configuration.getAttemptConnectionOrder(), shownVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(LegacyPing packet) {
|
public boolean handle(LegacyPing packet) {
|
||||||
createInitialPing()
|
getInitialPing()
|
||||||
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inboundWrapper,
|
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
|
||||||
ping)))
|
|
||||||
.thenAcceptAsync(event -> {
|
.thenAcceptAsync(event -> {
|
||||||
connection.closeWith(LegacyDisconnect.fromServerPing(event.getPing(),
|
connection.closeWith(LegacyDisconnect.fromServerPing(event.getPing(),
|
||||||
packet.getVersion()));
|
packet.getVersion()));
|
||||||
@ -129,9 +134,8 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(StatusRequest packet) {
|
public boolean handle(StatusRequest packet) {
|
||||||
createInitialPing()
|
getInitialPing()
|
||||||
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inboundWrapper,
|
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
|
||||||
ping)))
|
|
||||||
.thenAcceptAsync(
|
.thenAcceptAsync(
|
||||||
(event) -> {
|
(event) -> {
|
||||||
StringBuilder json = new StringBuilder();
|
StringBuilder json = new StringBuilder();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren