ReadDouble() public method

public ReadDouble ( ) : double
return double
コード例 #1
0
 protected override void OnRead(ByteBuffer buffer)
 {
     X        = buffer.ReadDouble();
     FeetY    = buffer.ReadDouble();
     HeadY    = buffer.ReadDouble();
     Z        = buffer.ReadDouble();
     OnGround = buffer.ReadBoolean();
 }
コード例 #2
0
        private void parsePacket(ByteBuffer data)
        {
            data.SetIndex(3);
            this._x = data.ReadInt32();
            this._y = data.ReadInt32();
            this._z = data.ReadInt32();
            data.ReadInt32();
            this._objectId    = data.ReadInt32();
            this._visibleName = data.ReadString();
            this._race        = data.ReadInt32();
            this._sex         = data.ReadInt32();
            this._class       = data.ReadInt32();

            this._paperdollHairall = data.ReadInt32();
            this._paperdollHead    = data.ReadInt32();
            this._paperdollRhand   = data.ReadInt32();
            this._paperdollLhand   = data.ReadInt32();
            this._paperdollGloves  = data.ReadInt32();
            this._paperdollChest   = data.ReadInt32();
            this._paperdollLegs    = data.ReadInt32();
            this._paperdollFeet    = data.ReadInt32();
            this._paperdollBack    = data.ReadInt32();
            this._paperdollLRhand  = data.ReadInt32();
            this._paperdollHair    = data.ReadInt32();
            this._paperdollHair2   = data.ReadInt32();

            data.SetIndex(data.GetIndex() + 112);
            this._pvpFlag = data.ReadInt32();
            this._karma   = data.ReadInt32();
            this._mAtkSpd = data.ReadInt32();
            this._pAtkSpd = data.ReadInt32();

            data.SetIndex(data.GetIndex() + 8); //dd

            this._speed = data.ReadInt32();
            data.SetIndex(data.GetIndex() + 28);

            this._movementSpeedMultip = data.ReadDouble();
            this._AttackSpeedMultip   = data.ReadDouble();

            // + ffddd
            data.SetIndex(data.GetIndex() + 28);
            this._title       = data.ReadString();
            this._clanId      = data.ReadInt32();
            this._clanCrestId = data.ReadInt32();
            this._allyId      = data.ReadInt32();
            this._allyCrestId = data.ReadInt32();
        }
コード例 #3
0
        private static void Packet_UpdateUserData(byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            //skip read pakcet id
            buffer.ReadLong();

            long connectionId = buffer.ReadLong();

            long UserId = buffer.ReadLong();

            string Nickname = buffer.ReadStringUnicode();

            double money = buffer.ReadDouble();

            // if avatar string is empty then skip. Otherwise read
            string avatarPath = "";

            if (buffer.Length() > 0)
            {
                int strLen = buffer.ReadInteger(false);
                if (strLen > 0)
                {
                    avatarPath = buffer.ReadString();
                }
            }

            //Invoke callback on observers
            FoolObservable.OnUpdateUserData(connectionId, UserId, Nickname, money, avatarPath);
        }
コード例 #4
0
        private static void Packet_EndGameFool(byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            //Skip packetId
            buffer.ReadLong();

            //Read player who fool
            long foolPlayerId = buffer.ReadLong();

            //Read rewards count
            int rewardsN = buffer.ReadInteger();
            //rewards
            Dictionary <long, double> rewards = new Dictionary <long, double>(rewardsN);

            for (int i = 0; i < rewardsN; i++)
            {
                long   player = buffer.ReadLong();
                double reward = buffer.ReadDouble();
                rewards.Add(player, reward);
            }

            //Invoke callback on observers
            FoolObservable.OnEndGameFool(foolPlayerId, rewards);
        }
コード例 #5
0
ファイル: ByteBufferWrap.cs プロジェクト: 737871854/FireMen2
    static int ReadDouble(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        ByteBuffer obj = (ByteBuffer)LuaScriptMgr.GetNetObjectSelf(L, 1, "ByteBuffer");
        double     o   = obj.ReadDouble();

        LuaScriptMgr.Push(L, o);
        return(1);
    }
コード例 #6
0
ファイル: ByteBufferTests.cs プロジェクト: FelCore/FelCore
        public void ShouldReadDouble()
        {
            _buffer = new ByteBuffer();
            var d1 = 9234432432423.00234;

            _buffer.Append(d1);
            _buffer.Append(9223372036854775807);

            Assert.AreEqual(d1, _buffer.ReadDouble());
        }
コード例 #7
0
ファイル: ByteBufferWrap.cs プロジェクト: moto2002/ARPG
 static int ReadDouble(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         ByteBuffer obj = (ByteBuffer)ToLua.CheckObject(L, 1, typeof(ByteBuffer));
         double     o   = obj.ReadDouble();
         LuaDLL.lua_pushnumber(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #8
0
        private static void Packet_PlayerWon(byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            //Skip packetId
            buffer.ReadLong();

            //Read player who won
            long wonPlayerId = buffer.ReadLong();

            //read winner's reward
            double reward = buffer.ReadDouble();

            //Invoke callback on observers
            FoolObservable.OnPlayerWon(wonPlayerId, reward);
        }
コード例 #9
0
    private static int ReadDouble(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            ByteBuffer byteBuffer = (ByteBuffer)ToLua.CheckObject(L, 1, typeof(ByteBuffer));
            double     number     = byteBuffer.ReadDouble();
            LuaDLL.lua_pushnumber(L, number);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
コード例 #10
0
        protected void Packet_CreateRoom(long connectionId, byte[] data)
        {
            //Add our data to buffer
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            //skip packet id
            buffer.ReadLong();

            //Read max players
            int maxPlayers = buffer.ReadInteger();
            //Read deckSize
            int deckSize = buffer.ReadInteger();
            //Read bet
            double bet = buffer.ReadDouble();

            RoomManager.CreateRoom(connectionId, maxPlayers, deckSize, bet);
        }
コード例 #11
0
 public override void ReadByte(ByteBuffer byteBuf)
 {
     Id                 = byteBuf.ReadInt();
     IsLeader           = byteBuf.ReadBool();
     Race               = StringConvert.IndexToEnum <ERaceType>(byteBuf.ReadInt());
     Name               = LANG.Convert(byteBuf.ReadInt());
     Model              = byteBuf.ReadUTF();
     Age                = byteBuf.ReadInt();
     Power              = byteBuf.ReadLong();
     Speed              = byteBuf.ReadFloat();
     Hp                 = byteBuf.ReadDouble();
     SomeIntParams      = byteBuf.ReadListInt();
     SomeLongParams     = byteBuf.ReadListLong();
     SomeFloatParams    = byteBuf.ReadListFloat();
     SomeDoubleParams   = byteBuf.ReadListDouble();
     SomeStringParams   = byteBuf.ReadListUTF();
     SomeLanguageParams = LANG.Convert(byteBuf.ReadListInt());
     SkillWrapper       = SkillWrapper.Parse(byteBuf);
 }
コード例 #12
0
        static int _m_ReadDouble(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                ByteBuffer gen_to_be_invoked = (ByteBuffer)translator.FastGetCSObj(L, 1);



                {
                    double gen_ret = gen_to_be_invoked.ReadDouble(  );
                    LuaAPI.lua_pushnumber(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
コード例 #13
0
ファイル: HisDataServerProcess.cs プロジェクト: cdy816/mars
        /// <summary>
        ///
        /// </summary>
        /// <param name="clientid"></param>
        /// <param name="block"></param>
        private void ProcessSetHisData(string clientid, ByteBuffer block)
        {
            var id    = block.ReadInt();
            var count = block.ReadInt();
            var typ   = block.ReadByte();
            //int timedu = block.ReadInt();
            var service = ServiceLocator.Locator.Resolve <ITagHisValueProduct>();

            //List<TagValue> tagvalues = new List<TagValue>();
            switch (typ)
            {
            case (byte)TagType.Bool:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadByte();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.Byte:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadByte();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    // service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.Short:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadShort();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    //  service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.UShort:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadUShort();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    // service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.Int:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadInt();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    // service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.UInt:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadUInt();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    //service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.Long:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadLong();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    // service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.ULong:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = (ulong)block.ReadLong();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    //service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.Float:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadFloat();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    //service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.Double:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadDouble();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    //service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.String:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = block.ReadString();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    //service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.DateTime:
                for (int i = 0; i < count; i++)
                {
                    var dt   = DateTime.FromBinary(block.ReadLong());
                    var bval = DateTime.FromBinary(block.ReadLong());
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    // service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.IntPoint:
                for (int i = 0; i < count; i++)
                {
                    var dt    = DateTime.FromBinary(block.ReadLong());
                    var bval1 = block.ReadInt();
                    var bval2 = block.ReadInt();
                    var qa    = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, bval1, bval2);
                    //service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.UIntPoint:
                for (int i = 0; i < count; i++)
                {
                    var dt = DateTime.FromBinary(block.ReadLong());
                    //var bval = new UIntPointData() { X = block.ReadUnsignedInt(), Y = block.ReadUnsignedInt() };
                    var bval1 = block.ReadUInt();
                    var bval2 = block.ReadUInt();
                    var qa    = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, bval1, bval2);
                    //service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.IntPoint3:
                for (int i = 0; i < count; i++)
                {
                    var dt = DateTime.FromBinary(block.ReadLong());
                    // var bval = new IntPoint3Data() { X = block.ReadInt(), Y = block.ReadInt(),Z=block.ReadInt() };
                    var bval1 = block.ReadInt();
                    var bval2 = block.ReadInt();
                    var bval3 = block.ReadInt();
                    var qa    = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, bval1, bval2, bval3);
                    // service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.UIntPoint3:
                for (int i = 0; i < count; i++)
                {
                    var dt = DateTime.FromBinary(block.ReadLong());
                    // var bval = new UIntPoint3Data() { X = block.ReadUnsignedInt(), Y = block.ReadUnsignedInt(), Z = block.ReadUnsignedInt() };
                    var bval1 = block.ReadUInt();
                    var bval2 = block.ReadUInt();
                    var bval3 = block.ReadUInt();
                    var qa    = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, bval1, bval2, bval3);
                    //service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.LongPoint:
                for (int i = 0; i < count; i++)
                {
                    var dt = DateTime.FromBinary(block.ReadLong());
                    // var bval = new LongPointData() { X = block.ReadLong(), Y = block.ReadLong() };
                    var bval1 = block.ReadLong();
                    var bval2 = block.ReadLong();
                    var qa    = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, bval1, bval2);
                    //service.SetTagHisValue(id, new TagValue() { Quality = qa, Time = dt, Value = bval });
                }
                break;

            case (byte)TagType.ULongPoint:
                for (int i = 0; i < count; i++)
                {
                    var dt = DateTime.FromBinary(block.ReadLong());
                    //  var bval = new ULongPointData() { X = (ulong)block.ReadLong(), Y = (ulong)block.ReadLong() };
                    var bval1 = (ulong)block.ReadLong();
                    var bval2 = (ulong)block.ReadLong();
                    var qa    = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, bval1, bval2);
                }
                break;

            case (byte)TagType.LongPoint3:
                for (int i = 0; i < count; i++)
                {
                    var dt = DateTime.FromBinary(block.ReadLong());
                    // var bval = new LongPoint3Data() { X = block.ReadLong(), Y = block.ReadLong(),Z=block.ReadLong() };
                    var bval1 = block.ReadLong();
                    var bval2 = block.ReadLong();
                    var bval3 = block.ReadLong();
                    var qa    = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, bval1, bval2, bval3);
                }
                break;

            case (byte)TagType.ULongPoint3:
                for (int i = 0; i < count; i++)
                {
                    var dt = DateTime.FromBinary(block.ReadLong());
                    //  var bval = new ULongPoint3Data() { X = (ulong)block.ReadLong(), Y = (ulong)block.ReadLong(), Z = (ulong)block.ReadLong() };
                    var bval1 = (ulong)block.ReadLong();
                    var bval2 = (ulong)block.ReadLong();
                    var bval3 = (ulong)block.ReadLong();
                    var qa    = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, bval1, bval2, bval3);
                }
                break;
            }


            //service.SetTagHisValue(id, tagvalues);

            Parent.AsyncCallback(clientid, ToByteBuffer(APIConst.HisValueFun, (byte)1));
        }
コード例 #14
0
ファイル: Bytes.cs プロジェクト: 2ez-bit/Ultimatefighter
 //Reads the next double of the byteArray using BitConverter from readLong
 public double readDouble()
 {
     return(ByteBuffer.ReadDouble());
 }
コード例 #15
0
 public override object          Deserialize(ByteBuffer buffer, Type fieldType)
 {
     return(buffer.ReadDouble());
 }
コード例 #16
0
        public void Test()
        {
            var bytes   = new byte[] { 3, 4, 5, 6 };
            var byteSeg = new ArraySegment <byte>(bytes, 1, 2);

            const string thisIsATest = "this is a test \u3333 \x22";
            const double d           = 1.2345e-200;
            const float  f           = 1.2345e22f;
            const ulong  ul          = 0xddddccccbbbbaaaaL;
            const long   l           = 0x4dddcc3cbb2baa1aL;

            var bb = new ByteBuffer(4);

            for (var i = 0; i < 4; ++i)
            {
                Console.WriteLine(i);
                var startingPos = ByteBuffer.StartWritePacket(bb);
                ByteBuffer.WriteUlong(bb, ul);
                ByteBuffer.WriteUshort(bb, 2345);
                ByteBuffer.WriteBool(bb, true);
                ByteBuffer.WriteLong(bb, l);
                ByteBuffer.WriteBool(bb, false);
                ByteBuffer.WriteByte(bb, 0x44);
                ByteBuffer.WriteDouble(bb, d);
                ByteBuffer.WriteFloat(bb, f);
                ByteBuffer.WriteInt(bb, 45);
                ByteBuffer.WriteUint(bb, 33);
                ByteBuffer.WriteBytes(bb, bytes);
                ByteBuffer.WriteBytes(bb, byteSeg);
                ByteBuffer.WriteString(bb, thisIsATest);
                ByteBuffer.WriteString(bb, null);
                ByteBuffer.WriteUlong(bb, 0xFDECBA9876543210L);
                ByteBuffer.WriteInt(bb, 0); // not read by reader
                ByteBuffer.EndWritePacket(bb, startingPos, 0);

                var startingPos1 = ByteBuffer.StartWritePacket(bb);
                ByteBuffer.WriteInt(bb, 55);
                ByteBuffer.EndWritePacket(bb, startingPos1, 0);

                Assert.IsFalse(ByteBuffer.TryReadPacket(bb, r => { }, 0));

                ByteBuffer.WriteCommit(bb);

                Assert.IsTrue(ByteBuffer.TryReadPacket(bb, r =>
                {
                    Assert.AreEqual(ul, ByteBuffer.ReadUlong(r));
                    Assert.AreEqual(2345, ByteBuffer.ReadUshort(r));
                    Assert.AreEqual(true, ByteBuffer.ReadBool(r));
                    Assert.AreEqual(l, ByteBuffer.ReadLong(r));
                    Assert.AreEqual(false, ByteBuffer.ReadBool(r));
                    Assert.AreEqual(0x44, ByteBuffer.ReadByte(r));
                    Assert.AreEqual(d, ByteBuffer.ReadDouble(r));
                    Assert.AreEqual(f, ByteBuffer.ReadFloat(r));
                    Assert.AreEqual(45, ByteBuffer.ReadInt(r));
                    Assert.AreEqual(33, ByteBuffer.ReadUint(r));
                    var readBytes = ByteBuffer.ReadBytes(r);
                    Assert.IsTrue(bytes.Eq(readBytes));
                    readBytes = ByteBuffer.ReadBytes(r);
                    Assert.IsTrue(byteSeg.Eq(readBytes));
                    var readString = ByteBuffer.ReadString(r);
                    Assert.AreEqual(thisIsATest, readString);
                    Assert.IsNull(ByteBuffer.ReadString(r));
                    Assert.AreEqual(0xFDECBA9876543210L, ByteBuffer.ReadUlong(r));
                },
                                                       0));

                var rp = bb.ReadPosition;
                Assert.Greater(rp, 0);
                ByteBuffer.ReadCommit(bb);
                Assert.Greater(bb.WriteCommitPosition, 0);
                Assert.AreEqual(0, bb.ReadPosition);
                ByteBuffer.ReadCommit(bb);

                Assert.IsTrue(ByteBuffer.TryReadPacket(bb, r => { Assert.AreEqual(55, ByteBuffer.ReadInt(r)); }, 0));

                ByteBuffer.ReadCommit(bb);
                Assert.AreEqual(0, bb.ReadPosition);
                Assert.AreEqual(0, bb.WritePosition);
                Assert.AreEqual(0, bb.WriteCommitPosition);

                var x = ByteBuffer.StartWritePacket(bb);
                ByteBuffer.WriteUlong(bb, 0xddddccccbbbbaaaaL);
                ByteBuffer.WriteString(bb, thisIsATest);
                ByteBuffer.WriteInt(bb, 45);
                ByteBuffer.WriteUint(bb, 33);
                ByteBuffer.WriteUlong(bb, 0xFDECBA9876543210L);
                ByteBuffer.WriteInt(bb, 0); // not read by reader
                ByteBuffer.EndWritePacket(bb, x, 0);
                ByteBuffer.WriteCommit(bb);
                int ep;
                ByteBuffer.StartTryReadPacket(bb, out ep, 0);
                Assert.AreEqual(0xddddccccbbbbaaaaL, ByteBuffer.ReadUlong(bb));
                Assert.AreEqual(thisIsATest, ByteBuffer.ReadString(bb));
                Assert.AreEqual(45, ByteBuffer.ReadInt(bb));
                Assert.AreEqual(33, ByteBuffer.ReadUint(bb));
                Assert.AreEqual(0xFDECBA9876543210L, ByteBuffer.ReadUlong(bb));
                ByteBuffer.EndReadPacket(bb, ep);

                ByteBuffer.ReadCommit(bb);
                Assert.AreEqual(0, bb.ReadPosition);
                Assert.AreEqual(0, bb.WritePosition);
                Assert.AreEqual(0, bb.WriteCommitPosition);
            }
        }
コード例 #17
0
ファイル: RealDataServerProcess.cs プロジェクト: cdy816/mars
        /// <summary>
        ///
        /// </summary>
        /// <param name="clientid"></param>
        /// <param name="block"></param>
        private void ProcessSetRealData(string clientid, ByteBuffer block)
        {
            var service = ServiceLocator.Locator.Resolve <IRealTagConsumer>();
            int count   = block.ReadInt();

            for (int i = 0; i < count; i++)
            {
                var    id    = block.ReadInt();
                byte   typ   = block.ReadByte();
                object value = null;
                switch (typ)
                {
                case (byte)TagType.Bool:
                    value = block.ReadByte();
                    break;

                case (byte)TagType.Byte:
                    value = block.ReadByte();
                    break;

                case (byte)TagType.Short:
                    value = block.ReadShort();
                    break;

                case (byte)TagType.UShort:
                    value = (ushort)block.ReadShort();
                    break;

                case (byte)TagType.Int:
                    value = block.ReadInt();
                    break;

                case (byte)TagType.UInt:
                    value = (uint)block.ReadInt();
                    break;

                case (byte)TagType.Long:
                    value = block.ReadLong();
                    break;

                case (byte)TagType.ULong:
                    value = (ulong)block.ReadLong();
                    break;

                case (byte)TagType.Float:
                    value = block.ReadFloat();
                    break;

                case (byte)TagType.Double:
                    value = block.ReadDouble();
                    break;

                case (byte)TagType.String:
                    value = block.ReadString();
                    break;

                case (byte)TagType.DateTime:
                    var tick = block.ReadLong();
                    value = new DateTime(tick);
                    break;

                case (byte)TagType.IntPoint:
                    value = new IntPointData(block.ReadInt(), block.ReadInt());
                    break;

                case (byte)TagType.UIntPoint:
                    value = new UIntPointData(block.ReadInt(), block.ReadInt());
                    break;

                case (byte)TagType.IntPoint3:
                    value = new IntPoint3Data(block.ReadInt(), block.ReadInt(), block.ReadInt());
                    break;

                case (byte)TagType.UIntPoint3:
                    value = new UIntPoint3Data(block.ReadInt(), block.ReadInt(), block.ReadInt());
                    break;

                case (byte)TagType.LongPoint:
                    value = new LongPointData(block.ReadLong(), block.ReadLong());
                    break;

                case (byte)TagType.ULongPoint:
                    value = new ULongPointData(block.ReadLong(), block.ReadLong());
                    break;

                case (byte)TagType.LongPoint3:
                    value = new LongPoint3Data(block.ReadLong(), block.ReadLong(), block.ReadLong());
                    break;

                case (byte)TagType.ULongPoint3:
                    value = new ULongPoint3Data(block.ReadLong(), block.ReadLong(), block.ReadLong());
                    break;
                }
                service.SetTagValueForConsumer(id, value);
            }
            Parent.AsyncCallback(clientid, ToByteBuffer(ApiFunConst.RealDataSetFun, (byte)1));
        }
コード例 #18
0
 public object Read(ByteBuffer buffer, bool peek = false) => buffer.ReadDouble(peek);
コード例 #19
0
        public void TestBasic()
        {
            ByteBuffer bb = ByteBuffer.Allocate();

            Assert.AreEqual(bb.ReadIndex, bb.WriteIndex);

            {
                bool v = true;
                bb.WriteBool(v);
                Assert.AreEqual(1, bb.Size);
                Assert.AreEqual(1, bb.Bytes[bb.ReadIndex]);
                Assert.AreEqual(v, bb.ReadBool());
                Assert.AreEqual(bb.ReadIndex, bb.WriteIndex);
            }
            {
                byte v = 1;
                bb.WriteByte(v);
                Assert.AreEqual(1, bb.Size);
                Assert.AreEqual(1, bb.Bytes[bb.ReadIndex]);
                Assert.AreEqual(v, bb.ReadByte());
                Assert.AreEqual(bb.ReadIndex, bb.WriteIndex);
            }
            {
                double v = 1.1;
                bb.WriteDouble(v);
                Assert.AreEqual(8, bb.Size);
                //Console.WriteLine(bb);
                Assert.AreEqual("9A-99-99-99-99-99-F1-3F", bb.ToString());
                Assert.AreEqual(v, bb.ReadDouble());
                Assert.AreEqual(bb.ReadIndex, bb.WriteIndex);
            }
            {
                float v = 1.1f;
                bb.WriteFloat(v);
                Assert.AreEqual(4, bb.Size);
                //Console.WriteLine(bb);
                Assert.AreEqual("CD-CC-8C-3F", bb.ToString());
                Assert.AreEqual(v, bb.ReadFloat());
                Assert.AreEqual(bb.ReadIndex, bb.WriteIndex);
            }
            {
                int int4 = 0x12345678;
                bb.WriteInt4(int4);
                Assert.AreEqual(4, bb.Size);
                //Console.WriteLine(bb);
                Assert.AreEqual("78-56-34-12", bb.ToString());
                Assert.AreEqual(int4, bb.ReadInt4());
                Assert.AreEqual(bb.ReadIndex, bb.WriteIndex);
            }
            {
                long long8 = 0x1234567801020304;
                bb.WriteLong8(long8);
                Assert.AreEqual(8, bb.Size);
                //Console.WriteLine(bb);
                Assert.AreEqual("04-03-02-01-78-56-34-12", bb.ToString());
                Assert.AreEqual(long8, bb.ReadLong8());
                Assert.AreEqual(bb.ReadIndex, bb.WriteIndex);
            }
            {
                long long8 = -12345678;
                bb.WriteLong8(long8);
                Assert.AreEqual(8, bb.Size);
                //Console.WriteLine(bb);
                Assert.AreEqual("B2-9E-43-FF-FF-FF-FF-FF", bb.ToString());
                Assert.AreEqual(long8, bb.ReadLong8());
                Assert.AreEqual(bb.ReadIndex, bb.WriteIndex);
            }
            {
                long long8 = -1;
                bb.WriteLong8(long8);
                Assert.AreEqual(8, bb.Size);
                //Console.WriteLine(bb);
                Assert.AreEqual("FF-FF-FF-FF-FF-FF-FF-FF", bb.ToString());
                Assert.AreEqual(long8, bb.ReadLong8());
                Assert.AreEqual(bb.ReadIndex, bb.WriteIndex);
            }
        }
コード例 #20
0
        private void ReadOperand(Instruction instruction)
        {
            switch (instruction.OpCode.OperandType)
            {
            case OperandType.InlineNone:
                break;

            case OperandType.InlineSwitch:
                int   length      = _il.ReadInt32();
                int   base_offset = _il.Position + (4 * length);
                int[] branches    = new int[length];
                for (int i = 0; i < length; i++)
                {
                    branches[i] = _il.ReadInt32() + base_offset;
                }

                instruction.Operand = branches;
                break;

            case OperandType.ShortInlineBrTarget:
                instruction.Operand = (((sbyte)_il.ReadByte()) + _il.Position);
                break;

            case OperandType.InlineBrTarget:
                instruction.Operand = _il.ReadInt32() + _il.Position;
                break;

            case OperandType.ShortInlineI:
                if (instruction.OpCode == OpCodes.Ldc_I4_S)
                {
                    instruction.Operand = (sbyte)_il.ReadByte();
                }
                else
                {
                    instruction.Operand = _il.ReadByte();
                }
                break;

            case OperandType.InlineI:
                instruction.Operand = _il.ReadInt32();
                break;

            case OperandType.ShortInlineR:
                instruction.Operand = _il.ReadSingle();
                break;

            case OperandType.InlineR:
                instruction.Operand = _il.ReadDouble();
                break;

            case OperandType.InlineI8:
                instruction.Operand = _il.ReadInt64();
                break;

            case OperandType.InlineSig:
                instruction.Operand = _module.ResolveSignature(_il.ReadInt32());
                break;

            case OperandType.InlineString:
                instruction.Operand = _module.ResolveString(_il.ReadInt32());
                break;

            case OperandType.InlineTok:
            case OperandType.InlineType:
            case OperandType.InlineMethod:
            case OperandType.InlineField:
                instruction.Operand = _module.ResolveMember(_il.ReadInt32(), _typeArguments, _methodArguments);
                break;

            case OperandType.ShortInlineVar:
                instruction.Operand = GetVariable(instruction, _il.ReadByte());
                break;

            case OperandType.InlineVar:
                instruction.Operand = GetVariable(instruction, _il.ReadInt16());
                break;

            default:
                throw new NotSupportedException();
            }
        }
コード例 #21
0
    void ReceiveMsg(object socket)
    {
        Socket mSocket = socket as Socket;

        while (isRunningThread)
        {
            try
            {
                int packageLength = mSocket.Receive(msg);
                Debug.Log(TAG + "Client id: " + mSocket.RemoteEndPoint.ToString() + " Package Length: " + packageLength);
            }
            catch (Exception e)
            {
                Debug.LogError(TAG + e.Message);
                socketList.Remove(mSocket);
                //mSocket.Shutdown(SocketShutdown.Both);
                //mSocket.Close();
                break;
            }

            ByteBuffer buff = new ByteBuffer(msg);

            int id = buff.ReadInt();
            if (id == (int)messageID.msgString)
            {
                string mssage = buff.ReadString();
                Debug.Log(TAG + "Client id: " + mSocket.RemoteEndPoint.ToString() + " Test Message: " + mssage);
            }
            else if (id == (int)messageID.msgInt)
            {
                int mssage = buff.ReadInt();
                Debug.Log(TAG + "Client id: " + mSocket.RemoteEndPoint.ToString() + " Test Message: " + mssage);
            }
            else if (id == (int)messageID.msgFloat)
            {
                float mssage = buff.ReadFloat();
                Debug.Log(TAG + "Client id: " + mSocket.RemoteEndPoint.ToString() + " Test Message: " + mssage);
            }
            else if (id == (int)messageID.EndThread)
            {
                isRunningThread = false;
                string mssage = buff.ReadString();
                Debug.Log(TAG + "Client id: " + mSocket.RemoteEndPoint.ToString() + " Test Message: " + mssage);
            }
            else if (id == (int)messageID.msgEmpatica)
            {
                float bvp = buff.ReadFloat();
                float ibi = buff.ReadFloat();
                float gsr = buff.ReadFloat();

                Debug.Log(TAG + "Client id: " + mSocket.RemoteEndPoint.ToString() + " BVP: " + bvp + " IBI: " + ibi + " GSR: " + gsr);
                textStr = TAG + "Client id: " + mSocket.RemoteEndPoint.ToString() + " BVP: " + bvp + " IVI: " + ibi + " GSR: " + gsr;
            }
            else if (id == (int)messageID.msgMuse)
            {
                double tp9  = buff.ReadDouble();
                double af7  = buff.ReadDouble();
                double af8  = buff.ReadDouble();
                double tf10 = buff.ReadDouble();

                Debug.Log(TAG + "Client id: " + mSocket.RemoteEndPoint.ToString() + " tp9: " + tp9 + " af7: " + af7 + " af8: " + af8 + " tf10: " + tf10);
                textStr = TAG + "Client id: " + mSocket.RemoteEndPoint.ToString() + " tp9: " + tp9 + " af7: " + af7 + " af8: " + af8 + " tf10: " + tf10;
            }

            else
            {
                continue;
            }
        }
    }
コード例 #22
0
ファイル: HisDataServerProcess.cs プロジェクト: cdy816/mars
        /// <summary>
        ///
        /// </summary>
        /// <param name="clientid"></param>
        /// <param name="block"></param>
        private void ProcessSetHisData2(string clientid, ByteBuffer block)
        {
            Parent.AsyncCallback(clientid, ToByteBuffer(APIConst.HisValueFun, (byte)1));
            var service = ServiceLocator.Locator.Resolve <ITagHisValueProduct>();
            int count   = block.ReadInt();

            for (int i = 0; i < count; i++)
            {
                int     id = block.ReadInt();
                var     dt = DateTime.FromBinary(block.ReadLong());
                TagType tp = (TagType)block.ReadByte();
                switch (tp)
                {
                case TagType.Bool:
                    var bval = block.ReadByte();
                    var qa   = block.ReadByte();
                    service.SetTagHisValue(id, dt, bval, qa);
                    break;

                case TagType.Byte:
                    var btval = block.ReadByte();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, btval, qa);
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = btval });
                    break;

                case TagType.Short:
                    var sbval = block.ReadShort();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, sbval, qa);
                    // service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = sbval });
                    break;

                case TagType.UShort:
                    var usbval = block.ReadUShort();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, usbval, qa);
                    // service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = usbval });
                    break;

                case TagType.Int:
                    var ibval = block.ReadInt();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, ibval, qa);
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = ibval });
                    break;

                case TagType.UInt:
                    var uibval = block.ReadUInt();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, uibval, qa);
                    // service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = uibval });
                    break;

                case TagType.Long:
                    var lbval = block.ReadLong();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, lbval, qa);
                    // service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = lbval });
                    break;

                case TagType.ULong:
                    var ulbval = (ulong)block.ReadLong();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, ulbval, qa);
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = ulbval });
                    break;

                case TagType.Float:
                    var fbval = block.ReadFloat();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, fbval, qa);

                    // service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = fbval });
                    break;

                case TagType.Double:
                    var dbval = block.ReadDouble();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, dbval, qa);
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = dbval });
                    break;

                case TagType.String:
                    var stbval = block.ReadString();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, stbval, qa);
                    // service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = stbval });
                    break;

                case TagType.DateTime:
                    var dtbval = DateTime.FromBinary(block.ReadLong());
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, dtbval, qa);
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = dtbval });
                    break;

                case TagType.IntPoint:
                    var ival1 = block.ReadInt();
                    var ival2 = block.ReadInt();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, ival1, ival2);
                    break;

                case TagType.UIntPoint:
                    //var upbval = new UIntPointData() { X = block.ReadUnsignedInt(), Y = block.ReadUnsignedInt() };
                    var uival1 = block.ReadInt();
                    var uival2 = block.ReadInt();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, uival1, uival2);

                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = upbval });
                    break;

                case TagType.IntPoint3:
                    ival1 = block.ReadInt();
                    ival2 = block.ReadInt();
                    var ival3 = block.ReadInt();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, ival1, ival2, ival3);
                    break;

                case TagType.UIntPoint3:
                    uival1 = block.ReadInt();
                    uival2 = block.ReadInt();
                    var uival3 = block.ReadInt();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, uival1, uival2, uival3);
                    break;

                case TagType.LongPoint:
                    var lval1 = block.ReadLong();
                    var lval2 = block.ReadLong();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, lval1, lval2);

                    //var lpbval = new LongPointData() { X = block.ReadLong(), Y = block.ReadLong() };
                    //qa = block.ReadByte();
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = lpbval });
                    break;

                case TagType.ULongPoint:
                    var ulval1 = (ulong)block.ReadLong();
                    var ulval2 = (ulong)block.ReadLong();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, ulval1, ulval2);
                    //var ulpbval = new ULongPointData() { X = (ulong)block.ReadLong(), Y = (ulong)block.ReadLong() };
                    //qa = block.ReadByte();
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = ulpbval });
                    break;

                case TagType.LongPoint3:
                    lval1 = block.ReadLong();
                    lval2 = block.ReadLong();
                    var lval3 = block.ReadLong();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, lval1, lval2, lval3);

                    //var lp3bval = new LongPoint3Data() { X = block.ReadLong(), Y = block.ReadLong(), Z = block.ReadLong() };
                    //qa = block.ReadByte();
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = lp3bval });
                    break;

                case TagType.ULongPoint3:
                    ulval1 = (ulong)block.ReadLong();
                    ulval2 = (ulong)block.ReadLong();
                    var ulval3 = (ulong)block.ReadLong();
                    qa = block.ReadByte();
                    service.SetTagHisValue(id, dt, qa, ulval1, ulval2, ulval3);
                    //var ulp3bval = new ULongPoint3Data() { X = (ulong)block.ReadLong(), Y = (ulong)block.ReadLong(), Z = (ulong)block.ReadLong() };
                    //qa = block.ReadByte();
                    //service.SetTagHisValue(id,new TagValue() { Quality = qa, Time = dt, Value = ulp3bval });
                    break;
                }
            }
        }
コード例 #23
0
ファイル: Pet_Info.cs プロジェクト: stephenZh/l2net
        public void Load_Pet(ByteBuffer buff)
        {
            SummonType = buff.ReadUInt32(); //1 = summon, 2 = pet
            ID = buff.ReadUInt32();
            NPCID = buff.ReadUInt32();
            isAttackAble = buff.ReadUInt32();//attackable = 0

            X = buff.ReadUInt32();
            Y = buff.ReadUInt32();
            Z = buff.ReadUInt32();
            Heading = buff.ReadInt32();
            buff.ReadUInt32();//0x00

            MatkSpeed = buff.ReadUInt32();
            PatkSpeed = buff.ReadUInt32();
            RunSpeed = buff.ReadUInt32();
            WalkSpeed = buff.ReadUInt32();
            SwimRunSpeed = buff.ReadUInt32();
            SwimWalkSpeed = buff.ReadUInt32();
            flRunSpeed = buff.ReadUInt32();
            flWalkSpeed = buff.ReadUInt32();
            if (Globals.gamedata.Chron >= Chronicle.CT1)
            {
                FlyRunSpeed = buff.ReadUInt32();
                FlyWalkSpeed = buff.ReadUInt32();
            }

            MoveSpeedMult = System.Convert.ToSingle(buff.ReadDouble());
            AttackSpeedMult = System.Convert.ToSingle(buff.ReadDouble());
            CollisionRadius = System.Convert.ToSingle(buff.ReadDouble());
            CollisionHeight = System.Convert.ToSingle(buff.ReadDouble());

            LWeapon = buff.ReadUInt32();
            Armor = buff.ReadUInt32();
            RWeapon = buff.ReadUInt32();

            HasOwner = buff.ReadByte(); //owneronline
            isRunning = buff.ReadByte();
            isInCombat = buff.ReadByte();
            isAlikeDead = buff.ReadByte();
            isSummoned = buff.ReadByte(); //isSummoned 0=teleported  1=default   2=summoned

            if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                buff.ReadUInt32(); //FF FF FF FF
            }
            Name = buff.ReadString();
            if (string.IsNullOrWhiteSpace(Name))
            {
                Name = Util.GetNPCName(NPCID);//"Unnamed Pet";
            }
            if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                buff.ReadUInt32(); //FF FF FF FF
            }
            Title = buff.ReadString(); //OwnerName
            buff.ReadUInt32();//1

            PvPFlag = buff.ReadUInt32();
            Karma = buff.ReadInt32();

            Cur_Fed = buff.ReadUInt32();
            Max_Fed = buff.ReadUInt32();

            Cur_HP = buff.ReadUInt32();
            Max_HP = buff.ReadUInt32();

            Cur_MP = buff.ReadUInt32();
            Max_MP = buff.ReadUInt32();

            SP = buff.ReadUInt32();
            Level = buff.ReadUInt32();
            XP = buff.ReadUInt64();

            XP_ThisLevel = buff.ReadUInt64();
            XP_NextLevel = buff.ReadUInt64();

            Cur_Load = buff.ReadUInt32();
            Max_Load = buff.ReadUInt32();

            Patk = buff.ReadUInt32();
            PDef = buff.ReadUInt32();
            Accuracy = buff.ReadUInt32();// p
            Evasion = buff.ReadUInt32();//p
            Focus = buff.ReadUInt32();//p
            Matk = buff.ReadUInt32();
            MDef = buff.ReadUInt32();

            buff.ReadUInt32();//m acu
            buff.ReadUInt32();//m eva
            buff.ReadUInt32();//m crit

            buff.ReadUInt32();// speed
            buff.ReadUInt32();//patak sped
            buff.ReadUInt32();// cast

            /*if (Globals.gamedata.Chron < Chronicle.CT3_0)
            {
                AbnormalEffects = buff.ReadUInt32(); //AbnormalEffect bleed=1; poison=2; poison & bleed=3; flame=4;
            }
            else
            {
                buff.ReadUInt32(); //??
            }*/
            Mountable = buff.ReadUInt16();

            buff.ReadByte();
            buff.ReadUInt16();

            if (Globals.gamedata.Chron >= Chronicle.CT1)
            {
                TeamCircle = buff.ReadByte();
                /*if (Globals.gamedata.Chron >= Chronicle.CT3_0)
                {
                    //buff.ReadUInt32(); //00 00 00 00
                    buff.ReadUInt16();
                    AbnormalEffects = buff.ReadUInt32();
                    buff.ReadUInt32(); //00 00 00 00
                    buff.ReadUInt16(); //00 00 00 00
                }*/
                SSUsage = buff.ReadUInt32();
                SPSUSage = buff.ReadUInt32();
                Form = buff.ReadUInt32();
                buff.ReadUInt32();//0x00
                if (Globals.gamedata.Chron >= Chronicle.CT3_0)
                {
                    //buff.ReadUInt16(); //00 00
                    try
                    {
                        buff.ReadUInt32(); //00 00
                        buff.ReadUInt32(); //02 00 00 00 current pet points
                        buff.ReadUInt32(); //06 00 00 00 max pet points

                        uint abn_count = buff.ReadUInt32();
                        if (abn_count < 30) // well ... its oddi wayso :P
                        {
                            _AbnEffects.Add(buff.ReadUInt32());
                        }


                    }
                    catch
                    {

                    }
                }
            }
            else
            {
                HasOwner = buff.ReadByte();
                SSUsage = buff.ReadUInt32();
                Form = buff.ReadUInt32();
                buff.ReadUInt32();//0x00
            }
        }
コード例 #24
0
        public void TestByteBuffer()
        {
            checkBufferEmpty(ByteBuffer.Empty);

            var buffer = new ByteBuffer();

            checkBufferEmpty(buffer);

            buffer = new ByteBuffer(checkCount);
            checkBufferNotEmpty(ref buffer, null, 0, checkCount);

            var tempBuffer = buffer;

            var array = new byte[checkCount];

            buffer = new ByteBuffer(array);
            checkBufferNotEmpty(ref buffer, array, 0, checkCount);
            Assert.IsTrue(buffer != tempBuffer);

            tempBuffer = buffer;

            buffer = new ByteBuffer(array, 1, 3);
            checkBufferNotEmpty(ref buffer, array, 1, 3);
            Assert.IsTrue(buffer != tempBuffer);

            buffer = new ByteBuffer(new ArraySegment <byte>(array));
            checkBufferNotEmpty(ref buffer, array, 0, checkCount);
            Assert.IsTrue(buffer == tempBuffer);

            buffer = new ByteBuffer(new ByteBufferNode(array));
            checkBufferNotEmpty(ref buffer, array, 0, checkCount);
            Assert.IsTrue(buffer == tempBuffer);

            buffer = new ByteBuffer(new ByteBuffer(array));
            checkBufferNotEmpty(ref buffer, array, 0, checkCount);
            Assert.IsTrue(buffer == tempBuffer);

            buffer = new ByteBuffer(array);
            buffer = new ByteBuffer(ref buffer, 1);
            checkBufferNotEmpty(ref buffer, array, 1, checkCount - 1);
            Assert.IsTrue(buffer != tempBuffer);

            buffer = new ByteBuffer(checkCount);
            checkBufferNotEmpty(ref buffer, null, 0, checkCount);

            for (int i = 0; i < checkCount; i++)
            {
                buffer[i] = (byte)i;
            }

            for (int i = 0; i < checkCount; i++)
            {
                Assert.AreEqual(buffer[i], (byte)i);
            }

            int advanceOffset = 10;

            tempBuffer = ByteBuffer.AdvanceOffset(ref buffer, advanceOffset);
            checkBufferNotEmpty(ref tempBuffer, null, advanceOffset, checkCount - advanceOffset);
            Assert.IsTrue(tempBuffer.CheckPtr(0, ref buffer, advanceOffset));

            tempBuffer = ByteBuffer.AdvanceSize(ref buffer, advanceOffset);
            checkBufferNotEmpty(ref tempBuffer, null, 0, checkCount - advanceOffset);
            Assert.IsTrue(tempBuffer.CheckPtr(ref buffer));

            tempBuffer = ByteBuffer.Resize(ref buffer, checkCount - advanceOffset);
            checkBufferNotEmpty(ref tempBuffer, null, 0, checkCount - advanceOffset);
            Assert.IsTrue(tempBuffer.CheckPtr(ref buffer));

            tempBuffer = buffer;
            tempBuffer.AdvanceOffset(advanceOffset);
            checkBufferNotEmpty(ref tempBuffer, null, advanceOffset, checkCount - advanceOffset);
            Assert.IsTrue(tempBuffer.CheckPtr(0, ref buffer, advanceOffset));

            tempBuffer = buffer;
            tempBuffer.AdvanceSize(advanceOffset);
            checkBufferNotEmpty(ref tempBuffer, null, 0, checkCount - advanceOffset);
            Assert.IsTrue(tempBuffer.CheckPtr(ref buffer));

            tempBuffer = buffer;
            tempBuffer.Resize(checkCount - advanceOffset);
            checkBufferNotEmpty(ref tempBuffer, null, 0, checkCount - advanceOffset);
            Assert.IsTrue(tempBuffer.CheckPtr(ref buffer));

            tempBuffer = buffer;
            buffer     = new ByteBuffer(checkCount);
            Assert.IsFalse(buffer.CheckPtr(ref tempBuffer));

            tempBuffer.CopyTo(ref buffer);
            for (int i = 0; i < checkCount; i++)
            {
                Assert.AreEqual(buffer[i], (byte)i);
            }

            tempBuffer.CopyTo(10, ref buffer, 20, 30);

            Assert.AreEqual(buffer[20 - 1], 20 - 1);
            for (int i = 0; i < 30; i++)
            {
                Assert.AreEqual(buffer[20 + i], (byte)(10 + i));
            }
            Assert.AreEqual(buffer[20 + 30], 20 + 30);

            buffer = new ByteBuffer(checkCount);

            for (int i = 0; i < checkCount; i++)
            {
                buffer.WriteByte(i, (byte)i);
            }

            for (int i = 0; i < checkCount; i++)
            {
                Assert.AreEqual(buffer.ReadByte(i), (byte)i);
            }

            var blockBuffer = new BlockBuffer();

            blockBuffer.Add(buffer);
            tempBuffer = blockBuffer.ToBuffer();
            checkBufferNotEmpty(ref tempBuffer, null, 0, buffer.Count);
            Assert.IsTrue(tempBuffer.CheckPtr(ref buffer));

            for (int i = 0; i < checkCount; i++)
            {
                Assert.AreEqual(tempBuffer.ReadByte(i), (byte)i);
            }

            buffer = new ByteBuffer(checkCount);
            long startValue = Byte.MaxValue * 2;
            int  count      = checkCount / 2;

            for (int i = 0; i < count; i++)
            {
                buffer.WriteUint16(i * 2, (ushort)(startValue + i));
            }

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(buffer.ReadUint16(i * 2), (ushort)(startValue + i));
            }

            buffer     = new ByteBuffer(checkCount);
            startValue = ushort.MaxValue * 2;
            count      = checkCount / 4;
            for (int i = 0; i < count; i++)
            {
                buffer.WriteUint32(i * 4, (uint)(startValue + i));
            }

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(buffer.ReadUint32(i * 4), (uint)(startValue + i));
            }

            buffer     = new ByteBuffer(checkCount);
            startValue = (long)uint.MaxValue * 2;
            count      = checkCount / 8;
            for (int i = 0; i < count; i++)
            {
                buffer.WriteUint64(i * 8, (uint)(startValue + i));
            }

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(buffer.ReadUint64(i * 8), (uint)(startValue + i));
            }

            tempBuffer = buffer;

            buffer = new ByteBuffer(checkCount);
            for (int i = 0; i < count; i++)
            {
                buffer.WriteBuffer(i * 8, ref tempBuffer, i * 8, 8);
            }

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(buffer.ReadUint64(i * 8), (uint)(startValue + i));
            }

            tempBuffer = buffer;
            buffer     = new ByteBuffer(checkCount);

            for (int i = 0; i < count; i++)
            {
                tempBuffer.ReadBuffer(i * 8, ref buffer, i * 8, 8);
            }

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(buffer.ReadUint64(i * 8), (uint)(startValue + i));
            }

            string checkString = "";

            for (int i = 0; i < checkCount / 2; i++)
            {
                checkString += i.ToString();
            }

            int stringSize = Encoding.UTF8.GetByteCount(checkString);

            Assert.IsTrue(stringSize > 0 && stringSize < checkCount);

            int index = Rand.Default.RandInt(checkCount - stringSize);

            buffer = new ByteBuffer(checkCount);
            buffer.WriteString(index, checkString);

            int readOffset;
            var value = buffer.ReadString(index, out readOffset);

            Assert.AreEqual(value, checkString);
            Assert.Less(stringSize, readOffset);

            buffer = new ByteBuffer(checkCount);
            count  = checkCount / 4;
            float[] checkFloatSet = new float[count];
            for (int i = 0; i < count; i++)
            {
                checkFloatSet[i] = Rand.Default.RandFloat();
            }

            for (int i = 0; i < count; i++)
            {
                buffer.WriteFloat(i * 4, checkFloatSet[i]);
            }

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(buffer.ReadFloat(i * 4), checkFloatSet[i]);
            }

            buffer = new ByteBuffer(checkCount);
            count  = checkCount / 8;
            double[] checkDoubleSet = new double[count];
            for (int i = 0; i < count; i++)
            {
                checkDoubleSet[i] = Rand.Default.RandFloat();
            }

            for (int i = 0; i < count; i++)
            {
                buffer.WriteDouble(i * 8, checkDoubleSet[i]);
            }

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(buffer.ReadDouble(i * 8), checkDoubleSet[i]);
            }

            buffer = new ByteBuffer(checkCount);
            count  = checkCount / 5;
            uint[] checkUintSet = new uint[count];
            for (int i = 0; i < count; i++)
            {
                checkUintSet[i] = Rand.Default.RandUint();
            }

            int offset = 0;

            for (int i = 0; i < count; i++)
            {
                offset += buffer.WriteVarint32(offset, checkUintSet[i]);
            }

            offset = 0;
            for (int i = 0; i < count; i++)
            {
                int size;
                Assert.AreEqual(buffer.ReadVarint32(offset, out size), checkUintSet[i]);
                offset += size;
            }

            count = checkCount / 9;
            long[] checkLongSet = new long[count];
            for (int i = 0; i < count; i++)
            {
                checkLongSet[i] = Rand.Default.RandLong();
            }

            offset = 0;
            for (int i = 0; i < count; i++)
            {
                offset += buffer.WriteVarint64(offset, (ulong)checkLongSet[i]);
            }

            offset = 0;
            for (int i = 0; i < count; i++)
            {
                int size;
                Assert.AreEqual(buffer.ReadVarint32(offset, out size), (uint)checkLongSet[i]);
                offset += size;
            }

            offset = 0;
            for (int i = 0; i < count; i++)
            {
                int size;
                Assert.AreEqual(buffer.ReadVarint64(offset, out size), checkLongSet[i]);
                offset += size;
            }
        }
コード例 #25
0
ファイル: NetTransformDriver.cs プロジェクト: cdy816/mars
        private void ProcessSingleBufferData(ByteBuffer block)
        {
            if (block == null)
            {
                return;
            }
            var count = block.ReadInt();

            for (int i = 0; i < count; i++)
            {
                var vid = block.ReadInt();
                if (vid < 0)
                {
                    Debug.Print("Invaild value!");
                }
                var    typ   = block.ReadByte();
                object value = null;
                switch (typ)
                {
                case (byte)TagType.Bool:
                    value = block.ReadByte();
                    break;

                case (byte)TagType.Byte:
                    value = block.ReadByte();
                    break;

                case (byte)TagType.Short:
                    value = block.ReadShort();
                    break;

                case (byte)TagType.UShort:
                    value = (ushort)block.ReadShort();
                    break;

                case (byte)TagType.Int:
                    value = block.ReadInt();
                    break;

                case (byte)TagType.UInt:
                    value = Convert.ToUInt32(block.ReadInt());
                    break;

                case (byte)TagType.Long:
                    value = block.ReadLong();
                    break;

                case (byte)TagType.ULong:
                    value = (ulong)block.ReadLong();
                    break;

                case (byte)TagType.Float:
                    value = block.ReadFloat();
                    break;

                case (byte)TagType.Double:
                    value = block.ReadDouble();
                    break;

                case (byte)TagType.String:
                    value = ReadString(block);
                    break;

                case (byte)TagType.DateTime:
                    var tick = block.ReadLong();
                    value = new DateTime(tick);
                    break;

                case (byte)TagType.IntPoint:
                    value = new IntPointData(block.ReadInt(), block.ReadInt());
                    break;

                case (byte)TagType.UIntPoint:
                    value = new UIntPointData(block.ReadInt(), block.ReadInt());
                    break;

                case (byte)TagType.IntPoint3:
                    value = new IntPoint3Data(block.ReadInt(), block.ReadInt(), block.ReadInt());
                    break;

                case (byte)TagType.UIntPoint3:
                    value = new UIntPoint3Data(block.ReadInt(), block.ReadInt(), block.ReadInt());
                    break;

                case (byte)TagType.LongPoint:
                    value = new LongPointData(block.ReadLong(), block.ReadLong());
                    break;

                case (byte)TagType.ULongPoint:
                    value = new ULongPointData(block.ReadLong(), block.ReadLong());
                    break;

                case (byte)TagType.LongPoint3:
                    value = new LongPoint3Data(block.ReadLong(), block.ReadLong(), block.ReadLong());
                    break;

                case (byte)TagType.ULongPoint3:
                    value = new ULongPoint3Data(block.ReadLong(), block.ReadLong(), block.ReadLong());
                    break;
                }
                var time = new DateTime(block.ReadLong());
                var qua  = block.ReadByte();
                mServier.SetTagValue(vid, ref value, time, qua);
            }
            block.UnlockAndReturn();
        }
コード例 #26
0
ファイル: Pet_Info.cs プロジェクト: zixela/l2net
        public void Load_Pet(ByteBuffer buff)
        {
            SummonType   = buff.ReadUInt32(); //1 = summon, 2 = pet
            ID           = buff.ReadUInt32();
            NPCID        = buff.ReadUInt32();
            isAttackAble = buff.ReadUInt32();//attackable = 0

            X       = buff.ReadUInt32();
            Y       = buff.ReadUInt32();
            Z       = buff.ReadUInt32();
            Heading = buff.ReadInt32();
            buff.ReadUInt32();//0x00

            MatkSpeed     = buff.ReadUInt32();
            PatkSpeed     = buff.ReadUInt32();
            RunSpeed      = buff.ReadUInt32();
            WalkSpeed     = buff.ReadUInt32();
            SwimRunSpeed  = buff.ReadUInt32();
            SwimWalkSpeed = buff.ReadUInt32();
            flRunSpeed    = buff.ReadUInt32();
            flWalkSpeed   = buff.ReadUInt32();
            if (Globals.gamedata.Chron >= Chronicle.CT1)
            {
                FlyRunSpeed  = buff.ReadUInt32();
                FlyWalkSpeed = buff.ReadUInt32();
            }

            MoveSpeedMult   = System.Convert.ToSingle(buff.ReadDouble());
            AttackSpeedMult = System.Convert.ToSingle(buff.ReadDouble());
            CollisionRadius = System.Convert.ToSingle(buff.ReadDouble());
            CollisionHeight = System.Convert.ToSingle(buff.ReadDouble());

            LWeapon = buff.ReadUInt32();
            Armor   = buff.ReadUInt32();
            RWeapon = buff.ReadUInt32();

            HasOwner    = buff.ReadByte(); //owneronline
            isRunning   = buff.ReadByte();
            isInCombat  = buff.ReadByte();
            isAlikeDead = buff.ReadByte();
            isSummoned  = buff.ReadByte(); //isSummoned 0=teleported  1=default   2=summoned

            if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                buff.ReadUInt32(); //FF FF FF FF
            }
            Name = buff.ReadString();
            if (string.IsNullOrWhiteSpace(Name))
            {
                Name = Util.GetNPCName(NPCID);//"Unnamed Pet";
            }
            if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                buff.ReadUInt32();     //FF FF FF FF
            }
            Title = buff.ReadString(); //OwnerName
            buff.ReadUInt32();         //1

            PvPFlag = buff.ReadUInt32();
            Karma   = buff.ReadInt32();

            Cur_Fed = buff.ReadUInt32();
            Max_Fed = buff.ReadUInt32();

            Cur_HP = buff.ReadUInt32();
            Max_HP = buff.ReadUInt32();

            Cur_MP = buff.ReadUInt32();
            Max_MP = buff.ReadUInt32();

            SP    = buff.ReadUInt32();
            Level = buff.ReadUInt32();
            XP    = buff.ReadUInt64();

            XP_ThisLevel = buff.ReadUInt64();
            XP_NextLevel = buff.ReadUInt64();

            Cur_Load = buff.ReadUInt32();
            Max_Load = buff.ReadUInt32();

            Patk     = buff.ReadUInt32();
            PDef     = buff.ReadUInt32();
            Accuracy = buff.ReadUInt32(); // p
            Evasion  = buff.ReadUInt32(); //p
            Focus    = buff.ReadUInt32(); //p
            Matk     = buff.ReadUInt32();
            MDef     = buff.ReadUInt32();

            buff.ReadUInt32(); //m acu
            buff.ReadUInt32(); //m eva
            buff.ReadUInt32(); //m crit

            buff.ReadUInt32(); // speed
            buff.ReadUInt32(); //patak sped
            buff.ReadUInt32(); // cast

            /*if (Globals.gamedata.Chron < Chronicle.CT3_0)
             * {
             *  AbnormalEffects = buff.ReadUInt32(); //AbnormalEffect bleed=1; poison=2; poison & bleed=3; flame=4;
             * }
             * else
             * {
             *  buff.ReadUInt32(); //??
             * }*/
            Mountable = buff.ReadUInt16();

            buff.ReadByte();
            buff.ReadUInt16();

            if (Globals.gamedata.Chron >= Chronicle.CT1)
            {
                TeamCircle = buff.ReadByte();

                /*if (Globals.gamedata.Chron >= Chronicle.CT3_0)
                 * {
                 *  //buff.ReadUInt32(); //00 00 00 00
                 *  buff.ReadUInt16();
                 *  AbnormalEffects = buff.ReadUInt32();
                 *  buff.ReadUInt32(); //00 00 00 00
                 *  buff.ReadUInt16(); //00 00 00 00
                 * }*/
                SSUsage  = buff.ReadUInt32();
                SPSUSage = buff.ReadUInt32();
                Form     = buff.ReadUInt32();
                buff.ReadUInt32();//0x00
                if (Globals.gamedata.Chron >= Chronicle.CT3_0)
                {
                    //buff.ReadUInt16(); //00 00
                    try
                    {
                        buff.ReadUInt32(); //00 00
                        buff.ReadUInt32(); //02 00 00 00 current pet points
                        buff.ReadUInt32(); //06 00 00 00 max pet points

                        uint abn_count = buff.ReadUInt32();
                        if (abn_count < 30) // well ... its oddi wayso :P
                        {
                            _AbnEffects.Add(buff.ReadUInt32());
                        }
                    }
                    catch
                    {
                    }
                }
            }
            else
            {
                HasOwner = buff.ReadByte();
                SSUsage  = buff.ReadUInt32();
                Form     = buff.ReadUInt32();
                buff.ReadUInt32();//0x00
            }
        }