Search in sources :

Example 1 with PacketTileReadException

use of com.builtbroken.mc.core.network.ex.PacketTileReadException in project Engine by VoltzEngine-Project.

the class PacketGui method handleClientSide.

@Override
public void handleClientSide(EntityPlayer player) {
    GuiScreen screen = Minecraft.getMinecraft().currentScreen;
    Location location = new Location(player);
    if (screen instanceof IPacketIDReceiver) {
        if (((IPacketIDReceiver) screen).shouldReadPacket(player, location, this)) {
            try {
                IPacketIDReceiver receiver = (IPacketIDReceiver) screen;
                ByteBuf buf = data().slice();
                int id;
                try {
                    id = buf.readInt();
                } catch (IndexOutOfBoundsException ex) {
                    Engine.instance.logger().error(new PacketIDException(location));
                    return;
                }
                receiver.read(buf, id, player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
                Engine.instance.logger().error("Error: ", e);
            } catch (NullPointerException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Null pointer while reading data", e));
                Engine.instance.logger().error("Error: ", e);
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                Engine.instance.logger().error("Error: ", e);
            }
        } else {
            Engine.instance.logger().error("Error: " + screen + " rejected packet " + this + " due to invalid conditions.");
        }
    } else if (screen instanceof IPacketReceiver) {
        if (((IPacketReceiver) screen).shouldReadPacket(player, location, this)) {
            try {
                IPacketReceiver receiver = (IPacketReceiver) screen;
                receiver.read(data().slice(), player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                e.printStackTrace();
            }
        } else {
            Engine.instance.logger().error("Error: " + screen + " rejected packet " + this + " due to invalid conditions.");
        }
    } else {
        Engine.instance.logger().error(new PacketTileReadException(location, "Unsupported action for " + screen));
    }
}
Also used : IPacketReceiver(com.builtbroken.mc.core.network.IPacketReceiver) IPacketIDReceiver(com.builtbroken.mc.core.network.IPacketIDReceiver) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) GuiScreen(net.minecraft.client.gui.GuiScreen) ByteBuf(io.netty.buffer.ByteBuf) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException) Location(com.builtbroken.mc.imp.transform.vector.Location) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException)

Example 2 with PacketTileReadException

use of com.builtbroken.mc.core.network.ex.PacketTileReadException in project Engine by VoltzEngine-Project.

the class PacketGui method handleServerSide.

@Override
public void handleServerSide(EntityPlayer player) {
    Container container = player.openContainer;
    Location location = new Location(player);
    if (container instanceof IPacketIDReceiver) {
        if (((IPacketIDReceiver) container).shouldReadPacket(player, location, this)) {
            try {
                IPacketIDReceiver receiver = (IPacketIDReceiver) container;
                ByteBuf buf = data().slice();
                int id;
                try {
                    id = buf.readInt();
                } catch (IndexOutOfBoundsException ex) {
                    Engine.instance.logger().error(new PacketIDException(location));
                    return;
                }
                receiver.read(buf, id, player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
                Engine.instance.logger().error("Error: ", e);
            } catch (NullPointerException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Null pointer while reading data", e));
                Engine.instance.logger().error("Error: ", e);
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                Engine.instance.logger().error("Error: ", e);
            }
        } else {
            Engine.instance.logger().error("Error: " + container + " rejected packet " + this + " due to invalid conditions.");
        }
    } else if (container instanceof IPacketReceiver) {
        if (((IPacketReceiver) container).shouldReadPacket(player, location, this)) {
            try {
                IPacketReceiver receiver = (IPacketReceiver) container;
                receiver.read(data().slice(), player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                e.printStackTrace();
            }
        } else {
            Engine.instance.logger().error("Error: " + container + " rejected packet " + this + " due to invalid conditions.");
        }
    } else {
        Engine.instance.logger().error(new PacketTileReadException(location, "Unsupported action for " + container));
    }
}
Also used : IPacketReceiver(com.builtbroken.mc.core.network.IPacketReceiver) Container(net.minecraft.inventory.Container) IPacketIDReceiver(com.builtbroken.mc.core.network.IPacketIDReceiver) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) ByteBuf(io.netty.buffer.ByteBuf) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException) Location(com.builtbroken.mc.imp.transform.vector.Location) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException)

Example 3 with PacketTileReadException

use of com.builtbroken.mc.core.network.ex.PacketTileReadException in project Engine by VoltzEngine-Project.

the class PacketTile method handle.

/**
 * Called to handler a packet when it is received
 *
 * @param player - player who received the packet
 * @param tile   - tile who is receiving the packet
 */
public void handle(EntityPlayer player, TileEntity tile) {
    final Location location = new Location(player.worldObj, x, y, z);
    sender_$eq(player);
    if (tile == null) {
        Engine.instance.logger().error(new PacketTileReadException(location, "Null tile"));
    } else if (tile.isInvalid()) {
        Engine.instance.logger().error(new PacketTileReadException(location, "Invalidated tile"));
    } else if (tile instanceof IPacketIDReceiver) {
        if (((IPacketIDReceiver) tile).shouldReadPacket(player, location, this)) {
            try {
                IPacketIDReceiver receiver = (IPacketIDReceiver) tile;
                ByteBuf buf = data().slice();
                int id;
                try {
                    id = buf.readInt();
                } catch (IndexOutOfBoundsException ex) {
                    Engine.instance.logger().error(new PacketIDException(location));
                    return;
                }
                receiver.read(buf, id, player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
                Engine.instance.logger().error("Error: ", e);
            } catch (NullPointerException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Null pointer while reading data", e));
                Engine.instance.logger().error("Error: ", e);
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                Engine.instance.logger().error("Error: ", e);
            }
        } else {
            Engine.instance.logger().error("Error: " + tile + " rejected packet " + this + " due to invalid conditions.");
        }
    } else if (tile instanceof IPacketReceiver) {
        if (((IPacketReceiver) tile).shouldReadPacket(player, location, this)) {
            try {
                IPacketReceiver receiver = (IPacketReceiver) tile;
                receiver.read(data().slice(), player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                e.printStackTrace();
            }
        } else {
            Engine.instance.logger().error("Error: " + tile + " rejected packet " + this + " due to invalid conditions.");
        }
    } else {
        Engine.instance.logger().error(new PacketTileReadException(location, "Unsupported action for " + tile));
    }
}
Also used : IPacketReceiver(com.builtbroken.mc.core.network.IPacketReceiver) IPacketIDReceiver(com.builtbroken.mc.core.network.IPacketIDReceiver) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) ByteBuf(io.netty.buffer.ByteBuf) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException) Location(com.builtbroken.mc.lib.transform.vector.Location) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException)

Aggregations

IPacketIDReceiver (com.builtbroken.mc.core.network.IPacketIDReceiver)3 IPacketReceiver (com.builtbroken.mc.core.network.IPacketReceiver)3 PacketIDException (com.builtbroken.mc.core.network.ex.PacketIDException)3 PacketTileReadException (com.builtbroken.mc.core.network.ex.PacketTileReadException)3 ByteBuf (io.netty.buffer.ByteBuf)3 Location (com.builtbroken.mc.imp.transform.vector.Location)2 Location (com.builtbroken.mc.lib.transform.vector.Location)1 GuiScreen (net.minecraft.client.gui.GuiScreen)1 Container (net.minecraft.inventory.Container)1