Skip to content

Commit 1dc04f3

Browse files
committed
fix
1 parent 0f2425f commit 1dc04f3

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

src/main/java/me/ayunami2000/ayunViaProxyEagUtils/EaglercraftInitialHandler.java

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,44 @@ protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final L
5050
ctx.pipeline().addBefore("eaglercraft-initial-handler", "ws-handler", new WebSocketServerProtocolHandler("/", null, true));
5151
ctx.pipeline().addBefore("eaglercraft-initial-handler", "ws-active-notifier", new WebSocketActiveNotifier());
5252
ctx.pipeline().addBefore("eaglercraft-initial-handler", "eaglercraft-handler", new EaglercraftHandler());
53-
ctx.pipeline().replace(Client2ProxyChannelInitializer.LEGACY_PASSTHROUGH_INITIAL_HANDLER_NAME, Client2ProxyChannelInitializer.LEGACY_PASSTHROUGH_INITIAL_HANDLER_NAME, new LegacyPassthroughInitialHandler() {
54-
@Override
55-
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
56-
if (ctx.channel().isOpen()) {
57-
if (msg.isReadable()) {
58-
int lengthOrPacketId = msg.getUnsignedByte(0);
59-
if (lengthOrPacketId == 0 || lengthOrPacketId == 1 || lengthOrPacketId == 2 || lengthOrPacketId == 254) {
60-
boolean fard = false;
61-
for (Map.Entry<String, ChannelHandler> entry : ctx.pipeline()) {
62-
if (entry.getKey().equals(Client2ProxyChannelInitializer.LEGACY_PASSTHROUGH_INITIAL_HANDLER_NAME)) {
63-
fard = true;
64-
} else {
65-
if (fard) {
66-
ctx.pipeline().remove(entry.getValue());
53+
if (ctx.pipeline().get(Client2ProxyChannelInitializer.LEGACY_PASSTHROUGH_INITIAL_HANDLER_NAME) != null) {
54+
ctx.pipeline().replace(Client2ProxyChannelInitializer.LEGACY_PASSTHROUGH_INITIAL_HANDLER_NAME, Client2ProxyChannelInitializer.LEGACY_PASSTHROUGH_INITIAL_HANDLER_NAME, new LegacyPassthroughInitialHandler() {
55+
@Override
56+
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
57+
if (ctx.channel().isOpen()) {
58+
if (msg.isReadable()) {
59+
int lengthOrPacketId = msg.getUnsignedByte(0);
60+
if (lengthOrPacketId == 0 || lengthOrPacketId == 1 || lengthOrPacketId == 2 || lengthOrPacketId == 254) {
61+
boolean fard = false;
62+
for (Map.Entry<String, ChannelHandler> entry : ctx.pipeline()) {
63+
if (entry.getKey().equals(Client2ProxyChannelInitializer.LEGACY_PASSTHROUGH_INITIAL_HANDLER_NAME)) {
64+
fard = true;
65+
} else {
66+
if (fard) {
67+
ctx.pipeline().remove(entry.getValue());
68+
}
6769
}
6870
}
69-
}
7071

71-
Supplier<ChannelHandler> handlerSupplier = () -> PluginManager.EVENT_MANAGER.call(new Client2ProxyHandlerCreationEvent(new PassthroughClient2ProxyHandler(), true)).getHandler();
72-
PassthroughClient2ProxyChannelInitializer channelInitializer = new PassthroughClient2ProxyChannelInitializer(handlerSupplier);
73-
try {
74-
initChannelMethod.invoke(channelInitializer, ctx.channel());
75-
} catch (IllegalAccessException | InvocationTargetException e) {
76-
throw new RuntimeException(e);
72+
Supplier<ChannelHandler> handlerSupplier = () -> PluginManager.EVENT_MANAGER.call(new Client2ProxyHandlerCreationEvent(new PassthroughClient2ProxyHandler(), true)).getHandler();
73+
PassthroughClient2ProxyChannelInitializer channelInitializer = new PassthroughClient2ProxyChannelInitializer(handlerSupplier);
74+
try {
75+
initChannelMethod.invoke(channelInitializer, ctx.channel());
76+
} catch (IllegalAccessException | InvocationTargetException e) {
77+
throw new RuntimeException(e);
78+
}
79+
ctx.fireChannelActive();
80+
ctx.fireChannelRead(msg.retain());
81+
ctx.pipeline().remove(this);
82+
} else {
83+
ctx.pipeline().remove(this);
84+
ctx.pipeline().fireChannelRead(msg.retain());
7785
}
78-
ctx.fireChannelActive();
79-
ctx.fireChannelRead(msg.retain());
80-
ctx.pipeline().remove(this);
81-
} else {
82-
ctx.pipeline().remove(this);
83-
ctx.pipeline().fireChannelRead(msg.retain());
8486
}
8587
}
8688
}
87-
}
88-
});
89+
});
90+
}
8991
ctx.fireUserEventTriggered(EaglercraftClientConnected.INSTANCE);
9092
ctx.pipeline().fireChannelRead(in.readBytes(in.readableBytes()));
9193
} else {

0 commit comments

Comments
 (0)