Example usage for io.netty.buffer ByteBuf writeLong

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

Introduction

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

Prototype

public abstract ByteBuf writeLong(long value);

Source Link

Document

Sets the specified 64-bit long integer at the current writerIndex and increases the writerIndex by 8 in this buffer.

Usage

From source file:daxum.temporalconvergence.network.PacketDodgeSuccess.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeLong(mainPlayerUUID.getMostSignificantBits());
    buf.writeLong(mainPlayerUUID.getLeastSignificantBits());

    buf.writeDouble(ox);/*from w  ww.  ja v  a2 s  .c  o  m*/
    buf.writeDouble(oy);
    buf.writeDouble(oz);
}

From source file:de.jackwhite20.comix.handler.HandshakeHandler.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> out)
        throws Exception {
    ByteBuf copy = byteBuf.copy();/*w  w w.  j a v  a  2 s.com*/

    Protocol.readVarInt(byteBuf);

    int packetId = Protocol.readVarInt(byteBuf);

    if (packetId == 0) {
        if (protocolMode == ProtocolState.HANDSHAKE) {
            Protocol.readVarInt(byteBuf);
            Protocol.readString(byteBuf);
            byteBuf.readUnsignedShort();
            protocolMode = ProtocolState.valueOf((byte) Protocol.readVarInt(byteBuf));
        }

        if (protocolMode == ProtocolState.STATUS) {
            ByteBuf responseBuffer = Unpooled.buffer();
            String response = Comix.getInstance().getStatusResponseString();
            response = response.replace("%online%", "" + Comix.getInstance().getClientsOnline()); // Replace online count
            Protocol.writeVarInt(3 + response.length(), responseBuffer); // Size
            Protocol.writeVarInt(0, responseBuffer); // Packet id
            Protocol.writeString(response, responseBuffer); // Data as json string
            channelHandlerContext.writeAndFlush(responseBuffer);

            // Sending Pong instant because otherwise the pong will not receive properly!
            ByteBuf pongBuffer = Unpooled.buffer();
            Protocol.writeVarInt(9, pongBuffer);
            Protocol.writeVarInt(1, pongBuffer);
            pongBuffer.writeLong(0);
            channelHandlerContext.writeAndFlush(pongBuffer);

            channelHandlerContext.close();
        }

        if (protocolMode == ProtocolState.LOGIN) {
            if (byteBuf.readableBytes() == 0) {
                upstreamHandler.connectDownstream(copy);

                downstreamInitialized = true;

                out.add(copy.retain());

                return;
            }

            String name = Protocol.readString(byteBuf);

            //TODO: Improve
            if (Comix.getInstance().getComixConfig().isMaintenance()) {
                if (Comix.getInstance().isWhitelistEnabled()) {
                    if (!Comix.getInstance().isWhitelisted(name)) {
                        kick(channelHandlerContext, Comix.getInstance().getWhitelistKickMessage());
                    }
                } else {
                    kick(channelHandlerContext,
                            Comix.getInstance().getComixConfig().getMaintenanceKickMessage());
                }

                channelHandlerContext.close();
                return;
            } else if (Comix.getInstance().isWhitelistEnabled() && !Comix.getInstance().isWhitelisted(name)) {
                kick(channelHandlerContext, Comix.getInstance().getWhitelistKickMessage());

                channelHandlerContext.close();
                return;
            }

            if (!downstreamInitialized)
                upstreamHandler.connectDownstream(copy);
            else
                upstreamHandler.addInitialPacket(copy);

            ComixClient comixClient = new ComixClient(name, upstreamHandler.getDownstreamHandler(),
                    upstreamHandler);
            Comix.getInstance().addClient(comixClient);
            upstreamHandler.setClient(comixClient);

            channelHandlerContext.channel().pipeline().remove(this);

            Comix.getLogger().log(Level.INFO, "Handshake", "Player logged in: " + name);

            out.add(copy.retain());
        }
    }
}

From source file:de.sanandrew.mods.turretmod.entity.turret.EntityTurret.java

License:Creative Commons License

@Override
public void writeSpawnData(ByteBuf buffer) {
    UUID turretId = this.delegate.getId();
    buffer.writeLong(turretId.getMostSignificantBits());
    buffer.writeLong(turretId.getLeastSignificantBits());

    NBTTagCompound targetNbt = new NBTTagCompound();
    this.targetProc.writeToNbt(targetNbt);
    ByteBufUtils.writeTag(buffer, targetNbt);

    NBTTagCompound upgNbt = new NBTTagCompound();
    this.upgProc.writeToNbt(upgNbt);
    ByteBufUtils.writeTag(buffer, upgNbt);

    buffer.writeBoolean(this.isUpsideDown);

    if (this.ownerUUID != null) {
        buffer.writeBoolean(true);//from w ww  .  j a  v a  2  s .  co  m
        buffer.writeLong(this.ownerUUID.getMostSignificantBits());
        buffer.writeLong(this.ownerUUID.getLeastSignificantBits());
        ByteBufUtils.writeUTF8String(buffer, this.ownerName);
    } else {
        buffer.writeBoolean(false);
    }

    this.delegate.writeSpawnData(this, buffer);
}

From source file:de.sanandrew.mods.turretmod.network.PacketSyncUpgradeInst.java

License:Creative Commons License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(this.turretId);
    buf.writeLong(this.upgradeId.getMostSignificantBits());
    buf.writeLong(this.upgradeId.getLeastSignificantBits());
    buf.writeInt(this.instData.length);
    buf.writeBytes(this.instData);
}

From source file:divconq.ctp.f.BlockCommand.java

License:Open Source License

@Override
public ByteBuf encode() {
    int size = 1 + 1; // code + CTP_F_BLOCK_TYPE_

    int type = 0;

    int hdrcnt = this.headers.size();

    if (hdrcnt > 0) {
        type |= CtpConstants.CTP_F_BLOCK_TYPE_HEADER;
        size += hdrcnt * 4 + 2; // each header is at least 4 bytes (2 attr, 2 len) + ATTR_END is 2 bytes

        for (byte[] val : this.headers.values())
            size += val.length;
    }// w w w .  j av  a  2  s  . c o m

    if (this.data != null) {
        type |= CtpConstants.CTP_F_BLOCK_TYPE_CONTENT;
        size += 3 + this.data.readableBytes();
    }

    if (this.eof)
        type |= CtpConstants.CTP_F_BLOCK_TYPE_EOF;

    // build buffer
    ByteBuf bb = Hub.instance.getBufferAllocator().buffer(size);

    bb.writeByte(this.cmdCode);
    bb.writeByte(type);

    // add header if any
    if (hdrcnt > 0) {
        for (Entry<Integer, byte[]> val : this.headers.entrySet()) {
            bb.writeShort(val.getKey());
            bb.writeShort(val.getValue().length);
            bb.writeBytes(val.getValue());
        }

        // end of list of headers
        bb.writeShort(CtpConstants.CTP_F_ATTR_END);
    }

    // add content if any
    if (this.data != null) {
        bb.writeLong(this.streamOffset);
        bb.writeMedium(this.data.readableBytes());
        bb.writeBytes(this.data);
    }

    return bb;
}

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

License:Open Source License

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

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

    for (int i = 0; i < 16; i++) {
        buf.writeLong(0);
    }// ww w  . ja  v a  2  s  .  c  o m
}

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//w w w.j av a2 s .c om
    // 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.stratosphere.nephele.AbstractID.java

License:Apache License

public void writeTo(ByteBuf buf) {
    buf.writeLong(this.lowerPart);
    buf.writeLong(this.upperPart);
}

From source file:eu.xworlds.util.raknet.protocol.BaseMessage.java

License:Open Source License

protected void writeTime(ByteBuf target, long time) {
    target.writeLong(time);
}

From source file:eu.xworlds.util.raknet.protocol.BaseMessage.java

License:Open Source License

protected void writeGuid(ByteBuf target, long time) {
    target.writeLong(time);
}