Example usage for io.netty.buffer ByteBuf writeShort

List of usage examples for io.netty.buffer ByteBuf writeShort

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeShort.

Prototype

public abstract ByteBuf writeShort(int value);

Source Link

Document

Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer.

Usage

From source file:eu.jangos.realm.network.packet.server.auth.SMSG_LOGIN_VERIFY_WORLD.java

License:Open Source License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 4b - 4b - 4b - 4b - 4b
    // Size (Little Endian) - Opcode (Big Endian) - map - posX - posY - posZ - orientation

    buf.writeShort(this.size);
    buf.writeShort(this.code.getValue());
    buf.writeInt(this.map);
    buf.writeFloat(this.posX);
    buf.writeFloat(this.posY);
    buf.writeFloat(this.posZ);
    buf.writeFloat(this.orientation);
}

From source file:eu.jangos.realm.network.packet.server.character.SMSG_CHAR_CREATE.java

License:Open Source License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 1b
    // Size (Little Endian) - Opcode (Big Endian) - result        

    buf.writeShort(this.size);
    buf.writeShort(this.code.getValue());
    buf.writeByte(this.result.getValue());
}

From source file:eu.jangos.realm.network.packet.server.character.SMSG_CHAR_ENUM.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 1b
    // Size (Little Endian) - Opcode (Big Endian) - number of characters 
    // If any character:
    // 8b - ?b - 1b - 1b - 1b - 1b - 1b - 1b - 1b - 1b - 1b - 4b - 4b - 4b - 4b - 4b - 4b - 1b - 4b - 4b - 4b 
    // GUID (Little Endian) - Name - Race - Class - Gender - Skin - Face - HairStyle - HairColor - FacialHair - level - zone - map - x - y - z - guild
    // char flags - first login - Pet id - Pet level - Pet Family
    // Then equipment: (19 pieces)
    // 4b - 1b/*from   ww w .  j a  va 2  s .co m*/
    // Item Display ID - Item Inventory Type
    // Then the bag
    // 4b - 1b
    // First bag display ID
    // First bag inventory type

    // TODO: 
    // - Guild membership
    // - Pet ID
    // - Pet Level
    // - Pet Family

    ItemService itemService = ItemServiceFactory.getInstance();
    ItemInstanceService iiService = new ItemInstanceService();

    buf.writeShort(this.size);
    buf.writeShort(this.code.getValue());
    buf.writeByte(this.numChars);

    for (Characters c : this.listChars) {
        buf = buf.order(ByteOrder.LITTLE_ENDIAN);
        buf.writeLong(c.getGuid());
        //buf = buf.order(ByteOrder.BIG_ENDIAN);
        ByteBufUtil.writeAscii(buf, c.getName());
        buf.writeByte((byte) 0); // End of string
        buf.writeByte(c.getRace());
        buf.writeByte(c.getFkDbcClass());
        buf.writeByte(c.getGender());
        buf.writeByte(c.getSkin());
        buf.writeByte(c.getFace());
        buf.writeByte(c.getHairstyle());
        buf.writeByte(c.getHaircolor());
        buf.writeByte(c.getFacialhair());
        buf.writeByte((byte) c.getLevel());
        buf.writeInt(c.getFkDbcZone());
        buf.writeInt(c.getFkDbcMap());
        buf.writeFloat((float) c.getPositionX()); // X
        buf.writeFloat((float) c.getPositionY()); // Y
        buf.writeFloat((float) c.getPositionZ()); // Z
        buf.writeInt(0); // Guild ID
        buf.writeInt(convertPlayersFlagsToInt(c)); // Char Flags            
        buf.writeByte(convertLoginFlagsToByte(c)); // First login
        buf.writeInt(0); // Pet ID
        buf.writeInt(0); // Pet Level
        buf.writeInt(0); // Pet family

        int count = 0;

        // We get the list of data for the equipment.
        for (Object data : iiService.getEquipmentCharEnum(c)) {
            Object[] itemInstance = (Object[]) data;
            int displayID = 0;
            byte inventoryType = 0;

            // We fill-in the data for the unoccupied slots.
            for (int i = count; i < Integer.parseInt(itemInstance[0].toString()); i++) {
                buf.writeInt(displayID);
                buf.writeByte(inventoryType);
                count++;
            }

            // We add the occupied slot.
            Object[] item = itemService.getItemByIDCharEnum(Integer.parseInt(itemInstance[1].toString()));

            displayID = Integer.parseInt(item[0].toString());
            inventoryType = Byte.parseByte(item[1].toString());

            buf.writeInt(displayID);
            buf.writeByte(inventoryType);

            count++;
        }

        // We fill in the data for the end of the equipment slot.
        for (int i = count; i <= EQUIPMENT_SLOT_END; i++) {
            buf.writeInt(0);
            buf.writeByte(0);
        }

    }

}

From source file:eu.jangos.realm.network.packet.server.character.SMSG_INITIAL_SPELLS.java

License:Open Source License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 1b
    // Size (Little Endian) - Opcode (Big Endian) - result        

    buf.writeShort(this.size);
    buf.writeShort(this.code.getValue());

}

From source file:eu.jangos.realm.network.packet.server.login.SMSG_LOGIN_SETTIMESPEED.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 4b - 4b
    // Size (Little Endian) - Opcode (Big Endian) - current time - world time speed

    buf.writeShort(this.size);
    buf.writeShort(this.code.getValue());
    buf.writeInt(this.time);
    buf.writeFloat(WORLD_TIME_SPEED);// w  w  w  .  j  a v a  2s .  c  o  m
}

From source file:eu.jangos.realm.network.packet.server.login.SMSG_LOGOUT_CANCEL.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b//from  w  ww .j ava  2  s  .  c  om
    // Size (Little Endian) - Opcode (Big Endian)

    buf.writeShort(this.size);
    buf.writeShort(this.code.getValue());
}

From source file:eu.jangos.realm.network.packet.server.login.SMSG_LOGOUT_RESPONSE.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 1b - 4b
    // Size (Little Endian) - Opcode (Big Endian) - reason - instant
    // There are uncertainty, Mangos claims structure is 1b + 4b
    // TC claims it's 4b + 1b.

    buf.writeShort(this.size);
    buf.writeShort(this.code.getValue());
    buf.writeByte(this.reason.getValue());
    buf.writeInt(this.instant ? 1 : 0);
}

From source file:eu.jangos.realm.network.packet.server.misc.SMSG_NEW_WORLD.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 4b - 4b - 4b - 4b - 4b
    // Size (Little Endian) - Opcode (Big Endian) - mapID - posX - posY - posZ - orientation        

    buf.writeShort(this.size);
    buf.writeShort(this.code.getValue());
    buf.writeInt(this.mapID);
    buf.writeFloat(this.posX);
    buf.writeFloat(this.posY);
    buf.writeFloat(this.posZ);
    buf.writeFloat(this.orientation);
}

From source file:eu.jangos.realm.network.packet.server.misc.SMSG_TRANSFER_ABORT.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 4b - 1b - 1b
    // Size (Little Endian) - Opcode (Big Endian) - mapID - reason - unknown

    buf.writeShort(this.size);
    buf.writeShort(this.code.getValue());
    buf.writeInt(this.mapID);
    buf.writeByte(this.reason.getValue());
    buf.writeByte(this.unknown);
}

From source file:eu.jangos.realm.network.packet.server.misc.SMSG_TRANSFER_PENDING.java

License:Apache License

@Override
public void encode(ByteBuf buf) throws Exception {
    // Packet structure:
    // 2b - 2b - 4b (- 4b - 4b)
    // Size (Little Endian) - Opcode (Big Endian) - mapID (- transportID - currentMapID)                

    buf.writeShort(this.size + (this.transportID != 0 ? 8 : 0));
    buf.writeShort(this.code.getValue());
    buf.writeInt(this.mapID);

    if (this.transportID != 0) {
        buf.writeInt(this.transportID);
        buf.writeInt(this.currentMapID);
    }/*from ww w .ja  v  a  2 s .  c o  m*/
}