Search in sources :

Example 1 with MessageLoginOutSetCompression

use of org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginOutSetCompression in project LanternServer by LanternPowered.

the class HandlerLoginFinish method handle.

@Override
public void handle(NetworkContext context, MessageLoginInFinish message) {
    final LanternGameProfile gameProfile = message.getGameProfile();
    final NetworkSession session = context.getSession();
    int compressionThreshold = Lantern.getGame().getGlobalConfig().getNetworkCompressionThreshold();
    if (compressionThreshold != -1) {
        session.sendWithFuture(new MessageLoginOutSetCompression(compressionThreshold)).addListener(future -> context.getChannel().pipeline().replace(NetworkSession.COMPRESSION, NetworkSession.COMPRESSION, new MessageCompressionHandler(compressionThreshold)));
    } else {
        // Remove the compression handler placeholder
        context.getChannel().pipeline().remove(NetworkSession.COMPRESSION);
    }
    final GameProfileCache gameProfileCache = Lantern.getGame().getGameProfileManager().getCache();
    // Store the old profile temporarily
    gameProfileCache.getById(gameProfile.getUniqueId()).ifPresent(profile -> context.getChannel().attr(NetworkSession.PREVIOUS_GAME_PROFILE).set(profile));
    // Cache the new profile
    gameProfileCache.add(gameProfile, true, (Instant) null);
    session.sendWithFuture(new MessageLoginOutSuccess(gameProfile.getUniqueId(), gameProfile.getName().get())).addListener(future -> {
        session.setGameProfile(gameProfile);
        session.setProtocolState(ProtocolState.FORGE_HANDSHAKE);
        session.messageReceived(new MessageForgeHandshakeInStart());
    });
}
Also used : MessageCompressionHandler(org.lanternpowered.server.network.pipeline.MessageCompressionHandler) MessageForgeHandshakeInStart(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInStart) NetworkSession(org.lanternpowered.server.network.NetworkSession) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) GameProfileCache(org.spongepowered.api.profile.GameProfileCache) MessageLoginOutSetCompression(org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginOutSetCompression) MessageLoginOutSuccess(org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginOutSuccess)

Aggregations

NetworkSession (org.lanternpowered.server.network.NetworkSession)1 MessageForgeHandshakeInStart (org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInStart)1 MessageCompressionHandler (org.lanternpowered.server.network.pipeline.MessageCompressionHandler)1 MessageLoginOutSetCompression (org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginOutSetCompression)1 MessageLoginOutSuccess (org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginOutSuccess)1 LanternGameProfile (org.lanternpowered.server.profile.LanternGameProfile)1 GameProfileCache (org.spongepowered.api.profile.GameProfileCache)1