Search in sources :

Example 6 with BinaryStream

use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.

the class DPAddonBukkit method detectedBedrockPlayer.

public void detectedBedrockPlayer(Player player) {
    getLogger().info("Detected bedrock player: " + player.getName() + " " + player.getUniqueId().toString());
    bedrockPlayers.add(player.getUniqueId());
    BedrockPlayer.createForPlayer(player);
    // enable packet foward
    BinaryStream bis = new BinaryStream();
    bis.putString("PacketForward");
    bis.putBoolean(true);
    player.sendPluginMessage(this, "DragonProxy", bis.getBuffer());
}
Also used : BinaryStream(org.dragonet.common.utilities.BinaryStream)

Example 7 with BinaryStream

use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.

the class Protocol method decode.

public static PEPacket[] decode(byte[] data) throws Exception {
    if (data == null || data.length < 1)
        return null;
    byte[] inflated;
    try {
        inflated = Zlib.inflate(Arrays.copyOfRange(data, 1, data.length));
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    ArrayList<PEPacket> packets = new ArrayList<>(2);
    BinaryStream stream = new BinaryStream(inflated);
    while (stream.offset < inflated.length) {
        byte[] buffer = stream.get((int) stream.getUnsignedVarInt());
        PEPacket decoded = decodeSingle(buffer);
        if (decoded != null)
            packets.add(decoded);
        else
            System.out.println("decode fail");
    }
    return packets.size() > 0 ? packets.toArray(new PEPacket[0]) : null;
}
Also used : ArrayList(java.util.ArrayList) BinaryStream(org.dragonet.common.utilities.BinaryStream) IOException(java.io.IOException)

Example 8 with BinaryStream

use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.

the class BedrockPlayer method sendForm.

// NOT SUPPORTED YET
/* public void setPacketSubscription(Class<? extends PEPacket> clazz, boolean sub) {
        if(clazz.equals(PEPacket.class)) throw new IllegalArgumentException();
        BinaryStream bis = new BinaryStream();
        bis.putString("PacketSubscription");
        bis.putString(clazz.getSimpleName());
        bis.putBoolean(sub);
        player.sendPluginMessage(DPAddonBukkit.getInstance(), "DragonProxy", bis.getBuffer());
    } */
public void sendForm(int formId, ModalFormComponent form) {
    String formData = form.serializeToJson().toString();
    ModalFormRequestPacket request = new ModalFormRequestPacket();
    request.formId = formId;
    request.formData = formData;
    request.encode();
    BinaryStream bis = new BinaryStream();
    bis.putString("SendPacket");
    bis.putByteArray(request.getBuffer());
    player.sendPluginMessage(DPAddonBukkit.getInstance(), "DragonProxy", bis.getBuffer());
}
Also used : BinaryStream(org.dragonet.common.utilities.BinaryStream) ModalFormRequestPacket(org.dragonet.protocol.packets.ModalFormRequestPacket)

Example 9 with BinaryStream

use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.

the class DPPluginMessageListener method onPluginMessageReceived.

@Override
public void onPluginMessageReceived(String channel, Player player, byte[] data) {
    // not likely to happen but...
    if (!channel.equals("DragonProxy"))
        return;
    BinaryStream bis = new BinaryStream(data);
    String command = bis.getString();
    if (command.equals("Notification")) {
        plugin.detectedBedrockPlayer(player);
    } else if (command.equals("PacketForward")) {
        processPacketForward(player, bis.getByteArray());
    }
}
Also used : BinaryStream(org.dragonet.common.utilities.BinaryStream)

Example 10 with BinaryStream

use of org.dragonet.common.utilities.BinaryStream in project DragonProxy by DragonetMC.

the class PEPacketProcessor method handlePacket.

// this method should be in UpstreamSession
public void handlePacket(PEPacket packet) {
    if (packet == null)
        return;
    if (!client.getProxy().getConfig().disable_packet_events) {
        PacketfromPlayerEvent packetEvent = new PacketfromPlayerEvent(client, packet);
        client.getProxy().getEventManager().callEvent(packetEvent);
        if (packetEvent.isCancelled()) {
            return;
        }
    }
    // Wait for player logginig in
    if ("online_login_wait".equals(this.client.getDataCache().get(CacheKey.AUTHENTICATION_STATE))) {
        if (packet.pid() == ProtocolInfo.MOVE_PLAYER_PACKET) {
            InputComponent username = new InputComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_USERNAME)).setPlaceholder("steve@example.com");
            InputComponent password = new InputComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_PASSWORD)).setPlaceholder("123456");
            if (this.client.getProxy().getConfig().auto_login) {
                username.setDefaultValue(this.client.getProxy().getConfig().online_username);
                password.setDefaultValue(this.client.getProxy().getConfig().online_password);
            }
            // client.getDataCache().put(CacheKey.AUTHENTICATION_STATE, "online_login");
            ModalFormRequestPacket packetForm = new ModalFormRequestPacket();
            CustomFormComponent form = new CustomFormComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_TITLE));
            form.addComponent(new LabelComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_DESC)));
            form.addComponent(new LabelComponent(this.client.getProxy().getLang().get(Lang.FORM_LOGIN_PROMPT)));
            form.addComponent(username);
            form.addComponent(password);
            packetForm.formId = 1;
            packetForm.formData = form.serializeToJson().toString();
            this.client.sendPacket(packetForm, true);
            return;
        }
        if (packet.pid() == ProtocolInfo.MODAL_FORM_RESPONSE_PACKET) {
            try {
                this.client.sendChat(this.client.getProxy().getLang().get(Lang.MESSAGE_LOGIN_PROGRESS));
                ModalFormResponsePacket formResponse = (ModalFormResponsePacket) packet;
                JsonArray array = JsonUtil.parseArray(formResponse.formData);
                this.client.getDataCache().remove(CacheKey.AUTHENTICATION_STATE);
                this.client.authenticate(array.get(2).getAsString(), array.get(3).getAsString(), authProxy);
            } catch (Exception ex) {
                this.client.sendChat(this.client.getProxy().getLang().get(Lang.MESSAGE_ONLINE_LOGIN_FAILD));
            }
            return;
        }
    }
    switch(packet.pid()) {
        case ProtocolInfo.BATCH_PACKET:
            DragonProxy.getInstance().getLogger().debug("Received batch packet from client !");
            break;
        case ProtocolInfo.LOGIN_PACKET:
            this.client.onLogin((LoginPacket) packet);
            break;
        case ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET:
            if (!this.client.isLoggedIn())
                this.client.postLogin();
            break;
        default:
            if (this.client.getDownstream() == null || !this.client.getDownstream().isConnected())
                break;
            if (enableForward.get() && FORWARDED_PACKETS.contains(packet.getClass())) {
                BinaryStream bis = new BinaryStream();
                bis.putString("PacketForward");
                bis.putByteArray(packet.getBuffer());
                ClientPluginMessagePacket msg = new ClientPluginMessagePacket("DragonProxy", bis.getBuffer());
                client.getDownstream().send(msg);
            } else // IMPORTANT Do not send packet until client is connected !
            if (client.isSpawned()) {
                Packet[] translated = PacketTranslatorRegister.translateToPC(this.client, packet);
                if (translated == null || translated.length == 0)
                    break;
                client.getDownstream().send(translated);
            }
            break;
    }
}
Also used : JsonArray(com.google.gson.JsonArray) InputComponent(org.dragonet.common.gui.InputComponent) BinaryStream(org.dragonet.common.utilities.BinaryStream) PacketfromPlayerEvent(org.dragonet.proxy.events.defaults.packets.PacketfromPlayerEvent) CustomFormComponent(org.dragonet.common.gui.CustomFormComponent) ClientPluginMessagePacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket) JsonParseException(com.google.gson.JsonParseException) LabelComponent(org.dragonet.common.gui.LabelComponent)

Aggregations

BinaryStream (org.dragonet.common.utilities.BinaryStream)10 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)2 ArrayList (java.util.ArrayList)2 EventHandler (net.md_5.bungee.event.EventHandler)2 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)1 ClientTeleportConfirmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket)1 ServerJoinGamePacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket)1 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)1 JsonArray (com.google.gson.JsonArray)1 JsonParseException (com.google.gson.JsonParseException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 CustomFormComponent (org.dragonet.common.gui.CustomFormComponent)1 InputComponent (org.dragonet.common.gui.InputComponent)1 LabelComponent (org.dragonet.common.gui.LabelComponent)1 BlockPosition (org.dragonet.common.maths.BlockPosition)1 ChunkPos (org.dragonet.common.maths.ChunkPos)1 Vector3F (org.dragonet.common.maths.Vector3F)1 LoginChainDecoder (org.dragonet.common.utilities.LoginChainDecoder)1