Moved refs to encoder and decoder to connection to speed up access

This commit is contained in:
Nanit 2021-10-29 13:57:01 +03:00
parent 574261ef1e
commit cc5f92086a
2 changed files with 15 additions and 13 deletions

View File

@ -24,13 +24,16 @@ public class ClientChannelInitializer extends ChannelInitializer<Channel> {
protected void initChannel(Channel channel) {
ChannelPipeline pipeline = channel.pipeline();
PacketDecoder decoder = new PacketDecoder();
PacketEncoder encoder = new PacketEncoder();
pipeline.addLast("timeout", new ReadTimeoutHandler(server.getConfig().getReadTimeout(),
TimeUnit.MILLISECONDS));
pipeline.addLast("frame_decoder", new VarIntFrameDecoder());
pipeline.addLast("frame_encoder", new VarIntLengthEncoder());
pipeline.addLast("decoder", new PacketDecoder());
pipeline.addLast("encoder", new PacketEncoder());
pipeline.addLast("handler", new ClientConnection(channel, server));
pipeline.addLast("decoder", decoder);
pipeline.addLast("encoder", encoder);
pipeline.addLast("handler", new ClientConnection(channel, server, decoder, encoder));
}
}

View File

@ -47,15 +47,20 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
private final Channel channel;
private final GameProfile gameProfile;
private final PacketDecoder decoder;
private final PacketEncoder encoder;
private State state;
private Version clientVersion;
private SocketAddress address;
private int velocityLoginMessageId = -1;
public ClientConnection(Channel channel, LimboServer server) {
public ClientConnection(Channel channel, LimboServer server, PacketDecoder decoder, PacketEncoder encoder) {
this.server = server;
this.channel = channel;
this.decoder = decoder;
this.encoder = encoder;
this.address = channel.remoteAddress();
this.gameProfile = new GameProfile();
}
@ -244,18 +249,12 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
private void setPlayState() {
this.state = State.PLAY;
channel.pipeline().get(PacketDecoder.class)
.updateState(this.state);
channel.pipeline().get(PacketEncoder.class)
.updateState(this.state);
decoder.updateState(this.state);
encoder.updateState(this.state);
}
public void updateStateAndVersion(State state, Version version){
public void updateStateAndVersion(State state, Version version) {
this.state = state;
PacketDecoder decoder = channel.pipeline().get(PacketDecoder.class);
PacketEncoder encoder = channel.pipeline().get(PacketEncoder.class);
decoder.updateVersion(version);
decoder.updateState(state);
encoder.updateVersion(version);