コード例 #1
0
ファイル: AdvertiseCapacity.cs プロジェクト: jwofles/ForkSO
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     MaxLots       = input.GetInt16();
     CurrentLots   = input.GetInt16();
     CpuPercentAvg = input.Get();
     RamUsed       = input.GetInt64();
     RamAvaliable  = input.GetInt64();
 }
コード例 #2
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);
        }
コード例 #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);
            }
        }
コード例 #4
0
    public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
    {
        int size = input.GetInt16();
        int cap  = input.Capacity;

        Debug.Log(string.Format("{0} {1}", size, cap));
        return(MessageDecoderResult.OK);
    }
コード例 #5
0
        public static string GetUTF8(this IoBuffer buffer)
        {
            short len = buffer.GetInt16();

            if (len == -1)
            {
                return(null);
            }
            return(buffer.GetString(len, Encoding.UTF8));
        }
コード例 #6
0
        public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
        {
            // Return NeedData if the whole header is not read yet.
            if (input.Remaining < Constants.HEADER_LEN)
            {
                return(MessageDecoderResult.NeedData);
            }

            // Return OK if type and bodyLength matches.
            if (_type == input.GetInt16())
            {
                return(MessageDecoderResult.OK);
            }

            // Return NotOK if not matches.
            return(MessageDecoderResult.NotOK);
        }
コード例 #7
0
 private static short SeekShort(IoBuffer buf, bool peek)
 {
     if (buf.Remaining >= HEADER_TOTAL_BYTES)
     {
         int   _op    = buf.Position;
         short _value = buf.GetInt16();
         if (peek)
         {
             buf.Position = _op;
         }
         if (_value < 0)
         {
             throw new Exception("IO: 获取到非法数据");
         }
         return(_value);
     }
     else
     {
         return(-1);
     }
 }
コード例 #8
0
 public static ushort GetUInt16(this IoBuffer buffer)
 {
     return((ushort)buffer.GetInt16());
 }
コード例 #9
0
        public void Deserialize(IoBuffer input, ISerializationContext context)
        {
            AvatarId = input.GetUInt32();
            input.GetPascalVLCString(); //A
            input.GetPascalVLCString(); //B

            AvatarSkills_Logic             = input.GetInt16();
            AvatarSkills_LockLv_Logic      = input.GetInt16();
            AvatarSkills_Body              = input.GetInt16();
            AvatarSkills_LockLv_Body       = input.GetInt16();
            AvatarSkills_LockLv_Mechanical = input.GetInt16();
            AvatarSkills_LockLv_Creativity = input.GetInt16();
            AvatarSkills_LockLv_Cooking    = input.GetInt16();
            AvatarSkills_Cooking           = input.GetInt16();
            AvatarSkills_Charisma          = input.GetInt16();
            AvatarSkills_LockLv_Charisma   = input.GetInt16();
            AvatarSkills_Mechanical        = input.GetInt16();
            AvatarSkills_Creativity        = input.GetInt16();

            //Unknown
            input.GetUInt32(); //0x28292a2b
            input.GetUInt32(); //0x2c2d2e2f
            input.GetUInt32(); //0x30313233
            input.GetUInt32(); //0x34353637
            input.GetUInt32(); //0x38393a3b
            input.GetUInt32(); //0x3c3d3e3f
            input.GetUInt32(); //0x40414243
            input.Get();       //0x44
            input.Get();       //0x45

            Cash = input.GetUInt32();

            //More unknown
            input.GetUInt32();          //0x4a4b4c4d
            input.GetUInt32();          //0x4e4f5051
            input.Get();                //0x52

            input.GetPascalVLCString(); //C
            input.GetPascalVLCString(); //D
            input.GetPascalVLCString(); //E
            input.GetPascalVLCString(); //F
            input.GetPascalVLCString(); //G

            input.GetUInt32();          //0x54555657
            input.GetUInt32();          //0x58595A5B
            input.GetUInt32();          //0x5C5D5E5F
            input.GetUInt32();          //0x60616263
            input.GetUInt32();          //0x64656667
            input.GetUInt32();          //0x68696A6B
            input.GetUInt32();          //0x6C6D6E6F
            input.GetUInt32();          //0x70717273
            input.GetUInt32();          //0x74757677


            Bonus = new List <LoadAvatarBonus>();
            var bonusCount = input.GetUInt32();

            for (var i = 0; i < bonusCount; i++)
            {
                //Unknown
                input.GetUInt32(); //0x7C7D7E7F
                input.GetUInt32(); //0x80818283

                var simBonus      = input.GetUInt32();
                var propertyBonus = input.GetUInt32();
                var visitorBonus  = input.GetUInt32();
                var dateString    = input.GetPascalVLCString();

                Bonus.Add(new LoadAvatarBonus {
                    Date          = dateString,
                    PropertyBonus = propertyBonus,
                    VisitorBonus  = visitorBonus,
                    SimBonus      = simBonus
                });
            }
        }
コード例 #10
0
        public DuplexMessage Read(IoBuffer input)
        {
            DuplexMessage message = null;

            byte[] identifier = null;
            byte[] messageId  = null;
            try
            {
                using (var scope = ObjectHost.Host.BeginLifetimeScope())
                {
                    // skip 4 bytes length
                    input.Skip(4);
                    var filters     = new List <IMessageFilter>();
                    var version     = input.Get().ToEnum <MessageVersion>();
                    var commandCode = input.GetInt16().ToEnum <CommandCode>();
                    var errorCode   = input.Get().ToEnum <ErrorCode>();
                    var messageType = input.Get().ToEnum <MessageType>();
                    identifier = input.GetArray(16);
                    messageId  = input.GetArray(16);
                    var filterType    = input.Get().ToEnum <MessageFilterType>();
                    var filterCode    = new byte[] { input.Get(), input.Get() };
                    var serializeMode = input.Get().ToEnum <SerializeMode>();
                    input.Position = 0;
                    var header = input.GetArray(45);

                    var checksum = input.GetArray(4);
                    var body     = input.GetRemainingArray();

                    //make data stack like
                    //- checksum
                    //- header without checksum
                    //- body
                    //- identifier
                    var dataStack = new StackMessageDataContaner();
                    dataStack.Push(identifier);
                    dataStack.Push(body);
                    dataStack.Push(header);
                    dataStack.Push(checksum);

                    FilterResult result = new FilterResult {
                        OK = true
                    };
                    var filterFactory = scope.Resolve <MessageFilterFactory>();
                    filters.Add(filterFactory.CreateFilter(filterCode[0], filterType & MessageFilterType.Checksum));
                    filters.Add(filterFactory.CreateFilter(filterCode[0], filterType & MessageFilterType.Crypto));
                    filters.Add(filterFactory.CreateFilter(filterCode[0], filterType & MessageFilterType.Compression));

                    foreach (var filter in filters)
                    {
                        result = filter.In(dataStack);
                        if (!result.OK)
                        {
                            break;
                        }
                    }

                    if (result.OK)
                    {
                        message = DuplexMessage.CreateMessage(
                            new MessageHeader(
                                messageId.ToBase64(),
                                version,
                                identifier.ToHex(),
                                filterCode,
                                filterType,
                                errorCode == ErrorCode.NoError ? MessageState.Success : MessageState.Fail,
                                errorCode,
                                serializeMode,
                                commandCode,
                                messageType), dataStack.Take());
                    }
                    else
                    {
                        message = DuplexMessage.CreateMessage(
                            new MessageHeader(
                                messageId.ToBase64(),
                                version,
                                identifier.ToHex(),
                                filterCode,
                                MessageFilterType.Checksum,
                                MessageState.Fail,
                                result.Error,
                                SerializeMode.None,
                                commandCode,
                                messageType), null);
                    }
                }
            }
            catch (Exception ex)
            {
                //dont do anything, may be let requestor retry.
                Log.Error(ErrorCode.SysError.ToString(), ex);
            }
            return(message);
        }