Exemple #1
0
        string printObject( Mob m )
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine( CultureFree.Format( "{0} (#{1}) - at #{2}, parent #{3}, path {4}", m.name, m.id, m.locationId, m.parentId, m.fqpn ) );
            sb.AppendLine( m.desc );

            // The "deleted" should only ever happen while printing a canon world.
            foreach( var vn in m.verbList )
            {
            Verb v = m.verbGet( vn );
            if( v != null )
                sb.AppendLine( CultureFree.Format( "Verb {0}: {1}", v.name, v.code.Replace( "\n", "-cr-" ) ) );
            else
                sb.AppendLine( CultureFree.Format( "Verb {0} [deleted]", v.name ) );
            }
            foreach( var an in m.attrList )
            {
            TypedAttribute a = m.attrGet( an );
            if( a != null )
                sb.AppendLine( CultureFree.Format( "Attr {0}: {1}", an, a.str ) );
            else
                sb.AppendLine( CultureFree.Format( "Attr {0} [deleted]", an ) );
            }
            sb.AppendLine();

            return sb.ToString();
        }
Exemple #2
0
        /// <summary>
        /// Returns true if the verb in question is an anti-stick (and should be executed
        /// in the context of the caller, not the object).
        /// </summary>
        public static bool IsVerbAntistick( Mob m, string verb )
        {
            while( m != null )
            {
            if( m.verbGet( verb ) != null )
            {
                return m.permissions.Any( p => (p.perms & PermBits.VO) && p.specific == verb );
            }

            m = m.parent;
            }

            return false;
        }
Exemple #3
0
        /// <summary>
        /// Saves the specified Mob to the current checkpoint, overwriting any previous value.
        /// </summary>
        public void saveMob( Mob m )
        {
            lock( _lock )
            using( var token = _db.token() )
            using( var trans = _db.transaction( token ) )
            {
            // Get the current checkpoint ID.
            ulong curCheckpoint = getLatestCheckpoint( token );

            // Is it in the mob table for this checkpoint? If not, we just write out a new one.
            IEnumerable<DBMobTable> mt = _db.select( token,
                new DBMobTable()
                {
                    objectId = m.id
                },
                new string[] { "objectId" }
            );
            if( mt.Count( mtm => mtm.checkpoint == curCheckpoint ) > 0 )
            {
                // Just delete the mobtable entry.
                _db.delete( token,
                    new DBMobTable()
                    {
                        id = mt.First().id
                    },
                    new string[] { "id" }
                );

                // Is it used in any other checkpoints? If so, we have to make a new one too.
                if( mt.Count() == 1 )
                {
                    // Delete the existing data.
                    ulong mobId = mt.First().mob;
                    deleteMobInternal( token, mobId );
                }
            }

            // Any old object will have been deleted by this point, so we make a new one.
            DBMob dbmob = new DBMob()
            {
                objectId = m.id,
                location = m.locationId,
                owner = m.ownerId,
                parent = m.parentId,
                pathId = m.pathId,
                pulse = m.pulseFreq != 0
            };
            _db.insert( token, dbmob );

            // Write out a new mobtable entry.
            DBMobTable dbmobtable = new DBMobTable()
            {
                mob = dbmob.id,
                objectId = m.id,
                checkpoint = curCheckpoint
            };
            _db.insert( token, dbmobtable );

            // Save out all the attributes.
            foreach( var attrName in m.attrList )
            {
                // Canon mobs can return timestamped empties for deletion.
                TypedAttribute attr = m.attrGet( attrName );
                if( attr != null )
                {
                    AttributeSerialized ser = attr.serialize();
                    DBAttr dbattr = new DBAttr()
                    {
                        mime = ser.mimetype,
                        name = attrName,
                        mob = dbmob.id,
                        text = ser.strvalue,
                        data = ser.binvalue
                    };
                    _db.insert( token, dbattr );
                }
            }

            // Save out all the verbs.
            foreach( var verbName in m.verbList )
            {
                // Canon mobs can return timestamped empties for deletion.
                Verb v = m.verbGet( verbName );
                if( v != null )
                {
                    DBVerb dbverb = new DBVerb()
                    {
                        name = v.name,
                        code = v.code,
                        mob = dbmob.id,
                    };
                    _db.insert( token, dbverb );
                }
            }

            trans.commit();
            }
        }