geforkt von Mirrors/Velocity
Clarity improvements.
Dieser Commit ist enthalten in:
Ursprung
5b4992fd9c
Commit
566a306d18
@ -264,8 +264,6 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeString(buf, "plugins");
|
|
||||||
|
|
||||||
StringBuilder pluginsString = new StringBuilder();
|
StringBuilder pluginsString = new StringBuilder();
|
||||||
pluginsString.append(serverVersion).append(':').append(' ');
|
pluginsString.append(serverVersion).append(':').append(' ');
|
||||||
Iterator<QueryResponse.PluginInformation> iterator = plugins.iterator();
|
Iterator<QueryResponse.PluginInformation> iterator = plugins.iterator();
|
||||||
@ -279,7 +277,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeString(buf, pluginsString.toString());
|
write("plugins", pluginsString.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,6 @@ public class LegacyPingEncoder extends MessageToByteEncoder<LegacyDisconnect> {
|
|||||||
|
|
||||||
private static void writeLegacyString(ByteBuf out, String string) {
|
private static void writeLegacyString(ByteBuf out, String string) {
|
||||||
out.writeShort(string.length());
|
out.writeShort(string.length());
|
||||||
out.writeBytes(string.getBytes(StandardCharsets.UTF_16BE));
|
out.writeCharSequence(string, StandardCharsets.UTF_16BE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.velocitypowered.proxy.protocol.netty;
|
package com.velocitypowered.proxy.protocol.netty;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import static com.velocitypowered.proxy.protocol.util.NettyPreconditions.checkFrame;
|
||||||
|
|
||||||
import com.velocitypowered.natives.compression.VelocityCompressor;
|
import com.velocitypowered.natives.compression.VelocityCompressor;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
@ -22,23 +23,24 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
|
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
|
||||||
int uncompressedSize = ProtocolUtils.readVarInt(msg);
|
int expectedUncompressedSize = ProtocolUtils.readVarInt(msg);
|
||||||
if (uncompressedSize == 0) {
|
if (expectedUncompressedSize == 0) {
|
||||||
// Strip the now-useless uncompressed size, this message is already uncompressed.
|
// Strip the now-useless uncompressed size, this message is already uncompressed.
|
||||||
out.add(msg.retainedSlice());
|
out.add(msg.retainedSlice());
|
||||||
msg.skipBytes(msg.readableBytes());
|
msg.skipBytes(msg.readableBytes());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Preconditions.checkState(uncompressedSize >= threshold,
|
checkFrame(expectedUncompressedSize >= threshold,
|
||||||
"Uncompressed size %s is greater than threshold %s",
|
"Uncompressed size %s is greater than threshold %s",
|
||||||
uncompressedSize, threshold);
|
expectedUncompressedSize, threshold);
|
||||||
ByteBuf uncompressed = ctx.alloc()
|
ByteBuf uncompressed = ctx.alloc()
|
||||||
.buffer(Math.min(uncompressedSize, MAXIMUM_INITIAL_BUFFER_SIZE));
|
.buffer(Math.min(expectedUncompressedSize, MAXIMUM_INITIAL_BUFFER_SIZE));
|
||||||
try {
|
try {
|
||||||
compressor.inflate(msg, uncompressed);
|
compressor.inflate(msg, uncompressed);
|
||||||
Preconditions.checkState(uncompressedSize == uncompressed.readableBytes(),
|
checkFrame(expectedUncompressedSize == uncompressed.readableBytes(),
|
||||||
"Mismatched compression sizes");
|
"Mismatched compression sizes (got %s, expected %s)",
|
||||||
|
uncompressed.readableBytes(), expectedUncompressedSize);
|
||||||
out.add(uncompressed);
|
out.add(uncompressed);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
uncompressed.release();
|
uncompressed.release();
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.velocitypowered.proxy.protocol.util;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import io.netty.handler.codec.CorruptedFrameException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends {@link com.google.common.base.Preconditions} for Netty's {@link CorruptedFrameException}.
|
||||||
|
*/
|
||||||
|
public class NettyPreconditions {
|
||||||
|
private NettyPreconditions() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws {@link CorruptedFrameException} if {@code b} is false.
|
||||||
|
* @param b the expression to check
|
||||||
|
* @param message the message to include in the thrown {@link CorruptedFrameException}
|
||||||
|
*/
|
||||||
|
public static void checkFrame(boolean b, String message) {
|
||||||
|
if (!b) {
|
||||||
|
throw new CorruptedFrameException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws {@link CorruptedFrameException} if {@code b} is false.
|
||||||
|
* @param b the expression to check
|
||||||
|
* @param message the message to include in the thrown {@link CorruptedFrameException}, formatted
|
||||||
|
* like {@link com.google.common.base.Preconditions#checkArgument(boolean)} and
|
||||||
|
* friends
|
||||||
|
* @param arg1 the first argument to format the message with
|
||||||
|
*/
|
||||||
|
public static void checkFrame(boolean b, String message, Object arg1) {
|
||||||
|
if (!b) {
|
||||||
|
throw new CorruptedFrameException(Strings.lenientFormat(message, arg1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws {@link CorruptedFrameException} if {@code b} is false.
|
||||||
|
* @param b the expression to check
|
||||||
|
* @param message the message to include in the thrown {@link CorruptedFrameException}, formatted
|
||||||
|
* like {@link com.google.common.base.Preconditions#checkArgument(boolean)} and
|
||||||
|
* friends
|
||||||
|
* @param arg1 the first argument to format the message with
|
||||||
|
* @param arg2 the second argument to format the message with
|
||||||
|
*/
|
||||||
|
public static void checkFrame(boolean b, String message, Object arg1, Object arg2) {
|
||||||
|
if (!b) {
|
||||||
|
throw new CorruptedFrameException(Strings.lenientFormat(message, arg1, arg2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws {@link CorruptedFrameException} if {@code b} is false.
|
||||||
|
* @param b the expression to check
|
||||||
|
* @param message the message to include in the thrown {@link CorruptedFrameException}, formatted
|
||||||
|
* like {@link com.google.common.base.Preconditions#checkArgument(boolean)} and
|
||||||
|
* friends
|
||||||
|
* @param args the arguments to format the message with-
|
||||||
|
*/
|
||||||
|
public static void checkFrame(boolean b, String message, Object... args) {
|
||||||
|
if (!b) {
|
||||||
|
throw new CorruptedFrameException(Strings.lenientFormat(message, args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren