Fix PacketWrapper sending and implement Movement Transmitter for Bungee

This commit is contained in:
Myles 2016-09-29 21:29:58 +01:00
parent 31c9332e56
commit 10fc8f846d
9 changed files with 64 additions and 7 deletions

View File

@ -178,6 +178,11 @@ public class BukkitViaInjector implements ViaInjector {
return "encoder"; return "encoder";
} }
@Override
public String getDecoderName() {
return "decoder";
}
public static Object getServerConnection() throws Exception { public static Object getServerConnection() throws Exception {
Class<?> serverClazz = NMSUtil.nms("MinecraftServer"); Class<?> serverClazz = NMSUtil.nms("MinecraftServer");
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer"); Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");

View File

@ -116,7 +116,7 @@ public class BungeeConfigAPI implements ViaVersionConfig, ConfigurationProvider
@Override @Override
public boolean isStimulatePlayerTick() { public boolean isStimulatePlayerTick() {
return false; return true;
} }
@Override @Override

View File

@ -50,4 +50,9 @@ public class BungeeViaInjector implements ViaInjector {
public String getEncoderName() { public String getEncoderName() {
return "via-encoder"; return "via-encoder";
} }
@Override
public String getDecoderName() {
return "via-decoder";
}
} }

View File

@ -1,6 +1,9 @@
package us.myles.ViaVersion.bungee.platform; package us.myles.ViaVersion.bungee.platform;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
public class BungeeViaLoader implements ViaPlatformLoader { public class BungeeViaLoader implements ViaPlatformLoader {
@Override @Override
@ -8,6 +11,6 @@ public class BungeeViaLoader implements ViaPlatformLoader {
// TODO: Movement Transmitter // TODO: Movement Transmitter
// TODO: Config // TODO: Config
// TODO: Platform specific commands // TODO: Platform specific commands
// TODO: Get rid of bungeecord-proxy just use reflection Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
} }
} }

View File

@ -0,0 +1,34 @@
package us.myles.ViaVersion.bungee.providers;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
public class BungeeMovementTransmitter extends MovementTransmitterProvider {
@Override
public Object getFlyingPacket() {
return null;
}
@Override
public Object getGroundPacket() {
return null;
}
public void sendPlayer(UserConnection userConnection) {
if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) {
PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection);
wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround());
try {
wrapper.sendToServer();
} catch (Exception e) {
e.printStackTrace();
}
// PlayerPackets will increment idle
}
}
}

View File

@ -455,19 +455,16 @@ public class PacketWrapper {
/** /**
* Send the current packet to the server. * Send the current packet to the server.
* (Ensure the ID is suitable for the server version) * (Ensure the ID is suitable for viaversion)
* *
* @throws Exception If it failed to write * @throws Exception If it failed to write
*/ */
public void sendToServer() throws Exception { public void sendToServer() throws Exception {
// TODO: Fix for bungee
if (!isCancelled()) { if (!isCancelled()) {
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer(); ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
Type.VAR_INT.write(output, PacketWrapper.PASSTHROUGH_ID); // Pass through
writeToBuffer(output); writeToBuffer(output);
PipelineUtil.getContextBefore("decompress", user().getChannel().pipeline()).fireChannelRead(output); user().getChannel().pipeline().context(Via.getManager().getInjector().getDecoderName()).fireChannelRead(output);
} }
} }

View File

@ -29,4 +29,11 @@ public interface ViaInjector {
* @return The name * @return The name
*/ */
String getEncoderName(); String getEncoderName();
/**
* Get the name of the decoder for then netty pipeline for this platform.
*
* @return The name
*/
String getDecoderName();
} }

View File

@ -95,6 +95,7 @@ public class PipelineUtil {
boolean mark = false; boolean mark = false;
for (String s : pipeline.names()) { for (String s : pipeline.names()) {
if (mark) { if (mark) {
System.out.println("Context before: " + s);
return pipeline.context(pipeline.get(s)); return pipeline.context(pipeline.get(s));
} }
if (s.equalsIgnoreCase(name)) if (s.equalsIgnoreCase(name))

View File

@ -137,6 +137,11 @@ public class SpongeViaInjector implements ViaInjector {
return "encoder"; return "encoder";
} }
@Override
public String getDecoderName() {
return "decoder";
}
public static Object getServerConnection() throws Exception { public static Object getServerConnection() throws Exception {
Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer"); Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer");
Object server = getServer(); Object server = getServer();