Some changes in handlers

This commit is contained in:
creeper123123321 2018-08-18 14:11:38 -03:00
parent aed718d799
commit 469db0ffda
2 changed files with 20 additions and 20 deletions

View File

@ -30,41 +30,43 @@ public class VRInHandler extends ByteToMessageDecoder {
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
// Based on ViaVersion Sponge encoder code
ByteBuf buf = msg.alloc().buffer().writeBytes(msg);
// Increment sent
user.incrementSent();
if (user.isActive()) {
// Handle ID
int id = Type.VAR_INT.read(msg);
int id = Type.VAR_INT.read(buf);
if (id != PacketWrapper.PASSTHROUGH_ID) {
// Transform
ByteBuf old = msg.alloc().buffer().writeBytes(msg);
ByteBuf newPacket = msg.alloc().buffer();
ByteBuf newPacket = buf.alloc().buffer();
try {
PacketWrapper wrapper = new PacketWrapper(id, old, user);
PacketWrapper wrapper = new PacketWrapper(id, buf, user);
ProtocolInfo protInfo = user.get(ProtocolInfo.class);
protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
wrapper.writeToBuffer(newPacket);
old.release();
msg = newPacket;
buf.clear();
buf.writeBytes(newPacket);
} catch (Exception e) {
if (!(e instanceof CancelException))
e.printStackTrace();
msg.clear();
buf.clear();
throw e;
} finally {
newPacket.release();
}
}
}
// call minecraft encoder
try {
out.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, msg));
out.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, buf));
} catch (InvocationTargetException e) {
e.printStackTrace();
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
}
}
buf.release();
}

View File

@ -46,30 +46,28 @@ public class VROutHandler extends MessageToByteEncoder {
// Increment received
boolean second = user.incrementReceived();
// Check PPS
if (second) {
if (user.handlePPS())
return;
}
if (second && user.handlePPS())
return;
if (user.isActive()) {
// Handle ID
int id = Type.VAR_INT.read(pre);
// Transform
ByteBuf oldPacket = pre.copy();
ByteBuf newPacket = pre.alloc().buffer();
try {
if (id != PacketWrapper.PASSTHROUGH_ID) {
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, user);
PacketWrapper wrapper = new PacketWrapper(id, pre, user);
ProtocolInfo protInfo = user.get(ProtocolInfo.class);
protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper);
wrapper.writeToBuffer(newPacket);
pre.clear();
wrapper.writeToBuffer(pre);
pre.writeBytes(newPacket);
}
} catch (Exception e) {
if (!(e instanceof CancelException))
e.printStackTrace();
pre.clear();
throw e;
} finally {
oldPacket.release();
newPacket.release();
}
}
}