Search in sources :

Example 1 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutStatistics method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutStatistics message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    Set<Entry> entries = message.getEntries();
    buf.writeVarInt(entries.size());
    for (Entry entry : entries) {
        buf.writeString(entry.getName());
        buf.writeVarInt(entry.getValue());
    }
    return buf;
}
Also used : Entry(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStatistics.Entry) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 2 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutTabListEntries method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTabListEntries message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    List<Entry> entries = message.getEntries();
    int type = this.typeLookup.get(entries.get(0).getClass());
    buf.writeVarInt(type);
    buf.writeVarInt(entries.size());
    for (Entry entry : entries) {
        buf.writeUniqueId(entry.getGameProfile().getUniqueId());
        switch(type) {
            case ADD:
                buf.writeString(entry.getGameProfile().getName().orElse("unknown"));
                Collection<ProfileProperty> properties = entry.getGameProfile().getPropertyMap().values();
                buf.writeVarInt(properties.size());
                for (ProfileProperty property : properties) {
                    buf.writeString(property.getName());
                    buf.writeString(property.getValue());
                    Optional<String> signature = property.getSignature();
                    boolean flag = signature.isPresent();
                    buf.writeBoolean(flag);
                    if (flag) {
                        buf.writeString(signature.get());
                    }
                }
                buf.writeVarInt(((LanternGameMode) entry.getGameMode()).getInternalId());
                buf.writeVarInt(entry.getPing());
                Text displayName = entry.getDisplayName();
                boolean flag = displayName != null;
                buf.writeBoolean(flag);
                if (flag) {
                    buf.write(Types.TEXT, displayName);
                }
                break;
            case UPDATE_GAME_MODE:
                buf.writeVarInt(((LanternGameMode) entry.getGameMode()).getInternalId());
                break;
            case UPDATE_LATENCY:
                buf.writeVarInt(entry.getPing());
                break;
            case UPDATE_DISPLAY_NAME:
                Text displayName0 = entry.getDisplayName();
                boolean flag0 = displayName0 != null;
                buf.writeBoolean(flag0);
                if (flag0) {
                    buf.write(Types.TEXT, displayName0);
                }
                break;
            case REMOVE:
                break;
        }
    }
    return buf;
}
Also used : Entry(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutTabListEntries.Entry) ProfileProperty(org.spongepowered.api.profile.property.ProfileProperty) Text(org.spongepowered.api.text.Text) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 3 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutTeams method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTeams message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeString(message.getTeamName());
    if (message instanceof MessagePlayOutTeams.CreateOrUpdate) {
        buf.writeByte((byte) (message instanceof MessagePlayOutTeams.Create ? 0 : 2));
        final MessagePlayOutTeams.CreateOrUpdate message1 = (MessagePlayOutTeams.CreateOrUpdate) message;
        buf.writeString(message1.getDisplayName());
        buf.writeString(message1.getPrefix());
        buf.writeString(message1.getSuffix());
        int flags = 0;
        if (message1.getFriendlyFire()) {
            flags |= 0x01;
        }
        if (message1.getSeeFriendlyInvisibles()) {
            flags |= 0x02;
        }
        buf.writeByte((byte) flags);
        buf.writeString(message1.getNameTagVisibility().getId());
        buf.writeString(message1.getCollisionRule().getName());
        final TextColor c = message1.getColor();
        buf.writeByte((byte) (c == TextColors.NONE || c == TextColors.RESET ? -1 : FormattingCodeTextSerializer.FORMATS_TO_CODE.getChar(c)));
    } else {
        buf.writeByte((byte) (message instanceof MessagePlayOutTeams.Remove ? 1 : message instanceof MessagePlayOutTeams.AddPlayers ? 3 : 4));
    }
    if (message instanceof MessagePlayOutTeams.Players) {
        final List<String> players = ((MessagePlayOutTeams.Players) message).getPlayers();
        buf.writeVarInt(players.size());
        players.forEach(buf::writeString);
    }
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) MessagePlayOutTeams(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutTeams) TextColor(org.spongepowered.api.text.format.TextColor)

Example 4 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutTitle method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTitle message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    if (message instanceof MessagePlayOutTitle.Clear) {
        buf.writeVarInt(CLEAR);
    } else if (message instanceof MessagePlayOutTitle.Reset) {
        buf.writeVarInt(RESET);
    } else if (message instanceof MessagePlayOutTitle.SetTitle) {
        buf.writeVarInt(SET_TITLE);
        buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutTitle.SetTitle) message).getTitle());
    } else if (message instanceof MessagePlayOutTitle.SetSubtitle) {
        buf.writeVarInt(SET_SUBTITLE);
        buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutTitle.SetSubtitle) message).getTitle());
    } else if (message instanceof MessagePlayOutTitle.SetActionbarTitle) {
        buf.writeVarInt(SET_ACTIONBAR_TITLE);
        buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutTitle.SetActionbarTitle) message).getTitle());
    } else {
        final MessagePlayOutTitle.SetTimes message0 = (MessagePlayOutTitle.SetTimes) message;
        buf.writeVarInt(SET_TIMES);
        buf.writeInteger(message0.getFadeIn());
        buf.writeInteger(message0.getStay());
        buf.writeInteger(message0.getFadeOut());
    }
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) MessagePlayOutTitle(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutTitle)

Example 5 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutUnlockRecipes method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutUnlockRecipes message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    if (message instanceof MessagePlayOutUnlockRecipes.Remove) {
        buf.writeVarInt((short) 2);
    } else if (message instanceof MessagePlayOutUnlockRecipes.Add) {
        buf.writeVarInt((short) 1);
    } else if (message instanceof MessagePlayOutUnlockRecipes.Init) {
        buf.writeVarInt((short) 0);
    } else {
        throw new EncoderException();
    }
    buf.writeBoolean(message.hasOpenCraftingBook());
    buf.writeBoolean(message.hasCraftingFilter());
    IntList recipeIds = message.getRecipeIds();
    buf.writeVarInt(recipeIds.size());
    recipeIds.forEach(buf::writeVarInt);
    if (message instanceof MessagePlayOutUnlockRecipes.Init) {
        recipeIds = ((MessagePlayOutUnlockRecipes.Init) message).getRecipeIdsToBeDisplayed();
        buf.writeVarInt(recipeIds.size());
        recipeIds.forEach(buf::writeVarInt);
    }
    return buf;
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) MessagePlayOutUnlockRecipes(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutUnlockRecipes) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) IntList(it.unimi.dsi.fastutil.ints.IntList)

Aggregations

ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)75 EncoderException (io.netty.handler.codec.EncoderException)9 Vector3d (com.flowpowered.math.vector.Vector3d)7 Message (org.lanternpowered.server.network.message.Message)5 Map (java.util.Map)4 MessagePlayInOutChannelPayload (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload)4 AbstractParameterList (org.lanternpowered.server.network.entity.parameter.AbstractParameterList)3 NullMessage (org.lanternpowered.server.network.message.NullMessage)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 Vector3i (com.flowpowered.math.vector.Vector3i)2 CodecException (io.netty.handler.codec.CodecException)2 LanternPotionEffectType (org.lanternpowered.server.effect.potion.LanternPotionEffectType)2 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)2 NetworkSession (org.lanternpowered.server.network.NetworkSession)2 LanternByteBuffer (org.lanternpowered.server.network.buffer.LanternByteBuffer)2 BulkMessage (org.lanternpowered.server.network.message.BulkMessage)2 CodecRegistration (org.lanternpowered.server.network.message.CodecRegistration)2 HandlerMessage (org.lanternpowered.server.network.message.HandlerMessage)2 Codec (org.lanternpowered.server.network.message.codec.Codec)2 RawItemStack (org.lanternpowered.server.network.objects.RawItemStack)2