mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2025-01-02 18:17:36 +01:00
Some changes in handlers
This commit is contained in:
parent
aed718d799
commit
469db0ffda
@ -30,41 +30,43 @@ public class VRInHandler extends ByteToMessageDecoder {
|
|||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
|
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
|
||||||
// Based on ViaVersion Sponge encoder code
|
// Based on ViaVersion Sponge encoder code
|
||||||
|
|
||||||
|
ByteBuf buf = msg.alloc().buffer().writeBytes(msg);
|
||||||
|
|
||||||
// Increment sent
|
// Increment sent
|
||||||
user.incrementSent();
|
user.incrementSent();
|
||||||
if (user.isActive()) {
|
if (user.isActive()) {
|
||||||
// Handle ID
|
// Handle ID
|
||||||
int id = Type.VAR_INT.read(msg);
|
int id = Type.VAR_INT.read(buf);
|
||||||
|
|
||||||
if (id != PacketWrapper.PASSTHROUGH_ID) {
|
if (id != PacketWrapper.PASSTHROUGH_ID) {
|
||||||
// Transform
|
// Transform
|
||||||
ByteBuf old = msg.alloc().buffer().writeBytes(msg);
|
ByteBuf newPacket = buf.alloc().buffer();
|
||||||
ByteBuf newPacket = msg.alloc().buffer();
|
|
||||||
try {
|
try {
|
||||||
PacketWrapper wrapper = new PacketWrapper(id, old, user);
|
PacketWrapper wrapper = new PacketWrapper(id, buf, user);
|
||||||
ProtocolInfo protInfo = user.get(ProtocolInfo.class);
|
ProtocolInfo protInfo = user.get(ProtocolInfo.class);
|
||||||
protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
|
protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
|
||||||
wrapper.writeToBuffer(newPacket);
|
wrapper.writeToBuffer(newPacket);
|
||||||
old.release();
|
buf.clear();
|
||||||
msg = newPacket;
|
buf.writeBytes(newPacket);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (!(e instanceof CancelException))
|
buf.clear();
|
||||||
e.printStackTrace();
|
|
||||||
msg.clear();
|
|
||||||
throw e;
|
throw e;
|
||||||
|
} finally {
|
||||||
|
newPacket.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// call minecraft encoder
|
// call minecraft encoder
|
||||||
try {
|
try {
|
||||||
out.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, msg));
|
out.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, buf));
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (e.getCause() instanceof Exception) {
|
if (e.getCause() instanceof Exception) {
|
||||||
throw (Exception) e.getCause();
|
throw (Exception) e.getCause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
buf.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,30 +46,28 @@ public class VROutHandler extends MessageToByteEncoder {
|
|||||||
// Increment received
|
// Increment received
|
||||||
boolean second = user.incrementReceived();
|
boolean second = user.incrementReceived();
|
||||||
// Check PPS
|
// Check PPS
|
||||||
if (second) {
|
if (second && user.handlePPS())
|
||||||
if (user.handlePPS())
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user.isActive()) {
|
if (user.isActive()) {
|
||||||
// Handle ID
|
// Handle ID
|
||||||
int id = Type.VAR_INT.read(pre);
|
int id = Type.VAR_INT.read(pre);
|
||||||
// Transform
|
// Transform
|
||||||
ByteBuf oldPacket = pre.copy();
|
ByteBuf newPacket = pre.alloc().buffer();
|
||||||
try {
|
try {
|
||||||
if (id != PacketWrapper.PASSTHROUGH_ID) {
|
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);
|
ProtocolInfo protInfo = user.get(ProtocolInfo.class);
|
||||||
protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper);
|
protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper);
|
||||||
|
wrapper.writeToBuffer(newPacket);
|
||||||
pre.clear();
|
pre.clear();
|
||||||
wrapper.writeToBuffer(pre);
|
pre.writeBytes(newPacket);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (!(e instanceof CancelException))
|
pre.clear();
|
||||||
e.printStackTrace();
|
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
oldPacket.release();
|
newPacket.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user