ReadLong() public method

public ReadLong ( ) : long
return long
Example #1
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);
        }
Example #2
0
 public void deserialize(ByteBuffer buffer)
 {
     dealId  = buffer.ReadLong();
     orderId = buffer.ReadLong();
     content = buffer.ReadString();
     time    = buffer.ReadString();
 }
Example #3
0
        private static void Packet_NextTurn(byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            //Skip packetId
            buffer.ReadLong();

            //Read player id
            long firstPlayerId = buffer.ReadLong();
            //Read player slotN
            int slotN = buffer.ReadInteger();
            //Read def player id
            long defendingPlayerId = buffer.ReadLong();
            //Read def player slotN
            int defSlotN = buffer.ReadInteger();
            //Read turn number
            int turnN = buffer.ReadInteger();

            Debug.Log($"Player {firstPlayerId} (slot {slotN}) does turn. Defender: Player {defendingPlayerId} (slot {defendingPlayerId})");

            //Invoke callback on observers
            FoolObservable.OnNextTurn(firstPlayerId, slotN, defendingPlayerId, defSlotN, turnN);
        }
Example #4
0
    private static void PACKET_SyncAnimation(byte[] data)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteBytes(data);
        long          packetnum     = buffer.ReadLong();
        AnimationType animationType = (AnimationType)buffer.ReadLong();
        int           syncID        = buffer.ReadInteger();
        string        id            = buffer.ReadString();

        switch (animationType)
        {
        case AnimationType.Bool:
            int  i = buffer.ReadInteger();
            bool b = (i == 1);
            NetworkManager.UpdateSyncdObject(syncID, id, b);
            break;

        case AnimationType.Float:
            float f = buffer.ReadFloat();
            NetworkManager.UpdateSyncdObject(syncID, id, f);
            break;

        case AnimationType.Trigger:
            NetworkManager.UpdateSyncdObject(syncID, id);
            break;

        default:
            break;
        }

        buffer.Dispose();
    }
Example #5
0
 public override void Decode(ByteBuffer bb)
 {
     Term         = bb.ReadLong();
     CandidateId  = bb.ReadString();
     LastLogIndex = bb.ReadLong();
     LastLogTerm  = bb.ReadLong();
 }
Example #6
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);
        }
Example #7
0
    public static void HandleData(byte[] data)
    {
        byte[] Buffer;
        Buffer = (byte[])data.Clone();

        if (playerBuffer == null)
        {
            playerBuffer = new ByteBuffer();
        }
        playerBuffer.WriteBytes(Buffer);

        if (playerBuffer.Count() == 0)
        {
            playerBuffer.Clear();
            return;
        }

        if (playerBuffer.Length() >= 8)
        {
            pLength = playerBuffer.ReadLong(false);
            if (pLength <= 0)
            {
                playerBuffer.Clear();
                return;
            }
        }

        if (playerBuffer.Length() >= 8)
        {
            pLength = playerBuffer.ReadLong(false);
            if (pLength <= 0)
            {
                playerBuffer.Clear();
                return;
            }
        }

        while (pLength > 0 & pLength <= playerBuffer.Length() - 8)
        {
            if (pLength <= playerBuffer.Length() - 8)
            {
                playerBuffer.ReadLong();
                data = playerBuffer.ReadBytes((int)pLength);
                HandleDataPackets(data);
            }
            pLength = 0;

            if (playerBuffer.Length() >= 8)
            {
                pLength = playerBuffer.ReadLong(false);
                if (pLength < 0)
                {
                    playerBuffer.Clear();
                    return;
                }
            }
        }
    }
Example #8
0
        public static void HandleData(long clientId, byte[] data)
        {
            byte[] dataBuffer = (byte[])data.Clone();

            if (TCPStream.clients[clientId].buffer == null)
            {
                TCPStream.clients[clientId].buffer = new ByteBuffer();
            }

            ByteBuffer clientBuffer = TCPStream.clients[clientId].buffer;

            clientBuffer.WriteBytes(dataBuffer);

            if (clientBuffer.Count() == 0)
            {
                clientBuffer.Clear();
                return;
            }

            if (clientBuffer.Length() >= 4)
            {
                packetLength = clientBuffer.ReadLong(false);
                if (packetLength <= 0)
                {
                    clientBuffer.Clear();
                    return;
                }
            }

            while (packetLength > 0 && packetLength <= clientBuffer.Length() - 8)
            {
                if (packetLength <= clientBuffer.Length() - 8)
                {
                    clientBuffer.ReadLong();
                    data = clientBuffer.ReadBytes((int)packetLength);
                    HandleDataPackets(clientId, data);
                }

                packetLength = 0;

                if (clientBuffer.Length() >= 4)
                {
                    packetLength = clientBuffer.ReadLong(false);

                    if (packetLength <= 0)
                    {
                        clientBuffer.Clear();
                        return;
                    }
                }

                if (packetLength <= 1)
                {
                    clientBuffer.Clear();
                }
            }
        }
Example #9
0
File: Log.cs Project: e2wugui/zeze
        public void Decode(ByteBuffer bb)
        {
            Term  = bb.ReadLong();
            Index = bb.ReadLong();
            int logTypeId = bb.ReadInt4();

            Log = LogFactory(logTypeId);
            Log.Decode(bb);
        }
        public void ShouldReadLong()
        {
            _buffer = new ByteBuffer();
            _buffer.Append(-9223372036854775808);
            _buffer.Append(9223372036854775807);

            Assert.AreEqual(-9223372036854775808, _buffer.ReadLong());
            Assert.AreEqual(9223372036854775807, _buffer.ReadLong());
        }
Example #11
0
        /// <summary>
        /// Handles SevrerPacketId.RoomData
        /// </summary>
        private static void Packet_RoomData(byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            //Read packet id
            long packetId = buffer.ReadLong();

            //Read maxPlayers
            int maxPlayers = buffer.ReadInteger();

            //Init player array
            StaticRoomData.Players    = new PlayerInRoom[maxPlayers];
            StaticRoomData.MaxPlayers = maxPlayers;

            //Init slots dict
            Dictionary <int, long> slots = new Dictionary <int, long>();

            //Read players count
            int playersCount = buffer.ReadInteger();

            // Read players
            for (int i = 0; i < playersCount; i++)
            {
                //Read player id
                long         playerId = buffer.ReadLong();
                PlayerInRoom player   = new PlayerInRoom(playerId);

                //Read slots number
                int slotN = buffer.ReadInteger();
                player.SlotN = slotN;
                slots.Add(slotN, playerId);

                //if that part of data is about out player then set InRoomSlotNumber to read value
                if (playerId == FoolNetwork.LocalPlayer.ConnectionId)
                {
                    FoolNetwork.LocalPlayer.InRoomSlotNumber = slotN;
                }

                //read player nickname
                player.Nickname = buffer.ReadStringUnicode();

                //read player avatar url
                player.AvatarFile = buffer.ReadString();

                StaticRoomData.Players[i] = player;
            }

            StaticRoomData.ConnectedPlayersCount = playersCount;
            StaticRoomData.OccupiedSlots         = slots;

            //Invoke callback on observers
            FoolObservable.OnRoomDataUpdated();
        }
Example #12
0
        public byte flag = JustRun.NULL_FLAG; //标志

        public void deserialize(ByteBuffer buffer)
        {
            uid     = buffer.ReadLong();
            fid     = buffer.ReadLong();
            account = buffer.ReadString();
            fName   = buffer.ReadString();
            fFace   = buffer.ReadString();
            pass    = buffer.ReadByte();
            time    = buffer.ReadString();
            other   = buffer.ReadString();
        }
Example #13
0
        public byte showTime;   //0不显示,1显示

        public void deserialize(ByteBuffer buffer)
        {
            id       = buffer.ReadLong();
            sendId   = buffer.ReadLong();
            sendFace = buffer.ReadString();
            type     = buffer.ReadByte();
            look     = buffer.ReadByte();
            showTime = buffer.ReadByte();
            time     = buffer.ReadString();
            content  = buffer.ReadString();
        }
Example #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="clientId"></param>
        /// <param name="data"></param>
        private unsafe void ProcessRequestStatisticsDataByMemory(string clientId, ByteBuffer data)
        {
            int      id    = data.ReadInt();
            DateTime sTime = new DateTime(data.ReadLong());
            DateTime eTime = new DateTime(data.ReadLong());

            ByteBuffer re = DBRuntime.Proxy.DatabaseRunner.Manager.Proxy.QueryStatisticsHisValueByMemory(id, sTime, eTime);

            re.UnLock();
            Parent.AsyncCallback(clientId, re);
        }
Example #15
0
        public override void Decode(ByteBuffer bb)
        {
            Term              = bb.ReadLong();
            LeaderId          = bb.ReadString();
            LastIncludedIndex = bb.ReadLong();
            LastIncludedTerm  = bb.ReadLong();

            Offset = bb.ReadLong();
            Data   = bb.ReadBinary();
            Done   = bb.ReadBool();

            LastIncludedLog = bb.ReadBinary();
        }
Example #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="clientId"></param>
        /// <param name="data"></param>
        private void ProcessRequestHisDataByTimeSpanByMemory(string clientId, ByteBuffer data)
        {
            int id = data.ReadInt();

            Cdy.Tag.QueryValueMatchType type = (QueryValueMatchType)data.ReadByte();
            DateTime stime = new DateTime(data.ReadLong());
            DateTime etime = new DateTime(data.ReadLong());
            TimeSpan ts    = new TimeSpan(data.ReadLong());

            ByteBuffer re = DBRuntime.Proxy.DatabaseRunner.Manager.Proxy.QueryHisData(id, stime, etime, ts, type);

            re.UnLock();
            Parent.AsyncCallback(clientId, re);
        }
Example #17
0
        public static Revert read(ByteBuffer data)
        {
            Revert revert = new Revert();

            revert.id          = data.ReadLong();
            revert.dependentId = data.ReadLong();
            revert.uid         = data.ReadLong();
            revert.userName    = data.ReadString();
            revert.icon        = data.ReadString();
            revert.time        = data.ReadString();
            revert.context     = data.ReadString();
            revert.tar         = data.ReadString();
            return(revert);
        }
        protected void Packet_JoinRoom(long connectionId, byte[] data)
        {
            //Add our data to buffer
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            //skip packet id
            buffer.ReadLong();

            //Read room id
            long roomId = buffer.ReadLong();

            RoomManager.JoinRoom(connectionId, roomId);
        }
Example #19
0
        public override void Decode(ByteBuffer bb)
        {
            Term         = bb.ReadLong();
            LeaderId     = bb.ReadString();
            PrevLogIndex = bb.ReadLong();
            PrevLogTerm  = bb.ReadLong();

            Entries.Clear();
            for (int c = bb.ReadInt(); c > 0; --c)
            {
                Entries.Add(bb.ReadBinary());
            }

            LeaderCommit = bb.ReadLong();
        }
Example #20
0
        /// <summary>
        /// Handles SevrerPacketId.JoinRoomOk
        /// </summary>
        private static void Packet_JoinRoomOk(byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            buffer.ReadLong();

            long roomId = buffer.ReadLong();

            //Invoke callback on observers
            FoolObservable.OnJoinRoom(roomId);

            Debug.Log("You joined room: " + roomId);
        }
Example #21
0
    private void Start()
    {
        pb.PlayerSnapShootMsg msg = new pb.PlayerSnapShootMsg();
        msg.username = "******";
        msg.playerId = 9000001;
        byte[] data = ProtobufSerializer.Serialize(msg);
        Debug.LogError("data len " + data.Length);
        ByteBuffer buffer = ByteBuffer.Allocate(1024);

        buffer.WriteShort(1001);
        buffer.WriteShort(1002);
        buffer.WriteShort(1003);
        buffer.WriteLong(10055555);
        buffer.WriteBytes(data);

        short s1 = buffer.ReadShort();
        short s2 = buffer.ReadShort();
        short s3 = buffer.ReadShort();
        long  l1 = buffer.ReadLong();

        byte[] readData = new byte[buffer.ReadableBytes()];
        buffer.ReadBytes(readData, 0, buffer.ReadableBytes());
        Debug.LogError("readData len " + readData.Length);
        pb.PlayerSnapShootMsg dmsg = ProtobufSerializer.DeSerialize <pb.PlayerSnapShootMsg>(readData);
        Debug.LogError("user name " + dmsg.username);

        //socket receive bytes
        //
    }
Example #22
0
        public void ShouldReadLong()
        {
            byteBuffer.WriteLong(inputLong);
            long value = byteBuffer.ReadLong();

            Assert.Equal(value, inputLong);
        }
Example #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public bool Login(string username, string password, int timeount = 5000)
        {
            lock (mLoginLock)
            {
                if (IsLogin)
                {
                    return(true);
                }

                mUser = username;
                mPass = password;
                int size = username.Length + password.Length + 9;
                var mb   = GetBuffer(ApiFunConst.TagInfoRequest, size);
                mb.Write(ApiFunConst.Login);
                mb.Write(username);
                mb.Write(password);
                SendData(mb);
                if (infoRequreEvent.WaitOne(timeount) && (mInfoRequreData.WriteIndex - mInfoRequreData.ReadIndex) > 4)
                {
                    try
                    {
                        LoginId = mInfoRequreData.ReadLong();
                        return(IsLogin);
                    }
                    finally
                    {
                        mInfoRequreData?.UnlockAndReturn();
                    }
                }
                //mInfoRequreData?.Release();
                LoginId = -1;
                return(IsLogin);
            }
        }
Example #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="client"></param>
        /// <param name="data"></param>
        protected override void ProcessSingleData(string client, ByteBuffer data)
        {
            if (data.RefCount == 0)
            {
                LoggerService.Service.Warn("SpiderDriver_HisDataServerProcess", "invailed data buffer in HisDataServerProcess");
                return;
            }
            byte cmd = data.ReadByte();
            long id  = data.ReadLong();

            if (Cdy.Tag.ServiceLocator.Locator.Resolve <IRuntimeSecurity>().CheckLogin(id))
            {
                try
                {
                    switch (cmd)
                    {
                    case APIConst.SetTagHisValue:
                        ProcessSetHisData(client, data);
                        break;

                    case APIConst.SetTagHisValue2:
                        ProcessSetHisData2(client, data);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    LoggerService.Service.Warn("Spider HisDataServerProcess", ex.Message);
                }
            }
            base.ProcessSingleData(client, data);
        }
Example #25
0
 public void deserialize(ByteBuffer buffer, bool needSkip = false)
 {
     if (!needSkip)
     {
         id = buffer.ReadLong();
     }
     type       = buffer.ReadByte();
     status     = buffer.ReadByte();
     senderId   = buffer.ReadLong();
     time       = buffer.ReadString();
     theme      = buffer.ReadString();
     content    = buffer.ReadString();
     senderName = buffer.ReadString();
     senderIcon = buffer.ReadString();
     isNew      = status;
 }
Example #26
0
        private static void HandleDataPackets(long clientId, byte[] data)
        {
            long            packetId;
            ByteBuffer      buffer = new ByteBuffer();
            MessageHandlers msgHandler;
            IMessageMaker   msgMaker;

            buffer.WriteBytes(data);
            packetId = buffer.ReadLong();
            buffer.Dispose();

            if (messageMakers.TryGetValue((uint)packetId, out msgMaker))
            {
                IMessage message = msgMaker.FromBytes(data);
                if (messageHandlers.TryGetValue((uint)packetId, out msgHandler))
                {
                    msgHandler.HandleMessage(clientId, message);
                }
                else
                {
                    Console.WriteLine("We recieved a message who's handler was not registered.");
                }
            }
            else
            {
                Console.WriteLine("We recieved a message who's maker was not registered.");
            }
        }
Example #27
0
    private static void PACKET_NetSpawn(byte[] data)
    {
        ByteBuffer buffer = new ByteBuffer();

        buffer.WriteBytes(data);

        long packetnum  = buffer.ReadLong();
        int  assignedID = buffer.ReadInteger();

        string slug = buffer.ReadString();

        float x = buffer.ReadFloat();
        float y = buffer.ReadFloat();
        float z = buffer.ReadFloat();

        float rotX = buffer.ReadFloat();
        float rotY = buffer.ReadFloat();
        float rotZ = buffer.ReadFloat();
        float rotW = buffer.ReadFloat();

        Vector3    pos = new Vector3(x, y, z);
        Quaternion rot = new Quaternion(rotX, rotY, rotZ, rotW);

        Transform t = NetworkManager.SpawnRegisteredPrefab(slug, assignedID).transform;

        t.position = pos;
        t.rotation = rot;
    }
Example #28
0
        /// <summary>
        /// 解析数据
        /// </summary>
        public void Parse(byte[] bytes)
        {
            if (bytes == null)
            {
                throw new Exception("Fatal error : Param is null.");
            }
            if (_isParse)
            {
                throw new Exception("Fatal error : Package is already parse.");
            }

            _isParse = true;

            // 字节缓冲区
            ByteBuffer bb = new ByteBuffer(bytes);

            // 读取版本号
            Version = bb.ReadInt();

            // 读取元素总数
            int elementCount = bb.ReadInt();

            Elements = new Dictionary <string, PatchElement>(elementCount);

            int       tableLine       = 1;
            const int headMarkAndSize = 6;             //注意:short字节数+int字节数

            while (bb.IsReadable(headMarkAndSize))
            {
                // 检测行标记
                short tableHead = bb.ReadShort();
                if (tableHead != TableStreamHead)
                {
                    throw new Exception($"PatchManifest table stream head is invalid. Table line is {tableLine}");
                }

                // 检测行大小
                int tableSize = bb.ReadInt();
                if (!bb.IsReadable(tableSize) || tableSize > TableStreamMaxLen)
                {
                    throw new Exception($"PatchManifest table stream size is invalid. Table size is {tableSize},Table line {tableLine}");
                }

                // 读取行内容
                string        fileName      = bb.ReadUTF();
                string        fileMD5       = bb.ReadUTF();
                long          fileSizeBytes = bb.ReadLong();
                int           fileVersion   = bb.ReadInt();
                List <string> variantList   = bb.ReadListUTF();

                // 添加到集合
                if (Elements.ContainsKey(fileName))
                {
                    throw new Exception($"Fatal error : PatchManifest has same element : {fileName}");
                }
                Elements.Add(fileName, new PatchElement(fileName, fileMD5, fileSizeBytes, fileVersion, variantList));

                ++tableLine;
            }
        }
Example #29
0
File: Rpc.cs Project: e2wugui/zeze
        public override void Decode(ByteBuffer bb)
        {
            IsRequest       = bb.ReadBool();
            SessionId       = bb.ReadLong();
            ResultCode      = bb.ReadInt();
            UniqueRequestId = bb.ReadLong();

            if (IsRequest)
            {
                Argument.Decode(bb);
            }
            else
            {
                Result.Decode(bb);
            }
        }
Example #30
0
    // Update is called once per frame
    void Update()
    {
        if (pushs.Count == 0)
        {
            return;
        }
        if (!ConfirmUtil.isConfirmShow() && !LoadUtil.isActivity() && !DialogUtil.isPopTips())
        {
            if (!isOpen)
            {
                tryToOpenPush();
            }
        }
        ByteBuffer buffer = MyUtilTools.tryToLogic("DealGrab");

        if (buffer != null)
        {
            DialogUtil.tip("抢单成功", true);
        }
        buffer = MyUtilTools.tryToLogic("DealFavorite");
        if (buffer != null)
        {
            int type = buffer.ReadInt();
            int len  = buffer.ReadInt();
            MainData.instance.user.favorites.Clear();
            for (int i = 0; i < len; i++)
            {
                long value = buffer.ReadLong();
                MainData.instance.user.favorites.Add(value);
            }
            DialogUtil.tip(type == 0 ? "收藏成功" : "取消收藏成功", true);
        }
    }