Log the bad packet in a prettier way. Also, don't show the authlib debug data in the log file.
This commit is contained in:
parent
cb47b4ac46
commit
d92176fe8c
|
@ -179,4 +179,74 @@ public class ByteBufUtils {
|
|||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getContentDump(ByteBuf buffer)
|
||||
{
|
||||
int currentLength = buffer.readableBytes();
|
||||
StringBuffer returnString = new StringBuffer((currentLength * 3) + // The
|
||||
// hex
|
||||
(currentLength) + // The ascii
|
||||
(currentLength / 4) + // The tabs/\n's
|
||||
30); // The text
|
||||
|
||||
// returnString.append("Buffer contents:\n");
|
||||
int i, j; // Loop variables
|
||||
for (i = 0; i < currentLength; i++)
|
||||
{
|
||||
if ((i != 0) && (i % 16 == 0))
|
||||
{
|
||||
// If it's a multiple of 16 and i isn't null, show the ascii
|
||||
returnString.append('\t');
|
||||
for (j = i - 16; j < i; j++)
|
||||
{
|
||||
if (buffer.getByte(j) < 0x20 || buffer.getByte(j) > 0x7F)
|
||||
returnString.append('.');
|
||||
else
|
||||
returnString.append((char) buffer.getByte(j));
|
||||
}
|
||||
// Add a linefeed after the string
|
||||
returnString.append("\n");
|
||||
}
|
||||
|
||||
returnString.append(Integer.toString((buffer.getByte(i) & 0xF0) >> 4, 16) + Integer.toString((buffer.getByte(i) & 0x0F) >> 0, 16));
|
||||
returnString.append(' ');
|
||||
}
|
||||
|
||||
// Add padding spaces if it's not a multiple of 16
|
||||
if (i != 0 && i % 16 != 0)
|
||||
{
|
||||
for (j = 0; j < ((16 - (i % 16)) * 3); j++)
|
||||
{
|
||||
returnString.append(' ');
|
||||
}
|
||||
}
|
||||
// Add the tab for alignment
|
||||
returnString.append('\t');
|
||||
|
||||
// Add final chararacters at right, after padding
|
||||
|
||||
// If it was at the end of a line, print out the full line
|
||||
if (i > 0 && (i % 16) == 0)
|
||||
{
|
||||
j = i - 16;
|
||||
} else
|
||||
{
|
||||
j = (i - (i % 16));
|
||||
}
|
||||
|
||||
for (; i >= 0 && j < i; j++)
|
||||
{
|
||||
if (buffer.getByte(j) < 0x20 || buffer.getByte(j) > 0x7F)
|
||||
returnString.append('.');
|
||||
else
|
||||
returnString.append((char) buffer.getByte(j));
|
||||
}
|
||||
|
||||
// Finally, tidy it all up with a newline
|
||||
returnString.append('\n');
|
||||
returnString.append("Length: " + currentLength);
|
||||
|
||||
return returnString.toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package cpw.mods.fml.common.network.internal;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec;
|
||||
import cpw.mods.fml.common.network.FMLNetworkException;
|
||||
|
||||
|
@ -33,9 +34,10 @@ public class FMLRuntimeCodec extends FMLIndexedMessageToMessageCodec<FMLMessage>
|
|||
if (msg.payload().getByte(0) == 0 && msg.payload().readableBytes() > 2)
|
||||
{
|
||||
FMLLog.severe("The connection appears to have sent an invalid FML packet of type 0, this is likely because it think's it's talking to 1.6.4 FML");
|
||||
byte[] badData = new byte[msg.payload().readableBytes()];
|
||||
msg.payload().getBytes(0, badData);
|
||||
FMLLog.info("Bad data : %s",Bytes.asList(badData));
|
||||
FMLLog.info("Bad data :");
|
||||
for (String l : Splitter.on('\n').split(ByteBufUtils.getContentDump(msg.payload()))) {
|
||||
FMLLog.info("\t%s",l);
|
||||
}
|
||||
throw new FMLNetworkException("Invalid FML packet");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,11 @@
|
|||
</RollingRandomAccessFile>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger level="info" name="com.mojang" additivity="false">
|
||||
<AppenderRef ref="SysOut" level="INFO"/>
|
||||
<AppenderRef ref="File" />
|
||||
<AppenderRef ref="ServerGuiConsole" level="INFO"/>
|
||||
</Logger>
|
||||
<Logger level="info" name="net.minecraft" additivity="false">
|
||||
<filters>
|
||||
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL" />
|
||||
|
|
Loading…
Reference in New Issue