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);
}
}
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());
}
}
}
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;
}
}
Aggregations