Skip to content

Commit

Permalink
Fix possible NPE when trying to get encoder/decoder protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
BoomEaro committed Oct 28, 2024
1 parent 4886c4b commit d907e27
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/ServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public void sendPacket(DefinedPacket packet)
public void sendPacketQueued(DefinedPacket packet)
{
Protocol encodeProtocol = ch.getEncodeProtocol();
if ( encodeProtocol == null )
{
return;
}
if ( !encodeProtocol.TO_SERVER.hasPacket( packet.getClass(), ch.getEncodeVersion() ) )
{
packetQueue.add( packet );
Expand Down
4 changes: 4 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/UserConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public void sendPacket(PacketWrapper packet)
public void sendPacketQueued(DefinedPacket packet)
{
Protocol encodeProtocol = ch.getEncodeProtocol();
if ( encodeProtocol == null )
{
return;
}
if ( !encodeProtocol.TO_CLIENT.hasPacket( packet.getClass(), getPendingConnection().getVersion() ) )
{
packetQueue.add( packet );
Expand Down
35 changes: 27 additions & 8 deletions proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,32 @@ public ChannelWrapper(ChannelHandlerContext ctx)

public Protocol getDecodeProtocol()
{
return ch.pipeline().get( MinecraftDecoder.class ).getProtocol();
MinecraftDecoder minecraftDecoder = getMinecraftDecoder();
if ( minecraftDecoder == null )
{
return null;
}
return minecraftDecoder.getProtocol();
}

public void setDecodeProtocol(Protocol protocol)
{
ch.pipeline().get( MinecraftDecoder.class ).setProtocol( protocol );
getMinecraftDecoder().setProtocol( protocol );
}

public Protocol getEncodeProtocol()
{
return ch.pipeline().get( MinecraftEncoder.class ).getProtocol();

MinecraftEncoder minecraftEncoder = getMinecraftEncoder();
if ( minecraftEncoder == null )
{
return null;
}
return minecraftEncoder.getProtocol();
}

public void setEncodeProtocol(Protocol protocol)
{
ch.pipeline().get( MinecraftEncoder.class ).setProtocol( protocol );
getMinecraftEncoder().setProtocol( protocol );
}

public void setProtocol(Protocol protocol)
Expand All @@ -69,13 +78,23 @@ public void setProtocol(Protocol protocol)

public void setVersion(int protocol)
{
ch.pipeline().get( MinecraftDecoder.class ).setProtocolVersion( protocol );
ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol );
getMinecraftDecoder().setProtocolVersion( protocol );
getMinecraftEncoder().setProtocolVersion( protocol );
}

public MinecraftDecoder getMinecraftDecoder()
{
return ch.pipeline().get( MinecraftDecoder.class );
}

public MinecraftEncoder getMinecraftEncoder()
{
return ch.pipeline().get( MinecraftEncoder.class );
}

public int getEncodeVersion()
{
return ch.pipeline().get( MinecraftEncoder.class ).getProtocolVersion();
return getMinecraftEncoder().getProtocolVersion();
}

public void write(Object packet)
Expand Down

0 comments on commit d907e27

Please sign in to comment.