Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConnectServerContainer" /> class.
 /// </summary>
 /// <param name="servers">The servers.</param>
 /// <param name="persistenceContextProvider">The persistence context provider.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="connectServerFactory">The connect server factory.</param>
 public ConnectServerContainer(IList <IManageableServer> servers, IPersistenceContextProvider persistenceContextProvider, ILogger <ConnectServerContainer> logger, ConnectServerFactory connectServerFactory)
 {
     this.servers = servers;
     this.persistenceContextProvider = persistenceContextProvider;
     this.connectServerFactory       = connectServerFactory;
     this.logger = logger;
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private static ConnectServer CreateServer(ProgramConfiguration config)
        {
            var connectServer     = ConnectServerFactory.Create(config);
            var serviceController = ServiceControllerFactory.Create(config.RpcService, connectServer);

            connectServer.AddDependency(serviceController);
            return(connectServer);
        }
Ejemplo n.º 4
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"));
            }

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

            this.servers.Add(chatServer);
            var guildServer   = new GuildServer(this.gameServers, this.persistenceContextProvider);
            var friendServer  = new FriendServer(this.gameServers, chatServer, this.persistenceContextProvider);
            var connectServer = ConnectServerFactory.CreateConnectServer(signalRServerObserver);

            this.servers.Add(connectServer);
            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 mainPacketHandler in gameServer.Context.PacketHandlers.Take(1))
                    {
                        // At the moment only one main packet handler should be used.
                        // A TCP port can only be used for one TCP listener, so we have to introduce something to pair ports with main packets handlers.
                        gameServer.AddListener(new DefaultTcpGameServerListener(gameServerDefinition.NetworkPort, gameServer.ServerInfo, gameServer.Context, connectServer, mainPacketHandler));
                    }

                    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);
            Log.Info("Admin panel initialized");

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

                connectServer.Start();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerConfigurationChangeListener" /> class.
 /// </summary>
 /// <param name="servers">The servers.</param>
 /// <param name="connectServerFactory">The connect server factory.</param>
 public ServerConfigurationChangeListener(IList <IManageableServer> servers, ConnectServerFactory connectServerFactory)
 {
     this.servers = servers;
     this.connectServerFactory = connectServerFactory;
 }
Ejemplo n.º 6
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 persistenceContext    = this.persistenceContextProvider.CreateNewConfigurationContext();
            var loginServer           = new LoginServer();
            var chatServer            = new ChatServerListener(55980, 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, IConnectServer>();

            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);
                connectServers[connectServerDefinition.Client] = connectServer;
            }

            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, 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 connectServers.Values)
                {
                    connectServer.Start();
                }
            }
        }
        /// <summary>
        /// Adds a connection server after a new configuration has been added.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public void ConnectionServerAdded(ConnectServerDefinition configuration)
        {
            var connectServer = ConnectServerFactory.CreateConnectServer(configuration, this.stateObserver);

            this.servers.Add(connectServer);
        }
Ejemplo n.º 8
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"), args.Contains("-autoupdate"));
            }

            var ipResolver = IpAddressResolverFactory.DetermineIpResolver(args);

            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 clientVersion = new ClientVersion(connectServerDefinition.Client.Season, connectServerDefinition.Client.Episode, connectServerDefinition.Client.Language);
                var connectServer = ConnectServerFactory.CreateConnectServer(connectServerDefinition, signalRServerObserver, clientVersion);
                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}");
            var adminPort = this.DetermineAdminPort(args);

            Log.Info($"Start initializing admin panel for port {adminPort}.");

            this.adminPanel = new AdminPanel(adminPort, this.servers, this.persistenceContextProvider, serverConfigListener, Log4NetConfigFilePath);
            Log.Info($"Admin panel initialized, port {adminPort}.");

            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();
                }
            }
        }
        /// <summary>
        /// Adds a connection server after a new configuration has been added.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public void ConnectionServerAdded(ConnectServerDefinition configuration)
        {
            var connectServer = ConnectServerFactory.CreateConnectServer(configuration, new ClientVersion(configuration.Client.Season, configuration.Client.Episode, configuration.Client.Language), configuration.GetId());

            this.servers.Add(connectServer);
        }
Ejemplo n.º 10
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)
        {
            this.repositoryManager = new RepositoryManager();
            this.repositoryManager.InitializeSqlLogging();
            if (args.Contains("-reinit"))
            {
                Console.WriteLine("The database is getting reininitialized...");
                this.repositoryManager.ReInitializeDatabase();
            }
            else if (!this.repositoryManager.IsDatabaseUpToDate())
            {
                Console.WriteLine("The database needs to be updated before the server can be started. Apply update? (y/n)");
                var key = Console.ReadLine()?.ToLowerInvariant();
                if (key == "y")
                {
                    this.repositoryManager.ApplyAllPendingUpdates();
                    Console.WriteLine("The database has been successfully updated.");
                }
                else
                {
                    Console.WriteLine("Cancelled the update process, can't start the server.");
                    return;
                }
            }

            this.repositoryManager.RegisterRepositories();
            Log.Info("Start initializing sub-components");
            var loginServer = new LoginServer();
            var chatServer  = new ChatServerListener(55980);

            this.servers.Add(chatServer);
            var guildServer   = new GuildServer(this.gameServers, this.repositoryManager);
            var friendServer  = new FriendServer(this.gameServers, chatServer, this.repositoryManager);
            var connectServer = ConnectServerFactory.CreateConnectServer();

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

            stopwatch.Start();
            foreach (var gameServerDefinition in this.GetGameServers())
            {
                using (ThreadContext.Stacks["gameserver"].Push(gameServerDefinition.ServerID.ToString()))
                {
                    var gameServer = new GameServer(gameServerDefinition, guildServer, loginServer, this.repositoryManager, friendServer);
                    foreach (var mainPacketHandler in gameServer.Context.PacketHandlers)
                    {
                        gameServer.AddListener(new DefaultTcpGameServerListener(gameServerDefinition.NetworkPort, gameServer.ServerInfo, gameServer.Context, connectServer, mainPacketHandler));
                        //// At the moment only one main packet handler should be used;
                        //// A TCP port can only be used for one TCP listener, so we have to introduce something to pair ports with main packets handlers.
                        break;
                    }

                    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.repositoryManager);
            Log.Info("Admin panel initialized");

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

                connectServer.Start();
            }
        }