Esempio n. 1
0
        public ServerLandscapeManager(ServerCore server, IChunksStorage chunksStorage, WorldGenerator generator, EntityFactory factory, int chunkLiveTimeMinutes, int cleanUpInterval, int saveInterval, int chunksLimit, WorldParameters wp)
            : base(wp)
        {
            ChunkLiveTimeMinutes = chunkLiveTimeMinutes;
            CleanUpInterval      = cleanUpInterval;
            SaveInterval         = saveInterval;
            ChunkCountLimit      = chunksLimit;
            EntityFactory        = factory;


            if (chunksStorage == null)
            {
                throw new ArgumentNullException("chunksStorage");
            }
            if (generator == null)
            {
                throw new ArgumentNullException("generator");
            }

            _server        = server;
            _chunksStorage = chunksStorage;
            _generator     = generator;

            _server.ConnectionManager.ConnectionAdded   += ConnectionManagerConnectionAdded;
            _server.ConnectionManager.ConnectionRemoved += ConnectionManagerConnectionRemoved;

            _cleanUpTimer = new Timer(CleanUp, null, CleanUpInterval, CleanUpInterval);
            _saveTimer    = new Timer(SaveChunks, null, SaveInterval, SaveInterval);
        }
Esempio n. 2
0
        /// <summary>
        /// Create new instance of the Server class
        /// </summary>
        public ServerCore(
            XmlSettingsManager <ServerSettings> settingsManager,
            WorldGenerator worldGenerator,
            IUsersStorage usersStorage,
            IChunksStorage chunksStorage,
            IEntityStorage entityStorage,
            ICustomStorage customStorage,
            EntityFactory entityFactory,
            WorldParameters wp
            )
        {
            // dependency injection
            SettingsManager = settingsManager;
            UsersStorage    = usersStorage;
            EntityStorage   = entityStorage;
            CustomStorage   = customStorage;
            EntityFactory   = entityFactory;
            WorldParameters = wp;

            if (SettingsManager.Settings == null)
            {
                SettingsManager.Load();
            }

            var settings = SettingsManager.Settings;

            ConnectionManager = new ConnectionManager(SettingsManager.Settings.ServerPort);

            Scheduler = new ScheduleManager();

            UtopiaTime startTime = CustomStorage.GetVariable <UtopiaTime>("GameTimeElapsed");

            Clock = new Clock(this, startTime, TimeSpan.FromMinutes(20));

            LandscapeManager = new ServerLandscapeManager(
                this,
                chunksStorage,
                worldGenerator,
                EntityFactory,
                settings.ChunkLiveTimeMinutes,
                settings.CleanUpInterval,
                settings.SaveInterval,
                settings.ChunksCountLimit,
                wp);

            EntityManager = new EntityManager(this);

            AreaManager = new AreaManager(this);

            DynamicIdHelper.SetMaxExistsId(EntityStorage.GetMaximumId());

            Services = new ServiceManager(this);

            PerformanceManager = new PerformanceManager(AreaManager);

            CommandsManager = new CommandsManager(this);

            ChatManager = new ChatManager(this);

            GlobalStateManager = new GlobalStateManager(this);

            LoginManager = new LoginManager(this, EntityFactory);

            EntitySpawningManager = new EntitySpawningManager(this, worldGenerator.EntitySpawningControler);

            EntityGrowingManager = new Managers.EntityGrowingManager(this);
        }