Exemplo n.º 1
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     using (var mem = new MemoryStream())
     {
         using (var writer = new BinaryWriter(mem))
         {
             Tuning.SerializeInto(writer);
             var result = mem.ToArray();
             output.PutInt32(result.Length);
             output.Put(result, 0, result.Length);
         }
     }
     output.PutInt32(ObjectUpgrades.Length);
     output.Put(ObjectUpgrades, 0, ObjectUpgrades.Length);
 }
Exemplo n.º 2
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutEnum(Type);
     if (Type == MailRequestType.SEND)
     {
         byte[] dat;
         if (Item == null)
         {
             dat = new byte[0];
         }
         else
         {
             using (var str = new MemoryStream())
             {
                 Item.Save(str);
                 dat = str.ToArray();
             }
         }
         output.PutInt32(dat.Length);
         foreach (var b in dat)
         {
             output.Put(b);
         }
     }
     else
     {
         output.PutInt64(TimestampID);
     }
 }
Exemplo n.º 3
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutEnum <PurchaseLotStatus>(Status);
     output.PutEnum <PurchaseLotFailureReason>(Reason);
     output.PutUInt32(NewLotId);
     output.PutInt32(NewFunds);
 }
Exemplo n.º 4
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     base.Serialize(output, context);
     output.PutPascalString(TaskType);
     output.PutInt32(ShardId);
     output.PutString(ParameterJson, Encoding.UTF8);
 }
Exemplo n.º 5
0
        public void SendMsg()
        {
            //lock (this)
            {
                while (m_sendMsgs.Count > 0)
                {
                    MessageBody msg = m_sendMsgs.Dequeue();
                    if (msg != null)
                    {
                        m_sendBuffer.Clear();
                        Array.Clear(m_sendData, 0, m_sendData.Length);

                        int len = CPacket.HEADER_TYPE_BYTES + msg.data.Length;
                        m_sendBuffer.PutInt32(len);
                        m_sendBuffer.PutInt16((short)msg.type);
                        m_sendBuffer.Put(msg.data);
                        m_sendBuffer.Flip();

                        m_sendBuffer.Get(m_sendData, 0, len + CPacket.HEADER_LENGTH_BYTES);
                        m_currentSendBufferWritePosition = len + CPacket.HEADER_LENGTH_BYTES;
                        SendMsg(m_sendData);
                    }
                }
            }
        }
Exemplo n.º 6
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     base.Serialize(output, context);
     byte[] data = null;
     using (var mem = new MemoryStream())
     {
         foreach (var item in Items)
         {
             item.Save(mem);
         }
         data = mem.ToArray();
     }
     output.PutInt32(Items.Count);
     output.PutInt32(data.Length);
     output.Put(data);
 }
Exemplo n.º 7
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutUInt32(AvatarId);
     output.PutUInt32(ReplaceId);
     output.PutInt32(LotId);
     output.PutEnum(Change);
 }
Exemplo n.º 8
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutEnum(Status);
     output.PutEnum(Type);
     output.PutInt32(EntityId);
     output.PutUInt32(ClaimId);
     output.PutPascalString(NewOwner);
 }
 public void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutInt32(Outfits.Length);
     foreach (var outfit in Outfits)
     {
         outfit.Serialize(output, context);
     }
 }
Exemplo n.º 10
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutEnum(Type);
     output.PutEnum(Action);
     output.PutInt32(EntityId);
     output.PutUInt32(ClaimId);
     output.PutUInt32(SpecialId);
     output.PutPascalString(FromOwner);
 }
Exemplo n.º 11
0
    public void Encode(IoSession session, PacketOutStream message, IProtocolEncoderOutput output)
    {
        int      size = message.GetSize();
        IoBuffer buf  = IoBuffer.Allocate(size + 4);

        buf.PutInt32(size);
        buf.Put(message.getPackets2());
        buf.Flip();
        output.Write(buf);
    }
Exemplo n.º 12
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutEnum(Type);
     output.PutInt32(Messages.Length);
     foreach (var msg in Messages)
     {
         byte[] dat;
         using (var str = new MemoryStream())
         {
             msg.Save(str);
             dat = str.ToArray();
         }
         output.PutInt32(dat.Length);
         foreach (var b in dat)
         {
             output.Put(b);
         }
     }
 }
Exemplo n.º 13
0
 protected override void EncodeBody(IoSession session, T message, IoBuffer output)
 {
     if (message.OK)
     {
         output.PutInt16((short)Constants.RESULT_OK);
         output.PutInt32(message.Value);
     }
     else
     {
         output.PutInt16((short)Constants.RESULT_ERROR);
     }
 }
Exemplo n.º 14
0
        public void Encode(IoSession session, T message, IProtocolEncoderOutput output)
        {
            IoBuffer buf = IoBuffer.Allocate(16);

            buf.AutoExpand = true; // Enable auto-expand for easier encoding

            // Encode a header
            buf.PutInt16((short)_type);
            buf.PutInt32(message.Sequence);

            // Encode a body
            EncodeBody(session, message, buf);
            buf.Flip();
            output.Write(buf);
        }
Exemplo n.º 15
0
        private static FileInfo CreateLargeFile()
        {
            IoBuffer buffer = IoBuffer.Allocate(FILE_SIZE);

            for (Int32 i = 0; i < FILE_SIZE / 4; i++)
            {
                buffer.PutInt32(i);
            }
            buffer.Flip();

            String path = Path.GetTempFileName();

            Byte[] data = new Byte[buffer.Remaining];
            buffer.Get(data, 0, data.Length);
            File.WriteAllBytes(path, data);
            return(new FileInfo(path));
        }
Exemplo n.º 16
0
        public override void Serialize(IoBuffer output, ISerializationContext context)
        {
            output.PutBool(NominationMode);
            output.PutInt32(Candidates.Count);

            foreach (var candidate in Candidates)
            {
                output.PutUInt32(candidate.ID);
                output.PutPascalVLCString(candidate.Name);
                output.PutUInt32(candidate.Rating);

                if (!NominationMode)
                {
                    output.PutPascalVLCString(candidate.LastNhoodName);
                    output.PutUInt32(candidate.LastNhoodID);
                    output.PutUInt32(candidate.TermNumber);
                    output.PutPascalVLCString(candidate.Message);
                }
            }
        }
Exemplo n.º 17
0
        public void Encode(IoSession session, object message, IProtocolEncoderOutput output)
        {
            WampCommandBase cmd  = (WampCommandBase)message;
            string          json = cmd.toCommandJson();

            byte[] jsonByteArray = System.Text.Encoding.UTF8.GetBytes(json);
            int    len           = jsonByteArray.Length + 4;

            if (len > 1000000)
            {
                throw new ArgumentException("{msg:'data size > 1m', dataSize:" + len + "}");
            }
            IoBuffer buffer = IoBuffer.Allocate(len);

            buffer.AutoExpand = true;
            buffer.PutInt32(len);
            buffer.Put(jsonByteArray);

            buffer.Flip();
            output.Write(buffer);
        }
Exemplo n.º 18
0
        private cTSOValue SerializeValue(uint type, object value)
        {
            var      result = new cTSOValue();
            IoBuffer buffer = null;

            switch (type)
            {
            case 0x48BC841E:
                if (!(value is sbyte) && !(value is Enum))
                {
                    return(null);
                }
                result.Type  = cTSOValue_sint8;
                result.Value = new sbyte[] { Convert.ToSByte(value) };
                break;

            case 0x74336731:
                if (!(value is ushort))
                {
                    return(null);
                }

                buffer = AbstractVoltronPacket.Allocate(2);
                buffer.PutUInt16((ushort)value);
                buffer.Flip();

                result.Type  = cTSOValue_uint16;
                result.Value = buffer;
                break;

            case 0xF192ECA6:
                if (!(value is short))
                {
                    return(null);
                }

                buffer = AbstractVoltronPacket.Allocate(2);
                buffer.PutInt16((short)value);
                buffer.Flip();

                result.Type  = cTSOValue_sint16;
                result.Value = buffer;
                break;

            case 0xE0463A2F:
                if (!(value is uint))
                {
                    return(null);
                }

                buffer = AbstractVoltronPacket.Allocate(4);
                buffer.PutUInt32((uint)value);
                buffer.Flip();

                result.Type  = cTSOValue_uint32;
                result.Value = buffer;
                break;

            case 0xA0587098:
                if (!(value is int))
                {
                    return(null);
                }

                buffer = AbstractVoltronPacket.Allocate(4);
                buffer.PutInt32((int)value);
                buffer.Flip();

                result.Type  = cTSOValue_sint32;
                result.Value = buffer;
                break;

            case 0x385070C9:
                if (!(value is ulong))
                {
                    return(null);
                }

                buffer = AbstractVoltronPacket.Allocate(8);
                buffer.PutUInt64((ulong)value);
                buffer.Flip();

                result.Type  = cTSOValue_uint64;
                result.Value = buffer;
                break;

            case 0x90D315F7:
                if (!(value is long))
                {
                    return(null);
                }

                buffer = AbstractVoltronPacket.Allocate(8);
                buffer.PutInt64((long)value);
                buffer.Flip();

                result.Type  = cTSOValue_sint64;
                result.Value = buffer;
                break;

            default:
                //It may be a struct
                var _struct = Format.Structs.FirstOrDefault(x => x.ID == type);
                if (_struct != null)
                {
                    var body = new cITSOProperty();
                    body.StructType   = _struct.ID;
                    body.StructFields = new List <cITSOField>();

                    foreach (var field in _struct.Fields)
                    {
                        object fieldValue = GetFieldValue(value, field.Name);
                        if (fieldValue == null)
                        {
                            continue;
                        }

                        body.StructFields.Add(new cITSOField {
                            ID    = field.ID,
                            Value = SerializeValue(field.TypeID, fieldValue)
                        });
                    }

                    result.Type  = cTSOValue_property;
                    result.Value = body;
                    return(result);
                }

                return(null);
            }

            return(result);
        }
Exemplo n.º 19
0
        public static void PutUInt32(this IoBuffer buffer, uint value)
        {
            int converted = unchecked ((int)value);

            buffer.PutInt32(converted);
        }
Exemplo n.º 20
0
        public bool Write(IoBuffer output, DuplexMessage message)
        {
            var writeOk = false;

            try
            {
                using (var scope = ObjectHost.Host.BeginLifetimeScope())
                {
                    var filters       = new List <IMessageFilter>();
                    var dataStack     = new StackMessageDataContaner();
                    var filterFactory = scope.Resolve <MessageFilterFactory>();
                    filters.Add(filterFactory.CreateFilter(
                                    message.Header.FilterCode[0], message.Header.FilterType & MessageFilterType.Compression));
                    filters.Add(filterFactory.CreateFilter(
                                    message.Header.FilterCode[0], message.Header.FilterType & MessageFilterType.Crypto));
                    var identifierBinary = message.Header.Identifier.FromHex();
                    dataStack.Push(identifierBinary);
                    dataStack.Push(message.GetContentBinary());
                    FilterResult result = new FilterResult {
                        OK = true
                    };
                    foreach (var filter in filters)
                    {
                        result = filter.Out(message.Header, dataStack);
                        if (!result.OK)
                        {
                            break;
                        }
                    }
                    if (result.OK)
                    {
                        var body = dataStack.Take();
                        output.PutInt32(49 + body.Length);
                        output.Put(message.Header.Version.ToByte());
                        output.PutInt16(Convert.ToInt16(message.Header.CommandCode));
                        output.Put(message.Header.ErrorCode.ToByte());
                        output.Put(message.Header.MessageType.ToByte());
                        output.Put(identifierBinary);
                        output.Put(message.Header.MessageID.FromBase64());
                        output.Put(message.Header.FilterType.ToByte());
                        output.Put(message.Header.FilterCode);
                        output.Put(message.Header.SerializeMode.ToByte());
                        output.Flip();
                        var header = output.GetRemainingArray();
                        dataStack.Push(body);
                        dataStack.Push(header);
                        result = filterFactory
                                 .CreateFilter(message.Header.FilterCode[0],
                                               message.Header.FilterType & MessageFilterType.Checksum)
                                 .Out(message.Header, dataStack);
                        writeOk = result.OK;
                        if (writeOk)
                        {
                            output.Put(dataStack.Take());
                            output.Put(body);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ErrorCode.SysError.ToString(), ex);
            }
            return(writeOk);
        }
Exemplo n.º 21
0
 protected override void EncodeBody(IoSession session, T message, IoBuffer output)
 {
     output.PutInt32(message.Value);
 }
Exemplo n.º 22
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutInt32(Data.Length);
     output.Put(Data, 0, Data.Length);
 }
Exemplo n.º 23
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutUInt32(AvatarId);
     output.PutInt32(LotId);
     output.PutPascalString(FromOwner);
 }
Exemplo n.º 24
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     base.Serialize(output, context);
     output.PutInt32(TaskId);
 }