Skip to content

Commit

Permalink
Better compatibility with Arclight
Browse files Browse the repository at this point in the history
  • Loading branch information
adde0109 committed Oct 13, 2022
1 parent c129d0d commit ee97007
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'net.minecraftforge.gradle'
// MixinGradle:
apply plugin: 'org.spongepowered.mixin'

version = '1.16.5-0.2.1'
version = '1.16.5-0.2.3'
group = 'org.adde0109.ambassador' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'ambassador-forge'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.fml.network.NetworkDirection;
import org.adde0109.ambassador.forge.Ambassador;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;


@Mixin(ServerLoginNetHandler.class)
@Mixin(value = ServerLoginNetHandler.class, priority = 300)
public class ModernForwardingMixin {


Expand All @@ -38,12 +40,14 @@ private void disconnect(ITextComponent p_194026_1_) {}

private static final ResourceLocation VELOCITY_RESOURCE = new ResourceLocation("velocity:player_info");

@Inject(method = "handleHello", at = @At("RETURN"))
@Inject(method = "handleHello", at = @At("HEAD"), cancellable = true)
private void onHandleHello(CallbackInfo ci) {
Validate.validState(state == ServerLoginNetHandler.State.HELLO, "Unexpected hello packet");
if(Ambassador.modernForwardingInstance != null) {
this.state = ServerLoginNetHandler.State.HELLO;
LogManager.getLogger().warn("Sent Forward Request");
this.connection.send(NetworkDirection.LOGIN_TO_CLIENT.buildPacket(Pair.of(new PacketBuffer(Unpooled.EMPTY_BUFFER),100),VELOCITY_RESOURCE).getThis());
ci.cancel();
}
}

Expand All @@ -54,10 +58,14 @@ private void onHandleCustomQueryPacket(CCustomPayloadLoginPacket p_209526_1_, Ca
if(this.gameProfile == null) {
this.disconnect(new StringTextComponent("Direct connections to this server are not permitted!"));
LogManager.getLogger().error("Someone tried to join directly!");
} else {
arclight$preLogin();
this.state = ServerLoginNetHandler.State.NEGOTIATING;
}
this.state = ServerLoginNetHandler.State.NEGOTIATING;
ci.cancel();
}
}

private void arclight$preLogin() {}

}

0 comments on commit ee97007

Please sign in to comment.