Esempio n. 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());
        }
Esempio n. 2
0
        public static void DebugPackets()
        {
            MeshPacket p = new MeshPacket();

            p.SetSourceObjectId(5);
            p.SetTargetObjectId(10);
            p.SetSourcePlayerId(1234);
            p.SetTargetPlayerId(4321);
            p.SetSubcomponentID(2);
            p.SetPacketType(PacketType.DatabaseUpdate);
            p.SetContents(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            byte[]     buffer    = p.GetSerializedBytes();
            MeshPacket newPacket = new MeshPacket(buffer);

            Debug.Log(newPacket.GetTargetObjectId());
            Debug.Log(newPacket.GetPacketType());
        }
Esempio n. 3
0
        public static void ProfileSerialization()
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();


            DatabaseUpdate db = new DatabaseUpdate();

            for (int i = 0; i < 1; i++)
            {
                db.playerDelta.Add(new Player("PLAYERNAME", (ulong)i, "key"), StateChange.Addition);
            }
            db.isFullUpdate = true;


            for (int i = 0; i < 1; i++)
            {
                db.objectDelta.Add(new MeshNetworkIdentity((ushort)i, 20, 40, true), StateChange.Addition);
            }

            //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);

            stopwatch.Start();
            p.SetContents(db.GetSerializedBytes());
            stopwatch.Stop();
            byte[] transmitData = p.GetSerializedBytes();


            //THIS WOULD GET SENT ACROSS THE NETWORK

            MeshPacket received = new MeshPacket(transmitData);

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

            Debug.logger.logEnabled = true;
            Debug.Log("Testing: " + stopwatch.Elapsed.TotalMilliseconds);
        }
Esempio n. 4
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++;
            }
        }