mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-21 11:35:16 +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");
|
Mixins.addConfiguration("mixins.viarift.main.json");
|
||||||
Via.init(ViaManager.builder().injector(new VRInjector()).loader(new VRLoader()).platform(new VRPlatform()).build());
|
Via.init(ViaManager.builder().injector(new VRInjector()).loader(new VRLoader()).platform(new VRPlatform()).build());
|
||||||
Via.getManager().init();
|
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 {
|
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
|
||||||
// Based on Sponge ViaVersion decoder code
|
// Based on Sponge ViaVersion decoder code
|
||||||
|
|
||||||
|
ByteBuf pre = out.alloc().buffer();
|
||||||
|
|
||||||
// call minecraft encoder
|
// call minecraft encoder
|
||||||
try {
|
try {
|
||||||
PipelineUtil.callEncode(this.minecraftEncoder, ctx, msg, out);
|
PipelineUtil.callEncode(this.minecraftEncoder, ctx, msg, pre);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
if (e.getCause() instanceof Exception) {
|
if (e.getCause() instanceof Exception) {
|
||||||
throw (Exception) e.getCause();
|
throw (Exception) e.getCause();
|
||||||
@ -36,7 +38,7 @@ public class VROutHandler extends MessageToByteEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use transformers
|
// use transformers
|
||||||
if (out.readableBytes() > 0) {
|
if (pre.readableBytes() > 0) {
|
||||||
// Ignore if pending disconnect
|
// Ignore if pending disconnect
|
||||||
if (user.isPendingDisconnect()) {
|
if (user.isPendingDisconnect()) {
|
||||||
return;
|
return;
|
||||||
@ -51,16 +53,16 @@ public class VROutHandler extends MessageToByteEncoder {
|
|||||||
|
|
||||||
if (user.isActive()) {
|
if (user.isActive()) {
|
||||||
// Handle ID
|
// Handle ID
|
||||||
int id = Type.VAR_INT.read(out);
|
int id = Type.VAR_INT.read(pre);
|
||||||
// Transform
|
// Transform
|
||||||
ByteBuf oldPacket = out.copy();
|
ByteBuf oldPacket = pre.copy();
|
||||||
out.clear();
|
|
||||||
try {
|
try {
|
||||||
if (id != PacketWrapper.PASSTHROUGH_ID) {
|
if (id != PacketWrapper.PASSTHROUGH_ID) {
|
||||||
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, user);
|
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, 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(out);
|
pre.clear();
|
||||||
|
wrapper.writeToBuffer(pre);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (!(e instanceof CancelException))
|
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.VRInHandler;
|
||||||
import com.github.creeper123123321.viarift.handler.VROutHandler;
|
import com.github.creeper123123321.viarift.handler.VROutHandler;
|
||||||
|
import com.github.creeper123123321.viarift.platform.VRUserConnection;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
@ -20,7 +21,7 @@ public class MixinNetworkManagerClientChInit {
|
|||||||
private void onInitChannel(Channel channel, CallbackInfo ci) {
|
private void onInitChannel(Channel channel, CallbackInfo ci) {
|
||||||
System.out.println(channel);
|
System.out.println(channel);
|
||||||
if (channel instanceof SocketChannel) {
|
if (channel instanceof SocketChannel) {
|
||||||
UserConnection user = new UserConnection((SocketChannel) channel);
|
UserConnection user = new VRUserConnection((SocketChannel) channel);
|
||||||
new ProtocolPipeline(user);
|
new ProtocolPipeline(user);
|
||||||
|
|
||||||
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder");
|
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder");
|
||||||
|
@ -21,11 +21,11 @@ public class VRInjector implements ViaInjector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEncoderName() {
|
public String getEncoderName() {
|
||||||
return "decoder";
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDecoderName() {
|
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