public override byte[] Write()
    {
        PacketBuilder builder = new PacketBuilder();

        builder.WriteBytesCapped(BitConverter.GetBytes(this.Id), 15);
        builder.Write(this.Flag != null);
        if (this.Flag != null)
        {
            builder.Write((byte)this.Flag);

            if (this.Flag == LatentEventFlag.Head)
            {
                if (this.Header == null)
                {
                    throw new ArgumentNullException("Can not send a latent packet with Flag Head without header");
                }

                builder.Write((ushort)this.Header.Value.Category);
                builder.Write(this.Header.Value.FinalSize);
                builder.Write(this.Header.Value.Rate);
                builder.Write(this.Header.Value.ResourceNetId);
            }
        }

        builder.AlignToByteBoundary();
        builder.Write((ushort)this.Data.Count());
        builder.Write(this.Data);

        return(builder.Build());
    }
Esempio n. 2
0
 private static void WriteLuaString(PacketBuilder builder, LuaValue value)
 {
     if (value.StringValue != null)
     {
         if (value.StringValue.Length < ushort.MaxValue)
         {
             builder.WriteCapped((byte)LuaType.String, 4);
             builder.WriteCompressed((ushort)value.StringValue.Length);
             builder.WriteStringWithoutLength(value.StringValue);
         }
         else
         {
             builder.WriteCapped((byte)LuaType.LongString, 4);
             builder.WriteCompressed((uint)value.StringValue.Length);
             builder.AlignToByteBoundary();
             builder.WriteStringWithoutLength(value.StringValue);
         }
     }
 }