allow custom Channel type to be wrapped in InjectionFactory#fromChannel #2756
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can create your own custom Channel implementation by extending server socket channel classes that are available in Netty. In Minecraft server there are two transport APIs being used (NIO and Epoll), however extending two different server socket channel classes just to serve only a single purpose usually is not a good solution, as it is not worth effort to maintain two classes at the time.
Fortunately, in the network manager class there's a Channel field. For those plugins/Spigot forks want to do some tinkering with packet sending/receiving through Netty API, they can wrap the original Channel which was gotten from
ChannelHandlerContext
into their own implementation (which is exactly what ProtocolLib is doing).The worst part is the way how ProtocolLib injects into Netty channel during a server connection initialization and therefore it overwrites the declared custom Channel implementation in the network manager. The main culprit is
InjectionFactory#fromChannel
because it takes the Channel straight fromChannelHandlerContext
given byInjectionChannelInboundHandler
as the wrapped channel for the channel injector.This PR fixes the issue by looking up for existing Channel field inside an already found network manager and if the field has null value, use the Channel from
ChannelHandlerContext
as fallback.