Search in sources :

Example 11 with Packet

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

the class PCDownstreamSession method connect.

public void connect(String addr, int port) {
    if (this.protocol == null) {
        // Clear the flags
        upstream.onConnected();
        upstream.disconnect("ERROR! ");
        return;
    }
    remoteClient = new Client(addr, port, protocol, new TcpSessionFactory());
    remoteClient.getSession().setConnectTimeout(5);
    remoteClient.getSession().setReadTimeout(5);
    remoteClient.getSession().setWriteTimeout(5);
    remoteClient.getSession().addListener(new SessionAdapter() {

        @Override
        public void connected(ConnectedEvent event) {
            proxy.getLogger().info(proxy.getLang().get(Lang.MESSAGE_REMOTE_CONNECTED, upstream.getUsername(), upstream.getRemoteAddress()));
            upstream.onConnected();
        }

        @Override
        public void packetSending(PacketSendingEvent event) {
            if (proxy.getAuthMode().equalsIgnoreCase("hybrid")) {
                if (protocol.getSubProtocol() == SubProtocol.HANDSHAKE && event.getPacket() instanceof HandshakePacket) {
                    HandshakePacket packet = event.getPacket();
                    String host = remoteClient.getSession().getHost() + "\0" + upstream.getProfile().getChainJWT();
                    packet = new HandshakePacket(packet.getProtocolVersion(), host, packet.getPort(), packet.getIntent());
                    event.setPacket(packet);
                }
            }
        }

        @Override
        public void disconnected(DisconnectedEvent event) {
            System.out.println("DisconnectedEvent " + event.getCause() + " " + event.getReason());
            upstream.disconnect(proxy.getLang().get(event.getReason()));
        }

        @Override
        public void disconnecting(DisconnectingEvent event) {
            System.out.println("DisconnectingEvent " + event.getCause() + " " + event.getReason());
            upstream.disconnect(proxy.getLang().get(event.getReason()));
        }

        @Override
        public void packetReceived(PacketReceivedEvent event) {
            // Handle the packet
            try {
                PEPacket[] packets = PacketTranslatorRegister.translateToPE(upstream, event.getPacket());
                if (packets == null) {
                    return;
                }
                if (packets.length <= 0) {
                    return;
                }
                if (packets.length == 1) {
                    upstream.sendPacket(packets[0]);
                } else {
                    upstream.sendAllPackets(packets, false);
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
            }
        }
    });
    remoteClient.getSession().connect();
}
Also used : PacketReceivedEvent(com.github.steveice10.packetlib.event.session.PacketReceivedEvent) HandshakePacket(com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket) PacketSendingEvent(com.github.steveice10.packetlib.event.session.PacketSendingEvent) DisconnectedEvent(com.github.steveice10.packetlib.event.session.DisconnectedEvent) DisconnectingEvent(com.github.steveice10.packetlib.event.session.DisconnectingEvent) ConnectedEvent(com.github.steveice10.packetlib.event.session.ConnectedEvent) Client(com.github.steveice10.packetlib.Client) SessionAdapter(com.github.steveice10.packetlib.event.session.SessionAdapter) TcpSessionFactory(com.github.steveice10.packetlib.tcp.TcpSessionFactory)

Example 12 with Packet

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

the class PCNotifyClientPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerNotifyClientPacket packet) {
    switch(packet.getNotification()) {
        case CHANGE_GAMEMODE:
            GameMode gm = (GameMode) packet.getValue();
            SetPlayerGameTypePacket pkgm = new SetPlayerGameTypePacket();
            pkgm.gamemode = gm == GameMode.CREATIVE ? 1 : 0;
            AdventureSettingsPacket adv = new AdventureSettingsPacket();
            adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, gm.equals(GameMode.ADVENTURE));
            adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, gm.equals(GameMode.CREATIVE) || gm.equals(GameMode.SPECTATOR));
            adv.setFlag(AdventureSettingsPacket.NO_CLIP, gm.equals(GameMode.SPECTATOR));
            adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !gm.equals(GameMode.SPECTATOR) || !gm.equals(GameMode.ADVENTURE));
            adv.setFlag(AdventureSettingsPacket.FLYING, gm.equals(GameMode.SPECTATOR));
            adv.setFlag(AdventureSettingsPacket.MUTED, false);
            adv.eid = session.getEntityCache().getClientEntity().proxyEid;
            adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL;
            adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER;
            session.sendPacket(pkgm);
            session.sendPacket(adv);
            if (gm == GameMode.CREATIVE)
                session.sendCreativeInventory();
            break;
        case START_RAIN:
            LevelEventPacket evtStartRain = new LevelEventPacket();
            evtStartRain.eventId = LevelEventPacket.EVENT_START_RAIN;
            return new PEPacket[] { evtStartRain };
        case STOP_RAIN:
            LevelEventPacket evtStopRain = new LevelEventPacket();
            evtStopRain.eventId = LevelEventPacket.EVENT_STOP_RAIN;
            return new PEPacket[] { evtStopRain };
    }
    return null;
}
Also used : SetPlayerGameTypePacket(org.dragonet.protocol.packets.SetPlayerGameTypePacket) GameMode(com.github.steveice10.mc.protocol.data.game.entity.player.GameMode) AdventureSettingsPacket(org.dragonet.protocol.packets.AdventureSettingsPacket) LevelEventPacket(org.dragonet.protocol.packets.LevelEventPacket) PEPacket(org.dragonet.protocol.PEPacket)

Example 13 with Packet

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

the class PCEntityPropertiesPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityPropertiesPacket 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;
        }
    }
    for (Attribute attr : packet.getAttributes()) {
        switch(attr.getType()) {
            case GENERIC_FOLLOW_RANGE:
                entity.attributes.put(PEEntityAttribute.FOLLOW_RANGE, PEEntityAttribute.findAttribute(PEEntityAttribute.FOLLOW_RANGE).setValue((float) attr.getValue()));
                break;
            case GENERIC_KNOCKBACK_RESISTANCE:
                entity.attributes.put(PEEntityAttribute.KNOCKBACK_RESISTANCE, PEEntityAttribute.findAttribute(PEEntityAttribute.KNOCKBACK_RESISTANCE).setValue((float) attr.getValue()));
                break;
            case GENERIC_MOVEMENT_SPEED:
                entity.attributes.put(PEEntityAttribute.MOVEMENT_SPEED, PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED).setValue((float) attr.getValue()));
                break;
            case GENERIC_ATTACK_DAMAGE:
                entity.attributes.put(PEEntityAttribute.ATTACK_DAMAGE, PEEntityAttribute.findAttribute(PEEntityAttribute.ATTACK_DAMAGE).setValue((float) attr.getValue()));
                break;
            case GENERIC_FLYING_SPEED:
                entity.attributes.put(PEEntityAttribute.MOVEMENT_SPEED, PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED).setValue((float) attr.getValue()));
                break;
        }
    }
    if (entity.spawned) {
        UpdateAttributesPacket pk = new UpdateAttributesPacket();
        pk.rtid = entity.proxyEid;
        pk.entries = entity.attributes.values();
        return new PEPacket[] { pk };
    }
    return null;
}
Also used : Attribute(com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute) PEEntityAttribute(org.dragonet.common.data.entity.PEEntityAttribute) UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket)

Example 14 with Packet

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

the class PCExplosionTranslator method translate.

@Override
public PEPacket[] translate(UpstreamSession session, ServerExplosionPacket packet) {
    ExplodePacket pk = new ExplodePacket();
    pk.position = new Vector3F(packet.getX(), packet.getY(), packet.getZ());
    pk.radius = packet.getRadius();
    pk.destroyedBlocks = new ArrayList<>(packet.getExploded().size());
    for (ExplodedBlockRecord record : packet.getExploded()) pk.destroyedBlocks.add(new BlockPosition(record.getX(), record.getY(), record.getZ()));
    return new PEPacket[] { pk };
}
Also used : ExplodedBlockRecord(com.github.steveice10.mc.protocol.data.game.world.block.ExplodedBlockRecord) Vector3F(org.dragonet.common.maths.Vector3F) BlockPosition(org.dragonet.common.maths.BlockPosition) PEPacket(org.dragonet.protocol.PEPacket) ExplodePacket(org.dragonet.protocol.packets.ExplodePacket)

Example 15 with Packet

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

the class PCPlayerListItemPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlayerListEntryPacket packet) {
    PlayerListPacket pk = new PlayerListPacket();
    if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) {
        PlayerListEntry[] entries = packet.getEntries();
        Set<org.dragonet.protocol.type.PlayerListEntry> peEntries = new HashSet();
        for (PlayerListEntry entry : entries) {
            session.getPlayerInfoCache().put(entry.getProfile().getId(), entry);
            org.dragonet.protocol.type.PlayerListEntry peEntry = new org.dragonet.protocol.type.PlayerListEntry();
            peEntry.uuid = entry.getProfile().getId();
            peEntry.eid = 1;
            peEntry.username = entry.getProfile().getName();
            peEntry.skin = Skin.DEFAULT_SKIN_STEVE;
            peEntry.xboxUserId = entry.getProfile().getId().toString();
            peEntries.add(peEntry);
        }
        pk.type = PlayerListPacket.TYPE_ADD;
        pk.entries = (org.dragonet.protocol.type.PlayerListEntry[]) peEntries.toArray(new org.dragonet.protocol.type.PlayerListEntry[peEntries.size()]);
    } else if (packet.getAction() == PlayerListEntryAction.REMOVE_PLAYER) {
        PlayerListEntry[] entries = packet.getEntries();
        Set<org.dragonet.protocol.type.PlayerListEntry> peEntries = new HashSet();
        for (PlayerListEntry entry : entries) {
            session.getPlayerInfoCache().remove(entry.getProfile().getId());
            org.dragonet.protocol.type.PlayerListEntry peEntry = new org.dragonet.protocol.type.PlayerListEntry();
            peEntry.uuid = entry.getProfile().getId();
            peEntry.eid = 1;
            peEntry.username = entry.getProfile().getName();
            peEntry.skin = Skin.DEFAULT_SKIN_STEVE;
            peEntry.xboxUserId = entry.getProfile().getId().toString();
            peEntries.add(peEntry);
        }
        pk.type = PlayerListPacket.TYPE_REMOVE;
        pk.entries = (org.dragonet.protocol.type.PlayerListEntry[]) peEntries.toArray(new org.dragonet.protocol.type.PlayerListEntry[peEntries.size()]);
    }
    return new PEPacket[] { pk };
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) PEPacket(org.dragonet.protocol.PEPacket) PlayerListPacket(org.dragonet.protocol.packets.PlayerListPacket) PlayerListEntry(com.github.steveice10.mc.protocol.data.game.PlayerListEntry) HashSet(java.util.HashSet)

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