/// <summary> /// The main entry point for the application. /// </summary> /// <param name="args">The arguments. </param> internal static void Main(string[] args) { BasicConfigurator.Configure(); XmlConfigurator.ConfigureAndWatch(new FileInfo(Log4NetConfigFilePath)); var settings = new Settings("ChatServer.cfg"); int chatServerListenerPort = settings.ChatServerListenerPort ?? 55980; int exDbPort = settings.ExDbPort ?? 55906; string exDbHost = settings.ExDbHost ?? "127.0.0.1"; byte[] customXor32Key = settings.Xor32Key; try { var chatServer = new ChatServerListener(chatServerListenerPort, null); chatServer.Xor32Key = customXor32Key ?? chatServer.Xor32Key; chatServer.Start(); var exDbClient = new ExDbClient(exDbHost, exDbPort, chatServer, chatServerListenerPort); Log.Info("ChatServer started and ready"); while (Console.ReadLine() != "exit") { // keep application running } exDbClient.Disconnect(); chatServer.Shutdown(); } catch (Exception ex) { Log.Fatal("Unexpected error occured", ex); } }
/// <summary> /// The main entry point for the application. /// </summary> /// <param name="args">The arguments. </param> internal static void Main(string[] args) { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.ConfigureAndWatch(logRepository, new FileInfo(Log4NetConfigFilePath)); var addressResolver = args.Contains("-local") ? (IIpAddressResolver) new LocalIpResolver() : new PublicIpResolver(); var settings = new Settings("ChatServer.cfg"); int chatServerListenerPort = settings.ChatServerListenerPort ?? 55980; int exDbPort = settings.ExDbPort ?? 55906; string exDbHost = settings.ExDbHost ?? "127.0.0.1"; byte[] customXor32Key = settings.Xor32Key; try { var chatServer = new ChatServerListener(chatServerListenerPort, null, addressResolver); chatServer.Xor32Key = customXor32Key ?? chatServer.Xor32Key; chatServer.Start(); var exDbClient = new ExDbClient(exDbHost, exDbPort, chatServer, chatServerListenerPort); Log.Info("ChatServer started and ready"); while (Console.ReadLine() != "exit") { // keep application running } exDbClient.Disconnect(); chatServer.Shutdown(); } catch (Exception ex) { Log.Fatal("Unexpected error occured", ex); } }
/// <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(); } }
/// <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> /// 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(); } }