Search in sources :

Example 1 with BatchPacket

use of org.dragonet.net.packet.minecraft.BatchPacket 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 BatchPacket

use of org.dragonet.net.packet.minecraft.BatchPacket in project Dragonet-Legacy by DragonetMC.

the class RakNetInterface method sendPacket.

public void sendPacket(String identifier, PEPacket packet, boolean needACK, boolean immediate) {
    packet.encode();
    byte[] buffer = packet.getData();
    if (buffer.length > 1024 && !BatchPacket.class.isAssignableFrom(packet.getClass())) {
        BatchPacket batch = new BatchPacket();
        batch.packets.add(packet);
        sendPacket(identifier, batch, needACK, immediate);
        return;
    }
    EncapsulatedPacket encapsulated = new EncapsulatedPacket();
    encapsulated.buffer = buffer;
    encapsulated.needACK = needACK;
    encapsulated.reliability = needACK ? (byte) 2 : (byte) 3;
    encapsulated.messageIndex = 0;
    this.handler.sendEncapsulated(identifier, encapsulated, (needACK ? RakNet.FLAG_NEED_ACK : 0) | (immediate ? RakNet.PRIORITY_IMMEDIATE : RakNet.PRIORITY_NORMAL));
}
Also used : BatchPacket(org.dragonet.net.packet.minecraft.BatchPacket) EncapsulatedPacket(org.dragonet.raknet.protocol.EncapsulatedPacket)

Aggregations

BatchPacket (org.dragonet.net.packet.minecraft.BatchPacket)2 Matcher (java.util.regex.Matcher)1 PlayerProfile (net.glowstone.entity.meta.profile.PlayerProfile)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 EncapsulatedPacket (org.dragonet.raknet.protocol.EncapsulatedPacket)1