Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
Further confinement of preconnect checks to event loop.
Dieser Commit ist enthalten in:
Ursprung
fa954ab717
Commit
b0f1398b45
@ -1,5 +1,8 @@
|
|||||||
package com.velocitypowered.proxy.connection.client;
|
package com.velocitypowered.proxy.connection.client;
|
||||||
|
|
||||||
|
import static com.velocitypowered.proxy.connection.util.ConnectionRequestResults.plainResult;
|
||||||
|
import static java.util.concurrent.CompletableFuture.completedFuture;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
@ -33,7 +36,6 @@ import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
|
|||||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||||
import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants;
|
import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants;
|
||||||
import com.velocitypowered.proxy.connection.util.ConnectionMessages;
|
import com.velocitypowered.proxy.connection.util.ConnectionMessages;
|
||||||
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults;
|
|
||||||
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
|
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
|
||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
import com.velocitypowered.proxy.protocol.packet.Chat;
|
import com.velocitypowered.proxy.protocol.packet.Chat;
|
||||||
@ -711,8 +713,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ConnectionRequestBuilder.Status> checkServer(RegisteredServer server) {
|
private Optional<ConnectionRequestBuilder.Status> checkServer(RegisteredServer server) {
|
||||||
Preconditions
|
Preconditions.checkArgument(server instanceof VelocityRegisteredServer,
|
||||||
.checkState(server instanceof VelocityRegisteredServer, "Not a valid Velocity server.");
|
"Not a valid Velocity server.");
|
||||||
if (connectionInFlight != null || (connectedServer != null
|
if (connectionInFlight != null || (connectedServer != null
|
||||||
&& !connectedServer.hasCompletedJoin())) {
|
&& !connectedServer.hasCompletedJoin())) {
|
||||||
return Optional.of(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS);
|
return Optional.of(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS);
|
||||||
@ -723,38 +725,41 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<Impl> internalConnect() {
|
private CompletableFuture<Optional<Status>> getInitialStatus() {
|
||||||
Optional<ConnectionRequestBuilder.Status> initialCheck = checkServer(toConnect);
|
return CompletableFuture.supplyAsync(() -> checkServer(toConnect), connection.eventLoop());
|
||||||
if (initialCheck.isPresent()) {
|
|
||||||
return CompletableFuture
|
|
||||||
.completedFuture(ConnectionRequestResults.plainResult(initialCheck.get(), toConnect));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, initiate the connection.
|
private CompletableFuture<Impl> internalConnect() {
|
||||||
ServerPreConnectEvent event = new ServerPreConnectEvent(ConnectedPlayer.this, toConnect);
|
return this.getInitialStatus()
|
||||||
|
.thenCompose(initialCheck -> {
|
||||||
|
if (initialCheck.isPresent()) {
|
||||||
|
return completedFuture(plainResult(initialCheck.get(), toConnect));
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerPreConnectEvent event = new ServerPreConnectEvent(ConnectedPlayer.this,
|
||||||
|
toConnect);
|
||||||
return server.getEventManager().fire(event)
|
return server.getEventManager().fire(event)
|
||||||
.thenComposeAsync(newEvent -> {
|
.thenComposeAsync(newEvent -> {
|
||||||
Optional<RegisteredServer> connectTo = newEvent.getResult().getServer();
|
Optional<RegisteredServer> newDest = newEvent.getResult().getServer();
|
||||||
if (!connectTo.isPresent()) {
|
if (!newDest.isPresent()) {
|
||||||
return CompletableFuture.completedFuture(
|
return completedFuture(
|
||||||
ConnectionRequestResults
|
plainResult(ConnectionRequestBuilder.Status.CONNECTION_CANCELLED, toConnect)
|
||||||
.plainResult(ConnectionRequestBuilder.Status.CONNECTION_CANCELLED, toConnect)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredServer rs = connectTo.get();
|
RegisteredServer realDestination = newDest.get();
|
||||||
Optional<ConnectionRequestBuilder.Status> lastCheck = checkServer(rs);
|
Optional<ConnectionRequestBuilder.Status> check = checkServer(realDestination);
|
||||||
if (lastCheck.isPresent()) {
|
if (check.isPresent()) {
|
||||||
return CompletableFuture
|
return completedFuture(plainResult(check.get(), realDestination));
|
||||||
.completedFuture(ConnectionRequestResults.plainResult(lastCheck.get(), rs));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VelocityRegisteredServer vrs = (VelocityRegisteredServer) rs;
|
VelocityRegisteredServer vrs = (VelocityRegisteredServer) realDestination;
|
||||||
VelocityServerConnection con = new VelocityServerConnection(vrs, ConnectedPlayer.this,
|
VelocityServerConnection con = new VelocityServerConnection(vrs,
|
||||||
server);
|
ConnectedPlayer.this, server);
|
||||||
connectionInFlight = con;
|
connectionInFlight = con;
|
||||||
return con.connect();
|
return con.connect();
|
||||||
}, connection.eventLoop());
|
}, connection.eventLoop());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren