Example usage for io.netty.buffer ByteBuf writeByte

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

Introduction

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

Prototype

public abstract ByteBuf writeByte(int value);

Source Link

Document

Sets the specified byte at the current writerIndex and increases the writerIndex by 1 in this buffer.

Usage

From source file:com.rs3e.network.protocol.codec.login.LoginDecoder.java

License:Open Source License

/**
 * Decodes the header of login./*  w  w w . j  a v  a2  s .c om*/
 * 
 * @param ctx
 *            The channel handler context.
 * @param buf
 *            The byte buf for writing data.
 * @return The login message, or {@code Null}.
 */
private Object decodeHeader(ChannelHandlerContext ctx, ByteBuf buf) {
    if (buf.readable()) {

        new SecureRandom().nextInt();

        ByteBuf unpooled = Unpooled.buffer();
        unpooled.writeByte(0);
        // unpooled.writeLong(secureKey);
        ctx.channel().write(unpooled);

        setState(LoginState.CONNECTION_TYPE);
    }
    return null;
}

From source file:com.rs3e.network.protocol.login.LoginDecoder.java

License:Open Source License

/**
 * Decodes the header of login.//ww  w .j a va  2s . com
 * @param ctx The channel handler context.
 * @param buf The byte buf for writing data.
 * @return The login message, or {@code Null}.
 */
private Object decodeHeader(ChannelHandlerContext ctx, ByteBuf buf) {
    if (buf.readable()) {

        @SuppressWarnings("unused")
        //long clientHash = buf.readUnsignedByte();
        int secureKey = new SecureRandom().nextInt();

        ByteBuf unpooled = Unpooled.buffer();
        unpooled.writeByte(0);
        //unpooled.writeLong(secureKey);
        ctx.channel().write(unpooled);

        setState(LoginState.CONNECTION_TYPE);
    }
    return null;
}

From source file:com.rs3e.network.protocol.worldlist.WorldListEncoder.java

License:Open Source License

@Override
public void encode(ChannelHandlerContext ctx, WorldListMessage list, ByteBuf out) throws Exception {
    ByteBuf buf = Unpooled.buffer();
    buf.writeByte(1);
    buf.writeByte(1);/*from   w w w .jav  a  2  s  . co m*/

    Country[] countries = list.getCountries();
    ByteBufUtils.writeSmart(buf, countries.length);
    for (Country country : countries) {
        ByteBufUtils.writeSmart(buf, country.getFlag());
        ByteBufUtils.writeWorldListString(buf, country.getName());
    }

    World[] worlds = list.getWorlds();
    int minId = worlds[0].getId();
    int maxId = worlds[0].getId();
    for (int i = 1; i < worlds.length; i++) {
        World world = worlds[i];
        int id = world.getId();

        if (id > maxId)
            maxId = id;
        if (id < minId)
            minId = id;
    }

    ByteBufUtils.writeSmart(buf, minId);
    ByteBufUtils.writeSmart(buf, maxId);
    ByteBufUtils.writeSmart(buf, worlds.length);

    for (World world : worlds) {
        ByteBufUtils.writeSmart(buf, world.getId() - minId);
        buf.writeByte(world.getCountry());
        buf.writeInt(world.getFlags());
        ByteBufUtils.writeWorldListString(buf, world.getActivity());
        ByteBufUtils.writeWorldListString(buf, world.getIp());
    }

    buf.writeInt(list.getSessionId());
    for (int i = 0; i < worlds.length; i++) {
        World world = worlds[i];
        ByteBufUtils.writeSmart(buf, world.getId() - minId);
        buf.writeShort(0);
    }

    out.writeByte(0); // 0 = ok, 7/9 = world full
    out.writeShort(buf.readableBytes());
    out.writeBytes(buf);
}

From source file:com.rs3e.utility.ByteBufUtils.java

License:Open Source License

public static void writeString(ByteBuf buffer, String str) {
    byte[] bytes = str.getBytes(Charsets.ASCII_LATIN1_CHARSET);
    buffer.writeBytes(bytes);/*from w  ww .  j  a v a 2  s. c  o  m*/
    buffer.writeByte(0);
}

From source file:com.rs3e.utility.ByteBufUtils.java

License:Open Source License

public static void writeSmart(ByteBuf buffer, int value) {
    if (value < 128)
        buffer.writeByte(value);
    else//from w  w  w.  j a  va2 s.com
        buffer.writeShort(32768 + value);
}

From source file:com.rs3e.utility.ByteBufUtils.java

License:Open Source License

public static void writeWorldListString(ByteBuf buffer, String str) {
    buffer.writeByte(0);
    buffer.writeBytes(str.getBytes(Charsets.ASCII_LATIN1_CHARSET));
    buffer.writeByte(0);// w w  w .j  a va2  s.com
}

From source file:com.savageboy74.savagetech.handler.packets.OpenGuiPacket.java

License:Open Source License

@Override
public void encodeInto(ChannelHandlerContext context, ByteBuf buffer) {
    buffer.writeByte(id);
}

From source file:com.savageboy74.savagetech.handler.packets.PacketPipeline.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, AbstractPacket msg, List<Object> out) throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    Class<? extends AbstractPacket> apClass = msg.getClass();

    if (!this.packets.contains(apClass)) {
        throw new NullPointerException(Strings.Packets.NOT_REGISTERED + apClass.getCanonicalName());
    }/*from w  ww.  ja  v a2s . com*/

    byte discriminator = (byte) this.packets.indexOf(apClass);
    buffer.writeByte(discriminator);
    msg.encodeInto(ctx, buffer);

    FMLProxyPacket packet = new FMLProxyPacket(buffer.copy(),
            ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    out.add(packet);

}

From source file:com.savageboy74.savagetech.network.message.MessageKeyPressed.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeByte(keyPressed);
}

From source file:com.savageboy74.savagetech.network.message.MessageTileEntityBase.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(x);//from w ww  . j  av  a 2 s  . c om
    buf.writeInt(y);
    buf.writeInt(z);
    buf.writeByte(orientation);
    buf.writeByte(state);
    buf.writeInt(customName.length());
    buf.writeBytes(customName.getBytes());
    buf.writeInt(owner.length());
    buf.writeBytes(owner.getBytes());
}