mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-12-21 16:17:37 +01:00
versionprovider, license, fix userconnection#sendRaw
This commit is contained in:
parent
83f7feb4e1
commit
53be441e01
7
LICENSE
Normal file
7
LICENSE
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright 2018 creeper123123321
|
||||
|
||||
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.
|
@ -17,5 +17,6 @@ public class ViaRift implements InitializationListener {
|
||||
Mixins.addConfiguration("mixins.viarift.main.json");
|
||||
Via.init(ViaManager.builder().injector(new VRInjector()).loader(new VRLoader()).platform(new VRPlatform()).build());
|
||||
Via.getManager().init();
|
||||
//Via.getManager().setDebug(true);
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,11 @@ public class VROutHandler extends MessageToByteEncoder {
|
||||
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
|
||||
try {
|
||||
PipelineUtil.callEncode(this.minecraftEncoder, ctx, msg, out);
|
||||
PipelineUtil.callEncode(this.minecraftEncoder, ctx, msg, pre);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof Exception) {
|
||||
throw (Exception) e.getCause();
|
||||
@ -36,7 +38,7 @@ public class VROutHandler extends MessageToByteEncoder {
|
||||
}
|
||||
|
||||
// use transformers
|
||||
if (out.readableBytes() > 0) {
|
||||
if (pre.readableBytes() > 0) {
|
||||
// Ignore if pending disconnect
|
||||
if (user.isPendingDisconnect()) {
|
||||
return;
|
||||
@ -51,16 +53,16 @@ public class VROutHandler extends MessageToByteEncoder {
|
||||
|
||||
if (user.isActive()) {
|
||||
// Handle ID
|
||||
int id = Type.VAR_INT.read(out);
|
||||
int id = Type.VAR_INT.read(pre);
|
||||
// Transform
|
||||
ByteBuf oldPacket = out.copy();
|
||||
out.clear();
|
||||
ByteBuf oldPacket = pre.copy();
|
||||
try {
|
||||
if (id != PacketWrapper.PASSTHROUGH_ID) {
|
||||
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, user);
|
||||
ProtocolInfo protInfo = user.get(ProtocolInfo.class);
|
||||
protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper);
|
||||
wrapper.writeToBuffer(out);
|
||||
pre.clear();
|
||||
wrapper.writeToBuffer(pre);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof CancelException))
|
||||
@ -71,6 +73,9 @@ public class VROutHandler extends MessageToByteEncoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.writeBytes(pre);
|
||||
pre.release();
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.github.creeper123123321.viarift.mixin;
|
||||
|
||||
import com.github.creeper123123321.viarift.handler.VRInHandler;
|
||||
import com.github.creeper123123321.viarift.handler.VROutHandler;
|
||||
import com.github.creeper123123321.viarift.platform.VRUserConnection;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
@ -20,7 +21,7 @@ public class MixinNetworkManagerClientChInit {
|
||||
private void onInitChannel(Channel channel, CallbackInfo ci) {
|
||||
System.out.println(channel);
|
||||
if (channel instanceof SocketChannel) {
|
||||
UserConnection user = new UserConnection((SocketChannel) channel);
|
||||
UserConnection user = new VRUserConnection((SocketChannel) channel);
|
||||
new ProtocolPipeline(user);
|
||||
|
||||
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder");
|
||||
|
@ -21,11 +21,11 @@ public class VRInjector implements ViaInjector {
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
return "decoder";
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
return "encoder";
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.github.creeper123123321.viarift.platform;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
|
||||
|
||||
public class VRUserConnection extends UserConnection {
|
||||
public VRUserConnection(SocketChannel socketChannel) {
|
||||
super(socketChannel);
|
||||
}
|
||||
// Based on https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/reflection/Injector.java
|
||||
|
||||
@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();
|
||||
if (currentThread) {
|
||||
try {
|
||||
channel.pipeline().context("decoder").fireChannelRead(copy);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
channel.eventLoop().submit(() -> {
|
||||
try {
|
||||
channel.pipeline().context("decoder").fireChannelRead(copy);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
try {
|
||||
channel.pipeline().context("decoder").fireChannelRead(copy);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.github.creeper123123321.viarift.provider;
|
||||
|
||||
import com.github.creeper123123321.viarift.ViaRift;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||
|
||||
public class VRVersionProvider extends VersionProvider {
|
||||
@Override
|
||||
public int getServerProtocol(UserConnection connection) throws Exception {
|
||||
return ViaRift.fakeServerVersion;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user