Compare commits

..
2 Commits
5 changed files with 29 additions and 16 deletions

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
# ViaVersion 0.4.0
# ViaVersion 0.4.2
**Allows the connection of 1.8 clients to 1.9**
This plugin modifies netty to allow connection of 1.9 clients to 1.8,
@@ -6,7 +6,6 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -1,15 +1,12 @@
package us.myles.ViaVersion.handlers;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.ByteToMessageDecoder;
import us.myles.ViaVersion.CancelException;
import us.myles.ViaVersion.ConnectionInfo;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion.transformers.IncomingTransformer;
import us.myles.ViaVersion.util.PacketUtil;
import java.util.List;
@@ -27,8 +24,8 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> list) throws Exception {
// use transformers
if(bytebuf.readableBytes() > 0) {
if(info.isActive()) {
if (bytebuf.readableBytes() > 0) {
if (info.isActive()) {
int id = PacketUtil.readVarInt(bytebuf);
// Transform
ByteBuf newPacket = ctx.alloc().buffer();
@@ -36,7 +33,8 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
incomingTransformer.transform(id, bytebuf, newPacket);
bytebuf = newPacket;
} catch (CancelException e) {
return;
bytebuf.readBytes(bytebuf.readableBytes());
throw e;
}
}
// call minecraft decoder
@@ -44,5 +42,13 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (!(cause.getCause() instanceof CancelException)) {
if (cause instanceof Exception) {
throw (Exception) cause;
}
}
}
}
@@ -26,11 +26,10 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
@Override
protected void encode(ChannelHandlerContext ctx, Object o, ByteBuf bytebuf) throws Exception {
// handle the packet type
if (o == null) return;
if (!(o instanceof ByteBuf)) {
info.setLastPacket(o);
/* This transformer is more for fixing issues which we find hard at packet level :) */
if (o.getClass().getName().endsWith("PacketPlayOutMapChunkBulk")) {
if (o.getClass().getName().endsWith("PacketPlayOutMapChunkBulk") && info.isActive()) {
int[] locX = ReflectionUtil.get(o, "a", int[].class);
int[] locZ = ReflectionUtil.get(o, "b", int[].class);
@@ -45,14 +44,14 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
Object packet = constructor.newInstance(chunk, true, 65535);
ctx.pipeline().writeAndFlush(packet);
}
bytebuf.clear();
return;
bytebuf.readBytes(bytebuf.readableBytes());
throw new CancelException();
}
// call minecraft encoder
PacketUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf);
}
if (bytebuf.readableBytes() == 0) {
return;
throw new CancelException();
}
if(info.isActive()) {
int id = PacketUtil.readVarInt(bytebuf);
@@ -62,11 +61,20 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
try {
outgoingTransformer.transform(id, oldPacket, bytebuf);
} catch (CancelException e) {
return;
bytebuf.readBytes(bytebuf.readableBytes());
throw e;
} finally {
oldPacket.release();
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if(!(cause.getCause() instanceof CancelException)) {
if(cause instanceof Exception){
throw (Exception) cause;
}
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
name: ViaVersion
main: us.myles.ViaVersion.ViaVersionPlugin
author: _MylesC
version: 0.4.0
version: 0.4.2
load: startup
loadbefore: [ProtocolLib, ProxyPipe]