Search in sources :

Example 1 with BaseTranslator

use of org.dragonet.net.translator.BaseTranslator 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)

Aggregations

Matcher (java.util.regex.Matcher)1 PlayerProfile (net.glowstone.entity.meta.profile.PlayerProfile)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