13
0
geforkt von Mirrors/Velocity

Properly implement fallback support.

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-02-15 15:07:38 -05:00
Ursprung c5fefd55ed
Commit 12f5bdfc48
3 geänderte Dateien mit 74 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -41,6 +41,25 @@ public final class KickedFromServerEvent implements
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
public ServerKickResult getResult() {
return result;

Datei anzeigen

@ -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.Notify;
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.PlayerSettingsChangedEvent;
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.server.VelocityRegisteredServer;
import com.velocitypowered.proxy.tablist.VelocityTabList;
import com.velocitypowered.proxy.util.VelocityMessages;
import io.netty.buffer.ByteBufUtil;
import java.net.InetSocketAddress;
import java.util.Collections;
@ -367,8 +369,23 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
disconnect(friendlyReason);
}
} 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,
!connectedServer.getServer().equals(rs), friendlyReason);
!kickedFromCurrent, result);
handleKickEvent(originalEvent, friendlyReason);
}
}
private void handleKickEvent(KickedFromServerEvent originalEvent,
Component friendlyReason) {
server.getEventManager().fire(originalEvent)
.thenAcceptAsync(event -> {
if (event.getResult() instanceof DisconnectPlayer) {
@ -376,7 +393,15 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
disconnect(res.getReason());
} else if (event.getResult() instanceof RedirectPlayer) {
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) {
Notify res = (Notify) event.getResult();
if (event.kickedDuringServerConnect()) {
@ -390,7 +415,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
}
}, minecraftConnection.eventLoop());
}
}
/**
* 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();
}
if (tryIndex >= serversToTry.size()) {
return Optional.empty();
for (; tryIndex < serversToTry.size(); tryIndex++) {
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 Optional.empty();
}
/**
* Sets the player's new connected server and clears the in-flight connection.

Datei anzeigen

@ -14,6 +14,8 @@ public class VelocityMessages {
.of("No available servers", TextColor.RED);
public static final Component ALREADY_CONNECTED = TextComponent
.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() {
throw new AssertionError();