Search in sources :

Example 16 with Session

use of com.github.steveice10.packetlib.Session 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 17 with Session

use of com.github.steveice10.packetlib.Session 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 18 with Session

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

the class InventoryTranslatorRegister method open.

public static void open(UpstreamSession session, ServerOpenWindowPacket win) {
    closeOpened(session, true);
    if (TRANSLATORS.containsKey(win.getType())) {
        CachedWindow cached = new CachedWindow(win.getWindowId(), win.getType(), win.getSlots() + 36);
        session.getWindowCache().cacheWindow(cached);
        final IInventoryTranslator translator = TRANSLATORS.get(win.getType());
        session.getDataCache().put(CacheKey.CURRENT_WINDOW_ID, win.getWindowId());
        // -36 for the player inv size
        session.getDataCache().put(CacheKey.CURRENT_WINDOW_SIZE, win.getSlots());
        translator.prepare(session, cached);
        DragonProxy.getInstance().getGeneralThreadPool().schedule(() -> {
            // with this -> double chest, without -> content....
            translator.open(session, cached);
            cached.isOpen = true;
            com.github.steveice10.packetlib.packet.Packet[] items = session.getWindowCache().getCachedPackets(win.getWindowId());
            for (com.github.steveice10.packetlib.packet.Packet item : items) if (item != null)
                if (ServerWindowItemsPacket.class.isAssignableFrom(item.getClass()))
                    updateContent(session, (ServerWindowItemsPacket) item);
                else
                    updateSlot(session, (ServerSetSlotPacket) item);
        }, 200, TimeUnit.MILLISECONDS);
    } else
        // Not supported
        session.getDownstream().send(new ClientCloseWindowPacket(win.getWindowId()));
}
Also used : InventoryContentPacket(org.dragonet.protocol.packets.InventoryContentPacket) ServerOpenWindowPacket(com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket) ClientCloseWindowPacket(com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket) PEPacket(org.dragonet.protocol.PEPacket) ServerWindowItemsPacket(com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket) ServerSetSlotPacket(com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket) ContainerClosePacket(org.dragonet.protocol.packets.ContainerClosePacket) CachedWindow(org.dragonet.proxy.network.cache.CachedWindow) ServerSetSlotPacket(com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket) ClientCloseWindowPacket(com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket) IInventoryTranslator(org.dragonet.proxy.network.translator.IInventoryTranslator) ServerWindowItemsPacket(com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket)

Example 19 with Session

use of com.github.steveice10.packetlib.Session 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)7 PEPacket (org.dragonet.protocol.PEPacket)6 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)5 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)3 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)3 ClientCloseWindowPacket (com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket)3 Packet (com.github.steveice10.packetlib.packet.Packet)3 Vector3F (org.dragonet.common.maths.Vector3F)3 CachedWindow (org.dragonet.proxy.network.cache.CachedWindow)3 IInventoryTranslator (org.dragonet.proxy.network.translator.IInventoryTranslator)3 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)2 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)2 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)2 HashSet (java.util.HashSet)2 ByteArrayMeta (org.dragonet.common.data.entity.meta.type.ByteArrayMeta)2 SlotMeta (org.dragonet.common.data.entity.meta.type.SlotMeta)2 MinecraftConstants (com.github.steveice10.mc.protocol.MinecraftConstants)1 MinecraftProtocol (com.github.steveice10.mc.protocol.MinecraftProtocol)1 SubProtocol (com.github.steveice10.mc.protocol.data.SubProtocol)1 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1