/// <summary>
        /// Serialization the specified data and buf.
        /// </summary>
        /// <param name="data">Data.</param>
        /// <param name="buf">Buffer.</param>
        public static Int32 Serialization(IDataWraper data, ref byte[] buf)
        {
            if (data == null)
            {
                return(0);
            }

//            object[] objs = data.Serialization();
            CustomerArray <byte> objs = data.Serialization();

            if (objs == null || objs.CurrentLength < 1)
            {
                return(0);
            }

            int len = 0;

            for (int i = 0, max = objs.CurrentLength; i < max; i++)
            {
                if (objs[i].GetType() == typeof(byte))
                {
                    buf[len]     = 3;
                    buf[len + 1] = 1;
                    buf[len + 2] = Convert.ToByte(objs[i]);
                    len         += 3;
                }
            }

            return(len);
        }
Exemple #2
0
 public GameOperationBase()
 {
     MsgID        = GlobalConstantNet.CodePlayGame;
     DestType     = NetObjectType.FE_TABLE;
     DestId       = Session.TableID;
     subOperation = new CustomerArray <byte>(512);
 }
Exemple #3
0
 /// <summary>
 /// Memeories the copy.
 /// </summary>
 /// <returns>The copy.</returns>
 /// <param name="value">Value.</param>
 /// <param name="buff">Buff.</param>
 /// <param name="offset">offset.</param>
 public static int MemoryCopy(UInt64 value, ref CustomerArray <byte> buff, int offset)
 {
     if (buff == null || offset >= buff.MaxLength - 8)
     {
         return(0);
     }
     #if BIG_ENDIAN
     buff [offset + 7] = (byte)(value & 0xff);
     buff [offset + 6] = (byte)((value & 0xff00) >> 8);
     buff [offset + 5] = (byte)((value & 0xff0000) >> 16);
     buff [offset + 4] = (byte)((value & 0xff000000) >> 24);
     buff [offset + 3] = (byte)((value & 0xff00000000) >> 32);
     buff [offset + 2] = (byte)((value & 0xff0000000000) >> 40);
     buff [offset + 1] = (byte)((value & 0xff000000000000) >> 48);
     buff [offset + 0] = (byte)((value & 0xff00000000000000) >> 56);
     #else
     buff [offset + 0] = (byte)(value & 0xff);
     buff [offset + 1] = (byte)((value & 0xff00) >> 8);
     buff [offset + 2] = (byte)((value & 0xff0000) >> 16);
     buff [offset + 3] = (byte)((value & 0xff000000) >> 24);
     buff [offset + 4] = (byte)((value & 0xff00000000) >> 32);
     buff [offset + 5] = (byte)((value & 0xff0000000000) >> 40);
     buff [offset + 6] = (byte)((value & 0xff000000000000) >> 48);
     buff [offset + 7] = (byte)((value & 0xff00000000000000) >> 56);
     #endif
     return(8);
 }
Exemple #4
0
        /// <summary>
        /// Memeories the copy.
        /// </summary>
        /// <returns>The copy.</returns>
        /// <param name="value">Value.</param>
        /// <param name="buff">Buff.</param>
        /// <param name="offset">offset.</param>
        public static int MemoryCopy(char value, ref CustomerArray <byte> buff, int offset)
        {
            if (buff == null || offset >= buff.MaxLength)
            {
                return(0);
            }

            buff [offset] = (byte)value;

            return(1);
        }
        /// <summary>
        /// Serialization this instance.
        /// </summary>
        public virtual CustomerArray <byte> Serialization()
        {
            CustomerArray <byte> b = new CustomerArray <byte>();

            int start = 0;

            start += BitConvert.MemoryCopy(MsgID, ref b, start);
            start += BitConvert.MemoryCopy(MsgType, ref b, start);
            start += BitConvert.MemoryCopy(MsgSeq, ref b, start);
            start += BitConvert.MemoryCopy(SourceType, ref b, start);
            start += BitConvert.MemoryCopy(DestType, ref b, start);
            start += BitConvert.MemoryCopy(Session.PlayerID, ref b, start);
            start += BitConvert.MemoryCopy(DestId, ref b, start);
            return(b);
        }
Exemple #6
0
        /// <summary>
        /// Serialization this instance.
        /// </summary>
        public override CustomerArray <byte> Serialization()
        {
            CustomerArray <byte> b = base.Serialization();

            if (b == null)
            {
                return(null);
            }

            int offset = b.CurrentLength;

            offset += BitConvert.MemoryCopy(Name, ref b, offset);
            offset += BitConvert.MemoryCopy(Password, ref b, offset);

            return(b);
        }
Exemple #7
0
        /// <summary>
        /// Memeories the copy.
        /// </summary>
        /// <returns>The copy.</returns>
        /// <param name="value">Value.</param>
        /// <param name="buff">Buff.</param>
        /// <param name="offset">offset.</param>
        public static int MemoryCopy(Int16 value, ref CustomerArray <byte> buff, int offset)
        {
            if (buff == null || offset > buff.MaxLength - 2)
            {
                return(0);
            }
            #if BIG_ENDIAN
            buff [offset + 1] = (byte)(value & 0xff);
            buff [offset + 0] = (byte)((value & 0xff00) >> 8);
            #else
            buff [offset + 0] = (byte)(value & 0xff);
            buff [offset + 1] = (byte)((value & 0xff00) >> 8);
            #endif

            return(2);
        }
Exemple #8
0
 /// <summary>
 /// Memeories the copy.
 /// </summary>
 /// <returns>The copy.</returns>
 /// <param name="value">If set to <c>true</c> value.</param>
 /// <param name="buff">Buff.</param>
 /// <param name="offset">offset.</param>
 public static int MemoryCopy(bool value, ref CustomerArray <byte> buff, int offset)
 {
     if (buff == null || offset >= buff.MaxLength)
     {
         return(0);
     }
     if (value)
     {
         buff[offset] = 1;
     }
     else
     {
         buff[offset] = 0;
     }
     return(1);
 }
Exemple #9
0
        /// <summary>
        /// Serialization this instance.
        /// </summary>
        public override CustomerArray <byte> Serialization()
        {
            CustomerArray <byte> b = base.Serialization();

            if (b == null)
            {
                return(null);
            }

            int offset = b.CurrentLength;

            offset += BitConvert.MemoryCopy((UInt64)Session.Uid, ref b, offset);
            offset += BitConvert.MemoryCopy(0, ref b, offset); //time.

            return(b);
        }
Exemple #10
0
        /// <summary>
        /// Memories the copy.
        /// </summary>
        /// <returns>The copy.</returns>
        /// <param name="value">Value.</param>
        /// <param name="buff">Buff.</param>
        /// <param name="offset">Offset.</param>
        public static int MemoryCopy(string value, ref CustomerArray <byte> buff, int offset)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(0);
            }
            char[] c = value.ToCharArray();

            if (buff == null || offset >= buff.MaxLength - 2 - c.Length || c.Length < 1)
            {
                return(0);
            }
            offset += MemoryCopy((Int16)c.Length, ref buff, offset);
            for (int i = 0, max = c.Length; i < max; i++)
            {
                buff [offset + i] = (byte)c [i];
            }
            return(2 + c.Length);
        }
Exemple #11
0
        /// <summary>
        /// Serialization this instance.
        /// </summary>
        public override CustomerArray <byte> Serialization()
        {
            CustomerArray <byte> b = base.Serialization();

            if (b == null)
            {
                return(null);
            }

            int offset = b.CurrentLength;

            offset += BitConvert.MemoryCopy((UInt64)Session.Uid, ref b, offset);
            offset += BitConvert.MemoryCopy(0, ref b, offset); //time.
            offset += BitConvert.MemoryCopy((ushort)subOperation.CurrentLength, ref b, offset);
            for (int i = 0, max = subOperation.CurrentLength, j = b.CurrentLength; i < max; i++, j++)
            {
                b[j] = subOperation[i];
            }

            return(b);
        }
Exemple #12
0
        /// <summary>
        /// Deserialization the specified val and offset.
        /// </summary>
        /// <param name="val">Value.</param>
        /// <param name="offset">Offset.</param>
        public override int Deserialization(byte[] val, int offset)
        {
            int index = base.Deserialization(val, offset);

            index += 2;                                      //gameId;
            index += 2;                                      //roomType;

            short num = BitConvert.GetInt16(val, ref index); //table num.

            tables = new CustomerArray <TableInfo>(num);
            num    = BitConvert.GetInt16(val, ref index); //player num.
            TableInfo table;

            for (int i = 0, max = tables.MaxLength; i < max; i++)
            {
                table        = new TableInfo();
                table.ID     = BitConvert.GetInt32(val, ref index);
                table.Status = BitConvert.GetUInt16(val, ref index);
                tables[i]    = table;
            }
            return(index);
        }