Better fix for when packets of type HANDSHAKING are not found in the registry.#2945
Better fix for when packets of type HANDSHAKING are not found in the registry.#2945nickuc wants to merge 2 commits intodmulloy2:masterfrom
Conversation
…nd in the registry (fixes dmulloy2#2601) This reverts commit 564349c.
|
I'm wondering: if the key is not present in the handshaking phase, how are packets encoded during that phase? They do need to get the information from somewhere, can this be detected more dynamically than just assuming that it must be handshaking if the key is not present (especially if at some point another protocol is not using the key anymore: the decoding process works but fails with a misleading error + we would have to implement such a detection anyway) |
|
I believe a better solution would be to iterate over the entire pipeline. Since ChannelPipeline implements Iterable<Map.Entry<String, ChannelHandler>>, we can directly check each entry. If we encounter a PacketEncoder or PacketDecoder, we can use them as handler instances. This approach allows us to avoid the need for handler name dependent code. Edit: this is a partial duplicate of #2933 but I would still prefer my suggested solution since it's more dynamic and less dependent on names not changing. Maybe something along those lines: @Override
public Object apply(Channel channel, PacketType.Sender sender) {
Class<? extends ChannelHandler> handlerClass = this.getHandlerClass(sender)
.asSubclass(ChannelHandler.class);
ChannelHandlerContext handlerContext = channel.pipeline().context(handlerClass);
if (handlerContext == null) {
return null;
}
Function<Object, Object> protocolAccessor = this.getProtocolAccessor(handlerClass, sender);
return protocolAccessor.apply(handlerContext.handler());
}
private Class<?> getHandlerClass(PacketType.Sender sender) {
switch (sender) {
case SERVER:
return MinecraftReflection.getMinecraftClass("network.PacketEncoder");
case CLIENT:
return MinecraftReflection.getMinecraftClass("network.PacketDecoder");
default:
throw new IllegalArgumentException("Illegal packet sender " + sender.name());
}
} |
I liked your solution. But I'm still having trouble identifying the protocol when the HANDSHAKE packet is received. I did some tests, and I think I found something:
Oh, I also enabled PR editing, I didn't realize it was disabled. |
|
Closed in favor of #2951 |
This PR finally fixes the problem that was reported in #2601 introduced by commit af33a2a and replaces the workaround that was previously used.
Based on this code comment:
ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/channel/NettyChannelInjector.java
Lines 208 to 210 in b0c4b7f