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());
});
}
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));
}
}
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();
});
}
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);
}
Aggregations