Search in sources :

Example 1 with PacketReceivedEvent

use of com.github.steveice10.packetlib.event.session.PacketReceivedEvent in project CyanBot by XjCyan1de.

the class PacketWorldListener method packetReceived.

@Override
public void packetReceived(PacketReceivedEvent event) {
    try {
        Packet packetHandle = event.getPacket();
        if (packetHandle instanceof ServerJoinGamePacket) {
            ServerJoinGamePacket packet = (ServerJoinGamePacket) packetHandle;
            bot.setEntityId(packet.getEntityId());
        } else if (packetHandle instanceof ServerPlayerPositionRotationPacket) {
            ServerPlayerPositionRotationPacket packet = (ServerPlayerPositionRotationPacket) packetHandle;
            Location location = new Location(packet.getX(), packet.getY(), packet.getZ(), packet.getYaw(), packet.getPitch());
            bot.setLoc(location);
            // bot.sendMessage("Меня тпхнуло: "+location);
            // System.out.println(" \nТелепортируем : ["+location.getX()+" "+location.getY()+" "+location.getZ()+"]");
            bot.sendPacket(new ClientTeleportConfirmPacket(packet.getTeleportId()));
        // bot.groundHandler.move(location);
        } else if (packetHandle instanceof ServerChunkDataPacket) {
            ServerChunkDataPacket packet = (ServerChunkDataPacket) packetHandle;
            bot.getWorld().onLoadChunk(bot, packet.getColumn());
        } else if (packetHandle instanceof ServerUnloadChunkPacket) {
            ServerUnloadChunkPacket packet = (ServerUnloadChunkPacket) packetHandle;
            bot.getWorld().onUnloadChunk(bot, packet.getX(), packet.getZ());
        } else if (packetHandle instanceof ServerPlayerHealthPacket) {
            ServerPlayerHealthPacket packet = (ServerPlayerHealthPacket) packetHandle;
            if (packet.getHealth() == 0) {
                Schedule.later(() -> {
                    bot.sendPacket(new ClientRequestPacket(ClientRequest.RESPAWN));
                }, 500);
            }
        } else if (packetHandle instanceof ServerBlockChangePacket) {
            ServerBlockChangePacket packet = (ServerBlockChangePacket) packetHandle;
            BlockState blockState = packet.getRecord().getBlock();
            if (blockState != null) {
                Position position = packet.getRecord().getPosition();
                Block block = bot.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
                if (block != null) {
                    block.setIdAndData(blockState.getId(), blockState.getData());
                // System.out.println("Новый блок = " + block);
                } else {
                    System.out.println("Чё за хуйня у нас блок == Null" + position.getX() + " " + position.getY() + " " + position.getZ());
                }
            }
        } else {
        /*if (packetHandle instanceof ServerUpdateTimePacket ||
                        packetHandle instanceof ServerKeepAlivePacket ||
                        packetHandle instanceof ServerPlaySoundPacket ||
                        packetHandle instanceof ServerEntityEffectPacket

                        ) {
                } else {
                    //System.out.println(bot.getUsername()+" <- "+packetHandle);
                }*/
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) Packet(com.github.steveice10.packetlib.packet.Packet) ServerPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket) ServerPlayerHealthPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket) ServerPlayerHealthPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) ServerPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket) BlockState(com.github.steveice10.mc.protocol.data.game.world.block.BlockState) Block(me.xjcyan1de.cyanbot.world.Block) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) Location(me.xjcyan1de.cyanbot.world.Location)

Example 2 with PacketReceivedEvent

use of com.github.steveice10.packetlib.event.session.PacketReceivedEvent in project CyanBot by XjCyan1de.

the class ChatToGuiListener method onReceived.

@Override
public void onReceived(PacketReceivedEvent event) {
    final ServerChatPacket packet = event.getPacket();
    if (packet.getType() == MessageType.CHAT || packet.getType() == MessageType.SYSTEM) {
        final String message = packet.getMessage().getFullText();
        if (!chatMessageChache.contains(message)) {
            chatMessageChache.add(message);
            mainFrame.getChat().append(message + "\n");
            mainFrame.getChat().setCaretPosition(mainFrame.getChat().getDocument().getLength());
            Schedule.later(() -> chatMessageChache.remove(message), 3000);
        }
    }
}
Also used : ServerChatPacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket)

Example 3 with PacketReceivedEvent

use of com.github.steveice10.packetlib.event.session.PacketReceivedEvent 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)

Aggregations

Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)1 HandshakePacket (com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket)1 ClientRequestPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket)1 ClientTeleportConfirmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket)1 ServerChatPacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket)1 ServerJoinGamePacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket)1 ServerPlayerHealthPacket (com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket)1 ServerPlayerPositionRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket)1 Client (com.github.steveice10.packetlib.Client)1 ConnectedEvent (com.github.steveice10.packetlib.event.session.ConnectedEvent)1 DisconnectedEvent (com.github.steveice10.packetlib.event.session.DisconnectedEvent)1 DisconnectingEvent (com.github.steveice10.packetlib.event.session.DisconnectingEvent)1 PacketReceivedEvent (com.github.steveice10.packetlib.event.session.PacketReceivedEvent)1 PacketSendingEvent (com.github.steveice10.packetlib.event.session.PacketSendingEvent)1 SessionAdapter (com.github.steveice10.packetlib.event.session.SessionAdapter)1 Packet (com.github.steveice10.packetlib.packet.Packet)1 TcpSessionFactory (com.github.steveice10.packetlib.tcp.TcpSessionFactory)1 Block (me.xjcyan1de.cyanbot.world.Block)1 Location (me.xjcyan1de.cyanbot.world.Location)1