コード例 #1
0
ファイル: Program.cs プロジェクト: kayateia/climoo
        static void Main( string[] args )
        {
            if( args.Length != 2 )
            {
            Console.WriteLine( "Please specify the filename of an ImpExporter database config file and a player login name." );
            return;
            }

            // Load up the config.
            ImpExporterConfig cfg = XmlPersistence.Load<ImpExporterConfig>( args[0] );

            // Create a world, sans realtime save and pulse.
            Assembly asm = Assembly.Load( cfg.DatabaseAssembly );
            Type dbType = asm.GetType( cfg.DatabaseClass );
            IDatabase db = (IDatabase)Activator.CreateInstance( dbType );
            db.setup( cfg.ConnectionString, new TableInfo() );
            var coredb = new CoreDatabase( db );
            var worlddb = new WorldDatabase( coredb );
            var world = CanonWorld.FromWorldDatabase( worlddb, true, true );
            world.attributeUrlGenerator = ( obj, name ) => CultureFree.Format( "<attr:{0}.{1}>", obj.name, name );

            // Look up the player. If they passed "anon", then we use an anonymous, pre-login player.
            int mobid;
            if( args[1] == "anon" )
            {
            mobid = Mob.Anon.id;
            }
            else
            {
            using( var token = coredb.token() )
            {
                var users = coredb.select( token, new DBUser() { login = args[1] }, new string[] { "login" } );
                if( users.Count() != 1 )
                {
                    Console.WriteLine( "Couldn't match exactly one user with the login '{0}'", args[1] );
                    return;
                }

                mobid = users.First().@object;
            }
            }

            // Make a shadow world for us to use.
            var shadowWorld = new ShadowWorld( world );
            Mob playerMob = mobid > 0 ? Mob.Wrap( shadowWorld.findObject( mobid ) ) : null;

            // Make a player object.
            Player player = new Player( mobid );
            player.NewOutput = (o) =>
            {
            Console.WriteLine( "{0}", o );
            };
            player.NewSound = (o) =>
            {
            Console.WriteLine( "Would play sound: {0}", o );
            };
            player.NewErrorOutput = (o) =>
            {
            Console.WriteLine( "[error] {0}", o );
            };
            player.world = World.Wrap( shadowWorld );
            if( playerMob != null )
            playerMob.player = player;

            while( true )
            {
            Console.Write( "climoo> " );

            string command = Console.ReadLine();
            if( command == "exit" )
                break;

            string result = MooCore.InputParser.ProcessInput( command, player );
            if( !result.IsNullOrEmpty() )
                Console.WriteLine( result );

            shadowWorld.waitForMerge();
            }

            // Clear out any changes and timers.
            shadowWorld.Dispose();
            world.Dispose();
        }
コード例 #2
0
ファイル: WorldDatabase.cs プロジェクト: kayateia/climoo
 public WorldDatabase( CoreDatabase db )
 {
     _db = db;
 }
コード例 #3
0
ファイル: WorldTest.cs プロジェクト: kayateia/climoo
        // This makes a basic world with 5 objects:
        // God (#1) /
        // Templates (#2) /templates
        // PlayerTemplate (#3) /templates/player
        // Player (#4)
        // Test (#5)
        void createBasicDatabase()
        {
            var mdb = new MemoryDatabase();
            var cdb = new CoreDatabase( mdb );
            _wdb = new WorldDatabase( cdb );

            _wdb.setConfigInt( World.ConfigNextId, 6 );

            // Create a new checkpoint.
            using( var token = cdb.token() )
            {
            DBCheckpoint cp = new DBCheckpoint()
            {
                name = "initial",
                time = DateTimeOffset.UtcNow
            };
            cdb.insert( token, cp );
            }

            // This will let our stubs function in a minimal way for saving.
            _stubworld = new StubWorld();

            // Create a god object.
            _god = makeMob( 1, 0, 0, "God", "The god object!" );

            // Create a template room.
            _templates = makeMob( 2, 1, 1, "Templates", "Template room", (m) => { m.pathId = "templates"; } );

            // Create a player template.
            _playerTemplate = makeMob( 3, 1, 2, "PlayerTemplate", "Playter template", (m) => { m.pathId = "player"; } );

            // Create a player.
            _player = makeMob( 4, 3, 1, "Player", "Test player" );

            _testObj = makeMob( 5, 1, 1, "Test", "Test object" );
        }
コード例 #4
0
ファイル: WorldData.cs プロジェクト: kayateia/climoo
        public static void Init()
        {
            if( s_world != null && s_db != null )
            return;

            // Load up all the strings of interest from the web.config file.
            var strings = System.Configuration.ConfigurationManager.ConnectionStrings;
            string dbString = strings["climoo_dbcConnectionString"].ConnectionString;
            string dbClass = strings["climoo_dbcConnectionString"].ProviderName;
            //string xmlString = strings["climoo_xmlImportPathString"].ConnectionString;

            // We'll use this in multiple places below.
            var ti = new TableInfo();

            // Break up the pieces of the connection class to figure out what to load.
            string[] classPieces = dbClass.Split( ',' ).Select( x => x.Trim() ).ToArray();
            if( classPieces.Length < 2 )
            throw new ArgumentException( "Too few comma-delimited strings in the database connection class string", dbClass );

            string className = classPieces[0];
            string asmName = classPieces[1];

            // This assembly we want is possibly already loaded, but this gets us a handle to it.
            Assembly dbAsm = Assembly.Load( asmName );
            Type dbType = dbAsm.GetType( className );

            // Create the actual database class.
            IDatabase db = (IDatabase)(Activator.CreateInstance( dbType ));
            db.setup( dbString, ti );

            if (s_world == null) {
            // s_world = MooCore.World.FromXml( xmlString );
            var coredb = new CoreDatabase( db );
            var wdb = new WorldDatabase( coredb );
            s_world = CanonWorld.FromWorldDatabase( wdb, true, false );
            s_world.attributeUrlGenerator = (mob, attr) =>
            {
                return string.Format( "/Game/ServeAttribute?objectId={0}&attributeName={1}", mob.id, attr );
            };
            }
            if (s_db == null) {
            s_db = db;
            // s_db = new MemoryDatabase();
            // Models.XmlModelPersistence.Import(System.IO.Path.Combine(basePath, "web.xml"), s_db);
            }
        }