Search in sources :

Example 1 with PlayerProfile

use of net.glowstone.entity.meta.profile.PlayerProfile in project Dragonet-Legacy by DragonetMC.

the class PENetworkClient method handlePacket.

public void handlePacket(PEPacket packet) {
    //System.out.println("Received Packet: " + packet.getClass().getSimpleName());
    switch(packet.pid()) {
        case PEPacketIDs.LOGIN_PACKET:
            LoginPacket packetLogin = (LoginPacket) packet;
            this.username = packetLogin.username;
            BaseTranslator translator = TranslatorProvider.getByPEProtocolID(packetLogin.protocol1, packetLogin.protocol2);
            if (!(translator instanceof BaseTranslator)) {
                LoginStatusPacket pkLoginStatus = new LoginStatusPacket();
                pkLoginStatus.status = LoginStatusPacket.LOGIN_FAILED_CLIENT;
                this.sendPacket(pkLoginStatus);
                this.disconnect("Unsupported game version! ");
                break;
            }
            session = new MCPESession(inf.getSesMan().getServer(), this, translator);
            LoginStatusPacket pkLoginStatus = new LoginStatusPacket();
            pkLoginStatus.status = LoginStatusPacket.LOGIN_SUCCESS;
            this.sendPacket(pkLoginStatus);
            inf.getSesMan().getServer().getLogger().info("Accepted connection by [" + this.username + "]. ");
            Matcher matcher = DragonetSession.PATTERN_USERNAME.matcher(this.username);
            if (!matcher.matches()) {
                this.disconnect("Bad username! ");
                break;
            }
            session.setPlayer(new PlayerProfile(this.username, UUID.nameUUIDFromBytes(("OfflinePlayer:" + this.username).getBytes(StandardCharsets.UTF_8))));
            break;
        case PEPacketIDs.BATCH_PACKET:
            BatchPacket packetBatch = (BatchPacket) packet;
            if (packetBatch.packets == null || packetBatch.packets.isEmpty()) {
                break;
            }
            for (PEPacket pk : packetBatch.packets) {
                this.handlePacket(pk);
            }
            break;
        default:
            if (session == null) {
                disconnect("Network error! ");
                return;
            }
            session.onPacketReceived(packet);
    }
}
Also used : BaseTranslator(org.dragonet.net.translator.BaseTranslator) BatchPacket(org.dragonet.net.packet.minecraft.BatchPacket) Matcher(java.util.regex.Matcher) LoginPacket(org.dragonet.net.packet.minecraft.LoginPacket) PlayerProfile(net.glowstone.entity.meta.profile.PlayerProfile) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) LoginStatusPacket(org.dragonet.net.packet.minecraft.LoginStatusPacket)

Example 2 with PlayerProfile

use of net.glowstone.entity.meta.profile.PlayerProfile in project Glowstone by GlowstoneMC.

the class GlowSkull method setOwner.

@Override
public boolean setOwner(String name) {
    PlayerProfile owner = PlayerProfile.getProfile(name);
    if (owner == null) {
        return false;
    }
    this.owner = owner;
    setSkullType(SkullType.PLAYER);
    return true;
}
Also used : PlayerProfile(net.glowstone.entity.meta.profile.PlayerProfile)

Example 3 with PlayerProfile

use of net.glowstone.entity.meta.profile.PlayerProfile 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)

Example 4 with PlayerProfile

use of net.glowstone.entity.meta.profile.PlayerProfile in project Glowstone by GlowstoneMC.

the class GlowMetaSkull method setOwner.

@Override
public boolean setOwner(String name) {
    PlayerProfile owner = PlayerProfile.getProfile(name);
    if (owner == null) {
        return false;
    }
    this.owner = owner;
    return true;
}
Also used : PlayerProfile(net.glowstone.entity.meta.profile.PlayerProfile)

Example 5 with PlayerProfile

use of net.glowstone.entity.meta.profile.PlayerProfile in project Glowstone by GlowstoneMC.

the class GlowServer method getOfflinePlayer.

@Override
@Deprecated
public OfflinePlayer getOfflinePlayer(String name) {
    Player onlinePlayer = getPlayerExact(name);
    if (onlinePlayer != null) {
        return onlinePlayer;
    }
    OfflinePlayer result = getPlayerExact(name);
    if (result == null) {
        //probably blocking (same player once per minute)
        PlayerProfile profile = PlayerProfile.getProfile(name);
        if (profile == null) {
            result = getOfflinePlayer(new PlayerProfile(name, UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes())));
        } else {
            result = getOfflinePlayer(profile);
        }
    }
    return result;
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) PlayerProfile(net.glowstone.entity.meta.profile.PlayerProfile)

Aggregations

PlayerProfile (net.glowstone.entity.meta.profile.PlayerProfile)7 IntBuffer (java.nio.IntBuffer)1 UUID (java.util.UUID)1 Matcher (java.util.regex.Matcher)1 GlowPlayer (net.glowstone.entity.GlowPlayer)1 ProxyData (net.glowstone.net.ProxyData)1 EncryptionKeyRequestMessage (net.glowstone.net.message.login.EncryptionKeyRequestMessage)1 Player (org.bukkit.entity.Player)1 AsyncPlayerPreLoginEvent (org.bukkit.event.player.AsyncPlayerPreLoginEvent)1 BatchPacket (org.dragonet.net.packet.minecraft.BatchPacket)1 LoginPacket (org.dragonet.net.packet.minecraft.LoginPacket)1 LoginStatusPacket (org.dragonet.net.packet.minecraft.LoginStatusPacket)1 PEPacket (org.dragonet.net.packet.minecraft.PEPacket)1 BaseTranslator (org.dragonet.net.translator.BaseTranslator)1 GLFWVidMode (org.lwjgl.glfw.GLFWVidMode)1 MemoryStack (org.lwjgl.system.MemoryStack)1