Skip to content

Commit b40365e

Browse files
Make all possible pipeline handler names static. (#880)
This allows for easier integration with tools from ViaVersion like ViaLoader/ViaBedrock and also allows easier modification of the MCPL pipeline.
1 parent 6dd20b1 commit b40365e

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

protocol/src/main/java/org/geysermc/mcprotocollib/network/NetworkConstants.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@
77
public class NetworkConstants {
88
public static final AttributeKey<CompressionConfig> COMPRESSION_ATTRIBUTE_KEY = AttributeKey.valueOf("compression");
99
public static final AttributeKey<EncryptionConfig> ENCRYPTION_ATTRIBUTE_KEY = AttributeKey.valueOf("encryption");
10+
public static final String PROXY_NAME = "proxy";
11+
public static final String PROXY_PROTOCOL_ENCODER_NAME = "proxy-protocol-encoder";
12+
public static final String PROXY_PROTOCOL_PACKET_SENDER_NAME = "proxy-protocol-packet-sender";
13+
public static final String READ_TIMEOUT_NAME = "read-timeout";
14+
public static final String WRITE_TIMEOUT_NAME = "write-timeout";
15+
public static final String ENCRYPTION_NAME = "encryption";
16+
public static final String SIZER_NAME = "sizer";
17+
public static final String COMPRESSION_NAME = "compression";
18+
public static final String FLOW_CONTROL_NAME = "flow-control";
19+
public static final String CODEC_NAME = "codec";
20+
public static final String FLUSH_HANDLER_NAME = "flush-handler";
21+
public static final String MANAGER_NAME = "manager";
1022
}

protocol/src/main/java/org/geysermc/mcprotocollib/network/helper/NettyHelper.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.checkerframework.checker.nullness.qual.NonNull;
1616
import org.checkerframework.checker.nullness.qual.Nullable;
1717
import org.geysermc.mcprotocollib.network.BuiltinFlags;
18+
import org.geysermc.mcprotocollib.network.NetworkConstants;
1819
import org.geysermc.mcprotocollib.network.ProxyInfo;
1920
import org.geysermc.mcprotocollib.network.Session;
2021
import org.slf4j.Logger;
@@ -128,8 +129,8 @@ public static void initializeHAProxySupport(Session session, Channel channel) {
128129
return;
129130
}
130131

131-
channel.pipeline().addLast("proxy-protocol-encoder", HAProxyMessageEncoder.INSTANCE);
132-
channel.pipeline().addLast("proxy-protocol-packet-sender", new ChannelInboundHandlerAdapter() {
132+
channel.pipeline().addLast(NetworkConstants.PROXY_PROTOCOL_ENCODER_NAME, HAProxyMessageEncoder.INSTANCE);
133+
channel.pipeline().addLast(NetworkConstants.PROXY_PROTOCOL_PACKET_SENDER_NAME, new ChannelInboundHandlerAdapter() {
133134
@Override
134135
public void channelActive(ChannelHandlerContext ctx) throws Exception {
135136
HAProxyProxiedProtocol proxiedProtocol = getProxiedProtocol(clientAddress);
@@ -187,23 +188,23 @@ public static void addProxy(ProxyInfo proxy, ChannelPipeline pipeline) {
187188
switch (proxy.type()) {
188189
case HTTP -> {
189190
if (proxy.username() != null && proxy.password() != null) {
190-
pipeline.addLast("proxy", new HttpProxyHandler(proxy.address(), proxy.username(), proxy.password()));
191+
pipeline.addLast(NetworkConstants.PROXY_NAME, new HttpProxyHandler(proxy.address(), proxy.username(), proxy.password()));
191192
} else {
192-
pipeline.addLast("proxy", new HttpProxyHandler(proxy.address()));
193+
pipeline.addLast(NetworkConstants.PROXY_NAME, new HttpProxyHandler(proxy.address()));
193194
}
194195
}
195196
case SOCKS4 -> {
196197
if (proxy.username() != null) {
197-
pipeline.addLast("proxy", new Socks4ProxyHandler(proxy.address(), proxy.username()));
198+
pipeline.addLast(NetworkConstants.PROXY_NAME, new Socks4ProxyHandler(proxy.address(), proxy.username()));
198199
} else {
199-
pipeline.addLast("proxy", new Socks4ProxyHandler(proxy.address()));
200+
pipeline.addLast(NetworkConstants.PROXY_NAME, new Socks4ProxyHandler(proxy.address()));
200201
}
201202
}
202203
case SOCKS5 -> {
203204
if (proxy.username() != null && proxy.password() != null) {
204-
pipeline.addLast("proxy", new Socks5ProxyHandler(proxy.address(), proxy.username(), proxy.password()));
205+
pipeline.addLast(NetworkConstants.PROXY_NAME, new Socks5ProxyHandler(proxy.address(), proxy.username(), proxy.password()));
205206
} else {
206-
pipeline.addLast("proxy", new Socks5ProxyHandler(proxy.address()));
207+
pipeline.addLast(NetworkConstants.PROXY_NAME, new Socks5ProxyHandler(proxy.address()));
207208
}
208209
}
209210
default -> throw new UnsupportedOperationException("Unsupported proxy type: " + proxy.type());

protocol/src/main/java/org/geysermc/mcprotocollib/network/netty/MinecraftChannelInitializer.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.netty.handler.timeout.WriteTimeoutHandler;
99
import lombok.RequiredArgsConstructor;
1010
import org.geysermc.mcprotocollib.network.BuiltinFlags;
11+
import org.geysermc.mcprotocollib.network.NetworkConstants;
1112
import org.geysermc.mcprotocollib.network.Session;
1213
import org.geysermc.mcprotocollib.network.packet.PacketProtocol;
1314

@@ -33,16 +34,16 @@ protected void addHandlers(S session, Channel ch) {
3334
PacketProtocol protocol = session.getPacketProtocol();
3435
ChannelPipeline pipeline = ch.pipeline();
3536

36-
pipeline.addLast("read-timeout", new ReadTimeoutHandler(session.getFlag(BuiltinFlags.READ_TIMEOUT, 30)));
37-
pipeline.addLast("write-timeout", new WriteTimeoutHandler(session.getFlag(BuiltinFlags.WRITE_TIMEOUT, 0)));
37+
pipeline.addLast(NetworkConstants.READ_TIMEOUT_NAME, new ReadTimeoutHandler(session.getFlag(BuiltinFlags.READ_TIMEOUT, 30)));
38+
pipeline.addLast(NetworkConstants.WRITE_TIMEOUT_NAME, new WriteTimeoutHandler(session.getFlag(BuiltinFlags.WRITE_TIMEOUT, 0)));
3839

39-
pipeline.addLast("encryption", new PacketEncryptorCodec());
40-
pipeline.addLast("sizer", new PacketSizerCodec(protocol.getPacketHeader()));
41-
pipeline.addLast("compression", new PacketCompressionCodec());
40+
pipeline.addLast(NetworkConstants.ENCRYPTION_NAME, new PacketEncryptorCodec());
41+
pipeline.addLast(NetworkConstants.SIZER_NAME, new PacketSizerCodec(protocol.getPacketHeader()));
42+
pipeline.addLast(NetworkConstants.COMPRESSION_NAME, new PacketCompressionCodec());
4243

43-
pipeline.addLast("flow-control", new AutoReadFlowControlHandler());
44-
pipeline.addLast("codec", new PacketCodec(session, client));
45-
pipeline.addLast("flush-handler", new FlushHandler());
46-
pipeline.addLast("manager", session);
44+
pipeline.addLast(NetworkConstants.FLOW_CONTROL_NAME, new AutoReadFlowControlHandler());
45+
pipeline.addLast(NetworkConstants.CODEC_NAME, new PacketCodec(session, client));
46+
pipeline.addLast(NetworkConstants.FLUSH_HANDLER_NAME, new FlushHandler());
47+
pipeline.addLast(NetworkConstants.MANAGER_NAME, session);
4748
}
4849
}

0 commit comments

Comments
 (0)