示例#1
0
        public MinimalMockServer(GalacticProperties gp, IDatabaseManager databaseManager, IDbIdIoService dbIdIoService)
        {
            Logger.Initialize();

            DatabaseManager = databaseManager;
            DbIdIoService   = dbIdIoService;

            //Minimal initializations
            GalaxyIDManager  = new LocalIDManager(null, IDTypes.GalaxyID);
            TeamIDManager    = new LocalIDManager(null, IDTypes.TeamID);
            accountIDManager = new LocalIDManager(null, IDTypes.AccountID);

            InitializeIdData(gp);

            globalGalaxyIDManager = new GlobalGalaxyIDManager(dbIdIoService, gp);
            GenerateIDsForLocalIDManager(globalGalaxyIDManager, GalaxyIDManager, gp.IdProperties[IDTypes.GalaxyID].LastIDAdded);

            globalTeamIDManager = new GlobalTeamIDManager(dbIdIoService, gp);
            GenerateIDsForLocalIDManager(globalTeamIDManager, TeamIDManager, gp.IdProperties[IDTypes.TeamID].LastIDAdded);

            globalAccountIDManager = new GlobalAccountIDManager(dbIdIoService, gp);
            GenerateIDsForLocalIDManager(globalAccountIDManager, accountIDManager, gp.IdProperties[IDTypes.AccountID].LastIDAdded);

            _redisServer = new RedisServer(Logger.LogRedisError, Logger.LogRedisInfo, new RedisConfig().Address);


            TeamManager        = new GlobalTeamManager(TeamIDManager, null, null, null, DatabaseManager);
            PlayerManager      = new PlayerManager(DatabaseManager, null, _redisServer, GalaxyIDManager, null);
            GalaxyManager      = new GalaxyManager(gp.SolID, TeamManager);
            shipManager        = new ShipManager(null, GalaxyManager, null, null, DatabaseManager);
            CollisionManager   = new CollisionManager(GalaxyManager, null, null, null);
            GalaxyGenerator    = new DebugGalaxyGenerator(PlayerManager, GalaxyManager, shipManager);
            AccountManager     = new AccountManager_MasterServer(accountIDManager, DatabaseManager, false);
            CargoSynchronizer  = new Server.Managers.CargoSynchronizer();
            StructureManager   = new StructureManager(DatabaseManager, GalaxyManager, GalaxyIDManager, CargoSynchronizer);
            RegistrationManger = new GalaxyRegistrationManager(GalaxyManager, shipManager, CollisionManager, GalaxyIDManager, PlayerManager, null, CargoSynchronizer, StructureManager);
            ColonyFactory.Initialize(GalaxyIDManager, RegistrationManger);
            StructureFactory.Initialize(GalaxyIDManager, RegistrationManger);
            LocatorService = new LocatorService(RegistrationManger, PlayerManager, GalaxyManager, shipManager, AccountManager, TeamManager, TeamManager, null, StructureManager, null);

            WarpManager = new WarpManager(GalaxyManager, null, null, _redisServer, AccountManager, null);

            CargoSynchronizer.Start(10, 4);
        }
示例#2
0
        public GlobalIDManager(IDbIdIoService dbIdIoService, IDTypes idType)
        {
            _dbIdIoService = dbIdIoService;
            IDType         = idType;

            var idData = _dbIdIoService.GetIdData(idType);

            if (idData == null)
            {
                throw new Exception("ID data for IdType " + idType + " not initialized in database.");
            }

            _lastIdGenerated = idData.LastIdGenerated;

            _reservedIDs = idData.ReservedIds;

            _freeIDs      = new ConcurrentStack <int>(idData.FreeIDs);
            _generatedIDs = new ConcurrentStack <int>(idData.UsedIDs);
        }
示例#3
0
        public MasterServerManager(MasterServerConfig c, GalacticProperties gp, IDatabaseManager dbm, IDbIdIoService dbIdIoService, RedisServer redisServer, SlaveServerConfigService slaveServerConfigService)
        {
            _redisServer              = redisServer;
            _databaseManager          = dbm;
            _dbIdIoService            = dbIdIoService;
            _slaveServerConfigService = slaveServerConfigService;
            MasterServerConfig        = c;
            GalacticProperties        = gp;

            SlaveID = _slaveServerConfigService.CurrentServiceId;

            if (!_checkForMasterServer())
            {
                List <PSystemModel> allSystems = new List <PSystemModel>(_databaseManager.GetAllSystemsAsync().Result);
                _promoteToMasterServer(MasterServerConfig, GalacticProperties, allSystems, _databaseManager, _dbIdIoService, _redisServer);
            }
            else
            {
#if DEBUG
                ConsoleManager.WriteLine("Existing master server detected. Initializating as slave only.", ConsoleMessageType.Debug);
#endif
            }

            if (!IsMasterServer)
            {
                ConsoleManager.WriteLine("Initializing as slave only.", ConsoleMessageType.Notification);//Leaving this here to remember to log it later, might be useful
            }

            _connectToServer();

            redisServer.Subscribe(MessageTypes.Redis_SlaveConnectionResponse, _handleSlaveConnectionResponse);


            _pingTimer          = new Timer(c.SlaveHeartbeatPeriodMS);
            _pingTimer.Elapsed += _updateSlaveHeartbeat;
            _pingTimer.Start();
        }
示例#4
0
        public MasterServer(MasterServerConfig c, GalacticProperties gp, IEnumerable <PSystemModel> allSystemModels, IDatabaseManager dbm, IDbIdIoService dbIdIoService, RedisServer redisServer)
        {
            _config = c;

            Dictionary <IDTypes, GlobalIDManager> globalIDManagers = new Dictionary <IDTypes, GlobalIDManager>();

            globalIDManagers.Add(IDTypes.GalaxyID, new GlobalGalaxyIDManager(dbIdIoService, gp));
            globalIDManagers.Add(IDTypes.TeamID, new GlobalTeamIDManager(dbIdIoService, gp));
            globalIDManagers.Add(IDTypes.TransactionID, new GlobalTransactionIDManager(dbIdIoService, gp));
            globalIDManagers.Add(IDTypes.AccountID, new GlobalAccountIDManager(dbIdIoService, gp));

            GlobalIDManagers = globalIDManagers;

            _redisServer     = redisServer;
            _databaseManager = dbm;

            _systemIDToSlaveServer = new ConcurrentDictionary <int, SlaveServer>();

            AccountManager_MasterServer acm = new AccountManager_MasterServer(new LocalIDManager_MS((GlobalAccountIDManager)globalIDManagers[IDTypes.AccountID], IDTypes.AccountID), dbm, true);

            _allSystemModels = new Dictionary <int, PSystemModel>();
            foreach (var sm in allSystemModels)
            {
                if (!_allSystemModels.ContainsKey(sm.Id))
                {
                    _allSystemModels.Add(sm.Id, sm);
                }
            }

            _redisServer.Subscribe(MessageTypes.Redis_SlaveConnectionRequest, _slaveConnected);
            _redisServer.Subscribe(MessageTypes.Redis_IDRequest, _handleIDRequest);

            _initTimeMs = TimeKeeper.MsSinceInitialization;//If this class gets an initializer or a reset method, this should be moved there.
        }
示例#5
0
        /// <summary>
        /// Sets IsMasterServer=true if succesful
        /// </summary>
        /// <param name="c"></param>
        /// <param name="gp"></param>
        /// <param name="allSystemModels"></param>
        /// <param name="dbm"></param>
        /// <param name="redisServer"></param>
        void _promoteToMasterServer(MasterServerConfig c, GalacticProperties gp, IEnumerable <PSystemModel> allSystemModels, IDatabaseManager dbm, IDbIdIoService dbIdIoService, RedisServer redisServer)
        {
            #if DEBUG
            ConsoleManager.WriteLine("Promoting to master server...", ConsoleMessageType.Notification);
            #endif


            string masterServerID = Rand.Random.Next(-int.MaxValue, int.MaxValue).ToString();


            bool setSuccessful = _redisServer.SetValue(
                RedisDBKeyTypes.MasterServerTimestamp,
                new MasterServerTimestamp()
            {
                MasterServerID = masterServerID
            },
                new TimeSpan(0, 0, 0, 0, c.InitializationTimestampTimeoutMS),
                SetWhen.NotExists
                );

            // Check if this instance was the first to set a timestamp, so we're clear to initialize a master server
            if (!setSuccessful)
            {
                ConsoleManager.WriteLine("Slave promotion failed, master server already exists, although master server check passed. Race Condition?", ConsoleMessageType.Error);
                // Another server exists already.
                return;
            }

            // Clear to initialize a master server.
            _masterServer = new MasterServer(c, gp, allSystemModels, dbm, dbIdIoService, redisServer);

            _masterServer.Id = int.Parse(masterServerID);

            IsMasterServer = true;

#if DEBUG
            ConsoleManager.WriteLine("Master Server spawn Successful", ConsoleMessageType.Notification);
#endif
        }
示例#6
0
 public GlobalTransactionIDManager(IDbIdIoService dbIdIoService, GalacticProperties c)
     : base(dbIdIoService, IDTypes.AccountID)
 {
 }
示例#7
0
 public GlobalTeamIDManager(IDbIdIoService dbIdIoService, GalacticProperties c)
     : base(dbIdIoService, IDTypes.TeamID)
 {
 }