Merge pull request #1302 from creeper123123321/master

Workaround for packet order issue in neighbour chunk updates
This commit is contained in:
Myles 2019-04-27 18:43:56 +01:00 committed by GitHub
commit 643e3dc2da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder; import io.netty.handler.codec.MessageToMessageEncoder;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
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.api.type.Type;
import us.myles.ViaVersion.bungee.util.BungeePipelineUtil; import us.myles.ViaVersion.bungee.util.BungeePipelineUtil;
@ -28,7 +29,7 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
@Override @Override
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception { protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (bytebuf.readableBytes() == 0) { if (bytebuf.readableBytes() == 0) {
throw new CancelException(); throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
} }
boolean needsCompress = false; boolean needsCompress = false;
if (!handledCompression) { if (!handledCompression) {

View File

@ -167,8 +167,9 @@ public abstract class Protocol {
// remap // remap
if (protocolPacket.getRemapper() != null) { if (protocolPacket.getRemapper() != null) {
protocolPacket.getRemapper().remap(packetWrapper); protocolPacket.getRemapper().remap(packetWrapper);
if (packetWrapper.isCancelled()) if (packetWrapper.isCancelled()) {
throw new CancelException(); throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
}
} }
} }

View File

@ -1,4 +1,29 @@
package us.myles.ViaVersion.exception; package us.myles.ViaVersion.exception;
public class CancelException extends Exception { public class CancelException extends Exception {
public static final CancelException CACHED = new CancelException("Cached - Enable /viaver debug to not use cached exception") {
@Override
public synchronized Throwable fillInStackTrace() {
return this;
}
};
public CancelException() {
}
public CancelException(String message) {
super(message);
}
public CancelException(String message, Throwable cause) {
super(message, cause);
}
public CancelException(Throwable cause) {
super(cause);
}
public CancelException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
} }

View File

@ -118,7 +118,7 @@ public class ConnectionData {
wrapper.write(Type.INT, chunkZ + chunkDeltaZ); wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(new BlockChangeRecord[0])); wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(new BlockChangeRecord[0]));
try { try {
wrapper.send(Protocol1_13To1_12_2.class); wrapper.send(Protocol1_13To1_12_2.class, true, true);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -366,10 +366,6 @@ public class WorldPackets {
} }
} }
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.connectBlocks(wrapper.user(), chunk);
}
// Rewrite biome id 255 to plains // Rewrite biome id 255 to plains
if (chunk.isBiomeData()) { if (chunk.isBiomeData()) {
int latestBiomeWarn = Integer.MIN_VALUE; int latestBiomeWarn = Integer.MIN_VALUE;
@ -405,6 +401,18 @@ public class WorldPackets {
chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId); chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId);
} }
} }
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.connectBlocks(wrapper.user(), chunk);
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class, true, true);
wrapper.cancel();
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue;
ConnectionData.updateChunkSectionNeighbours(wrapper.user(), chunk.getX(), chunk.getZ(), i);
}
}
} }
}); });
} }

View File

@ -4,6 +4,7 @@ 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.MessageToByteEncoder;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
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.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
@ -37,7 +38,7 @@ public class SpongeEncodeHandler extends MessageToByteEncoder {
} }
} }
if (bytebuf.readableBytes() == 0) { if (bytebuf.readableBytes() == 0) {
throw new CancelException(); throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
} }
// Increment sent // Increment sent
info.incrementSent(); info.incrementSent();

View File

@ -9,6 +9,7 @@ import io.netty.handler.codec.MessageToMessageEncoder;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
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.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
@ -28,7 +29,7 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
@Override @Override
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception { protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (bytebuf.readableBytes() == 0) { if (bytebuf.readableBytes() == 0) {
throw new CancelException(); throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
} }
boolean needsCompress = false; boolean needsCompress = false;
if (!handledCompression if (!handledCompression