Search in sources :

Example 16 with Packet

use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.

the class PCChatPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerChatPacket packet) {
    TextPacket pe = new TextPacket();
    switch(packet.getType()) {
        case NOTIFICATION:
            pe.message = pe.message = MessageTranslator.translate(packet.getMessage());
            pe.type = TYPE_POPUP;
            break;
        case CHAT:
            if (packet.getMessage() instanceof TranslationMessage) {
                pe.type = TYPE_TRANSLATION;
                pe.needsTranslation = true;
                pe.message = MessageTranslator.translationTranslateText((TranslationMessage) packet.getMessage());
                pe.params = MessageTranslator.translationTranslateParams(((TranslationMessage) packet.getMessage()).getTranslationParams());
            } else {
                pe.message = pe.message = MessageTranslator.translate(packet.getMessage());
                pe.type = TYPE_RAW;
            }
            break;
        case SYSTEM:
            if (packet.getMessage() instanceof TranslationMessage) {
                pe.type = TYPE_TRANSLATION;
                pe.needsTranslation = true;
                pe.message = MessageTranslator.translationTranslateText((TranslationMessage) packet.getMessage());
                pe.params = MessageTranslator.translationTranslateParams(((TranslationMessage) packet.getMessage()).getTranslationParams());
            } else {
                pe.message = pe.message = MessageTranslator.translate(packet.getMessage());
                pe.type = TYPE_RAW;
            }
            break;
    }
    return new PEPacket[] { pe };
}
Also used : TextPacket(org.dragonet.protocol.packets.TextPacket) PEPacket(org.dragonet.protocol.PEPacket) TranslationMessage(com.github.steveice10.mc.protocol.data.message.TranslationMessage)

Example 17 with Packet

use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.

the class PERequestChunkRadiusPacketTranslator method translate.

@Override
public Packet[] translate(UpstreamSession session, RequestChunkRadiusPacket packet) {
    session.getDataCache().put(CacheKey.PLAYER_REQUESTED_CHUNK_RADIUS, packet.radius);
    // System.out.println("Requested chunk radius : " + packet.radius);
    session.sendPacket(new ChunkRadiusUpdatedPacket(((RequestChunkRadiusPacket) packet).radius));
    session.getChunkCache().sendOrderedChunks();
    ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket((String) session.getDataCache().getOrDefault(CacheKey.PLAYER_LANGUAGE, "enUS"), (int) session.getDataCache().getOrDefault(CacheKey.PLAYER_REQUESTED_CHUNK_RADIUS, 5), ChatVisibility.FULL, false, new SkinPart[] {}, Hand.OFF_HAND);
    ((PCDownstreamSession) session.getDownstream()).send(clientSettingsPacket);
    return null;
}
Also used : ChunkRadiusUpdatedPacket(org.dragonet.protocol.packets.ChunkRadiusUpdatedPacket) RequestChunkRadiusPacket(org.dragonet.protocol.packets.RequestChunkRadiusPacket) ClientSettingsPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket) PCDownstreamSession(org.dragonet.proxy.network.PCDownstreamSession)

Example 18 with Packet

use of com.github.steveice10.packetlib.packet.Packet 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)

Example 19 with Packet

use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.

the class InventoryTranslatorRegister method updateSlot.

public static void updateSlot(UpstreamSession session, ServerSetSlotPacket packet) {
    if (packet.getWindowId() == 0)
        // We don't process player inventory updates here.
        return;
    if (!session.getDataCache().containsKey(CacheKey.CURRENT_WINDOW_ID) || !session.getWindowCache().hasWindow(packet.getWindowId())) {
        session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
        return;
    }
    int openedId = (int) session.getDataCache().get(CacheKey.CURRENT_WINDOW_ID);
    if (packet.getWindowId() != openedId) {
        // Hmm
        closeOpened(session, true);
        session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
        return;
    }
    CachedWindow win = session.getWindowCache().get(openedId);
    if (win.size <= packet.getSlot()) {
        session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
        return;
    }
    IInventoryTranslator translator = TRANSLATORS.get(win.pcType);
    if (translator == null) {
        session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
        return;
    }
    // Update here
    win.slots[packet.getSlot()] = packet.getItem();
    translator.updateSlot(session, win, packet.getSlot());
}
Also used : CachedWindow(org.dragonet.proxy.network.cache.CachedWindow) IInventoryTranslator(org.dragonet.proxy.network.translator.IInventoryTranslator) ClientCloseWindowPacket(com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket)

Example 20 with Packet

use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.

the class InventoryTranslatorRegister method updateContent.

public static void updateContent(UpstreamSession session, ServerWindowItemsPacket packet) {
    if (packet.getWindowId() == 0)
        // We don't process player inventory updates here.
        return;
    if (!session.getDataCache().containsKey(CacheKey.CURRENT_WINDOW_ID) || !session.getWindowCache().hasWindow(packet.getWindowId())) {
        session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
        return;
    }
    int openedId = (int) session.getDataCache().get(CacheKey.CURRENT_WINDOW_ID);
    if (packet.getWindowId() != openedId) {
        // Hmm
        closeOpened(session, true);
        return;
    }
    CachedWindow win = session.getWindowCache().get(openedId);
    IInventoryTranslator translator = TRANSLATORS.get(win.pcType);
    if (translator == null) {
        session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId()));
        return;
    }
    win.slots = packet.getItems();
    translator.updateContent(session, win);
}
Also used : CachedWindow(org.dragonet.proxy.network.cache.CachedWindow) IInventoryTranslator(org.dragonet.proxy.network.translator.IInventoryTranslator) ClientCloseWindowPacket(com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket)

Aggregations

BlockPosition (org.dragonet.common.maths.BlockPosition)5 PEPacket (org.dragonet.protocol.PEPacket)5 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)4 Packet (com.github.steveice10.packetlib.packet.Packet)4 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)4 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)2 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)2 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)2 ClientRequestPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket)2 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)2 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)2 ClientCloseWindowPacket (com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket)2 ClientTeleportConfirmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket)2 ServerJoinGamePacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket)2 HashSet (java.util.HashSet)2 CachedWindow (org.dragonet.proxy.network.cache.CachedWindow)2 IInventoryTranslator (org.dragonet.proxy.network.translator.IInventoryTranslator)2 Timing (co.aikar.timings.Timing)1 RequestException (com.github.steveice10.mc.auth.exception.request.RequestException)1 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1