Search in sources :

Example 6 with Session

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

the class PingThread method setClient.

private void setClient() {
    this.client = new Client(DragonProxy.getInstance().getConfig().remote_server_addr, DragonProxy.getInstance().getConfig().remote_server_port, new MinecraftProtocol(SubProtocol.STATUS), new TcpSessionFactory());
    this.client.getSession().setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (ServerInfoHandler) (session, info) -> {
        this.info = info;
        this.client.getSession().disconnect(null);
    });
}
Also used : Client(com.github.steveice10.packetlib.Client) Session(com.github.steveice10.packetlib.Session) TcpSessionFactory(com.github.steveice10.packetlib.tcp.TcpSessionFactory) SubProtocol(com.github.steveice10.mc.protocol.data.SubProtocol) DragonProxy(org.dragonet.proxy.DragonProxy) MinecraftProtocol(com.github.steveice10.mc.protocol.MinecraftProtocol) ServerInfoHandler(com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler) ServerStatusInfo(com.github.steveice10.mc.protocol.data.status.ServerStatusInfo) Executors(java.util.concurrent.Executors) MinecraftConstants(com.github.steveice10.mc.protocol.MinecraftConstants) MinecraftProtocol(com.github.steveice10.mc.protocol.MinecraftProtocol) Client(com.github.steveice10.packetlib.Client) TcpSessionFactory(com.github.steveice10.packetlib.tcp.TcpSessionFactory)

Example 7 with Session

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

the class PCEntityEquipmentPacketTranslator method translate.

@Override
public PEPacket[] translate(UpstreamSession session, ServerEntityEquipmentPacket packet) {
    CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId());
    if (entity == null) {
        if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) {
            entity = session.getEntityCache().getClientEntity();
        } else {
            return null;
        }
    }
    ItemStack items = packet.getItem();
    boolean handModified = false;
    switch(packet.getSlot()) {
        case HELMET:
            entity.helmet = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case CHESTPLATE:
            entity.chestplate = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case LEGGINGS:
            entity.leggings = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case BOOTS:
            entity.boots = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case MAIN_HAND:
            entity.mainHand = ItemBlockTranslator.translateSlotToPE(items);
        case OFF_HAND:
            handModified = true;
            break;
    }
    entity.updateEquipment(session);
    if (handModified) {
        MobEquipmentPacket equipPacket = new MobEquipmentPacket();
        equipPacket.rtid = entity.proxyEid;
        equipPacket.item = entity.mainHand;
        equipPacket.inventorySlot = 0;
        equipPacket.hotbarSlot = 0;
        equipPacket.windowId = 0;
        session.sendPacket(equipPacket);
    }
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) ItemStack(com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack) MobEquipmentPacket(org.dragonet.protocol.packets.MobEquipmentPacket)

Example 8 with Session

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

the class PCPlaySoundPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlaySoundPacket packet) {
    try {
        String soundName;
        if (BuiltinSound.class.isAssignableFrom(packet.getSound().getClass())) {
            BuiltinSound sound = (BuiltinSound) packet.getSound();
            soundName = sound.name();
        } else {
            soundName = ((CustomSound) packet.getSound()).getName();
        }
        if (soundName == null) {
            return null;
        }
        PlaySoundPacket pk = new PlaySoundPacket();
        pk.blockPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ());
        pk.name = soundName;
        pk.volume = packet.getVolume();
        pk.pitch = packet.getPitch();
        return new PEPacket[] { pk };
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition) PEPacket(org.dragonet.protocol.PEPacket) BuiltinSound(com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound) PlaySoundPacket(org.dragonet.protocol.packets.PlaySoundPacket) ServerPlaySoundPacket(com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket)

Example 9 with Session

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

the class PEBlockPickRequestPacketTranslator method translate.

@Override
public Packet[] translate(UpstreamSession session, BlockPickRequestPacket packet) {
    ItemStack item = session.getChunkCache().getBlock(new Position(packet.x, packet.y, packet.z));
    int selectedSlot = (int) session.getDataCache().getOrDefault(CacheKey.PLAYER_SELECTED_SLOT, 36);
    ClientCreativeInventoryActionPacket backPacket = new ClientCreativeInventoryActionPacket(selectedSlot + 36, item);
    // System.out.println("BlockPickRequestPacket " + DebugTools.getAllFields(packet));
    // System.out.println("ItemStack " + DebugTools.getAllFields(item));
    session.getChunkCache().getDebugGrid();
    return new Packet[] { backPacket };
}
Also used : Packet(com.github.steveice10.packetlib.packet.Packet) PlayerSkinPacket(org.dragonet.protocol.packets.PlayerSkinPacket) ClientCreativeInventoryActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket) BlockPickRequestPacket(org.dragonet.protocol.packets.BlockPickRequestPacket) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) ClientCreativeInventoryActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket) ItemStack(com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)

Example 10 with Session

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

the class PEMovePlayerPacketTranslator method translate.

public Packet[] translate(UpstreamSession session, MovePlayerPacket packet) {
    CachedEntity entity = session.getEntityCache().getClientEntity();
    if (entity.riding != 0 && packet.ridingRuntimeId != 0) {
        // Riding case
        ClientVehicleMovePacket pk = new ClientVehicleMovePacket(packet.position.x, packet.position.y - EntityType.PLAYER.getOffset(), packet.position.z, packet.yaw, packet.pitch);
        session.getDownstream().send(pk);
    } else {
        // not riding
        ClientPlayerPositionRotationPacket pk = new ClientPlayerPositionRotationPacket(packet.onGround, packet.position.x, // To simplify the movements
        ceilToHalf(packet.position.y - EntityType.PLAYER.getOffset()), packet.position.z, packet.yaw, packet.pitch);
        // Special blocks handling
        boolean isColliding = false;
        BlockPosition blockPos = new BlockPosition(NukkitMath.floorDouble(packet.position.x), NukkitMath.floorDouble(packet.position.y), NukkitMath.floorDouble(packet.position.z));
        // System.out.println("block " + blockPos.toString());
        try {
            ItemEntry PEBlock = session.getChunkCache().translateBlock(blockPos.asPosition());
            if (PEBlock != null) {
                Block b = Block.get(PEBlock.getId(), PEBlock.getPEDamage(), blockPos);
                if (b != null && b.collidesWithBB(session.getEntityCache().getClientEntity().boundingBox.clone())) {
                    DragonProxy.getInstance().getLogger().info("Player position : " + entity.x + ", " + entity.y + ", " + entity.z + " collide with " + b.getClass().getSimpleName() + " on " + blockPos.toString());
                    isColliding = true;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        entity.absoluteMove(pk.getX(), pk.getY(), pk.getZ(), (float) pk.getYaw(), (float) pk.getPitch());
        if (!isColliding) {
            session.getDownstream().send(pk);
            session.getChunkCache().sendOrderedChunks();
        }
    }
    return null;
}
Also used : ClientVehicleMovePacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) BlockPosition(org.dragonet.common.maths.BlockPosition) ClientPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket) Block(org.dragonet.common.data.blocks.Block) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

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