Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 08:10:12 +01:00
Properly implement fallback support.
Dieser Commit ist enthalten in:
Ursprung
c5fefd55ed
Commit
12f5bdfc48
@ -41,6 +41,25 @@ public final class KickedFromServerEvent implements
|
|||||||
this.result = new Notify(fancyReason);
|
this.result = new Notify(fancyReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@code KickedFromServerEvent} instance.
|
||||||
|
* @param player the player affected
|
||||||
|
* @param server the server the player disconnected from
|
||||||
|
* @param originalReason the reason for being kicked, optional
|
||||||
|
* @param duringServerConnect whether or not the player was kicked during the connection process
|
||||||
|
* @param result the initial result
|
||||||
|
*/
|
||||||
|
public KickedFromServerEvent(Player player,
|
||||||
|
RegisteredServer server,
|
||||||
|
@Nullable Component originalReason, boolean duringServerConnect,
|
||||||
|
ServerKickResult result) {
|
||||||
|
this.player = Preconditions.checkNotNull(player, "player");
|
||||||
|
this.server = Preconditions.checkNotNull(server, "server");
|
||||||
|
this.originalReason = originalReason;
|
||||||
|
this.duringServerConnect = duringServerConnect;
|
||||||
|
this.result = Preconditions.checkNotNull(result, "result");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerKickResult getResult() {
|
public ServerKickResult getResult() {
|
||||||
return result;
|
return result;
|
||||||
|
@ -7,6 +7,7 @@ import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
|||||||
import com.velocitypowered.api.event.player.KickedFromServerEvent.DisconnectPlayer;
|
import com.velocitypowered.api.event.player.KickedFromServerEvent.DisconnectPlayer;
|
||||||
import com.velocitypowered.api.event.player.KickedFromServerEvent.Notify;
|
import com.velocitypowered.api.event.player.KickedFromServerEvent.Notify;
|
||||||
import com.velocitypowered.api.event.player.KickedFromServerEvent.RedirectPlayer;
|
import com.velocitypowered.api.event.player.KickedFromServerEvent.RedirectPlayer;
|
||||||
|
import com.velocitypowered.api.event.player.KickedFromServerEvent.ServerKickResult;
|
||||||
import com.velocitypowered.api.event.player.PlayerModInfoEvent;
|
import com.velocitypowered.api.event.player.PlayerModInfoEvent;
|
||||||
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
|
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||||
@ -42,6 +43,7 @@ import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest;
|
|||||||
import com.velocitypowered.proxy.protocol.packet.TitlePacket;
|
import com.velocitypowered.proxy.protocol.packet.TitlePacket;
|
||||||
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
||||||
import com.velocitypowered.proxy.tablist.VelocityTabList;
|
import com.velocitypowered.proxy.tablist.VelocityTabList;
|
||||||
|
import com.velocitypowered.proxy.util.VelocityMessages;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -367,8 +369,23 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
disconnect(friendlyReason);
|
disconnect(friendlyReason);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
boolean kickedFromCurrent = connectedServer.getServer().equals(rs);
|
||||||
|
ServerKickResult result;
|
||||||
|
if (kickedFromCurrent) {
|
||||||
|
Optional<RegisteredServer> next = getNextServerToTry();
|
||||||
|
result = next.<ServerKickResult>map(RedirectPlayer::create)
|
||||||
|
.orElseGet(() -> DisconnectPlayer.create(friendlyReason));
|
||||||
|
} else {
|
||||||
|
result = Notify.create(friendlyReason);
|
||||||
|
}
|
||||||
KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason,
|
KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason,
|
||||||
!connectedServer.getServer().equals(rs), friendlyReason);
|
!kickedFromCurrent, result);
|
||||||
|
handleKickEvent(originalEvent, friendlyReason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleKickEvent(KickedFromServerEvent originalEvent,
|
||||||
|
Component friendlyReason) {
|
||||||
server.getEventManager().fire(originalEvent)
|
server.getEventManager().fire(originalEvent)
|
||||||
.thenAcceptAsync(event -> {
|
.thenAcceptAsync(event -> {
|
||||||
if (event.getResult() instanceof DisconnectPlayer) {
|
if (event.getResult() instanceof DisconnectPlayer) {
|
||||||
@ -376,7 +393,15 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
disconnect(res.getReason());
|
disconnect(res.getReason());
|
||||||
} else if (event.getResult() instanceof RedirectPlayer) {
|
} else if (event.getResult() instanceof RedirectPlayer) {
|
||||||
RedirectPlayer res = (RedirectPlayer) event.getResult();
|
RedirectPlayer res = (RedirectPlayer) event.getResult();
|
||||||
createConnectionRequest(res.getServer()).fireAndForget();
|
createConnectionRequest(res.getServer())
|
||||||
|
.connectWithIndication()
|
||||||
|
.whenCompleteAsync((newResult, exception) -> {
|
||||||
|
if (newResult == null || !newResult) {
|
||||||
|
disconnect(friendlyReason);
|
||||||
|
} else {
|
||||||
|
sendMessage(VelocityMessages.MOVED_TO_NEW_SERVER);
|
||||||
|
}
|
||||||
|
}, minecraftConnection.eventLoop());
|
||||||
} else if (event.getResult() instanceof Notify) {
|
} else if (event.getResult() instanceof Notify) {
|
||||||
Notify res = (Notify) event.getResult();
|
Notify res = (Notify) event.getResult();
|
||||||
if (event.kickedDuringServerConnect()) {
|
if (event.kickedDuringServerConnect()) {
|
||||||
@ -390,7 +415,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
}
|
}
|
||||||
}, minecraftConnection.eventLoop());
|
}, minecraftConnection.eventLoop());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds another server to attempt to log into, if we were unexpectedly disconnected from the
|
* Finds another server to attempt to log into, if we were unexpectedly disconnected from the
|
||||||
@ -408,14 +432,16 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
serversToTry = server.getConfiguration().getAttemptConnectionOrder();
|
serversToTry = server.getConfiguration().getAttemptConnectionOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tryIndex >= serversToTry.size()) {
|
for (; tryIndex < serversToTry.size(); tryIndex++) {
|
||||||
return Optional.empty();
|
String toTryName = serversToTry.get(tryIndex);
|
||||||
|
if (connectedServer != null && toTryName.equals(connectedServer.getServerInfo().getName())) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String toTryName = serversToTry.get(tryIndex);
|
|
||||||
tryIndex++;
|
|
||||||
return server.getServer(toTryName);
|
return server.getServer(toTryName);
|
||||||
}
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the player's new connected server and clears the in-flight connection.
|
* Sets the player's new connected server and clears the in-flight connection.
|
||||||
|
@ -14,6 +14,8 @@ public class VelocityMessages {
|
|||||||
.of("No available servers", TextColor.RED);
|
.of("No available servers", TextColor.RED);
|
||||||
public static final Component ALREADY_CONNECTED = TextComponent
|
public static final Component ALREADY_CONNECTED = TextComponent
|
||||||
.of("You are already connected to this proxy!", TextColor.RED);
|
.of("You are already connected to this proxy!", TextColor.RED);
|
||||||
|
public static final Component MOVED_TO_NEW_SERVER = TextComponent
|
||||||
|
.of("You were moved from the server you were on because you were kicked", TextColor.RED);
|
||||||
|
|
||||||
private VelocityMessages() {
|
private VelocityMessages() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren