CanonWorld( WorldDatabase wdb, bool runtime, bool readOnly ) { Log.Info( "Starting World" ); _wdb = wdb; _readOnly = readOnly; // Load up managers for all the mobs in the world. int highest = -1; foreach( int mobId in _wdb.mobList ) { _objects[mobId] = _wdb.loadMob( mobId, this ); highest = Math.Max( highest, mobId ); } // And load up the previous nextId. int? nid = _wdb.getConfigInt( World.ConfigNextId ); if( !nid.HasValue ) { // Just divine it from what we have. (This might be an import.) _nextId = highest + 1; } else _nextId = nid.Value; if( runtime ) { if( !readOnly ) { _saver = new SaveRunner( this, _wdb ); _saver.start(); } _pulse = new PulseRunner( World.Wrap( new ShadowWorld( this ) ) ); _pulse.start( wdb ); } }
// Called at load to dethaw any existing pulse list. void pulseReload( WorldDatabase wdb ) { var list = wdb.mobPulseList; foreach( int id in list ) pulseCheck( id ); }
public void start( WorldDatabase wdb ) { Log.Info( " Starting pulse timer" ); pulseReload( wdb ); _pulseTimer = new Timer( (o) => pulseCallback() ); _pulseTimer.Change( PulseFrequency * 1000, PulseFrequency * 1000 ); }
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(); }
/// <summary> /// Loads a World from a database. /// </summary> /// <param name="wdb">The database</param> /// <param name="runtime">If true, we will set up shop for runtime usage (timers, etc)</param> /// <param name="readOnly">If true, no database writes will occur.</param> public static CanonWorld FromWorldDatabase( WorldDatabase wdb, bool runtime, bool readOnly ) { return new CanonWorld( wdb, runtime, readOnly ); }
public SaveRunner( CanonWorld canon, WorldDatabase wdb ) { _canon = canon; _wdb = wdb; }
// 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" ); }
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); } }