示例#1
0
        public PlayerManager(IDatabaseManager databaseManager, ConnectionManager cm, RedisServer rs, LocalIDManager idm, ClientUpdateManager cum) : base(databaseManager)
        {
            _usernameToPlayer  = new ConcurrentDictionary <string, Player>();
            connectionToPlayer = new ConcurrentDictionary <NetConnection, Player>();

            _clientUpdateManager = cum;
            _connectionManager   = cm;
            _redisServer         = rs;
            _playerIDManager     = idm;

            _redisServer.Subscribe(MessageTypes.Redis_PlayerRemoveTeam, _teamRemove_Handler);
        }
示例#2
0
        /// <summary>
        /// Initializes the entire server
        /// </summary>
        private void Initialize()
        {
            for (int i = 0; i < 20; i++)
            {
                msgAvgQue.Enqueue(0);
            }

            var rand = new Random(3);

            // Logging Enabled
            Logger.Initialize();

            _synchronizers = new List <ISynchronizer>();


            //Load configs
            ConnectionManagerConfig connectionManagerConfig = new ConnectionManagerConfig(new CoreNetworkConfig());
            GalacticProperties      galacticProperties      = new GalacticProperties();

            _consoleManager = new ConsoleManager();

            _projectileManager = new ProjectileManager();

            ConsoleManager.WriteLine("Starting database...", ConsoleMessageType.Startup);
            _databaseManager = new MongoDatabaseManager();

            ShipStatManager.ReadShipsFromDBSList(_databaseManager.GetStatsFromDBAsync().Result);
            ConsoleManager.WriteLine("Ship types loaded.", ConsoleMessageType.Startup);

            RedisConfig rc = new RedisConfig();

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

            var slaveId = SlaveServerConfigService.GetFreeSlaveID(_redisServer).Result;

            _slaveServerConfigService = new SlaveServerConfigService(_redisServer, slaveId);

            _masterServerManager = new MasterServerManager(new MasterServerConfig(), new GalacticProperties(), _databaseManager, _databaseManager, _redisServer, _slaveServerConfigService);

            _cargoSynchronizer = new CargoSynchronizer();
            _synchronizers.Add(_cargoSynchronizer);

            connectionManagerConfig.MyConfig.Port = ConnectionManager.GetFreePort(28002, 28010);
            _connectionManager = new ConnectionManager();
            _connectionManager.Initialize(connectionManagerConfig);

            //Poll to listen to Lidgren until it is ready
            //LidgrenMessagePoller_Init initializationPoller = new LidgrenMessagePoller_Init(_connectionManager.Server, this);
            //initializationPoller.Poll();

            _galaxyIDManager      = new LocalIDManager(_masterServerManager, IDTypes.GalaxyID);
            _teamIDManager        = new LocalIDManager(_masterServerManager, IDTypes.TeamID);
            _accountIDManager     = new LocalIDManager(_masterServerManager, IDTypes.AccountID);
            _transactionIDManager = new LocalIDManager(_masterServerManager, IDTypes.TransactionID);

            _accountManager = new AccountManager(_accountIDManager, _databaseManager);

            _messageManager = new MessageManager(_connectionManager);

            _clientUpdateManager = new ClientUpdateManager(_playerManager);

            _playerManager = new PlayerManager(_databaseManager, _connectionManager, _redisServer, _galaxyIDManager, _clientUpdateManager);

            var chatCommands = new List <IChatCommand>()
            {
                new HelpCommand(),
                new ShoutCommand(_redisServer),
                new RadioCommand(),
                new TellCommand(_playerManager)
            };

            var asyncChatCommands = new List <IAsyncChatCommand>()
            {
                new AdminWarpCommand(_databaseManager, _redisServer, new Random())
            };

            _teamManager = new GlobalTeamManager(_teamIDManager, _connectionManager, _redisServer, _playerManager, _databaseManager);

            _galaxyManager = new GalaxyManager(galacticProperties.SolID, _teamManager);

            _chatManager = new ChatManager(chatCommands, asyncChatCommands, _playerManager, _messageManager, _redisServer);

            _warpManager = new WarpManager(_galaxyManager, _messageManager, _chatManager, _redisServer, _accountManager, _databaseManager);

            _shipManager = new ShipManager(_messageManager, _galaxyManager, _warpManager, _connectionManager, _databaseManager);

            _structureManager = new StructureManager(_databaseManager, _galaxyManager, _galaxyIDManager, _cargoSynchronizer);

            loginManager = new LoginManager(_accountManager, _playerManager, _connectionManager, _redisServer);

            // Todo: Convert everything over to ServerNetworkMessage to propogate full request context.
            _simulatorManager = new SimulatorManager(new SimulatorConfig(), _redisServer, (sender, container) => ProcessMessage(sender, new ServerNetworkMessage(container, null)));

            StructureStatManager.Initialize();

            ConsoleManager.WriteLine("Completed Initialization", ConsoleMessageType.Startup);

            _economyManager      = new EconomyManager(_transactionIDManager, _playerManager, _galaxyManager, _cargoSynchronizer, _shipManager, _databaseManager, _masterServerManager);
            _killManager         = new KillManager(_cargoSynchronizer, _playerManager, _galaxyManager, _messageManager, _connectionManager, _warpManager, _chatManager, _economyManager);
            _collisionManager    = new CollisionManager(_galaxyManager, _messageManager, _killManager, _projectileManager);
            _registrationManager = new GalaxyRegistrationManager(_galaxyManager, _shipManager, _collisionManager, _galaxyIDManager, _playerManager, _accountManager, _cargoSynchronizer, _structureManager);
            _warpManager.SetRegistrationManager(_registrationManager);//Gross, I know.
            _locatorService   = new LocatorService(_registrationManager, _playerManager, _galaxyManager, _shipManager, _accountManager, _teamManager, _teamManager, _messageManager, _structureManager, _masterServerManager);
            _msMessageHandler = new MasterServerMessageHandler((int)_masterServerManager.SlaveID, _redisServer, _connectionManager, _locatorService, _accountManager, _accountIDManager, _databaseManager, _galaxyManager, _galaxyIDManager, _playerManager, _shipManager, _registrationManager, _teamIDManager, _messageManager, _teamManager, _warpManager, _transactionIDManager, ProcessRoutedMessage);

            StructureFactory.Initialize(_galaxyIDManager, _registrationManager);
            ColonyFactory.Initialize(_galaxyIDManager, _registrationManager);

            dbSyncer = new DBSyncer(_databaseManager, _galaxyManager, _shipManager, _playerManager, _accountManager, _structureManager);

#if DEBUG
            _typesToExcludeIgnore.Add(MessageTypes.PositionUpdateData);
            _typesToExcludeIgnore.Add(MessageTypes.ShipFireRequest);
            _typesToExcludeIgnore.Add(MessageTypes.ProjectileCollisionReport);
            _typesToExcludeIgnore.Add(MessageTypes.StructureFireRequest);
            _typesToExcludeIgnore.Add(MessageTypes.ObjectPickupRequest);
#endif
        }