Beispiel #1
0
        public static void TransactionTesting()
        {
            StateChangeTransaction t = new StateChangeTransaction(1234, StateChange.Addition, new MeshNetworkIdentity(101, 2, 1234, true));

            byte[]     bytes = t.GetSerializedBytes();
            MeshPacket p     = new MeshPacket(bytes, PacketType.DatabaseChangeRequest, 4325, 911, 45, 45, (byte)ReservedSubcomponentIDs.Unspecified);

            byte[] bytesToSend = p.GetSerializedBytes();

            //SENDDDD

            MeshPacket destPacket = new MeshPacket(bytesToSend);

            Debug.Log("Source player: " + destPacket.GetSourcePlayerId());
            Debug.Log("Source object: " + destPacket.GetSourceObjectId());
            Debug.Log("Target player: " + destPacket.GetTargetPlayerId());
            Debug.Log("Target object: " + destPacket.GetTargetObjectId());
            Debug.Log("Packet type: " + destPacket.GetPacketType());
            Debug.Log("<<<<<<  Transaction:  >>>>>>");
            StateChangeTransaction destTransaction = StateChangeTransaction.ParseSerializedBytes(destPacket.GetContents());

            Debug.Log("Change type: " + destTransaction.GetChangeType());
            Debug.Log("Transaction id: " + destTransaction.GetTransactionID());
            Debug.Log("Object id: " + destTransaction.GetObjectData().GetObjectID());
            Debug.Log("Owner id: " + destTransaction.GetObjectData().GetOwnerID());
        }
Beispiel #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);
        }