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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations