Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Include server that we attempted to connect to in the result.
Dieser Commit ist enthalten in:
Ursprung
fa9d5f6499
Commit
c7a379ebb8
@ -69,6 +69,13 @@ public interface ConnectionRequestBuilder {
|
|||||||
* @return the reason why the user could not connect to the server
|
* @return the reason why the user could not connect to the server
|
||||||
*/
|
*/
|
||||||
Optional<Component> getReason();
|
Optional<Component> getReason();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the server we actually tried to connect to.
|
||||||
|
*
|
||||||
|
* @return the server we actually tried to connect to
|
||||||
|
*/
|
||||||
|
RegisteredServer getAttemptedConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,7 +88,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(Disconnect packet) {
|
public boolean handle(Disconnect packet) {
|
||||||
resultFuture.complete(ConnectionRequestResults.forDisconnect(packet));
|
resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer()));
|
||||||
serverConn.disconnect();
|
serverConn.disconnect();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -103,7 +103,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
public boolean handle(ServerLoginSuccess packet) {
|
public boolean handle(ServerLoginSuccess packet) {
|
||||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
||||||
&& !informationForwarded) {
|
&& !informationForwarded) {
|
||||||
resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE));
|
resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE,
|
||||||
|
serverConn.getServer()));
|
||||||
serverConn.disconnect();
|
serverConn.disconnect();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -132,7 +133,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
server.getEventManager()
|
server.getEventManager()
|
||||||
.fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer()))
|
.fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer()))
|
||||||
.whenCompleteAsync((x, error) -> {
|
.whenCompleteAsync((x, error) -> {
|
||||||
resultFuture.complete(ConnectionRequestResults.SUCCESSFUL);
|
resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer()));
|
||||||
smc.setSessionHandler(new BackendPlaySessionHandler(server, serverConn));
|
smc.setSessionHandler(new BackendPlaySessionHandler(server, serverConn));
|
||||||
serverConn.getPlayer().setConnectedServer(serverConn);
|
serverConn.getPlayer().setConnectedServer(serverConn);
|
||||||
smc.getChannel().config().setAutoRead(true);
|
smc.getChannel().config().setAutoRead(true);
|
||||||
|
@ -254,7 +254,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
*
|
*
|
||||||
* @return whether or not the player is online
|
* @return whether or not the player is online
|
||||||
*/
|
*/
|
||||||
boolean isActive() {
|
public boolean isActive() {
|
||||||
return connection != null && !connection.isClosed() && !gracefulDisconnect
|
return connection != null && !connection.isClosed() && !gracefulDisconnect
|
||||||
&& proxyPlayer.isActive();
|
&& proxyPlayer.isActive();
|
||||||
}
|
}
|
||||||
|
@ -355,15 +355,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleConnectionException(RegisteredServer rs, @Nullable Component kickReason,
|
private void handleConnectionException(RegisteredServer rs,
|
||||||
Component friendlyReason) {
|
@Nullable Component kickReason, Component friendlyReason) {
|
||||||
if (connectedServer == null) {
|
if (connectedServer == null) {
|
||||||
// The player isn't yet connected to a server.
|
// The player isn't yet connected to a server.
|
||||||
Optional<RegisteredServer> nextServer = getNextServerToTry(rs);
|
Optional<RegisteredServer> nextServer = getNextServerToTry(rs);
|
||||||
if (nextServer.isPresent()) {
|
if (nextServer.isPresent()) {
|
||||||
// There can't be any connection in flight now.
|
// There can't be any connection in flight now.
|
||||||
resetInFlightConnection();
|
resetInFlightConnection();
|
||||||
|
|
||||||
createConnectionRequest(nextServer.get()).fireAndForget();
|
createConnectionRequest(nextServer.get()).fireAndForget();
|
||||||
} else {
|
} else {
|
||||||
disconnect(friendlyReason);
|
disconnect(friendlyReason);
|
||||||
@ -388,8 +387,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleKickEvent(KickedFromServerEvent originalEvent,
|
private void handleKickEvent(KickedFromServerEvent originalEvent, Component friendlyReason) {
|
||||||
Component friendlyReason) {
|
|
||||||
server.getEventManager().fire(originalEvent)
|
server.getEventManager().fire(originalEvent)
|
||||||
.thenAcceptAsync(event -> {
|
.thenAcceptAsync(event -> {
|
||||||
// There can't be any connection in flight now.
|
// There can't be any connection in flight now.
|
||||||
@ -628,7 +626,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
Optional<ConnectionRequestBuilder.Status> initialCheck = checkServer(toConnect);
|
Optional<ConnectionRequestBuilder.Status> initialCheck = checkServer(toConnect);
|
||||||
if (initialCheck.isPresent()) {
|
if (initialCheck.isPresent()) {
|
||||||
return CompletableFuture
|
return CompletableFuture
|
||||||
.completedFuture(ConnectionRequestResults.plainResult(initialCheck.get()));
|
.completedFuture(ConnectionRequestResults.plainResult(initialCheck.get(), toConnect));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, initiate the connection.
|
// Otherwise, initiate the connection.
|
||||||
@ -639,7 +637,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
if (!connectTo.isPresent()) {
|
if (!connectTo.isPresent()) {
|
||||||
return CompletableFuture.completedFuture(
|
return CompletableFuture.completedFuture(
|
||||||
ConnectionRequestResults
|
ConnectionRequestResults
|
||||||
.plainResult(ConnectionRequestBuilder.Status.CONNECTION_CANCELLED)
|
.plainResult(ConnectionRequestBuilder.Status.CONNECTION_CANCELLED, toConnect)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,7 +645,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
Optional<ConnectionRequestBuilder.Status> lastCheck = checkServer(rs);
|
Optional<ConnectionRequestBuilder.Status> lastCheck = checkServer(rs);
|
||||||
if (lastCheck.isPresent()) {
|
if (lastCheck.isPresent()) {
|
||||||
return CompletableFuture
|
return CompletableFuture
|
||||||
.completedFuture(ConnectionRequestResults.plainResult(lastCheck.get()));
|
.completedFuture(ConnectionRequestResults.plainResult(lastCheck.get(), rs));
|
||||||
}
|
}
|
||||||
|
|
||||||
VelocityRegisteredServer vrs = (VelocityRegisteredServer) rs;
|
VelocityRegisteredServer vrs = (VelocityRegisteredServer) rs;
|
||||||
@ -663,10 +661,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
return connect()
|
return connect()
|
||||||
.whenCompleteAsync((status, throwable) -> {
|
.whenCompleteAsync((status, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
handleConnectionException(toConnect, throwable);
|
// TODO: The exception handling from this is not very good. Find a better way.
|
||||||
|
handleConnectionException(status != null ? status.getAttemptedConnection()
|
||||||
|
: toConnect, throwable);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println(status);
|
||||||
|
|
||||||
switch (status.getStatus()) {
|
switch (status.getStatus()) {
|
||||||
case ALREADY_CONNECTED:
|
case ALREADY_CONNECTED:
|
||||||
sendMessage(ConnectionMessages.ALREADY_CONNECTED);
|
sendMessage(ConnectionMessages.ALREADY_CONNECTED);
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.velocitypowered.proxy.connection.util;
|
package com.velocitypowered.proxy.connection.util;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
||||||
|
import com.velocitypowered.api.proxy.ConnectionRequestBuilder.Result;
|
||||||
|
import com.velocitypowered.api.proxy.ConnectionRequestBuilder.Status;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import com.velocitypowered.proxy.protocol.packet.Disconnect;
|
import com.velocitypowered.proxy.protocol.packet.Disconnect;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
@ -8,20 +11,23 @@ import net.kyori.text.serializer.ComponentSerializers;
|
|||||||
|
|
||||||
public class ConnectionRequestResults {
|
public class ConnectionRequestResults {
|
||||||
|
|
||||||
public static final ConnectionRequestBuilder.Result SUCCESSFUL = plainResult(
|
|
||||||
ConnectionRequestBuilder.Status.SUCCESS);
|
|
||||||
|
|
||||||
private ConnectionRequestResults() {
|
private ConnectionRequestResults() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Result successful(RegisteredServer server) {
|
||||||
|
return plainResult(Status.SUCCESS, server);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a plain result (one with a status but no reason).
|
* Returns a plain result (one with a status but no reason).
|
||||||
* @param status the status to use
|
* @param status the status to use
|
||||||
|
* @param server the server to use
|
||||||
* @return the result
|
* @return the result
|
||||||
*/
|
*/
|
||||||
public static ConnectionRequestBuilder.Result plainResult(
|
public static ConnectionRequestBuilder.Result plainResult(
|
||||||
ConnectionRequestBuilder.Status status) {
|
ConnectionRequestBuilder.Status status,
|
||||||
|
RegisteredServer server) {
|
||||||
return new ConnectionRequestBuilder.Result() {
|
return new ConnectionRequestBuilder.Result() {
|
||||||
@Override
|
@Override
|
||||||
public ConnectionRequestBuilder.Status getStatus() {
|
public ConnectionRequestBuilder.Status getStatus() {
|
||||||
@ -32,20 +38,28 @@ public class ConnectionRequestResults {
|
|||||||
public Optional<Component> getReason() {
|
public Optional<Component> getReason() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RegisteredServer getAttemptedConnection() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionRequestBuilder.Result forDisconnect(Disconnect disconnect) {
|
public static ConnectionRequestBuilder.Result forDisconnect(Disconnect disconnect,
|
||||||
|
RegisteredServer server) {
|
||||||
Component deserialized = ComponentSerializers.JSON.deserialize(disconnect.getReason());
|
Component deserialized = ComponentSerializers.JSON.deserialize(disconnect.getReason());
|
||||||
return forDisconnect(deserialized);
|
return forDisconnect(deserialized, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a disconnect result with a reason.
|
* Returns a disconnect result with a reason.
|
||||||
* @param component the reason for disconnecting from the server
|
* @param component the reason for disconnecting from the server
|
||||||
|
* @param server the server to use
|
||||||
* @return the result
|
* @return the result
|
||||||
*/
|
*/
|
||||||
public static ConnectionRequestBuilder.Result forDisconnect(Component component) {
|
public static ConnectionRequestBuilder.Result forDisconnect(Component component,
|
||||||
|
RegisteredServer server) {
|
||||||
return new ConnectionRequestBuilder.Result() {
|
return new ConnectionRequestBuilder.Result() {
|
||||||
@Override
|
@Override
|
||||||
public ConnectionRequestBuilder.Status getStatus() {
|
public ConnectionRequestBuilder.Status getStatus() {
|
||||||
@ -56,6 +70,11 @@ public class ConnectionRequestResults {
|
|||||||
public Optional<Component> getReason() {
|
public Optional<Component> getReason() {
|
||||||
return Optional.of(component);
|
return Optional.of(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RegisteredServer getAttemptedConnection() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren