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

View File

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

View File

@ -1,4 +1,29 @@
package us.myles.ViaVersion.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.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(new BlockChangeRecord[0]));
try {
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.send(Protocol1_13To1_12_2.class, true, true);
} catch (Exception e) {
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
if (chunk.isBiomeData()) {
int latestBiomeWarn = Integer.MIN_VALUE;
@ -405,6 +401,18 @@ public class WorldPackets {
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.handler.codec.MessageToByteEncoder;
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;
@ -37,7 +38,7 @@ public class SpongeEncodeHandler extends MessageToByteEncoder {
}
}
if (bytebuf.readableBytes() == 0) {
throw new CancelException();
throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
}
// Increment sent
info.incrementSent();

View File

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