use of org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginOutEncryptionRequest 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));
}
}
Aggregations