use of net.glowstone.net.message.login.EncryptionKeyRequestMessage in project Glowstone by GlowstoneMC.
the class LoginStartHandler method handle.
@Override
public void handle(GlowSession session, LoginStartMessage message) {
String name = message.getUsername();
if (session.getServer().getOnlineMode()) {
// Get necessary information to create our request message
String sessionId = session.getSessionId();
//Convert to X509 format
byte[] publicKey = SecurityUtils.generateX509Key(session.getServer().getKeyPair().getPublic()).getEncoded();
byte[] verifyToken = SecurityUtils.generateVerifyToken();
// Set verify data on session for use in the response handler
session.setVerifyToken(verifyToken);
session.setVerifyUsername(name);
// Send created request message and wait for the response
session.send(new EncryptionKeyRequestMessage(sessionId, publicKey, verifyToken));
} else {
PlayerProfile profile;
ProxyData proxy = session.getProxyData();
if (proxy == null) {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
profile = new PlayerProfile(name, uuid);
} else {
profile = proxy.getProfile();
if (profile == null) {
profile = proxy.getProfile(name);
}
}
AsyncPlayerPreLoginEvent event = EventFactory.onPlayerPreLogin(profile.getName(), session.getAddress(), profile.getUniqueId());
if (event.getLoginResult() != Result.ALLOWED) {
session.disconnect(event.getKickMessage(), true);
return;
}
PlayerProfile finalProfile = profile;
session.getServer().getScheduler().runTask(null, () -> session.setPlayer(finalProfile));
}
}
Aggregations