Example #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());
        }
Example #2
0
        //Runs some checks to make sure that the serialization
        //systems are running and correctly translating the data.
        //TODO automate checking
        public static void DebugDatabaseSerialization()
        {
            Debug.Log("Creating player named Mary Jane.");
            Player p1 = new Player("Mary Janee", 2233443, "abcde");

            Debug.Log("Creating player named John Smith");
            Player p2 = new Player("John Smith", 52342342, "12345");

            DatabaseUpdate db = new DatabaseUpdate();

            db.playerDelta.Add(p1, StateChange.Addition);
            db.playerDelta.Add(p2, StateChange.Removal);
            db.isFullUpdate = true;

            MeshNetworkIdentity dummy1 = new MeshNetworkIdentity();
            MeshNetworkIdentity dummy2 = new MeshNetworkIdentity();

            dummy1.SetObjectID(1337);
            dummy1.SetOwnerID(1234);
            dummy1.SetLocked(true);
            dummy2.SetObjectID(4200);
            dummy2.SetOwnerID(4321);
            dummy2.SetLocked(false);

            db.objectDelta.Add(dummy1, StateChange.Change);
            db.objectDelta.Add(dummy2, StateChange.Addition);
            db.fullHash = 4321;

            Debug.Log("Total payload length: " + db.GetSerializedBytes().Length);
            //Debug.Log("Database hash: " + NetworkDatabase.GenerateDatabaseChecksum(db.playerDelta, db.objectDelta));
            MeshPacket p = new MeshPacket();

            p.SetPacketType(PacketType.DatabaseUpdate);
            p.SetSourceObjectId((byte)ReservedObjectIDs.DatabaseObject);
            p.SetSourcePlayerId(120);
            p.SetTargetObjectId((byte)ReservedObjectIDs.DatabaseObject);
            p.SetTargetPlayerId((byte)ReservedPlayerIDs.Broadcast);
            p.SetContents(db.GetSerializedBytes());

            byte[] transmitData = p.GetSerializedBytes();



            //THIS WOULD GET SENT ACROSS THE NETWORK

            MeshPacket received = new MeshPacket(transmitData);

            Debug.Log("Received packet:");
            Debug.Log("packetType: " + received.GetPacketType());
            Debug.Log("sourceObjectID: " + received.GetSourceObjectId());
            Debug.Log("sourcePlayerID: " + received.GetSourcePlayerId());
            Debug.Log("targetObjectID: " + received.GetTargetObjectId());
            Debug.Log("targetPlayerID: " + received.GetTargetPlayerId());
            Debug.Log("Payload length: " + received.GetContents().Length);


            DatabaseUpdate receivedDB = DatabaseUpdate.ParseContentAsDatabaseUpdate(received.GetContents());

            Debug.Log("Received DatabaseUpdate: isfullupdate = " + receivedDB.isFullUpdate);
            Debug.Log("Hash = " + receivedDB.fullHash);
            //Debug.Log("Database hash: " + NetworkDatabase.GenerateDatabaseChecksum(db.playerDelta, db.objectDelta));
            Debug.Log("Total number of objects: " + receivedDB.objectDelta.Count);
            int i = 1;

            foreach (MeshNetworkIdentity id in receivedDB.objectDelta.Keys)
            {
                Debug.Log("Object " + i + ": ");
                Debug.Log("objectID: " + id.GetObjectID());
                Debug.Log("prefabID: " + id.GetPrefabID());
                Debug.Log("ownerID : " + id.GetOwnerID());
                Debug.Log("Locked: " + id.GetLocked());
                i++;
            }
            Debug.Log("Total number of players: " + receivedDB.playerDelta.Count);
            i = 1;
            foreach (Player player in receivedDB.playerDelta.Keys)
            {
                Debug.Log("Player " + i + ": ");
                Debug.Log("Desanitized Name: " + player.GetNameDesanitized());
                Debug.Log("Sanitized Name: " + player.GetNameSanitized());
                Debug.Log("uniqueID: " + player.GetUniqueID());
                Debug.Log("privateKey: " + player.GetPrivateKey());
                i++;
            }
        }