Search in sources :

Example 1 with C17PacketCustomPayload

use of net.minecraft.network.play.client.C17PacketCustomPayload in project Hyperium by HyperiumClient.

the class MixinNetHandlerPlayClient method handleCustomPayload.

@Inject(method = "handleCustomPayload", at = @At("RETURN"))
private void handleCustomPayload(S3FPacketCustomPayload packetIn, CallbackInfo ci) {
    PacketBuffer packetBuffer = packetIn.getBufferData();
    try {
        int readableBytes = packetBuffer.readableBytes();
        if (readableBytes > 0) {
            byte[] payload = new byte[readableBytes - 1];
            packetBuffer.readBytes(payload);
            String message = new String(payload, Charsets.UTF_8);
            if (LoginReplyHandler.SHOW_MESSAGES) {
                GeneralChatHandler.instance().sendMessage("Packet message on channel " + packetIn.getChannelName() + " -> " + message);
            }
            if ("REGISTER".equalsIgnoreCase(packetIn.getChannelName())) {
                if (message.contains("Hyperium")) {
                    PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
                    buffer.writeString("Hyperium;" + Metadata.getVersion() + ";" + Metadata.getVersionID());
                    addToSendQueue(new C17PacketCustomPayload("REGISTER", buffer));
                    PacketBuffer addonbuffer = new PacketBuffer(Unpooled.buffer());
                    List<AddonManifest> addons = AddonBootstrap.INSTANCE.getAddonManifests();
                    addonbuffer.writeInt(addons.size());
                    for (AddonManifest addonmanifest : addons) {
                        String addonName = addonmanifest.getName();
                        String version = addonmanifest.getVersion();
                        if (addonName == null)
                            addonName = addonmanifest.getMainClass();
                        if (version == null)
                            version = "unknown";
                        addonbuffer.writeString(addonName);
                        addonbuffer.writeString(version);
                    }
                    addToSendQueue(new C17PacketCustomPayload("hyperium|Addons", addonbuffer));
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : C17PacketCustomPayload(net.minecraft.network.play.client.C17PacketCustomPayload) AddonManifest(cc.hyperium.internal.addons.AddonManifest) PacketBuffer(net.minecraft.network.PacketBuffer) URISyntaxException(java.net.URISyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

AddonManifest (cc.hyperium.internal.addons.AddonManifest)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 PacketBuffer (net.minecraft.network.PacketBuffer)1 C17PacketCustomPayload (net.minecraft.network.play.client.C17PacketCustomPayload)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1