예제 #1
0
        //Deserialize incoming byte data and construct a deserialized DatabaseUpdate
        //Note, this is static
        public static DatabaseUpdate ParseContentAsDatabaseUpdate(byte[] serializedData)
        {
            Dictionary <Player, StateChange> playerList = new Dictionary <Player, StateChange>();
            Dictionary <MeshNetworkIdentity, StateChange> networkObjects = new Dictionary <MeshNetworkIdentity, StateChange>();

            byte[] rawData         = serializedData;
            byte   numOfNewPlayers = rawData[0];
            int    pointer         = 1;
            byte   i = 0;

            while (i < numOfNewPlayers)
            {
                int blobLength = rawData[pointer];

                pointer++; //pointer is now at the beginning of the player data blob

                byte[] playerData = new byte[blobLength];
                Buffer.BlockCopy(rawData, pointer, playerData, 0, blobLength);
                Player p = Player.DeserializeFull(playerData);
                pointer += blobLength;
                StateChange s = (StateChange)rawData[pointer];
                playerList.Add(p, s);
                pointer++;
                i++;
            }
            byte numOfObjects = rawData[pointer];

            pointer++; //pointer now at the beginning of the first MeshNetworkIdentity data
            byte j = 0;

            while (j < numOfObjects)
            {
                MeshNetworkIdentity netid = new MeshNetworkIdentity();
                byte[] trimmed            = new byte[MeshNetworkIdentity.NETWORK_IDENTITY_BYTE_SIZE];
                Buffer.BlockCopy(rawData, pointer, trimmed, 0, trimmed.Length);
                netid.DeserializeAndApply(trimmed);
                pointer += MeshNetworkIdentity.NETWORK_IDENTITY_BYTE_SIZE;
                StateChange s = (StateChange)rawData[pointer];
                networkObjects.Add(netid, s);
                pointer++;
                j++;
            }
            ushort hash = BitConverter.ToUInt16(rawData, pointer);

            pointer += 2;
            bool fullUpdateFlag = BitConverter.ToBoolean(rawData, pointer);


            return(new DatabaseUpdate(playerList, networkObjects, hash, fullUpdateFlag));
        }
예제 #2
0
        public static StateChangeTransaction ParseSerializedBytes(byte[] data)
        {
            StateChangeTransaction transaction = new StateChangeTransaction();

            transaction.SetTransactionID(BitConverter.ToUInt16(data, 0));
            transaction.SetChangeType((StateChange)data[2]);

            if (data[3] == 1)
            {
                byte[] dataEndCap = new byte[data.Length - 4];
                Buffer.BlockCopy(data, 4, dataEndCap, 0, dataEndCap.Length); //hmmm
                MeshNetworkIdentity i = new MeshNetworkIdentity();
                i.DeserializeAndApply(dataEndCap);
                transaction.SetObjectData(i);
            }
            return(transaction);
        }