Merge branch 'abstraction'

This commit is contained in:
creeper123123321 2019-11-12 16:25:24 -03:00
commit 08ce779d4b
16 changed files with 252 additions and 502 deletions

26
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -0,0 +1,26 @@
---
name: Bug report
about: Create a bug report so we can fix it
---
**Describe the bug, provide any errors**
A clear and concise description of what the bug is. Can you https://hastebin.com the error?
**How can we reproduce it?**
Steps to reproduce the behavior:
1. Login on 1.12'
2. Click on '....'
3. The '....' is displayed wrong
**Expected behaviour**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**ViaVersion Dump:**
- Type /viaversion dump, and put the link here.
**Additional server info**
Do you use a proxy (eg. BungeeCord)? What software do you use and what plugins?

View File

@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for ViaVersion
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Which versions is this for?**
Does the feature apply to any specific versions? If so put them here.

View File

@ -9,13 +9,13 @@ plugins {
group = "com.github.creeper123123321.viafabric" group = "com.github.creeper123123321.viafabric"
val gitVersion: groovy.lang.Closure<Any> by extra val gitVersion: groovy.lang.Closure<Any> by extra
version = "0.1.0-SNAPSHOT+" + try { version = "0.2.0-SNAPSHOT+" + try {
gitVersion() gitVersion()
} catch (e: Exception) { } catch (e: Exception) {
"unknown" "unknown"
} }
extra.set("archivesBaseName", "ViaFabric") extra.set("archivesBaseName", "ViaFabric")
description = "Client-side and server-side ViaVersion for Fabric" description = "Client-side and server-side ViaVersion implementation for Fabric"
java { java {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
@ -46,8 +46,8 @@ tasks.named<ProcessResources>("processResources") {
dependencies { dependencies {
// transitive = false because Guava is conflicting on runClient // transitive = false because Guava is conflicting on runClient
compile("us.myles:viaversion:2.1.4-19w42a") { isTransitive = false } compile("us.myles:viaversion:3.0.0-SNAPSHOT") { isTransitive = false }
include("us.myles:viaversion:2.1.4-19w42a") //include("us.myles:viaversion:3.0.0-SNAPSHOT")
compileOnly("com.google.code.findbugs:jsr305:3.0.2") compileOnly("com.google.code.findbugs:jsr305:3.0.2")

View File

@ -0,0 +1,85 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.handler;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import java.util.function.Function;
// TODO delete this when https://github.com/ViaVersion/ViaVersion/pull/1505 is merged
public class CommonTransformer {
public static final String HANDLER_DECODER_NAME = "via-decoder";
public static final String HANDLER_ENCODER_NAME = "via-encoder";
public static boolean preServerboundCheck(UserConnection user) {
// Ignore if pending disconnect
if (user.isPendingDisconnect()) return true;
// Increment received + Check PPS
return user.incrementReceived() && user.handlePPS();
}
public static void preClientbound(UserConnection user) {
user.incrementSent();
}
public static boolean willTransformPacket(UserConnection user) {
return user.isActive();
}
public static void transformClientbound(ByteBuf draft, UserConnection user, Function<Throwable, Exception> cancelSupplier) throws Exception {
if (!draft.isReadable()) return;
transform(draft, user, Direction.OUTGOING, cancelSupplier);
}
public static void transformServerbound(ByteBuf draft, UserConnection user, Function<Throwable, Exception> cancelSupplier) throws Exception {
if (!draft.isReadable()) return;
transform(draft, user, Direction.INCOMING, cancelSupplier);
}
private static void transform(ByteBuf draft, UserConnection user, Direction direction, Function<Throwable, Exception> cancelSupplier) throws Exception {
int id = Type.VAR_INT.read(draft);
if (id == PacketWrapper.PASSTHROUGH_ID) return;
PacketWrapper wrapper = new PacketWrapper(id, draft, user);
ProtocolInfo protInfo = user.get(ProtocolInfo.class);
try {
protInfo.getPipeline().transform(direction, protInfo.getState(), wrapper);
} catch (CancelException ex) {
throw cancelSupplier.apply(ex);
}
ByteBuf transformed = draft.alloc().buffer();
try {
wrapper.writeToBuffer(transformed);
draft.clear().writeBytes(transformed);
} finally {
transformed.release();
}
}
}

View File

@ -24,72 +24,40 @@
package com.github.creeper123123321.viafabric.handler.clientside; package com.github.creeper123123321.viafabric.handler.clientside;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.util.PipelineUtil; import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
public class VRDecodeHandler extends ByteToMessageDecoder { public class VRDecodeHandler extends ByteToMessageDecoder {
private UserConnection user; private UserConnection user;
private ByteToMessageDecoder minecraftDecoder;
public VRDecodeHandler(UserConnection user, ByteToMessageDecoder minecraftDecoder) { public VRDecodeHandler(UserConnection user) {
this.user = user; this.user = user;
this.minecraftDecoder = minecraftDecoder;
} }
@Override @Override
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 CommonTransformer.preClientbound(user);
if (!CommonTransformer.willTransformPacket(user)) {
ByteBuf buf = msg.alloc().buffer().writeBytes(msg); out.add(msg.readRetainedSlice(msg.readableBytes()));
return;
// Increment sent }
user.incrementSent(); ByteBuf draft = msg.alloc().buffer().writeBytes(msg);
if (user.isActive()) {
// Handle ID
int id = Type.VAR_INT.read(buf);
if (id != PacketWrapper.PASSTHROUGH_ID) {
// Transform
ByteBuf newPacket = buf.alloc().buffer();
try { try {
PacketWrapper wrapper = new PacketWrapper(id, buf, user); CommonTransformer.transformClientbound(draft, user, ignored -> CancelException.CACHED);
ProtocolInfo protInfo = user.get(ProtocolInfo.class); out.add(draft.retain());
protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
wrapper.writeToBuffer(newPacket);
buf.clear();
buf.writeBytes(newPacket);
} catch (Exception e) {
buf.release();
throw e;
} finally { } finally {
newPacket.release(); draft.release();
} }
} }
}
// call minecraft encoder
try {
out.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, buf));
} catch (InvocationTargetException e) {
e.printStackTrace();
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
}
}
buf.release();
}
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
@ -98,12 +66,8 @@ public class VRDecodeHandler extends ByteToMessageDecoder {
} }
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelRead(ctx, msg); super.channelInactive(ctx);
}
@Override
public void channelInactive(ChannelHandlerContext ctx) {
ProtocolInfo info = user.get(ProtocolInfo.class); ProtocolInfo info = user.get(ProtocolInfo.class);
if (info.getUuid() != null) { if (info.getUuid() != null) {
Via.getManager().removePortedClient(info.getUuid()); Via.getManager().removePortedClient(info.getUuid());

View File

@ -24,91 +24,44 @@
package com.github.creeper123123321.viafabric.handler.clientside; package com.github.creeper123123321.viafabric.handler.clientside;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.util.PipelineUtil; import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException; import java.util.List;
public class VREncodeHandler extends MessageToByteEncoder { public class VREncodeHandler extends MessageToMessageEncoder<ByteBuf> {
private UserConnection user; private UserConnection user;
private MessageToByteEncoder minecraftEncoder;
public VREncodeHandler(UserConnection user, MessageToByteEncoder minecraftEncoder) { public VREncodeHandler(UserConnection user) {
this.user = user; this.user = user;
this.minecraftEncoder = minecraftEncoder;
} }
@Override @Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
// Based on Sponge ViaVersion decoder code if (CommonTransformer.preServerboundCheck(user)) {
throw CancelException.CACHED; // Theoretically a server with m2m decoder would hold this packet, but we'll just cancel for now and this is used for kicking packet spamming
ByteBuf pre = out.alloc().buffer();
// call minecraft encoder
try {
PipelineUtil.callEncode(this.minecraftEncoder, ctx, msg, pre);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
} }
} if (!CommonTransformer.willTransformPacket(user)) {
out.add(msg.readRetainedSlice(msg.readableBytes()));
// use transformers
if (pre.readableBytes() > 0) {
// Ignore if pending disconnect
if (user.isPendingDisconnect()) {
return; return;
} }
// Increment received ByteBuf draft = ctx.alloc().buffer().writeBytes(msg);
boolean second = user.incrementReceived();
// Check PPS
if (second && user.handlePPS())
return;
if (user.isActive()) {
// Handle ID
int id = Type.VAR_INT.read(pre);
// Transform
ByteBuf newPacket = pre.alloc().buffer();
try { try {
if (id != PacketWrapper.PASSTHROUGH_ID) { CommonTransformer.transformServerbound(draft, user, ignored -> CancelException.CACHED);
PacketWrapper wrapper = new PacketWrapper(id, pre, user); out.add(draft.retain());
ProtocolInfo protInfo = user.get(ProtocolInfo.class);
protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper);
wrapper.writeToBuffer(newPacket);
pre.clear();
pre.writeBytes(newPacket);
}
} catch (Exception e) {
pre.release();
throw e;
} finally { } finally {
newPacket.release(); draft.release();
} }
} }
}
out.writeBytes(pre);
pre.release();
}
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelException.class)) return; if (PipelineUtil.containsCause(cause, CancelException.class)) return;
super.exceptionCaught(ctx, cause); super.exceptionCaught(ctx, cause);
} }
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
super.write(ctx, msg, promise);
}
} }

View File

@ -24,85 +24,38 @@
package com.github.creeper123123321.viafabric.handler.serverside; package com.github.creeper123123321.viafabric.handler.serverside;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.util.PipelineUtil; import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
public class FabricDecodeHandler extends ByteToMessageDecoder { public class FabricDecodeHandler extends ByteToMessageDecoder {
// https://github.com/MylesIsCool/ViaVersion/blob/1abc3ebea66878192b08b577353dff7d619ed51e/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeDecodeHandler.java private final UserConnection user;
private final ByteToMessageDecoder minecraftDecoder;
private final UserConnection info;
public FabricDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) { public FabricDecodeHandler(UserConnection user) {
this.info = info; this.user = user;
this.minecraftDecoder = minecraftDecoder;
} }
@Override @Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> list) throws Exception { protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
// use transformers if (CommonTransformer.preServerboundCheck(user)) return;
if (bytebuf.readableBytes() > 0) { if (!CommonTransformer.willTransformPacket(user)) {
// Ignore if pending disconnect out.add(in.readRetainedSlice(in.readableBytes()));
if (info.isPendingDisconnect()) {
return; return;
} }
// Increment received ByteBuf draft = ctx.alloc().buffer().writeBytes(in);
boolean second = info.incrementReceived();
// Check PPS
if (second) {
if (info.handlePPS())
return;
}
if (info.isActive()) {
// Handle ID
int id = Type.VAR_INT.read(bytebuf);
// Transform
ByteBuf newPacket = ctx.alloc().buffer();
try { try {
if (id == PacketWrapper.PASSTHROUGH_ID) { CommonTransformer.transformServerbound(draft, user, ignored -> CancelException.CACHED);
newPacket.writeBytes(bytebuf); out.add(draft.retain());
} else {
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info);
ProtocolInfo protInfo = info.get(ProtocolInfo.class);
protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper);
wrapper.writeToBuffer(newPacket);
}
bytebuf.clear();
bytebuf = newPacket;
} catch (Exception e) {
// Clear Buffer
bytebuf.clear();
// Release Packet, be free!
newPacket.release();
throw e;
}
}
// call minecraft decoder
try {
list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, bytebuf));
} catch (InvocationTargetException e) {
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
}
} finally { } finally {
if (info.isActive()) { draft.release();
bytebuf.release();
}
}
} }
} }
@ -113,8 +66,9 @@ public class FabricDecodeHandler extends ByteToMessageDecoder {
} }
@Override @Override
public void channelInactive(ChannelHandlerContext ctx) { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
ProtocolInfo pi = info.get(ProtocolInfo.class); super.channelInactive(ctx); // May call decode
ProtocolInfo pi = user.get(ProtocolInfo.class);
if (pi.getUuid() != null) { if (pi.getUuid() != null) {
Via.getManager().removePortedClient(pi.getUuid()); Via.getManager().removePortedClient(pi.getUuid());
} }

View File

@ -24,66 +24,36 @@
package com.github.creeper123123321.viafabric.handler.serverside; package com.github.creeper123123321.viafabric.handler.serverside;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToMessageEncoder;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.util.PipelineUtil; import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException; import java.util.List;
public class FabricEncodeHandler extends MessageToByteEncoder { public class FabricEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
// https://github.com/MylesIsCool/ViaVersion/blob/master/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeEncodeHandler.java private final UserConnection user;
private final UserConnection info;
private final MessageToByteEncoder minecraftEncoder;
public FabricEncodeHandler(UserConnection info, MessageToByteEncoder minecraftEncoder) { public FabricEncodeHandler(UserConnection user) {
this.info = info; this.user = user;
this.minecraftEncoder = minecraftEncoder;
} }
@Override @Override
protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception { protected void encode(final ChannelHandlerContext ctx, ByteBuf in, final List<Object> out) throws Exception {
// handle the packet type CommonTransformer.preClientbound(user);
if (!(o instanceof ByteBuf)) { if (!CommonTransformer.willTransformPacket(user)) {
// call minecraft encoder out.add(in.readRetainedSlice(in.readableBytes()));
return;
}
ByteBuf draft = ctx.alloc().buffer().writeBytes(in);
try { try {
PipelineUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf); CommonTransformer.transformClientbound(draft, user, ignored -> CancelException.CACHED);
} catch (InvocationTargetException e) { out.add(draft.retain());
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
}
}
}
if (bytebuf.readableBytes() == 0) {
throw new CancelException();
}
// Increment sent
info.incrementSent();
if (info.isActive()) {
// Handle ID
int id = Type.VAR_INT.read(bytebuf);
// Transform
ByteBuf oldPacket = bytebuf.copy();
bytebuf.clear();
try {
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, info);
ProtocolInfo protInfo = info.get(ProtocolInfo.class);
protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
wrapper.writeToBuffer(bytebuf);
} catch (Exception e) {
bytebuf.clear();
throw e;
} finally { } finally {
oldPacket.release(); draft.release();
}
} }
} }

View File

@ -24,6 +24,9 @@
package com.github.creeper123123321.viafabric.mixin; package com.github.creeper123123321.viafabric.mixin;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
import net.minecraft.network.ClientConnection; import net.minecraft.network.ClientConnection;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -40,11 +43,33 @@ public class MixinClientConnection {
value = "INVOKE", value = "INVOKE",
target = "Lorg/apache/logging/log4j/Logger;debug(Ljava/lang/String;Ljava/lang/Throwable;)V" target = "Lorg/apache/logging/log4j/Logger;debug(Ljava/lang/String;Ljava/lang/Throwable;)V"
)) ))
public void redirectDebug(Logger logger, String message, Throwable t) { private void redirectDebug(Logger logger, String message, Throwable t) {
if ("Failed to sent packet".equals(message)) { if ("Failed to sent packet".equals(message)) {
logger.info(message, t); logger.info(message, t);
} else { } else {
logger.debug(message, t); logger.debug(message, t);
} }
} }
@Redirect(method = "setMinCompressedSize", at = @At(
value = "INVOKE",
remap = false,
target = "Lio/netty/channel/ChannelPipeline;addBefore(Ljava/lang/String;Ljava/lang/String;Lio/netty/channel/ChannelHandler;)Lio/netty/channel/ChannelPipeline;"
))
private ChannelPipeline decodeEncodePlacement(ChannelPipeline instance, String base, String newHandler, ChannelHandler handler) {
// Fixes the handler order
switch (base) {
case "decoder": {
if (instance.get(CommonTransformer.HANDLER_DECODER_NAME) != null)
base = CommonTransformer.HANDLER_DECODER_NAME;
break;
}
case "encoder": {
if (instance.get(CommonTransformer.HANDLER_ENCODER_NAME) != null)
base = CommonTransformer.HANDLER_ENCODER_NAME;
break;
}
}
return instance.addBefore(base, newHandler, handler);
}
} }

View File

@ -24,12 +24,11 @@
package com.github.creeper123123321.viafabric.mixin; package com.github.creeper123123321.viafabric.mixin;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import com.github.creeper123123321.viafabric.handler.serverside.FabricDecodeHandler; import com.github.creeper123123321.viafabric.handler.serverside.FabricDecodeHandler;
import com.github.creeper123123321.viafabric.handler.serverside.FabricEncodeHandler; import com.github.creeper123123321.viafabric.handler.serverside.FabricEncodeHandler;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@ -45,11 +44,8 @@ public class MixinServerNetworkIoChInit {
UserConnection user = new UserConnection(channel); UserConnection user = new UserConnection(channel);
new ProtocolPipeline(user); new ProtocolPipeline(user);
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder"); channel.pipeline().addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user));
ByteToMessageDecoder oldDecoder = (ByteToMessageDecoder) channel.pipeline().get("decoder"); channel.pipeline().addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user));
channel.pipeline().replace("encoder", "encoder", new FabricEncodeHandler(user, oldEncoder));
channel.pipeline().replace("decoder", "decoder", new FabricDecodeHandler(user, oldDecoder));
} }
} }
} }

View File

@ -24,13 +24,12 @@
package com.github.creeper123123321.viafabric.mixin.client; package com.github.creeper123123321.viafabric.mixin.client;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import com.github.creeper123123321.viafabric.handler.clientside.VRDecodeHandler; import com.github.creeper123123321.viafabric.handler.clientside.VRDecodeHandler;
import com.github.creeper123123321.viafabric.handler.clientside.VREncodeHandler; import com.github.creeper123123321.viafabric.handler.clientside.VREncodeHandler;
import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection; import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@ -46,11 +45,8 @@ public class MixinClientConnectionChInit {
UserConnection user = new VRClientSideUserConnection(channel); UserConnection user = new VRClientSideUserConnection(channel);
new ProtocolPipeline(user); new ProtocolPipeline(user);
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder"); channel.pipeline().addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new VREncodeHandler(user));
ByteToMessageDecoder oldDecoder = (ByteToMessageDecoder) channel.pipeline().get("decoder"); channel.pipeline().addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new VRDecodeHandler(user));
channel.pipeline().replace("encoder", "encoder", new VREncodeHandler(user, oldEncoder));
channel.pipeline().replace("decoder", "decoder", new VRDecodeHandler(user, oldDecoder));
} }
} }
} }

View File

@ -24,14 +24,11 @@
package com.github.creeper123123321.viafabric.platform; package com.github.creeper123123321.viafabric.platform;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.util.PipelineUtil;
public class VRClientSideUserConnection extends UserConnection { public class VRClientSideUserConnection extends UserConnection {
public VRClientSideUserConnection(Channel socketChannel) { public VRClientSideUserConnection(Channel socketChannel) {
@ -41,46 +38,28 @@ public class VRClientSideUserConnection extends UserConnection {
@Override @Override
public void sendRawPacket(final ByteBuf packet, boolean currentThread) { public void sendRawPacket(final ByteBuf packet, boolean currentThread) {
ByteBuf copy = packet.alloc().buffer(); Runnable act = () -> getChannel().pipeline().context(CommonTransformer.HANDLER_DECODER_NAME)
try { .fireChannelRead(packet);
Type.VAR_INT.write(copy, PacketWrapper.PASSTHROUGH_ID);
} catch (Exception e) {
e.printStackTrace();
}
copy.writeBytes(packet);
packet.release();
final Channel channel = this.getChannel();
if (currentThread) { if (currentThread) {
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy); act.run();
} else { } else {
channel.eventLoop().submit(() -> { getChannel().eventLoop().execute(act);
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
});
} }
} }
@Override @Override
public ChannelFuture sendRawPacketFuture(ByteBuf packet) { public ChannelFuture sendRawPacketFuture(ByteBuf packet) {
ByteBuf copy = packet.alloc().buffer(); getChannel().pipeline().context(CommonTransformer.HANDLER_DECODER_NAME).fireChannelRead(packet);
try { return getChannel().newSucceededFuture();
Type.VAR_INT.write(copy, PacketWrapper.PASSTHROUGH_ID);
} catch (Exception e) {
e.printStackTrace();
}
copy.writeBytes(packet);
packet.release();
final Channel channel = this.getChannel();
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
return channel.newSucceededFuture();
} }
@Override @Override
public void sendRawPacketToServer(ByteBuf packet, boolean currentThread) { public void sendRawPacketToServer(ByteBuf packet, boolean currentThread) {
if (currentThread) { if (currentThread) {
getChannel().pipeline().context("encoder").writeAndFlush(packet); getChannel().pipeline().context(CommonTransformer.HANDLER_ENCODER_NAME).writeAndFlush(packet);
} else { } else {
getChannel().eventLoop().submit(() -> { getChannel().eventLoop().submit(() -> {
getChannel().pipeline().context("encoder").writeAndFlush(packet); getChannel().pipeline().context(CommonTransformer.HANDLER_ENCODER_NAME).writeAndFlush(packet);
}); });
} }
} }

View File

@ -24,6 +24,7 @@
package com.github.creeper123123321.viafabric.platform; package com.github.creeper123123321.viafabric.platform;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.SharedConstants; import net.minecraft.SharedConstants;
@ -52,12 +53,12 @@ public class VRInjector implements ViaInjector {
@Override @Override
public String getEncoderName() { public String getEncoderName() {
return "encoder"; return CommonTransformer.HANDLER_ENCODER_NAME;
} }
@Override @Override
public String getDecoderName() { public String getDecoderName() {
return "decoder"; return CommonTransformer.HANDLER_DECODER_NAME;
} }
@Override @Override

View File

@ -24,7 +24,7 @@
package com.github.creeper123123321.viafabric.platform; package com.github.creeper123123321.viafabric.platform;
import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.AbstractViaConfig;
import us.myles.ViaVersion.util.Config; import us.myles.ViaVersion.util.Config;
import java.io.File; import java.io.File;
@ -33,7 +33,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class VRViaConfig extends Config implements ViaVersionConfig { public class VRViaConfig extends AbstractViaConfig {
// Based on Sponge ViaVersion // Based on Sponge ViaVersion
private static List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval", private static List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval",
"bungee-ping-save", "bungee-servers", "quick-move-action-fix", "nms-player-ticking", "bungee-ping-save", "bungee-servers", "quick-move-action-fix", "nms-player-ticking",
@ -61,117 +61,11 @@ public class VRViaConfig extends Config implements ViaVersionConfig {
return UNSUPPORTED; return UNSUPPORTED;
} }
public boolean isCheckForUpdates() {
return getBoolean("checkforupdates", true);
}
@Override
public boolean isPreventCollision() {
return getBoolean("prevent-collision", true);
}
@Override
public boolean isNewEffectIndicator() {
return getBoolean("use-new-effect-indicator", true);
}
@Override
public boolean isShowNewDeathMessages() {
return getBoolean("use-new-deathmessages", true);
}
@Override
public boolean isSuppressMetadataErrors() {
return getBoolean("suppress-metadata-errors", false);
}
@Override
public boolean isShieldBlocking() {
return getBoolean("shield-blocking", true);
}
@Override
public boolean isHologramPatch() {
return getBoolean("hologram-patch", false);
}
@Override
public boolean isPistonAnimationPatch() {
return getBoolean("piston-animation-patch", false);
}
@Override
public boolean isBossbarPatch() {
return getBoolean("bossbar-patch", true);
}
@Override
public boolean isBossbarAntiflicker() {
return getBoolean("bossbar-anti-flicker", false);
}
@Override
@Deprecated
public boolean isUnknownEntitiesSuppressed() {
return false;
}
@Override
public double getHologramYOffset() {
return getDouble("hologram-y", -0.96D);
}
@Override
@Deprecated
public boolean isBlockBreakPatch() {
return false;
}
@Override
public int getMaxPPS() {
return getInt("max-pps", 800);
}
@Override
public String getMaxPPSKickMessage() {
return getString("max-pps-kick-msg", "Sending packets too fast? lag?");
}
@Override
public int getTrackingPeriod() {
return getInt("tracking-period", 6);
}
@Override
public int getWarningPPS() {
return getInt("tracking-warning-pps", 120);
}
@Override
public int getMaxWarnings() {
return getInt("tracking-max-warnings", 3);
}
@Override
public String getMaxWarningsKickMessage() {
return getString("tracking-max-kick-msg", "You are sending too many packets, :(");
}
@Override @Override
public boolean isAntiXRay() { public boolean isAntiXRay() {
return false; return false;
} }
@Override
public boolean isSendSupportedVersions() {
return getBoolean("send-supported-versions", false);
}
@Override
public boolean isStimulatePlayerTick() {
return getBoolean("simulate-pt", true);
}
@Override @Override
public boolean isItemCache() { public boolean isItemCache() {
return false; return false;
@ -182,111 +76,16 @@ public class VRViaConfig extends Config implements ViaVersionConfig {
return false; return false;
} }
@Override
public boolean isReplacePistons() {
return getBoolean("replace-pistons", false);
}
@Override
public int getPistonReplacementId() {
return getInt("replacement-piston-id", 0);
}
public boolean isAutoTeam() {
// Collision has to be enabled first
return isPreventCollision() && getBoolean("auto-team", true);
}
@Override
public boolean isForceJsonTransform() {
return getBoolean("force-json-transform", false);
}
@Override
public boolean is1_12NBTArrayFix() {
return getBoolean("chat-nbt-fix", true);
}
@Override @Override
public boolean is1_12QuickMoveActionFix() { public boolean is1_12QuickMoveActionFix() {
return false; return false;
} }
@Override
public List<Integer> getBlockedProtocols() {
return getIntegerList("block-protocols");
}
@Override
public String getBlockedDisconnectMsg() {
return getString("block-disconnect-msg", "You are using an unsupported Minecraft version!");
}
@Override
public String getReloadDisconnectMsg() {
return getString("reload-disconnect-msg", "Server reload, please rejoin!");
}
@Override
public boolean is1_13TeamColourFix() {
return getBoolean("team-colour-fix", true);
}
@Override
public boolean isSuppress1_13ConversionErrors() {
return getBoolean("suppress-1_13-conversion-errors", false);
}
@Override
public boolean isMinimizeCooldown() {
return this.getBoolean("minimize-cooldown", true);
}
@Override
public boolean isDisable1_13AutoComplete() {
return this.getBoolean("disable-1_13-auto-complete", false);
}
@Override
public boolean isServersideBlockConnections() {
return this.getBoolean("serverside-blockconnections", false);
}
@Override @Override
public String getBlockConnectionMethod() { public String getBlockConnectionMethod() {
return "packet"; return "packet";
} }
@Override
public boolean isReduceBlockStorageMemory() {
return this.getBoolean("reduce-blockstorage-memory", false);
}
@Override
public boolean isStemWhenBlockAbove() {
return this.getBoolean("flowerstem-when-block-above", false);
}
@Override
public boolean isSnowCollisionFix() {
return this.getBoolean("fix-low-snow-collision", false);
}
@Override
public int get1_13TabCompleteDelay() {
return this.getInt("1_13-tab-complete-delay", 0);
}
@Override
public boolean isTruncate1_14Books() {
return this.getBoolean("truncate-1_14-books", false);
}
@Override
public boolean isLeftHandedHandling() {
return this.getBoolean("left-handed-handling", true);
}
@Override @Override
public boolean is1_9HitboxFix() { public boolean is1_9HitboxFix() {
return false; return false;
@ -296,19 +95,4 @@ public class VRViaConfig extends Config implements ViaVersionConfig {
public boolean is1_14HitboxFix() { public boolean is1_14HitboxFix() {
return false; return false;
} }
@Override
public boolean isNonFullBlockLightFix() {
return this.getBoolean("fix-non-full-blocklight", true);
}
@Override
public boolean is1_14HealthNaNFix() {
return this.getBoolean("fix-1_14-health-nan", true);
}
@Override
public boolean is1_15InstantRespawn() {
return this.getBoolean("use-1_15-instant-respawn", false);
}
} }

View File

@ -10,7 +10,6 @@
"issues": "https://github.com/ViaVersion/ViaFabric/issues", "issues": "https://github.com/ViaVersion/ViaFabric/issues",
"sources": "https://github.com/ViaVersion/ViaFabric" "sources": "https://github.com/ViaVersion/ViaFabric"
}, },
"icon": "assets/viaversion/textures/logo.png",
"environment": "*", "environment": "*",
"authors": [ "authors": [
"creeper123123321" "creeper123123321"
@ -27,7 +26,8 @@
"fabricloader": ">=0.4.0", "fabricloader": ">=0.4.0",
"fabric-textures-v0": "*", "fabric-textures-v0": "*",
"fabric-resource-loader-v0": "*", "fabric-resource-loader-v0": "*",
"fabric-commands-v0": "*" "fabric-commands-v0": "*",
"viaversion": ">=3.0.0-SNAPSHOT"
}, },
"recommends": { "recommends": {
"cotton-client-commands": "*" "cotton-client-commands": "*"

View File

@ -3,8 +3,8 @@
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_8",
"package": "com.github.creeper123123321.viafabric.mixin", "package": "com.github.creeper123123321.viafabric.mixin",
"mixins": [ "mixins": [
"MixinServerNetworkIoChInit", "MixinClientConnection",
"MixinClientConnection" "MixinServerNetworkIoChInit"
], ],
"client": [ "client": [
"client.MixinClientConnectionChInit", "client.MixinClientConnectionChInit",