Search in sources :

Example 1 with WrappedMCPEPacket

use of io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket in project ProxProx by GoMint.

the class DownstreamConnection method send.

public void send(byte packetId, PacketBuffer buffer) {
    if (this.tcpConnection != null) {
        PacketBuffer newBuffer = new PacketBuffer(64);
        newBuffer.writeByte(packetId);
        newBuffer.writeShort((short) 0);
        byte[] data = new byte[buffer.getRemaining()];
        buffer.readBytes(data);
        newBuffer.writeBytes(data);
        WrappedMCPEPacket mcpePacket = new WrappedMCPEPacket();
        mcpePacket.setBuffer(newBuffer);
        this.tcpConnection.send(mcpePacket);
    } else {
        byte[] data = new byte[buffer.getRemaining()];
        buffer.readBytes(data);
        PacketBuffer packetBuffer = new PacketBuffer(64);
        packetBuffer.writeByte(packetId);
        packetBuffer.writeShort((short) 0);
        packetBuffer.writeBytes(data);
        this.postProcessWorker.sendPacket(packetBuffer);
    }
}
Also used : WrappedMCPEPacket(io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket)

Example 2 with WrappedMCPEPacket

use of io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket in project ProxProx by GoMint.

the class DownstreamConnection method send.

@Override
public void send(Packet packet) {
    PacketBuffer buffer = new PacketBuffer(64);
    buffer.writeByte(packet.getId());
    buffer.writeShort((short) 0);
    packet.serialize(buffer);
    // Do we send via TCP or UDP?
    if (this.tcpConnection != null) {
        WrappedMCPEPacket mcpePacket = new WrappedMCPEPacket();
        mcpePacket.setBuffer(buffer);
        this.tcpConnection.send(mcpePacket);
    } else if (this.connection != null) {
        if (!(packet instanceof PacketBatch)) {
            this.postProcessWorker.sendPacket(buffer);
        } else {
            this.getConnection().send(PacketReliability.RELIABLE_ORDERED, packet.orderingChannel(), buffer.getBuffer(), 0, buffer.getPosition());
        }
    }
}
Also used : WrappedMCPEPacket(io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket)

Example 3 with WrappedMCPEPacket

use of io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket in project ProxProx by GoMint.

the class Decoder method decode.

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf buf, List<Object> objects) throws Exception {
    if (buf instanceof EmptyByteBuf) {
        // The Channel has disconnected and this is the last message we got. R.I.P. connection
        return;
    }
    byte packetId = buf.readByte();
    switch(packetId) {
        case 1:
            WrappedMCPEPacket wrappedMCPEPacket = new WrappedMCPEPacket();
            wrappedMCPEPacket.read(buf);
            objects.add(wrappedMCPEPacket);
            break;
        case 2:
            UpdatePingPacket updatePingPacket = new UpdatePingPacket();
            updatePingPacket.read(buf);
            objects.add(updatePingPacket);
            break;
        case 3:
            SendPlayerToServerPacket sendPlayerToServerPacket = new SendPlayerToServerPacket();
            sendPlayerToServerPacket.read(buf);
            objects.add(sendPlayerToServerPacket);
            break;
        default:
            break;
    }
}
Also used : SendPlayerToServerPacket(io.gomint.proxprox.network.tcp.protocol.SendPlayerToServerPacket) UpdatePingPacket(io.gomint.proxprox.network.tcp.protocol.UpdatePingPacket) EmptyByteBuf(io.netty.buffer.EmptyByteBuf) WrappedMCPEPacket(io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket)

Aggregations

WrappedMCPEPacket (io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket)3 SendPlayerToServerPacket (io.gomint.proxprox.network.tcp.protocol.SendPlayerToServerPacket)1 UpdatePingPacket (io.gomint.proxprox.network.tcp.protocol.UpdatePingPacket)1 EmptyByteBuf (io.netty.buffer.EmptyByteBuf)1