Search in sources :

Example 51 with ByteBuffer

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

the class CodecLoginOutEncryptionRequest method encode.

@Override
public ByteBuffer encode(CodecContext context, MessageLoginOutEncryptionRequest message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    byte[] publicKey = message.getPublicKey();
    byte[] verifyToken = message.getVerifyToken();
    buf.writeString(message.getSessionId());
    // Write the public key
    buf.writeByteArray(publicKey);
    // Write the verify token
    buf.writeByteArray(verifyToken);
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 52 with ByteBuffer

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

the class CodecLoginOutSuccess method encode.

@Override
public ByteBuffer encode(CodecContext context, MessageLoginOutSuccess message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeString(message.getUniqueId().toString());
    buf.writeString(message.getUsername());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 53 with ByteBuffer

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

the class AbstractCodecPlayInOutCustomPayload method encode.

@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    final String channel;
    final ByteBuffer content;
    if (message instanceof MessagePlayInOutChannelPayload) {
        final MessagePlayInOutChannelPayload message1 = (MessagePlayInOutChannelPayload) message;
        content = message1.getContent();
        channel = message1.getChannel();
    } else if (message instanceof MessagePlayInOutRegisterChannels) {
        content = encodeChannels(((MessagePlayInOutRegisterChannels) message).getChannels());
        channel = "REGISTER";
    } else if (message instanceof MessagePlayInOutUnregisterChannels) {
        content = encodeChannels(((MessagePlayInOutUnregisterChannels) message).getChannels());
        channel = "UNREGISTER";
    } else {
        final MessageResult result = encode0(context, message);
        channel = result.channel;
        content = result.byteBuf;
    }
    buf.writeString(channel);
    buf.writeBytes(content);
    return buf;
}
Also used : MessagePlayInOutRegisterChannels(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels) MessagePlayInOutUnregisterChannels(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutUnregisterChannels) MessagePlayInOutChannelPayload(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 54 with ByteBuffer

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

the class CodecPlayOutOpenWindow method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutOpenWindow message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeByte((byte) message.getWindowId());
    MessagePlayOutOpenWindow.WindowType windowType = message.getWindowType();
    String type;
    if (windowType == MessagePlayOutOpenWindow.WindowType.HORSE) {
        type = "EntityHorse";
    } else {
        type = "minecraft:" + windowType.name().toLowerCase();
    }
    buf.writeString(type);
    buf.write(Types.TEXT, message.getTitle());
    // That logic...
    if (windowType == MessagePlayOutOpenWindow.WindowType.ANVIL || windowType == MessagePlayOutOpenWindow.WindowType.CRAFTING_TABLE || windowType == MessagePlayOutOpenWindow.WindowType.ENCHANTING_TABLE) {
        buf.writeByte((byte) 0);
    } else {
        buf.writeByte((byte) message.getSlotCount());
    }
    if (windowType == MessagePlayOutOpenWindow.WindowType.HORSE) {
        buf.writeInteger(message.getEntityId());
    }
    return buf;
}
Also used : MessagePlayOutOpenWindow(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenWindow) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 55 with ByteBuffer

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

the class CodecPlayOutPlayerHealthUpdate method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerHealthUpdate message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeFloat(message.getHealth());
    buf.writeVarInt((int) message.getFood());
    buf.writeFloat(message.getSaturation());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

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