use of org.spongepowered.common.bridge.server.players.PlayerListBridge in project SpongeCommon by SpongePowered.
the class ServerLoginPacketListenerImplMixin method handleAcceptedLogin.
/**
* @author morph - April 27th, 2021
* @author dualspiral - July 17th, 2021
*
* @reason support async ban/whitelist service and user->player syncing.
*/
@Overwrite
public void handleAcceptedLogin() {
if (!this.gameProfile.isComplete()) {
this.gameProfile = this.shadow$createFakeProfile(this.gameProfile);
}
// Sponge start - avoid #tick calling handleAcceptedLogin more than once.
if (this.impl$accepted) {
return;
}
this.impl$accepted = true;
final PlayerList playerList = this.server.getPlayerList();
// Sponge end
// Sponge start - completable future
((PlayerListBridge) playerList).bridge$canPlayerLogin(this.connection.getRemoteAddress(), this.gameProfile).handle((componentOpt, throwable) -> {
if (throwable != null) {
// An error occurred during login checks so we ask to abort.
((ConnectionBridge) this.connection).bridge$setKickReason(new TextComponent("An error occurred checking ban/whitelist status."));
SpongeCommon.logger().error("An error occurred when checking the ban/whitelist status of {}.", this.gameProfile.getId().toString());
SpongeCommon.logger().error(throwable);
} else if (componentOpt != null) {
// We handle this later
((ConnectionBridge) this.connection).bridge$setKickReason(componentOpt);
}
try {
((SpongeServer) SpongeCommon.server()).userManager().handlePlayerLogin(this.gameProfile);
} catch (final IOException e) {
throw new CompletionException(e);
}
return null;
}).handleAsync((ignored, throwable) -> {
if (throwable != null) {
// We're just going to disconnect here, because something went horribly wrong.
if (throwable instanceof CompletionException) {
throw (CompletionException) throwable;
} else {
throw new CompletionException(throwable);
}
}
// Sponge end
this.state = ServerLoginPacketListenerImpl.State.ACCEPTED;
if (this.server.getCompressionThreshold() >= 0 && !this.connection.isMemoryConnection()) {
this.connection.send(new ClientboundLoginCompressionPacket(this.server.getCompressionThreshold()), (param0) -> this.connection.setupCompression(this.server.getCompressionThreshold()));
}
this.connection.send(new ClientboundGameProfilePacket(this.gameProfile));
final ServerPlayer var1 = this.server.getPlayerList().getPlayer(this.gameProfile.getId());
if (var1 != null) {
this.state = ServerLoginPacketListenerImpl.State.DELAY_ACCEPT;
this.delayedAcceptPlayer = this.server.getPlayerList().getPlayerForLogin(this.gameProfile);
} else {
// Sponge start - Also send the channel registrations using the minecraft channel, for compatibility
final ServerSideConnection connection = (ServerSideConnection) this;
((SpongeChannelManager) Sponge.channelManager()).sendChannelRegistrations(connection);
try {
this.server.getPlayerList().placeNewPlayer(this.connection, this.server.getPlayerList().getPlayerForLogin(this.gameProfile));
// invalidate just to be sure there is no user cached for the online player anymore
Sponge.server().userManager().removeFromCache(this.gameProfile.getId());
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
return null;
}, SpongeCommon.server()).exceptionally(throwable -> {
// If a throwable exists, we're just going to disconnect the user, better than leaving them in limbo.
if (throwable != null) {
this.impl$disconnectError(throwable, this.state == ServerLoginPacketListenerImpl.State.ACCEPTED || this.state == ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT);
}
return null;
// Sponge End
});
}
use of org.spongepowered.common.bridge.server.players.PlayerListBridge in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin method impl$usePlayerDimensionForRespawn.
@Redirect(method = "handleClientCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;respawn(Lnet/minecraft/server/level/ServerPlayer;Z)Lnet/minecraft/server/level/ServerPlayer;"))
private net.minecraft.server.level.ServerPlayer impl$usePlayerDimensionForRespawn(final PlayerList playerList, final net.minecraft.server.level.ServerPlayer player, final boolean keepAllPlayerData) {
// A few changes to Vanilla logic here that, by default, still preserve game mechanics:
// - If we have conquered The End then keep the dimension type we're headed to (which is Overworld as of 1.15)
// - Otherwise, check the platform hooks for which dimension to respawn to. In Sponge, this is the Player's dimension they
// are already in if we can respawn there which is only true for Overworld dimensions
final ResourceKey<Level> respawnDimension = player.getRespawnDimension();
@Nullable final ServerLevel destinationWorld = this.server.getLevel(respawnDimension);
final ServerLevel overworld = this.server.getLevel(Level.OVERWORLD);
if (overworld == null) {
throw new IllegalStateException("Somehow the Overworld is not retrievable while trying to respawn player " + player.getGameProfile().getName());
}
final ServerLevel destination = destinationWorld == null ? overworld : destinationWorld;
final RespawnPlayerEvent.SelectWorld event = SpongeEventFactory.createRespawnPlayerEventSelectWorld(PhaseTracker.getCauseStackManager().currentCause(), (org.spongepowered.api.world.server.ServerWorld) destination, (org.spongepowered.api.world.server.ServerWorld) player.getLevel(), (org.spongepowered.api.world.server.ServerWorld) overworld, (ServerPlayer) player);
SpongeCommon.post(event);
((PlayerListBridge) this.server.getPlayerList()).bridge$setOriginalDestinationDimension(((ServerLevel) event.originalDestinationWorld()).dimension());
((PlayerListBridge) this.server.getPlayerList()).bridge$setNewDestinationDimension(((ServerLevel) event.destinationWorld()).dimension());
// The key is reset to null in the overwrite
return playerList.respawn(player, keepAllPlayerData);
}
Aggregations