Exemplo n.º 1
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            var dataLen = input.GetInt32();

            if (dataLen > 4000000 || dataLen > input.Remaining)
            {
                throw new Exception("Tuning too long");
            }
            var data = new byte[dataLen];

            input.Get(data, 0, dataLen);
            using (var mem = new MemoryStream(data))
            {
                using (var reader = new BinaryReader(mem))
                {
                    Tuning = new DynamicTuning(reader);
                }
            }
            var upgLen = input.GetInt32();

            if (upgLen > 10000000 || upgLen > input.Remaining)
            {
                throw new Exception("Upgrades too long");
            }
            ObjectUpgrades = new byte[upgLen];
            input.Get(ObjectUpgrades, 0, upgLen);
        }
Exemplo n.º 2
0
 public void Deserialize(IoBuffer input, ISerializationContext context)
 {
     outfit_id      = input.GetUInt32();
     asset_id       = input.GetUInt64();
     sale_price     = input.GetInt32();
     purchase_price = input.GetInt32();
     owner_type     = input.GetEnum <VMGLOutfitOwner>();
     owner_id       = input.GetUInt32();
     outfit_type    = input.Get();
     outfit_source  = input.GetEnum <VMGLOutfitSource>();
 }
Exemplo n.º 3
0
        protected override AbstractMessage DecodeBody(IoSession session, IoBuffer input)
        {
            if (!_readCode)
            {
                if (input.Remaining < Constants.RESULT_CODE_LEN)
                {
                    return(null); // Need more data.
                }

                _code     = input.GetInt16();
                _readCode = true;
            }

            if (_code == Constants.RESULT_OK)
            {
                if (input.Remaining < Constants.RESULT_VALUE_LEN)
                {
                    return(null);
                }

                ResultMessage m = new ResultMessage();
                m.OK      = true;
                m.Value   = input.GetInt32();
                _readCode = false;
                return(m);
            }
            else
            {
                ResultMessage m = new ResultMessage();
                m.OK      = false;
                _readCode = false;
                return(m);
            }
        }
Exemplo n.º 4
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     Status   = input.GetEnum <PurchaseLotStatus>();
     Reason   = input.GetEnum <PurchaseLotFailureReason>();
     NewLotId = input.GetUInt32();
     NewFunds = input.GetInt32();
 }
Exemplo n.º 5
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     AvatarId  = input.GetUInt32();
     ReplaceId = input.GetUInt32();
     LotId     = input.GetInt32();
     Change    = input.GetEnum <ChangeType>();
 }
Exemplo n.º 6
0
        public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
        {
            if (input.Remaining < MESSAGE_LENGTH_BYTES_LENGTH)
            {
                return(MessageDecoderResult.NeedData);
            }
            var len = input.GetInt32();

            if (len > MAX_MESSAGE_LENGTH)
            {
                return(MessageDecoderResult.NotOK);
            }
            if (input.Remaining + MESSAGE_LENGTH_BYTES_LENGTH < len)
            {
                return(MessageDecoderResult.NeedData);
            }
            var version = input.Get().ToEnum <MessageVersion>();

            if (version == MessageVersion.BadVersion)
            {
                return(MessageDecoderResult.NotOK);
            }
            if (len < FixedHeaderLength(version))
            {
                return(MessageDecoderResult.NotOK);
            }

            return(MessageDecoderResult.OK);
        }
Exemplo n.º 7
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            var dataLen = input.GetInt32(); //TODO: limits? 4MB is probably reasonable.

            Data = new byte[dataLen];
            input.Get(Data, 0, dataLen);
        }
Exemplo n.º 8
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            NominationMode = input.GetBool();
            int candCount = input.GetInt32();

            Candidates = new List <NhoodCandidate>();
            for (int i = 0; i < candCount; i++)
            {
                var candidate = new NhoodCandidate()
                {
                    ID     = input.GetUInt32(),
                    Name   = input.GetPascalVLCString(),
                    Rating = input.GetUInt32()
                };

                if (!NominationMode)
                {
                    candidate.LastNhoodName = input.GetPascalVLCString();
                    candidate.LastNhoodID   = input.GetUInt32();
                    candidate.TermNumber    = input.GetUInt32();
                    candidate.Message       = input.GetPascalVLCString();
                }
                Candidates.Add(candidate);
            }
        }
Exemplo n.º 9
0
        public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
        {
            // Try to skip header if not read.
            if (!_readHeader)
            {
                input.GetInt16();               // Skip 'type'.
                _sequence   = input.GetInt32(); // Get 'sequence'.
                _readHeader = true;
            }

            // Try to decode body
            AbstractMessage m = DecodeBody(session, input);

            // Return NEED_DATA if the body is not fully read.
            if (m == null)
            {
                return(MessageDecoderResult.NeedData);
            }
            else
            {
                _readHeader = false; // reset readHeader for the next decode
            }
            m.Sequence = _sequence;
            output.Write(m);

            return(MessageDecoderResult.OK);
        }
Exemplo n.º 10
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     base.Deserialize(input, context);
     TaskType      = input.GetPascalString();
     ShardId       = input.GetInt32();
     ParameterJson = input.GetString(Encoding.UTF8);
 }
Exemplo n.º 11
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     Status   = input.GetEnum <TransferClaimResponseStatus>();
     Type     = input.GetEnum <ClaimType>();
     EntityId = input.GetInt32();
     ClaimId  = input.GetUInt32();
     NewOwner = input.GetPascalString();
 }
Exemplo n.º 12
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            base.Deserialize(input, context);
            var itemCount = input.GetInt32();
            var dataSize  = input.GetInt32();
            var data      = input.GetSlice(dataSize).GetBytes();

            using (var mem = new MemoryStream(data)) {
                Items = new List <MessageItem>();
                for (int i = 0; i < itemCount; i++)
                {
                    var message = new MessageItem();
                    message.Read(mem);
                    Items.Add(message);
                }
            }
        }
Exemplo n.º 13
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     Type      = input.GetEnum <ClaimType>();
     Action    = input.GetEnum <ClaimAction>();
     EntityId  = input.GetInt32();
     ClaimId   = input.GetUInt32();
     SpecialId = input.GetUInt32();
     FromOwner = input.GetPascalString();
 }
        public void Deserialize(IoBuffer input, ISerializationContext context)
        {
            var length = input.GetInt32();

            Outfits = new VMGLOutfit[length];
            for (var i = 0; i < length; i++)
            {
                Outfits[i] = new VMGLOutfit();
                Outfits[i].Deserialize(input, context);
            }
        }
Exemplo n.º 15
0
        /// <inheritdoc/>
        protected override Boolean DoDecode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
        {
            if (!input.PrefixedDataAvailable(4, _maxObjectSize))
            {
                return(false);
            }

            input.GetInt32();
            output.Write(input.GetObject());
            return(true);
        }
Exemplo n.º 16
0
        protected override Message.AbstractMessage DecodeBody(IoSession session, IoBuffer input)
        {
            if (input.Remaining < Constants.ADD_BODY_LEN)
            {
                return(null);
            }

            AddMessage m = new AddMessage();

            m.Value = input.GetInt32();
            return(m);
        }
Exemplo n.º 17
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            Type = input.GetEnum <MailResponseType>();
            var numMessages = input.GetInt32();

            Messages = new MessageItem[numMessages];
            for (int j = 0; j < numMessages; j++)
            {
                var length = input.GetInt32();
                var dat    = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    dat[i] = input.Get();
                }

                using (var str = new MemoryStream(dat))
                {
                    Messages[j] = new MessageItem(str);
                }
            }
        }
            protected override Boolean DoDecode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
            {
                Assert.IsTrue(input.HasRemaining);

                if (input.Remaining < 4)
                {
                    return(false);
                }

                output.Write(input.GetInt32());
                return(true);
            }
Exemplo n.º 19
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            var dataLen = input.GetInt32(); //TODO: limits? 4MB is probably reasonable.
            var data    = new byte[dataLen];

            input.Get(data, 0, dataLen);
            using (var mem = new MemoryStream(data))
            {
                using (var reader = new BinaryReader(mem))
                {
                    Tuning = new DynamicTuning(reader);
                }
            }
        }
Exemplo n.º 20
0
        public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
        {
            int totalLen = input.GetInt32();
            int len      = totalLen - 4;

            if (input.Remaining < len)
            {
                return(MessageDecoderResult.NeedData);
            }
            byte[] jsonBuffer = new byte[len];
            input.Get(jsonBuffer, 0, len);
            string msg = System.Text.Encoding.UTF8.GetString(jsonBuffer);

            output.Write(msg);
            return(MessageDecoderResult.OK);
        }
Exemplo n.º 21
0
        public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
        {
            if (input.Remaining < 4)
            {
                return(MessageDecoderResult.NeedData);
            }
            int len = input.GetInt32();

            if (input.Remaining < len - 4)
            {
                return(MessageDecoderResult.NeedData);
            }
            if (len > 1000000)
            {
                return(MessageDecoderResult.NotOK);
            }
            return(MessageDecoderResult.OK);
        }
Exemplo n.º 22
0
 /**
  * 从buf中获得一个16位的无符号的整数
  *
  * @param buf
  * @param peek
  * @return
  */
 protected static int SeekIntFromBuffer(IoBuffer buf, bool peek)
 {
     if (buf.Remaining >= HEADER_TOTAL_BYTES)
     {
         int _op    = buf.Position;
         int _value = buf.GetInt32();
         if (peek)
         {
             buf.Position = _op;
         }
         if (_value > MAX_MESSAGE_LENGTH)
         {
             throw new Exception("接收消息标记的长度超过最大限定长度");
         }
         return(_value);
     }
     else
     {
         return(-1);
     }
 }
Exemplo n.º 23
0
        public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
        {
            int limit    = input.Limit;
            int position = input.Position;
            var len      = input.GetInt32();
            var version  = input.Get();

            input.Position = position;
            input.Limit    = input.Position + len;
            var buffer = input.Slice();

            input.Position = input.Limit;
            input.Limit    = limit;
            var message = DoDecode(version.ToEnum <MessageVersion>(), buffer);

            if (message != null)
            {
                output.Write(message);
            }
            return(MessageDecoderResult.OK);
        }
Exemplo n.º 24
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            Type = input.GetEnum <MailRequestType>();
            if (Type == MailRequestType.SEND)
            {
                var length = input.GetInt32();
                var dat    = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    dat[i] = input.Get();
                }

                using (var str = new MemoryStream(dat))
                {
                    Item = new MessageItem(str);
                }
            }
            else
            {
                TimestampID = input.GetInt64();
            }
        }
Exemplo n.º 25
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     base.Deserialize(input, context);
     TaskId = input.GetInt32();
 }
Exemplo n.º 26
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     AvatarId  = input.GetUInt32();
     LotId     = input.GetInt32();
     FromOwner = input.GetPascalString();
 }
Exemplo n.º 27
0
 public static uint GetUInt32(this IoBuffer buffer)
 {
     return((uint)buffer.GetInt32());
 }
Exemplo n.º 28
0
        public void TestSendLargeFile()
        {
            Assert.AreEqual(FILE_SIZE, file.Length, "Test file not as big as specified");

            CountdownEvent countdown = new CountdownEvent(1);

            Boolean[]   success   = { false };
            Exception[] exception = { null };

            Int32       port      = 12345;
            IoAcceptor  acceptor  = CreateAcceptor();
            IoConnector connector = CreateConnector();

            try
            {
                acceptor.ExceptionCaught += (s, e) =>
                {
                    exception[0] = e.Exception;
                    e.Session.Close(true);
                };

                Int32 index = 0;
                acceptor.MessageReceived += (s, e) =>
                {
                    IoBuffer buffer = (IoBuffer)e.Message;
                    while (buffer.HasRemaining)
                    {
                        int x = buffer.GetInt32();
                        if (x != index)
                        {
                            throw new Exception(String.Format("Integer at {0} was {1} but should have been {0}", index, x));
                        }
                        index++;
                    }
                    if (index > FILE_SIZE / 4)
                    {
                        throw new Exception("Read too much data");
                    }
                    if (index == FILE_SIZE / 4)
                    {
                        success[0] = true;
                        e.Session.Close(true);
                    }
                };

                acceptor.Bind(CreateEndPoint(port));

                connector.ExceptionCaught += (s, e) =>
                {
                    exception[0] = e.Exception;
                    e.Session.Close(true);
                };
                connector.SessionClosed += (s, e) => countdown.Signal();

                IConnectFuture future = connector.Connect(CreateEndPoint(port));
                future.Await();

                IoSession session = future.Session;
                session.Write(file);

                countdown.Wait();

                if (exception[0] != null)
                {
                    throw exception[0];
                }

                Assert.IsTrue(success[0], "Did not complete file transfer successfully");
                Assert.AreEqual(1, session.WrittenMessages, "Written messages should be 1 (we wrote one file)");
                Assert.AreEqual(FILE_SIZE, session.WrittenBytes, "Written bytes should match file size");
            }
            finally
            {
                try
                {
                    connector.Dispose();
                }
                finally
                {
                    acceptor.Dispose();
                }
            }
        }