Skip to content

Commit

Permalink
Workaround for #1, #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Feb 26, 2022
1 parent 88f37b5 commit 1e46f5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Expand Up @@ -2,6 +2,7 @@

import com.ishland.raknetfabric.mixin.access.IClientConnection;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -21,19 +22,23 @@ public class MixinServerLoginNetworkAddon {
@Final
private ClientConnection connection;

@Shadow
@Final
private MinecraftServer server;

@SuppressWarnings("DefaultAnnotationParam")
@Dynamic("Pseudo")
@Inject(method = "sendCompressionPacket()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", ordinal = 0, shift = At.Shift.AFTER, remap = true), remap = false)
private void setupDummyCompressionImmediately(CallbackInfo info) {
((IClientConnection) this.connection).getChannel().eventLoop().execute(() -> {
try {
try {
this.connection.setCompressionThreshold(512, false);
this.connection.setCompressionThreshold(this.server.getNetworkCompressionThreshold(), false);
} catch (NoSuchMethodError e) {
System.out.println("An error occurred when starting compression, using alternative method: ");
System.out.println("An error occurred when starting compression, using alternative method: " + e.toString());
//noinspection JavaReflectionMemberAccess
final Method method_10760 = ClientConnection.class.getMethod("method_10760", int.class);
method_10760.invoke(this.connection, 512);
method_10760.invoke(this.connection, this.server.getNetworkCompressionThreshold());
}
} catch (Throwable t) {
t.printStackTrace();
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.ishland.raknetfabric.mixin.access.IClientConnection;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerLoginNetworkHandler;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -17,17 +18,19 @@ public class MixinServerLoginNetworkHandler {

@Shadow @Final public ClientConnection connection;

@Shadow @Final private MinecraftServer server;

@Inject(method = "acceptPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", ordinal = 0, shift = At.Shift.AFTER))
private void setupDummyCompressionImmediately(CallbackInfo ci) throws Throwable {
((IClientConnection) this.connection).getChannel().eventLoop().execute(() -> {
try {
try {
this.connection.setCompressionThreshold(512, false);
this.connection.setCompressionThreshold(this.server.getNetworkCompressionThreshold(), false);
} catch (NoSuchMethodError e) {
System.out.println("An error occurred when starting compression, using alternative method: ");
System.out.println("An error occurred when starting compression, using alternative method: " + e.toString());
//noinspection JavaReflectionMemberAccess
final Method method_10760 = ClientConnection.class.getMethod("method_10760", int.class);
method_10760.invoke(this.connection, 512);
method_10760.invoke(this.connection, this.server.getNetworkCompressionThreshold());
}
} catch (Throwable t) {
t.printStackTrace();
Expand Down

0 comments on commit 1e46f5c

Please sign in to comment.