Exemplo n.º 1
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutInt16(MaxLots);
     output.PutInt16(CurrentLots);
     output.Put(CpuPercentAvg);
     output.PutInt64(RamUsed);
     output.PutInt64(RamAvaliable);
 }
Exemplo n.º 2
0
 public static void PutUTF8(this IoBuffer buffer, string value)
 {
     if (value == null)
     {
         buffer.PutInt16(-1);
     }
     else
     {
         buffer.PutInt16((short)value.Length);
         buffer.PutString(value, Encoding.UTF8);
     }
 }
Exemplo n.º 3
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.º 4
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.º 5
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.º 6
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.º 7
0
 public static void PutUInt16(this IoBuffer buffer, ushort value)
 {
     buffer.PutInt16((short)value);
 }
Exemplo n.º 8
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.º 9
0
        public void Serialize(IoBuffer output, ISerializationContext context)
        {
            output.PutUInt32(AvatarId);
            output.PutPascalVLCString("A");
            output.PutPascalVLCString("B");

            output.PutInt16(AvatarSkills_Logic);
            output.PutInt16(AvatarSkills_LockLv_Logic);
            output.PutInt16(AvatarSkills_Body);
            output.PutInt16(AvatarSkills_LockLv_Body);
            output.PutInt16(AvatarSkills_LockLv_Mechanical);
            output.PutInt16(AvatarSkills_LockLv_Creativity);
            output.PutInt16(AvatarSkills_LockLv_Cooking);
            output.PutInt16(AvatarSkills_Cooking);
            output.PutInt16(AvatarSkills_Charisma);
            output.PutInt16(AvatarSkills_LockLv_Charisma);
            output.PutInt16(AvatarSkills_Mechanical);
            output.PutInt16(AvatarSkills_Creativity);

            //Unknown
            output.PutUInt32(0x28292a2b);
            output.PutUInt32(0x2c2d2e2f);
            output.PutUInt32(0x30313233);
            output.PutUInt32(0x34353637);
            output.PutUInt32(0x38393a3b);
            output.PutUInt32(0x3c3d3e3f);
            output.PutUInt32(0x40414243);
            output.Put(0x44);
            output.Put(0x45);

            output.PutUInt32(Cash);

            //Unknown
            output.PutUInt32(0x4a4b4c4d);
            output.PutUInt32(0x4e4f5051);
            output.Put(0x52);

            output.PutPascalVLCString("C");
            output.PutPascalVLCString("D");
            output.PutPascalVLCString("E");
            output.PutPascalVLCString("F");
            output.PutPascalVLCString("G");

            output.PutUInt32(0x54555657);
            output.PutUInt32(0x58595A5B);
            output.PutUInt32(0x5C5D5E5F);
            output.PutUInt32(0x60616263);
            output.PutUInt32(0x64656667);
            output.PutUInt32(0x68696A6B);
            output.PutUInt32(0x6C6D6E6F);
            output.PutUInt32(0x70717273);
            output.PutUInt32(0x74757677);

            //Bonus count
            if (Bonus == null)
            {
                output.PutUInt32(0);
            }
            else
            {
                output.PutUInt32((uint)Bonus.Count);
                for (var i = 0; i < Bonus.Count; i++)
                {
                    var bonus = Bonus[i];

                    //Unknown
                    output.PutUInt32(0x7C7D7E7F);
                    output.PutUInt32(0x80818283);

                    //Sim bonus
                    output.PutUInt32(bonus.SimBonus);

                    //Property bonus
                    output.PutUInt32(bonus.PropertyBonus);

                    //Visitor bonus
                    output.PutUInt32(bonus.VisitorBonus);

                    //Date string
                    output.PutPascalVLCString(bonus.Date);
                }
            }


            //Unknown
            //count
            output.PutUInt32(0x01);
            output.PutUInt32(0x94959697);
            output.PutUInt64(0x98999a9b9c9d9e9f);

            //Unknown
            //count
            output.PutUInt32(0x01);
            output.PutUInt32(0xa5a6a7a8);
            output.PutUInt32(0xa9aaabac);

            //Unknown
            //count
            output.PutUInt32(0x01);
            output.PutUInt16(0xb1b2);
            output.PutUInt16(0xb3b4);
            output.PutUInt32(0xb5b6b7b8);
            output.PutUInt16(0xb9ba);

            output.PutUInt16(0xbbbc);
            output.PutUInt16(0xbdbe);
            output.PutUInt32(0xbfc0c1c2);
            output.PutUInt32(0xc3c4c5c6);

            //Unknown
            //count
            output.PutUInt32(0x01);
            output.PutUInt32(0xcbcccdce);
            output.PutUInt32(0xcfd0d1d2);
            output.PutUInt32(0xd3d4d5d6);
            output.Put(0xd7);
            output.Put(0xd8);
            output.PutUInt32(0xd9dadbdc);
            output.PutUInt32(0xdddedfe0);
            output.PutUInt32(0xe1e2e3e4);

            //Unknown
            //count
            output.PutUInt32(0x01);
            output.PutUInt32(0xe9eaebec);
            output.PutUInt32(0xedeeeff0);
            output.PutUInt32(0xf1f2f3f4);
            output.Put(0xf5);
            output.Put(0xf6);
            output.PutUInt32(0xf7f8f9fa);
            output.PutUInt32(0xfbfcfdfe);
            output.PutUInt32(0xff808182);

            //Unknown
            //count
            output.PutUInt32(0x01);

            output.PutUInt32(0x8788898a);
            output.PutUInt16(0x8b8c);
            output.PutUInt32(0x8d8e8f90);
            output.PutUInt32(0x91929394);
            output.PutUInt32(0x95969798);
            output.PutUInt32(0x999a9b9c);

            //Unknown
            //count
            output.PutUInt32(0x01);
            output.PutUInt16(0x7071);
            output.PutUInt64(0x7273747576777879);

            //Unknown
            output.PutUInt32(0x7a7b7c7d);
            output.PutUInt32(0x7e7f6061);
            output.PutUInt32(0x62636465);
            output.PutUInt32(0x66676869);
            output.PutUInt32(0x6a6b6c6d);
            output.PutUInt32(0x6e6f5051);
            output.PutUInt32(0x52535455);
            output.PutUInt32(0x56575859);
            output.PutUInt32(0x69f4d5e8);
            output.PutUInt32(0x5e5f4041);
        }