Skip to content

Commit

Permalink
Fixed potential issues when using ViaLoader serverside
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Oct 15, 2024
1 parent 83462d8 commit b0de353
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ repositories {
```
Here is an example dependency configuration for all components:
```groovy
implementation "com.viaversion:viaversion:5.0.4"
implementation "com.viaversion:viaversion:5.0.5"
implementation "com.viaversion:viabackwards-common:5.0.4"
implementation "com.viaversion:viarewind-common:4.0.3"
implementation "net.raphimc:ViaLegacy:3.0.3"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repositories {
}

dependencies {
compileOnly "com.viaversion:viaversion-common:5.0.4"
compileOnly "com.viaversion:viaversion-common:5.0.5"
compileOnly "com.viaversion:viabackwards-common:5.0.4"
compileOnly "com.viaversion:viarewind-common:4.0.3"
compileOnly "net.raphimc:ViaLegacy:3.0.3"
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/net/raphimc/vialoader/netty/VLLegacyPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public VLLegacyPipeline(final UserConnection user) {
this(user, Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(user));
}

@Deprecated
public VLLegacyPipeline(final UserConnection user, final ProtocolVersion version) {
this.user = user;
this.version = version;
Expand All @@ -62,16 +61,18 @@ public void handlerAdded(ChannelHandlerContext ctx) {
ctx.pipeline().addBefore(this.packetDecoderName(), VIA_DECODER_NAME, this.createViaDecoder());
ctx.pipeline().addBefore(this.packetEncoderName(), VIA_ENCODER_NAME, this.createViaEncoder());

final ProtocolVersion r1_6_4 = ProtocolVersion.getProtocol(VersionType.RELEASE_INITIAL, 78);
if (r1_6_4.isKnown() && this.version.olderThanOrEqualTo(r1_6_4)) {
ctx.pipeline().addBefore(this.lengthSplitterName(), VIALEGACY_PRE_NETTY_LENGTH_PREPENDER_NAME, this.createViaLegacyPreNettyLengthPrepender());
ctx.pipeline().addBefore(this.lengthPrependerName(), VIALEGACY_PRE_NETTY_LENGTH_REMOVER_NAME, this.createViaLegacyPreNettyLengthRemover());
} else if (this.version.getName().startsWith("Bedrock")) {
ctx.pipeline().addBefore(this.lengthSplitterName(), VIABEDROCK_DISCONNECT_HANDLER_NAME, this.createViaBedrockDisconnectHandler());
ctx.pipeline().addBefore(this.lengthSplitterName(), VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME, this.createViaBedrockFrameEncapsulationHandler());
this.replaceLengthSplitter(ctx, this.createViaBedrockBatchLengthCodec());
ctx.pipeline().remove(this.lengthPrependerName());
ctx.pipeline().addBefore(VIA_DECODER_NAME, VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME, this.createViaBedrockPacketEncapsulationHandler());
if (this.user.isClientSide()) {
final ProtocolVersion r1_6_4 = ProtocolVersion.getProtocol(VersionType.RELEASE_INITIAL, 78);
if (r1_6_4.isKnown() && this.version.olderThanOrEqualTo(r1_6_4)) {
ctx.pipeline().addBefore(this.lengthSplitterName(), VIALEGACY_PRE_NETTY_LENGTH_PREPENDER_NAME, this.createViaLegacyPreNettyLengthPrepender());
ctx.pipeline().addBefore(this.lengthPrependerName(), VIALEGACY_PRE_NETTY_LENGTH_REMOVER_NAME, this.createViaLegacyPreNettyLengthRemover());
} else if (this.version.getName().startsWith("Bedrock")) {
ctx.pipeline().addBefore(this.lengthSplitterName(), VIABEDROCK_DISCONNECT_HANDLER_NAME, this.createViaBedrockDisconnectHandler());
ctx.pipeline().addBefore(this.lengthSplitterName(), VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME, this.createViaBedrockFrameEncapsulationHandler());
this.replaceLengthSplitter(ctx, this.createViaBedrockBatchLengthCodec());
ctx.pipeline().remove(this.lengthPrependerName());
ctx.pipeline().addBefore(VIA_DECODER_NAME, VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME, this.createViaBedrockPacketEncapsulationHandler());
}
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/main/java/net/raphimc/vialoader/netty/VLPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public VLPipeline(final UserConnection user) {
this(user, Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(user));
}

@Deprecated
public VLPipeline(final UserConnection user, final ProtocolVersion version) {
this.user = user;
this.version = version;
Expand All @@ -59,14 +58,16 @@ public VLPipeline(final UserConnection user, final ProtocolVersion version) {
public void handlerAdded(ChannelHandlerContext ctx) {
ctx.pipeline().addBefore(this.packetCodecName(), VIA_CODEC_NAME, this.createViaCodec());

final ProtocolVersion r1_6_4 = ProtocolVersion.getProtocol(VersionType.RELEASE_INITIAL, 78);
if (r1_6_4.isKnown() && this.version.olderThanOrEqualTo(r1_6_4)) {
ctx.pipeline().addBefore(this.lengthCodecName(), VIALEGACY_PRE_NETTY_LENGTH_CODEC_NAME, this.createViaLegacyPreNettyLengthCodec());
} else if (this.version.getName().startsWith("Bedrock")) {
ctx.pipeline().addBefore(this.lengthCodecName(), VIABEDROCK_DISCONNECT_HANDLER_NAME, this.createViaBedrockDisconnectHandler());
ctx.pipeline().addBefore(this.lengthCodecName(), VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME, this.createViaBedrockFrameEncapsulationHandler());
this.replaceLengthCodec(ctx, this.createViaBedrockBatchLengthCodec());
ctx.pipeline().addBefore(VIA_CODEC_NAME, VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME, this.createViaBedrockPacketEncapsulationHandler());
if (this.user.isClientSide()) {
final ProtocolVersion r1_6_4 = ProtocolVersion.getProtocol(VersionType.RELEASE_INITIAL, 78);
if (r1_6_4.isKnown() && this.version.olderThanOrEqualTo(r1_6_4)) {
ctx.pipeline().addBefore(this.lengthCodecName(), VIALEGACY_PRE_NETTY_LENGTH_CODEC_NAME, this.createViaLegacyPreNettyLengthCodec());
} else if (this.version.getName().startsWith("Bedrock")) {
ctx.pipeline().addBefore(this.lengthCodecName(), VIABEDROCK_DISCONNECT_HANDLER_NAME, this.createViaBedrockDisconnectHandler());
ctx.pipeline().addBefore(this.lengthCodecName(), VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME, this.createViaBedrockFrameEncapsulationHandler());
this.replaceLengthCodec(ctx, this.createViaBedrockBatchLengthCodec());
ctx.pipeline().addBefore(VIA_CODEC_NAME, VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME, this.createViaBedrockPacketEncapsulationHandler());
}
}
}

Expand Down

0 comments on commit b0de353

Please sign in to comment.