multiconnect

multiconnect

108k Downloads

Some questions about multiconnect api

plusls opened this issue · 2 comments

commented

I use MultiConnectAPI.instance().addServerboundIdentifierCustomPayloadListener to my callback function, and call ultiConnectAPI.instance().forceSendCustomPayload(channel, data); to send my packet to low version server.

forceSendCustomPayload use MinecraftClient.getInstance().getNetworkHandler() to get ClientPlayNetworkHandler. But sometimes, getNetworkHandler() return null but connect is established, and multiconnect will block some packet.

Some mod use some trick to bypass MinecraftClient.getInstance().getNetworkHandler() and get real getNetworkHandler, such as bbor:

((ClientPlayNetworkHandler) netHandlerPlayClient).sendPacket(SubscribeToServer.getPayload().build());

https://github.com/irtimaled/BoundingBoxOutlineReloaded/blob/9b3d975c355cb4087f9f33ff510e9b7e0f808025/src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSCustomPayloadPlayPacket.java#L34

I don't how to solve this problem elegantly. I use while loop to do this.

    @Override
    public void onCustomPayload(int protocol, Identifier channel, PacketByteBuf data) {
        while (true) {
            try {
                if (channel.equals(ServerNetworkHandler.REQUEST_BLOCK_ENTITY) || channel.equals(ServerNetworkHandler.REQUEST_ENTITY)) {
                    MasaGadgetMod.LOGGER.debug("forceSendCustomPayload: masagadget");
                    MultiConnectAPI.instance().forceSendCustomPayload(channel, data);
                } else if (channel.equals(new Identifier("bbor:subscribe"))) {
                    MasaGadgetMod.LOGGER.debug("forceSendCustomPayload: bbor");
                    MultiConnectAPI.instance().forceSendCustomPayload(channel, data);
                }
            } catch (IllegalStateException e) {
                // MinecraftClient.getInstance().getNetworkHandler() 在游戏刚连接时会返回 null
                // 由于 multiconnect mixin 了 ClientPlayNetworkHandler.sendPacket
                // 因此只能用死循环来缓解这个问题
                // 不知道有没有优雅的解决方案
                continue;
            }
            break;
        }
    }

I want to know how to solve this problem elegantly.

commented

MinecraftClient.getInstance().getNetworkHandler() can be null before the GameJoinS2CPacket has been processed. Multiconnect really shouldn't be using MinecraftClient.getNetworkHandler in this way. I'll work on a fix for this.

commented

The new multiconnect version 1.3.34, deprecates the old custom payload API and adds a new one which can properly handle this case. forceSendCustomPayload now takes in a ClientPlayNetworkHandler, which you can obtain from the ICustomPayloadEvent.