Search in sources :

Example 1 with MessageEncoder

use of org.apollo.net.release.MessageEncoder in project apollo by apollo-rsps.

the class GroupedRegionUpdateMessageEncoder method encode.

@Override
public GamePacket encode(GroupedRegionUpdateMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.VARIABLE_SHORT);
    Position base = message.getLastKnownRegion(), region = message.getRegionPosition();
    builder.put(DataType.BYTE, region.getLocalY(base));
    builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(base));
    for (RegionUpdateMessage update : message.getMessages()) {
        @SuppressWarnings("unchecked") MessageEncoder<RegionUpdateMessage> encoder = (MessageEncoder<RegionUpdateMessage>) release.getMessageEncoder(update.getClass());
        GamePacket packet = encoder.encode(update);
        builder.put(DataType.BYTE, packet.getOpcode());
        builder.putBytes(packet.getPayload());
    }
    return builder.toGamePacket();
}
Also used : GamePacket(org.apollo.net.codec.game.GamePacket) Position(org.apollo.game.model.Position) RegionUpdateMessage(org.apollo.game.message.impl.RegionUpdateMessage) GroupedRegionUpdateMessage(org.apollo.game.message.impl.GroupedRegionUpdateMessage) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) MessageEncoder(org.apollo.net.release.MessageEncoder)

Example 2 with MessageEncoder

use of org.apollo.net.release.MessageEncoder in project apollo by apollo-rsps.

the class GroupedRegionUpdateMessageEncoder method encode.

@Override
public GamePacket encode(GroupedRegionUpdateMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(183, PacketType.VARIABLE_SHORT);
    Position base = message.getLastKnownRegion(), region = message.getRegionPosition();
    builder.put(DataType.BYTE, region.getLocalX(base));
    builder.put(DataType.BYTE, DataTransformation.ADD, region.getLocalY(base));
    for (RegionUpdateMessage update : message.getMessages()) {
        @SuppressWarnings("unchecked") MessageEncoder<RegionUpdateMessage> encoder = (MessageEncoder<RegionUpdateMessage>) release.getMessageEncoder(update.getClass());
        GamePacket packet = encoder.encode(update);
        builder.put(DataType.BYTE, packet.getOpcode());
        builder.putBytes(packet.getPayload());
    }
    return builder.toGamePacket();
}
Also used : GamePacket(org.apollo.net.codec.game.GamePacket) Position(org.apollo.game.model.Position) RegionUpdateMessage(org.apollo.game.message.impl.RegionUpdateMessage) GroupedRegionUpdateMessage(org.apollo.game.message.impl.GroupedRegionUpdateMessage) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) MessageEncoder(org.apollo.net.release.MessageEncoder)

Aggregations

GroupedRegionUpdateMessage (org.apollo.game.message.impl.GroupedRegionUpdateMessage)2 RegionUpdateMessage (org.apollo.game.message.impl.RegionUpdateMessage)2 Position (org.apollo.game.model.Position)2 GamePacket (org.apollo.net.codec.game.GamePacket)2 GamePacketBuilder (org.apollo.net.codec.game.GamePacketBuilder)2 MessageEncoder (org.apollo.net.release.MessageEncoder)2