Search in sources :

Example 6 with LanternGameProfile

use of org.lanternpowered.server.profile.LanternGameProfile 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)

Example 7 with LanternGameProfile

use of org.lanternpowered.server.profile.LanternGameProfile in project LanternServer by LanternPowered.

the class HandlerLoginStart method handle.

@Override
public void handle(NetworkContext context, MessageLoginInStart message) {
    final NetworkSession session = context.getSession();
    final String username = message.getUsername();
    if (session.getServer().getOnlineMode()) {
        // Convert to X509 format
        final byte[] publicKey = SecurityHelper.generateX509Key(session.getServer().getKeyPair().getPublic()).getEncoded();
        final byte[] verifyToken = SecurityHelper.generateVerifyToken();
        final String sessionId = Long.toString(RANDOM.nextLong(), 16).trim();
        // Store the auth data
        context.getChannel().attr(AUTH_DATA).set(new LoginAuthData(username, sessionId, verifyToken));
        // Send created request message and wait for the response
        session.send(new MessageLoginOutEncryptionRequest(sessionId, publicKey, verifyToken));
    } else {
        // Remove the encryption handler placeholder
        context.getChannel().pipeline().remove(NetworkSession.ENCRYPTION);
        LanternGameProfile profile = context.getChannel().attr(SPOOFED_GAME_PROFILE).getAndSet(null);
        if (profile != null) {
            profile = new LanternGameProfile(profile.getUniqueId(), username, profile.getPropertyMap());
        } else {
            // Try the online id first
            try {
                profile = (LanternGameProfile) Lantern.getGame().getGameProfileManager().get(username).get();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
                // Generate a offline id
                final UUID uniqueId = UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
                profile = new LanternGameProfile(uniqueId, username);
            }
        }
        session.messageReceived(new MessageLoginInFinish(profile));
    }
}
Also used : NetworkSession(org.lanternpowered.server.network.NetworkSession) MessageLoginOutEncryptionRequest(org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginOutEncryptionRequest) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) ExecutionException(java.util.concurrent.ExecutionException) UUID(java.util.UUID) MessageLoginInFinish(org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginInFinish)

Example 8 with LanternGameProfile

use of org.lanternpowered.server.profile.LanternGameProfile in project LanternServer by LanternPowered.

the class CommandOp method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(new CommandElement(Text.of("player")) {

        @Nullable
        @Override
        protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
            return args.next();
        }

        @Override
        public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
            final String prefix = args.nextIfPresent().orElse("");
            final UserConfig<OpsEntry> config = Lantern.getGame().getOpsConfig();
            return Lantern.getGame().getGameProfileManager().getCache().getProfiles().stream().filter(p -> p.getName().isPresent() && !config.getEntryByUUID(p.getUniqueId()).isPresent()).map(p -> p.getName().get()).filter(new StartsWithPredicate(prefix)).collect(ImmutableList.toImmutableList());
        }
    }, GenericArguments.optional(GenericArguments.integer(Text.of("level")))).executor((src, args) -> {
        String playerName = args.<String>getOne("player").get();
        UserConfig<OpsEntry> config = Lantern.getGame().getOpsConfig();
        if (!(src instanceof ConsoleSource) && args.hasAny("level")) {
            throw new CommandException(Text.of("Only the console may specify the op level."));
        }
        int opLevel = args.<Integer>getOne("level").orElse(Lantern.getGame().getGlobalConfig().getDefaultOpPermissionLevel());
        Lantern.getGame().getGameProfileManager().get(playerName).whenComplete((profile, error) -> {
            if (error != null) {
                src.sendMessage(t("commands.op.failed", playerName));
            } else {
                src.sendMessage(t("commands.op.success", playerName));
                config.addEntry(new OpsEntry(((LanternGameProfile) profile).withoutProperties(), opLevel));
            }
        });
        return CommandResult.success();
    });
}
Also used : CommandArgs(org.spongepowered.api.command.args.CommandArgs) CommandResult(org.spongepowered.api.command.CommandResult) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) CommandSource(org.spongepowered.api.command.CommandSource) OpsEntry(org.lanternpowered.server.config.user.OpsEntry) ArgumentParseException(org.spongepowered.api.command.args.ArgumentParseException) CommandArgs(org.spongepowered.api.command.args.CommandArgs) CommandElement(org.spongepowered.api.command.args.CommandElement) GenericArguments(org.spongepowered.api.command.args.GenericArguments) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) UserConfig(org.lanternpowered.server.config.user.UserConfig) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) Lantern(org.lanternpowered.server.game.Lantern) StartsWithPredicate(org.spongepowered.api.util.StartsWithPredicate) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Nullable(javax.annotation.Nullable) CommandContext(org.spongepowered.api.command.args.CommandContext) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) StartsWithPredicate(org.spongepowered.api.util.StartsWithPredicate) CommandException(org.spongepowered.api.command.CommandException) CommandSource(org.spongepowered.api.command.CommandSource) OpsEntry(org.lanternpowered.server.config.user.OpsEntry) CommandElement(org.spongepowered.api.command.args.CommandElement) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource)

Example 9 with LanternGameProfile

use of org.lanternpowered.server.profile.LanternGameProfile in project LanternServer by LanternPowered.

the class LanternUserStorageService method getFromWhitelistService.

/**
 * Attempts to get a {@link User} from the {@link WhitelistService}.
 *
 * @param uniqueId The unique id
 * @return The user
 */
@Nullable
private ProxyUser getFromWhitelistService(UUID uniqueId) {
    final LanternGameProfile gameProfile;
    final WhitelistService whitelistService = this.whitelistService.get();
    if (whitelistService instanceof WhitelistConfig) {
        gameProfile = ((WhitelistConfig) whitelistService).getEntryByUUID(uniqueId).map(UserEntry::getProfile).orElse(null);
    } else {
        gameProfile = (LanternGameProfile) whitelistService.getWhitelistedProfiles().stream().filter(profile -> profile.getUniqueId().equals(uniqueId)).findFirst().orElse(null);
    }
    return gameProfile == null ? null : new ProxyUser(gameProfile);
}
Also used : WhitelistService(org.spongepowered.api.service.whitelist.WhitelistService) WhitelistConfig(org.lanternpowered.server.config.user.WhitelistConfig) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) UserEntry(org.lanternpowered.server.config.user.UserEntry) ProxyUser(org.lanternpowered.server.entity.living.player.ProxyUser) Nullable(javax.annotation.Nullable)

Aggregations

LanternGameProfile (org.lanternpowered.server.profile.LanternGameProfile)9 UUID (java.util.UUID)3 Nullable (javax.annotation.Nullable)3 NetworkSession (org.lanternpowered.server.network.NetworkSession)3 JsonObject (com.google.gson.JsonObject)2 List (java.util.List)2 ProxyUser (org.lanternpowered.server.entity.living.player.ProxyUser)2 Lantern (org.lanternpowered.server.game.Lantern)2 MessageLoginInFinish (org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginInFinish)2 LanternProfileProperty (org.lanternpowered.server.profile.LanternProfileProperty)2 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)2 CommandException (org.spongepowered.api.command.CommandException)2 CommandResult (org.spongepowered.api.command.CommandResult)2 GenericArguments (org.spongepowered.api.command.args.GenericArguments)2 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)2 PluginContainer (org.spongepowered.api.plugin.PluginContainer)2 WhitelistService (org.spongepowered.api.service.whitelist.WhitelistService)2 Text (org.spongepowered.api.text.Text)2 Joiner (com.google.common.base.Joiner)1 ImmutableList (com.google.common.collect.ImmutableList)1