Beispiel #1
0
        /// <inheritdoc />
        public Task StartAsync(CancellationToken cancellationToken)
        {
            using var persistenceContext = this.persistenceContextProvider.CreateNewConfigurationContext();
            foreach (var connectServerDefinition in persistenceContext.Get <ConnectServerDefinition>())
            {
                var clientVersion = new ClientVersion(connectServerDefinition.Client.Season, connectServerDefinition.Client.Episode, connectServerDefinition.Client.Language);
                var connectServer = ConnectServerFactory.CreateConnectServer(connectServerDefinition, clientVersion, connectServerDefinition.GetId());
                this.servers.Add(connectServer);
                this.connectServers.Add(connectServer);

                if (this.observers.TryGetValue(connectServerDefinition.Client, out var observer))
                {
                    this.logger.LogWarning($"Multiple connect servers for game client '{connectServerDefinition.Client.Description}' configured. Only one per client makes sense.");
                    if (!(observer is MulticastConnectionServerStateObserver))
                    {
                        var multicastObserver = new MulticastConnectionServerStateObserver();
                        multicastObserver.AddObserver(observer);
                        multicastObserver.AddObserver(connectServer);
                        this.observers[connectServerDefinition.Client] = multicastObserver;
                    }
                }
                else
                {
                    this.observers[connectServerDefinition.Client] = connectServer;
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Program"/> class.
        /// Constructor for the main entry program.
        /// </summary>
        /// <param name="args">The command line args.</param>
        public Program(string[] args)
        {
            if (args.Contains("-demo"))
            {
                this.persistenceContextProvider = new InMemoryPersistenceContextProvider();
                var initialization = new DataInitialization(this.persistenceContextProvider);
                initialization.CreateInitialData();
            }
            else
            {
                this.persistenceContextProvider = this.PrepareRepositoryManager(args.Contains("-reinit"));
            }

            var ipResolver = args.Contains("-local") ? (IIpAddressResolver) new LocalIpResolver() : new PublicIpResolver();

            Log.Info("Start initializing sub-components");
            var signalRServerObserver = new SignalRGameServerStateObserver();
            var serverConfigListener  = new ServerConfigurationChangeListener(this.servers, signalRServerObserver);
            var persistenceContext    = this.persistenceContextProvider.CreateNewConfigurationContext();
            var loginServer           = new LoginServer();

            var chatServerDefinition = persistenceContext.Get <ChatServerDefinition>().First();
            var chatServer           = new ChatServer(chatServerDefinition.ConvertToSettings(), signalRServerObserver, ipResolver);

            this.servers.Add(chatServer);
            var guildServer    = new GuildServer(this.gameServers, this.persistenceContextProvider);
            var friendServer   = new FriendServer(this.gameServers, chatServer, this.persistenceContextProvider);
            var connectServers = new Dictionary <GameClientDefinition, IGameServerStateObserver>();

            ClientVersionResolver.DefaultVersion = new ClientVersion(6, 3, ClientLanguage.English);
            foreach (var gameClientDefinition in persistenceContext.Get <GameClientDefinition>())
            {
                ClientVersionResolver.Register(gameClientDefinition.Version, new ClientVersion(gameClientDefinition.Season, gameClientDefinition.Episode, gameClientDefinition.Language));
            }

            foreach (var connectServerDefinition in persistenceContext.Get <ConnectServerDefinition>())
            {
                var connectServer = ConnectServerFactory.CreateConnectServer(connectServerDefinition, signalRServerObserver);
                this.servers.Add(connectServer);
                if (!connectServers.TryGetValue(connectServerDefinition.Client, out var observer))
                {
                    connectServers[connectServerDefinition.Client] = connectServer;
                }
                else
                {
                    Log.WarnFormat($"Multiple connect servers for game client '{connectServerDefinition.Client.Description}' configured. Only one per client makes sense.");
                    if (!(observer is MulticastConnectionServerStateObserver))
                    {
                        var multicastObserver = new MulticastConnectionServerStateObserver();
                        multicastObserver.AddObserver(observer);
                        multicastObserver.AddObserver(connectServer);
                        connectServers[connectServerDefinition.Client] = multicastObserver;
                    }
                }
            }

            Log.Info("Start initializing game servers");
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            foreach (var gameServerDefinition in persistenceContext.Get <DataModel.Configuration.GameServerDefinition>())
            {
                using (ThreadContext.Stacks["gameserver"].Push(gameServerDefinition.ServerID.ToString()))
                {
                    var gameServer = new GameServer(gameServerDefinition, guildServer, loginServer, this.persistenceContextProvider, friendServer, signalRServerObserver);
                    foreach (var endpoint in gameServerDefinition.Endpoints)
                    {
                        gameServer.AddListener(new DefaultTcpGameServerListener(endpoint, gameServer.ServerInfo, gameServer.Context, connectServers[endpoint.Client], ipResolver));
                    }

                    this.servers.Add(gameServer);
                    this.gameServers.Add(gameServer.Id, gameServer);
                    Log.InfoFormat("Game Server {0} - [{1}] initialized", gameServer.Id, gameServer.Description);
                }
            }

            stopwatch.Stop();
            Log.Info($"All game servers initialized, elapsed time: {stopwatch.Elapsed}");
            Log.Info("Start initializing admin panel");

            this.adminPanel = new AdminPanel(1234, this.servers, this.persistenceContextProvider, serverConfigListener, Log4NetConfigFilePath);
            Log.Info("Admin panel initialized");

            if (args.Contains("-autostart"))
            {
                chatServer.Start();
                foreach (var gameServer in this.gameServers.Values)
                {
                    gameServer.Start();
                }

                foreach (var connectServer in this.servers.OfType <IConnectServer>())
                {
                    connectServer.Start();
                }
            }
        }