Improve legacy client ping support.
This commit is contained in:
@@ -14,25 +14,26 @@ public class LegacyDecoder extends ByteToMessageDecoder
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
|
||||
{
|
||||
if ( in.readableBytes() < 3 )
|
||||
if ( !in.isReadable() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
int i = in.readerIndex();
|
||||
short b1 = in.getUnsignedByte( i++ );
|
||||
short b2 = in.getUnsignedByte( i++ );
|
||||
short b3 = in.getUnsignedByte( i++ );
|
||||
|
||||
if ( b1 == 0xFE && b2 == 0x01 && b3 == 0xFA )
|
||||
in.markReaderIndex();
|
||||
short packetID = in.readUnsignedByte();
|
||||
|
||||
if ( packetID == 0xFE )
|
||||
{
|
||||
out.add( new PacketWrapper( new LegacyPing(), Unpooled.EMPTY_BUFFER ) );
|
||||
out.add( new PacketWrapper( new LegacyPing( in.isReadable() && in.readUnsignedByte() == 0x01 ), Unpooled.EMPTY_BUFFER ) );
|
||||
return;
|
||||
}
|
||||
if ( b1 == 0x02 && b2 >= 60 && b2 <= 78 )
|
||||
} else if ( packetID == 0x02 && in.isReadable() )
|
||||
{
|
||||
in.skipBytes( in.readableBytes() );
|
||||
out.add( new PacketWrapper( new LegacyHandshake(), Unpooled.EMPTY_BUFFER ) );
|
||||
return;
|
||||
}
|
||||
|
||||
in.resetReaderIndex();
|
||||
ctx.pipeline().remove( this );
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,19 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class LegacyPing extends DefinedPacket
|
||||
{
|
||||
private final boolean v1_5;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
@@ -24,23 +32,4 @@ public class LegacyPing extends DefinedPacket
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
throw new UnsupportedOperationException( "Not supported yet." ); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
throw new UnsupportedOperationException( "Not supported yet." ); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
throw new UnsupportedOperationException( "Not supported yet." ); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user