Search in sources :

Example 1 with EncryptionKeyRequestMessage

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));
    }
}
Also used : ProxyData(net.glowstone.net.ProxyData) EncryptionKeyRequestMessage(net.glowstone.net.message.login.EncryptionKeyRequestMessage) PlayerProfile(net.glowstone.entity.meta.profile.PlayerProfile) AsyncPlayerPreLoginEvent(org.bukkit.event.player.AsyncPlayerPreLoginEvent) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)1 PlayerProfile (net.glowstone.entity.meta.profile.PlayerProfile)1 ProxyData (net.glowstone.net.ProxyData)1 EncryptionKeyRequestMessage (net.glowstone.net.message.login.EncryptionKeyRequestMessage)1 AsyncPlayerPreLoginEvent (org.bukkit.event.player.AsyncPlayerPreLoginEvent)1