mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-12-18 15:47:46 +01:00
Merge branch 'abstraction'
This commit is contained in:
commit
08ce779d4b
26
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
26
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal 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?
|
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal 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.
|
@ -9,13 +9,13 @@ plugins {
|
||||
|
||||
group = "com.github.creeper123123321.viafabric"
|
||||
val gitVersion: groovy.lang.Closure<Any> by extra
|
||||
version = "0.1.0-SNAPSHOT+" + try {
|
||||
version = "0.2.0-SNAPSHOT+" + try {
|
||||
gitVersion()
|
||||
} catch (e: Exception) {
|
||||
"unknown"
|
||||
}
|
||||
extra.set("archivesBaseName", "ViaFabric")
|
||||
description = "Client-side and server-side ViaVersion for Fabric"
|
||||
description = "Client-side and server-side ViaVersion implementation for Fabric"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
@ -46,8 +46,8 @@ tasks.named<ProcessResources>("processResources") {
|
||||
|
||||
dependencies {
|
||||
// transitive = false because Guava is conflicting on runClient
|
||||
compile("us.myles:viaversion:2.1.4-19w42a") { isTransitive = false }
|
||||
include("us.myles:viaversion:2.1.4-19w42a")
|
||||
compile("us.myles:viaversion:3.0.0-SNAPSHOT") { isTransitive = false }
|
||||
//include("us.myles:viaversion:3.0.0-SNAPSHOT")
|
||||
|
||||
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -24,71 +24,39 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.handler.clientside;
|
||||
|
||||
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
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 us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
public class VRDecodeHandler extends ByteToMessageDecoder {
|
||||
private UserConnection user;
|
||||
private ByteToMessageDecoder minecraftDecoder;
|
||||
|
||||
public VRDecodeHandler(UserConnection user, ByteToMessageDecoder minecraftDecoder) {
|
||||
public VRDecodeHandler(UserConnection user) {
|
||||
this.user = user;
|
||||
this.minecraftDecoder = minecraftDecoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
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(buf);
|
||||
|
||||
if (id != PacketWrapper.PASSTHROUGH_ID) {
|
||||
// Transform
|
||||
ByteBuf newPacket = buf.alloc().buffer();
|
||||
try {
|
||||
PacketWrapper wrapper = new PacketWrapper(id, buf, user);
|
||||
ProtocolInfo protInfo = user.get(ProtocolInfo.class);
|
||||
protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
|
||||
wrapper.writeToBuffer(newPacket);
|
||||
buf.clear();
|
||||
buf.writeBytes(newPacket);
|
||||
} catch (Exception e) {
|
||||
buf.release();
|
||||
throw e;
|
||||
} finally {
|
||||
newPacket.release();
|
||||
}
|
||||
}
|
||||
CommonTransformer.preClientbound(user);
|
||||
if (!CommonTransformer.willTransformPacket(user)) {
|
||||
out.add(msg.readRetainedSlice(msg.readableBytes()));
|
||||
return;
|
||||
}
|
||||
|
||||
// call minecraft encoder
|
||||
ByteBuf draft = msg.alloc().buffer().writeBytes(msg);
|
||||
try {
|
||||
out.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, buf));
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
if (e.getCause() instanceof Exception) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
CommonTransformer.transformClientbound(draft, user, ignored -> CancelException.CACHED);
|
||||
out.add(draft.retain());
|
||||
} finally {
|
||||
draft.release();
|
||||
}
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,12 +66,8 @@ public class VRDecodeHandler extends ByteToMessageDecoder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
super.channelRead(ctx, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelInactive(ctx);
|
||||
ProtocolInfo info = user.get(ProtocolInfo.class);
|
||||
if (info.getUuid() != null) {
|
||||
Via.getManager().removePortedClient(info.getUuid());
|
||||
|
@ -24,81 +24,39 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.handler.clientside;
|
||||
|
||||
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
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 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 MessageToByteEncoder minecraftEncoder;
|
||||
|
||||
public VREncodeHandler(UserConnection user, MessageToByteEncoder minecraftEncoder) {
|
||||
public VREncodeHandler(UserConnection user) {
|
||||
this.user = user;
|
||||
this.minecraftEncoder = minecraftEncoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
|
||||
// Based on Sponge ViaVersion decoder code
|
||||
|
||||
ByteBuf pre = out.alloc().buffer();
|
||||
|
||||
// call minecraft encoder
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
|
||||
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
|
||||
}
|
||||
if (!CommonTransformer.willTransformPacket(user)) {
|
||||
out.add(msg.readRetainedSlice(msg.readableBytes()));
|
||||
return;
|
||||
}
|
||||
ByteBuf draft = ctx.alloc().buffer().writeBytes(msg);
|
||||
try {
|
||||
PipelineUtil.callEncode(this.minecraftEncoder, ctx, msg, pre);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof Exception) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
CommonTransformer.transformServerbound(draft, user, ignored -> CancelException.CACHED);
|
||||
out.add(draft.retain());
|
||||
} finally {
|
||||
draft.release();
|
||||
}
|
||||
|
||||
// use transformers
|
||||
if (pre.readableBytes() > 0) {
|
||||
// Ignore if pending disconnect
|
||||
if (user.isPendingDisconnect()) {
|
||||
return;
|
||||
}
|
||||
// Increment received
|
||||
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 {
|
||||
if (id != PacketWrapper.PASSTHROUGH_ID) {
|
||||
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();
|
||||
pre.writeBytes(newPacket);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
pre.release();
|
||||
throw e;
|
||||
} finally {
|
||||
newPacket.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.writeBytes(pre);
|
||||
pre.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -106,9 +64,4 @@ public class VREncodeHandler extends MessageToByteEncoder {
|
||||
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||
super.write(ctx, msg, promise);
|
||||
}
|
||||
}
|
||||
|
@ -24,85 +24,38 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.handler.serverside;
|
||||
|
||||
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
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 us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
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 ByteToMessageDecoder minecraftDecoder;
|
||||
private final UserConnection info;
|
||||
private final UserConnection user;
|
||||
|
||||
public FabricDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
|
||||
this.info = info;
|
||||
this.minecraftDecoder = minecraftDecoder;
|
||||
public FabricDecodeHandler(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> list) throws Exception {
|
||||
// use transformers
|
||||
if (bytebuf.readableBytes() > 0) {
|
||||
// Ignore if pending disconnect
|
||||
if (info.isPendingDisconnect()) {
|
||||
return;
|
||||
}
|
||||
// Increment received
|
||||
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 {
|
||||
if (id == PacketWrapper.PASSTHROUGH_ID) {
|
||||
newPacket.writeBytes(bytebuf);
|
||||
} 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 {
|
||||
if (info.isActive()) {
|
||||
bytebuf.release();
|
||||
}
|
||||
}
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
if (CommonTransformer.preServerboundCheck(user)) return;
|
||||
if (!CommonTransformer.willTransformPacket(user)) {
|
||||
out.add(in.readRetainedSlice(in.readableBytes()));
|
||||
return;
|
||||
}
|
||||
ByteBuf draft = ctx.alloc().buffer().writeBytes(in);
|
||||
try {
|
||||
CommonTransformer.transformServerbound(draft, user, ignored -> CancelException.CACHED);
|
||||
out.add(draft.retain());
|
||||
} finally {
|
||||
draft.release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,8 +66,9 @@ public class FabricDecodeHandler extends ByteToMessageDecoder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
ProtocolInfo pi = info.get(ProtocolInfo.class);
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelInactive(ctx); // May call decode
|
||||
ProtocolInfo pi = user.get(ProtocolInfo.class);
|
||||
if (pi.getUuid() != null) {
|
||||
Via.getManager().removePortedClient(pi.getUuid());
|
||||
}
|
||||
|
@ -24,66 +24,36 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.handler.serverside;
|
||||
|
||||
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
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 us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
public class FabricEncodeHandler extends MessageToByteEncoder {
|
||||
// https://github.com/MylesIsCool/ViaVersion/blob/master/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeEncodeHandler.java
|
||||
private final UserConnection info;
|
||||
private final MessageToByteEncoder minecraftEncoder;
|
||||
public class FabricEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
|
||||
private final UserConnection user;
|
||||
|
||||
public FabricEncodeHandler(UserConnection info, MessageToByteEncoder minecraftEncoder) {
|
||||
this.info = info;
|
||||
this.minecraftEncoder = minecraftEncoder;
|
||||
public FabricEncodeHandler(UserConnection user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception {
|
||||
// handle the packet type
|
||||
if (!(o instanceof ByteBuf)) {
|
||||
// call minecraft encoder
|
||||
try {
|
||||
PipelineUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof Exception) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
}
|
||||
protected void encode(final ChannelHandlerContext ctx, ByteBuf in, final List<Object> out) throws Exception {
|
||||
CommonTransformer.preClientbound(user);
|
||||
if (!CommonTransformer.willTransformPacket(user)) {
|
||||
out.add(in.readRetainedSlice(in.readableBytes()));
|
||||
return;
|
||||
}
|
||||
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 {
|
||||
oldPacket.release();
|
||||
}
|
||||
ByteBuf draft = ctx.alloc().buffer().writeBytes(in);
|
||||
try {
|
||||
CommonTransformer.transformClientbound(draft, user, ignored -> CancelException.CACHED);
|
||||
out.add(draft.retain());
|
||||
} finally {
|
||||
draft.release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,4 +62,4 @@ public class FabricEncodeHandler extends MessageToByteEncoder {
|
||||
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@
|
||||
|
||||
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 org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@ -40,11 +43,33 @@ public class MixinClientConnection {
|
||||
value = "INVOKE",
|
||||
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)) {
|
||||
logger.info(message, t);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,11 @@
|
||||
|
||||
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.FabricEncodeHandler;
|
||||
import io.netty.channel.Channel;
|
||||
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.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -45,11 +44,8 @@ public class MixinServerNetworkIoChInit {
|
||||
UserConnection user = new UserConnection(channel);
|
||||
new ProtocolPipeline(user);
|
||||
|
||||
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder");
|
||||
ByteToMessageDecoder oldDecoder = (ByteToMessageDecoder) channel.pipeline().get("decoder");
|
||||
|
||||
channel.pipeline().replace("encoder", "encoder", new FabricEncodeHandler(user, oldEncoder));
|
||||
channel.pipeline().replace("decoder", "decoder", new FabricDecodeHandler(user, oldDecoder));
|
||||
channel.pipeline().addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user));
|
||||
channel.pipeline().addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,12 @@
|
||||
|
||||
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.VREncodeHandler;
|
||||
import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection;
|
||||
import io.netty.channel.Channel;
|
||||
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.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -46,11 +45,8 @@ public class MixinClientConnectionChInit {
|
||||
UserConnection user = new VRClientSideUserConnection(channel);
|
||||
new ProtocolPipeline(user);
|
||||
|
||||
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder");
|
||||
ByteToMessageDecoder oldDecoder = (ByteToMessageDecoder) channel.pipeline().get("decoder");
|
||||
|
||||
channel.pipeline().replace("encoder", "encoder", new VREncodeHandler(user, oldEncoder));
|
||||
channel.pipeline().replace("decoder", "decoder", new VRDecodeHandler(user, oldDecoder));
|
||||
channel.pipeline().addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new VREncodeHandler(user));
|
||||
channel.pipeline().addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new VRDecodeHandler(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,14 +24,11 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.platform;
|
||||
|
||||
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
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 VRClientSideUserConnection(Channel socketChannel) {
|
||||
@ -41,46 +38,28 @@ public class VRClientSideUserConnection extends UserConnection {
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(final ByteBuf packet, boolean currentThread) {
|
||||
ByteBuf copy = packet.alloc().buffer();
|
||||
try {
|
||||
Type.VAR_INT.write(copy, PacketWrapper.PASSTHROUGH_ID);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
copy.writeBytes(packet);
|
||||
packet.release();
|
||||
final Channel channel = this.getChannel();
|
||||
Runnable act = () -> getChannel().pipeline().context(CommonTransformer.HANDLER_DECODER_NAME)
|
||||
.fireChannelRead(packet);
|
||||
if (currentThread) {
|
||||
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||
act.run();
|
||||
} else {
|
||||
channel.eventLoop().submit(() -> {
|
||||
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||
});
|
||||
getChannel().eventLoop().execute(act);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelFuture sendRawPacketFuture(ByteBuf packet) {
|
||||
ByteBuf copy = packet.alloc().buffer();
|
||||
try {
|
||||
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();
|
||||
getChannel().pipeline().context(CommonTransformer.HANDLER_DECODER_NAME).fireChannelRead(packet);
|
||||
return getChannel().newSucceededFuture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawPacketToServer(ByteBuf packet, boolean currentThread) {
|
||||
if (currentThread) {
|
||||
getChannel().pipeline().context("encoder").writeAndFlush(packet);
|
||||
getChannel().pipeline().context(CommonTransformer.HANDLER_ENCODER_NAME).writeAndFlush(packet);
|
||||
} else {
|
||||
getChannel().eventLoop().submit(() -> {
|
||||
getChannel().pipeline().context("encoder").writeAndFlush(packet);
|
||||
getChannel().pipeline().context(CommonTransformer.HANDLER_ENCODER_NAME).writeAndFlush(packet);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.platform;
|
||||
|
||||
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.SharedConstants;
|
||||
@ -52,12 +53,12 @@ public class VRInjector implements ViaInjector {
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
return "encoder";
|
||||
return CommonTransformer.HANDLER_ENCODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
return "decoder";
|
||||
return CommonTransformer.HANDLER_DECODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
package com.github.creeper123123321.viafabric.platform;
|
||||
|
||||
import us.myles.ViaVersion.api.ViaVersionConfig;
|
||||
import us.myles.ViaVersion.AbstractViaConfig;
|
||||
import us.myles.ViaVersion.util.Config;
|
||||
|
||||
import java.io.File;
|
||||
@ -33,7 +33,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class VRViaConfig extends Config implements ViaVersionConfig {
|
||||
public class VRViaConfig extends AbstractViaConfig {
|
||||
// Based on Sponge ViaVersion
|
||||
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",
|
||||
@ -61,117 +61,11 @@ public class VRViaConfig extends Config implements ViaVersionConfig {
|
||||
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
|
||||
public boolean isAntiXRay() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSendSupportedVersions() {
|
||||
return getBoolean("send-supported-versions", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStimulatePlayerTick() {
|
||||
return getBoolean("simulate-pt", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemCache() {
|
||||
return false;
|
||||
@ -182,111 +76,16 @@ public class VRViaConfig extends Config implements ViaVersionConfig {
|
||||
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
|
||||
public boolean is1_12QuickMoveActionFix() {
|
||||
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
|
||||
public String getBlockConnectionMethod() {
|
||||
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
|
||||
public boolean is1_9HitboxFix() {
|
||||
return false;
|
||||
@ -296,19 +95,4 @@ public class VRViaConfig extends Config implements ViaVersionConfig {
|
||||
public boolean is1_14HitboxFix() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
"issues": "https://github.com/ViaVersion/ViaFabric/issues",
|
||||
"sources": "https://github.com/ViaVersion/ViaFabric"
|
||||
},
|
||||
"icon": "assets/viaversion/textures/logo.png",
|
||||
"environment": "*",
|
||||
"authors": [
|
||||
"creeper123123321"
|
||||
@ -27,7 +26,8 @@
|
||||
"fabricloader": ">=0.4.0",
|
||||
"fabric-textures-v0": "*",
|
||||
"fabric-resource-loader-v0": "*",
|
||||
"fabric-commands-v0": "*"
|
||||
"fabric-commands-v0": "*",
|
||||
"viaversion": ">=3.0.0-SNAPSHOT"
|
||||
},
|
||||
"recommends": {
|
||||
"cotton-client-commands": "*"
|
||||
|
@ -3,8 +3,8 @@
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"package": "com.github.creeper123123321.viafabric.mixin",
|
||||
"mixins": [
|
||||
"MixinServerNetworkIoChInit",
|
||||
"MixinClientConnection"
|
||||
"MixinClientConnection",
|
||||
"MixinServerNetworkIoChInit"
|
||||
],
|
||||
"client": [
|
||||
"client.MixinClientConnectionChInit",
|
||||
|
Loading…
Reference in New Issue
Block a user