Exemple #1
0
    //Object modification methods
    public DatabaseChangeResult AddObject(MeshNetworkIdentity i, bool publishChange)
    {
        if (objectList.ContainsKey(i.GetObjectID()))
        {
            return(new DatabaseChangeResult(false, "Object already exists"));
        }
        if (i.GetObjectID() == (ushort)ReservedObjectIDs.DatabaseObject)
        {
        }

        //If the object isn't the database, we need to assign an available objectID
        if (i.GetObjectID() != (ushort)ReservedObjectIDs.DatabaseObject)
        {
            IDAssignmentResult idresult = GetAvailableObjectID(); //Look for an available object id
            if (idresult.success)
            {
                i.SetObjectID(idresult.id);
            }
            else
            {
                return(new DatabaseChangeResult(false, "No object id available for use. Too many objects?"));
            }
        }
        objectList.Add(i.GetObjectID(), i);
        if (publishChange)
        {
            if (GetAuthorized())
            {
                SendObjectUpdate(i, StateChange.Addition);
                return(new DatabaseChangeResult(true, i.GetObjectID()));
            }
            else
            {
                Debug.LogError("Publishing changes not authorized.");
                return(new DatabaseChangeResult(false, "Publishing changes not authorized"));
            }
        }
        else
        {
            return(new DatabaseChangeResult(true, i.GetObjectID()));
        }
    }
Exemple #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++;
            }
        }