public void Run() { if (_running) { throw new Exception("Server is already running."); } _running = true; CliUtil.WriteHeader("Msgr Server", ConsoleColor.DarkCyan); CliUtil.LoadingTitle(); this.NavigateToRoot(); // Conf this.LoadConf(this.Conf = new MsgrConf()); // Database this.InitDatabase(this.Database = new MsgrDb(), this.Conf); // Start this.Server.Start(this.Conf.Msgr.Port); CliUtil.RunningTitle(); var cmd = new ConsoleCommands(); cmd.Wait(); }
/// <summary> /// Sets up default controllers and starts web server /// </summary> public void StartWebServer() { Log.Info("Starting web server..."); this.App = new WebApplication(); this.App.Engine("htm", new HandlebarsEngine()); this.App.Get("/favicon.ico", new StaticController(this.Conf.Web.Favicon)); this.App.Static("user/save/"); this.App.Static("user/resources/"); this.App.Static("system/web/public/"); this.App.Static("user/web/public/"); this.App.Get("/", new MainController()); this.App.Post("/ui", new UiStorageController()); this.App.Post("/visual-chat", new VisualChatController()); this.App.Post("/avatar-upload", new AvatarUploadController()); try { this.App.Listen(this.Conf.Web.Port); Log.Status("Server ready, listening on 0.0.0.0:{0}.", this.Conf.Web.Port); } catch (NHttp.NHttpException) { Log.Error("Failed to start web server."); Log.Info("Port {0} might already be in use, make sure no other application, like other web servers or Skype, are using it or set a different port in web.conf.", this.Conf.Web.Port); CliUtil.Exit(1); } }
/// <summary> /// Starts the server. /// </summary> public override void Run() { base.Run(); CliUtil.WriteHeader("Web", ConsoleColor.DarkRed); CliUtil.LoadingTitle(); // Conf this.LoadConf(this.Conf = new Conf()); // Database this.InitDatabase(this.Database = new MeliaDb(), this.Conf); // Data this.LoadData(DataToLoad.Servers, true); // Web server this.StartWebServer(); CliUtil.RunningTitle(); // Commands this.ConsoleCommands = new ConsoleCommands(); this.ConsoleCommands.Wait(); }
/// <summary> /// Starts web server for API /// </summary> private void LoadWebApi() { Log.Info("Loading Web API..."); // Trick compiler into referencing Mabi.dll, so Swebs references // it in the C# scripts as well. var x = Mabi.Const.GuildMemberRank.Applied; var conf = new Configuration(); conf.Port = this.Conf.Login.WebPort; conf.SourcePaths.Add("user/api/"); conf.SourcePaths.Add("system/api/"); this.HttpServer = new HttpServer(conf); this.HttpServer.UnhandledException += (s, e) => Log.Exception(e.Exception); try { this.HttpServer.Start(); Log.Info("Web API listening on 0.0.0.0:{0}.", this.Conf.Login.WebPort); } catch (NHttpException) { Log.Error("Failed to start web server."); Log.Info("Port {0} might already be in use, make sure no other application, like other web servers or Skype, are using it or set a different port in web.conf.", this.Conf.Login.WebPort); CliUtil.Exit(1); } }
/// <summary> /// Sets up default controllers and starts web server /// </summary> public void StartWebServer() { Log.Info("Starting web server..."); this.App = new WebApplication(); this.App.Engine("htm", new HandlebarsEngine()); this.App.Get("/toslive/patch/serverlist.xml", new ServerListController()); this.App.Get("/toslive/patch/static__Config.txt", new StaticConfigController()); try { int port; Int32.TryParse(Settings.Default.WebPort, out port); this.App.Listen(port); Log.Info("ServerListURL: http://*:{0}/{1}", Settings.Default.WebPort, "toslive/patch/serverlist.xml"); Log.Info("StaticConfigURL: http://*:{0}/{1}", Settings.Default.WebPort, "toslive/patch/"); Log.Status("Server ready, listening on 0.0.0.0:{0}.", Settings.Default.WebPort); } catch (NHttp.NHttpException) { Log.Error("Failed to start web server."); Log.Info("The port might already be in use, make sure no other application, like other web servers or Skype, are using it, or set a different port in web.conf."); CliUtil.Exit(1); } }
/// <summary> /// Handler for unhandled exceptions. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { try { Log.Error("Oh no! Ferghus escaped his memory block and infected the rest of the server!"); Log.Error("Aura has encountered an unexpected and unrecoverable error. We're going to try to save as much as we can."); } catch { } try { this.Server.Stop(); } catch { } try { // save the world } catch { } try { Log.Exception((Exception)e.ExceptionObject); Log.Status("Closing server."); } catch { } CliUtil.Exit(1, false); }
/// <summary> /// Loads all necessary components and starts the server. /// </summary> public void Run() { if (_running) { throw new Exception("Server is already running."); } CliUtil.WriteHeader("Web Server", ConsoleColor.DarkRed); CliUtil.LoadingTitle(); this.NavigateToRoot(); // Conf this.LoadConf(this.Conf = new WebConf()); // Database this.InitDatabase(this.Database = new AuraDb(), this.Conf); // Localization this.LoadLocalization(this.Conf); // Server this.StartWebServer(); // Scripts (after web server) this.LoadScripts(); CliUtil.RunningTitle(); _running = true; // Commands var commands = new ConsoleCommands(); commands.Wait(); }
/// <summary> /// Executes SQL update file. /// </summary> /// <param name="updateFile"></param> public void RunUpdate(string updateFile) { try { using (var conn = this.GetConnection()) { // Run update using (var cmd = new MySqlCommand(File.ReadAllText(Path.Combine("sql", updateFile)), conn)) cmd.ExecuteNonQuery(); // Log update using (var cmd = new InsertCommand("INSERT INTO `updates` {0}", conn)) { cmd.Set("path", updateFile); cmd.Execute(); } Log.Info("Successfully applied '{0}'.", updateFile); } } catch (Exception ex) { Log.Error("RunUpdate: Failed to run '{0}': {1}", updateFile, ex.Message); CliUtil.Exit(1); } }
/// <summary> /// Loads data from files. /// </summary> protected void LoadData(DataToLoad toLoad, bool reload) { Log.Info("Loading data..."); try { if ((toLoad & DataToLoad.Items) != 0) { this.LoadDb(this.Data.ItemDb, "db/items.txt", reload); } if ((toLoad & DataToLoad.Jobs) != 0) { this.LoadDb(this.Data.JobDb, "db/jobs.txt", reload); } if ((toLoad & DataToLoad.Maps) != 0) { this.LoadDb(this.Data.MapDb, "db/maps.txt", reload); } if ((toLoad & DataToLoad.Monsters) != 0) { this.LoadDb(this.Data.MonsterDb, "db/monsters.txt", reload); } if ((toLoad & DataToLoad.Servers) != 0) { this.LoadDb(this.Data.ServerDb, "db/servers.txt", reload); } if ((toLoad & DataToLoad.Barracks) != 0) { this.LoadDb(this.Data.BarrackDb, "db/barracks.txt", reload); } if ((toLoad & DataToLoad.Skills) != 0) { this.LoadDb(this.Data.SkillDb, "db/skills.txt", reload); } } catch (DatabaseErrorException ex) { Log.Error(ex.ToString()); CliUtil.Exit(1); } catch (FileNotFoundException ex) { Log.Error(ex.Message); CliUtil.Exit(1); } catch (Exception ex) { Log.Exception(ex, "Error while loading data."); CliUtil.Exit(1); } }
/// <summary> /// Loads all necessary components and starts the server. /// </summary> public void Run() { if (_running) { throw new Exception("Server is already running."); } CliUtil.WriteHeader("Channel Server", ConsoleColor.DarkGreen); CliUtil.LoadingTitle(); this.NavigateToRoot(); // Conf this.LoadConf(this.Conf = new ChannelConf()); // Database this.InitDatabase(this.Database = new ChannelDb(), this.Conf); // Data this.LoadData(DataLoad.ChannelServer, false); // Localization this.LoadLocalization(this.Conf); // World this.InitializeWorld(); // Skills this.LoadSkills(); // Scripts this.LoadScripts(); // Weather this.Weather.Initialize(); // Autoban if (this.Conf.Autoban.Enabled) { this.Events.SecurityViolation += (e) => Autoban.Incident(e.Client, e.Level, e.Report, e.StackReport); } // Start this.Server.Start(this.Conf.Channel.ChannelPort); // Inter this.ConnectToLogin(true); this.StartStatusUpdateTimer(); CliUtil.WriteHeader("Channel Server [" + this.Conf.Channel.ChannelName + "]", ConsoleColor.DarkGreen); CliUtil.RunningTitle(); _running = true; // Commands this.ConsoleCommands.Wait(); }
/// <summary> /// Executes SQL update file. /// </summary> /// <param name="updateFile"></param> public void RunUpdate(string updateFile) { string[] result = Regex.Split(File.ReadAllText(Path.Combine("sql", updateFile)), @"([^\\];)"); try { using (var connection = MySQL.CreateConnection()) { //stop autocommit using (var cmd = connection.CreateCommand()) { cmd.CommandText = "SET AUTOCOMMIT = 0"; cmd.ExecuteNonQuery(); } //Run update using (var cmd = new MySqlCommand(File.ReadAllText(Path.Combine("sql", updateFile)), connection)) { //_log.Info("GameServer need to connect only after loading all SQL! We are waiting for a long download of large SQL files!"); cmd.CommandTimeout = 120; //3600; //ждем долгой загрузки больших SQL файлов. Обычно, это значение - десятки секунд. cmd.ExecuteNonQuery(); } // Log update using (var cmd = new InsertCommand("INSERT INTO `updates` {0}", connection)) { cmd.Set("path", updateFile); cmd.Execute(); } // recovery autocommit using (var cmd = connection.CreateCommand()) { cmd.CommandText = "SET AUTOCOMMIT = 1"; cmd.ExecuteNonQuery(); } _log.Info("Successfully applied '{0}'.", updateFile); } } catch (Exception ex) { using (var connection = MySQL.CreateConnection()) { MySqlTransaction transaction = connection.BeginTransaction(); // recovery autocommit using (var cmd = connection.CreateCommand()) { cmd.CommandText = "SET AUTOCOMMIT = 1"; cmd.ExecuteNonQuery(); } } _log.Error("RunUpdate: Failed to run '{0}': {1}", updateFile, ex.Message); CliUtil.Exit(1); } }
/// <summary> /// Starts the server. /// </summary> public override void Run() { base.Run(); CliUtil.WriteHeader("Channel", ConsoleColor.DarkGreen); CliUtil.LoadingTitle(); // Conf this.LoadConf(); // Database this.Database = new ChannelDb(); this.InitDatabase(this.Database); // Data this.LoadData(DataToLoad.All, true); // GM Commands this.GmCommands = new GmCommands(); // Packet handlers ChannelPacketHandler.Instance.RegisterMethods(); // World Log.Info("Initializing world..."); this.World.Initialize(); Log.Info(" done loading {0} maps.", this.World.Count); // Script manager this.ScriptManager.Initialize(); this.ScriptManager.Load(); // Get channel data var serverId = 1; var serverData = this.Data.ServerDb.FindChannel(serverId); if (serverData == null) { Log.Error("Server data not found. ({0})", serverId); CliUtil.Exit(1); } // Server this.ConnectionManager = new ConnectionManager <ChannelConnection>(serverData.Port); this.ConnectionManager.Start(); // Ready CliUtil.RunningTitle(); Log.Status("Server ready, listening on {0}.", this.ConnectionManager.Address); // Commands this.ConsoleCommands = new ConsoleCommands(); this.ConsoleCommands.Wait(); }
static void Main(string[] args) { try { LoginServer.Instance.Run(); } catch (Exception ex) { Log.Error("Error on startup: {0}", ex); CliUtil.Exit(1, true); } }
static void Main(string[] args) { try { LoginServer.Instance.Run(); } catch (Exception ex) { Log.Error("Error on startup: {0}, {1}", ex.GetType().Name, ex.Message); CliUtil.Exit(1, true); } }
static void Main(string[] args) { try { ChannelServer.Instance.Run(); } catch (Exception ex) { Log.Error("Error on startup: {0}, {1}\r\n{2}\r\n{3}", ex.GetType().Name, ex.Message, ex.TargetSite, ex.StackTrace); CliUtil.Exit(1, true); } }
static void Main(string[] args) { try { GateServer.Instance.Run(); } catch (Exception ex) { Log.Exception(ex, "An exception occured while starting the server."); CliUtil.Exit(1); } }
private void ShutdownTimerDone(object timer) { ((Timer)timer).Dispose(); // Kill clients this.KillConnectedClients(); // Save global variables this.Database.SaveVars("Aura System", 0, this.ScriptManager.GlobalVars.Perm); CliUtil.Exit(0, false); }
/// <summary> /// Initializes ASD database connection with data from Conf. /// </summary> /// <param name="db"></param> /// <param name="conf"></param> protected void InitDatabase(Base db, Conf conf) { try { db.Init(conf.ASDDbHost, conf.ASDDbUserName, conf.ASDDbPassword, conf.ASDDbName); Log.Info("Initialized " + db.GetDbName() + " database connection"); } catch (Exception ex) { Log.Error("Failed to initialize " + db.GetDbName() + " database: {0}", ex.Message); CliUtil.Exit(1, true); } }
/// <summary> /// Initializes database connection with data from Conf. /// </summary> protected void InitDatabase(MeliaDb db, Conf conf) { try { Log.Info("Initializing database..."); db.Init(conf.Database.Host, conf.Database.User, conf.Database.Pass, conf.Database.Db); } catch (Exception ex) { Log.Error("Failed to initialize database: {0}", ex.Message); CliUtil.Exit(1, true); } }
/// <summary> /// Loads given conf class and stops start up when an error /// occurs. /// </summary> /// <param name="conf"></param> protected void LoadConf(Conf conf) { try { Log.Info("Loading configuration..."); conf.LoadAll(); } catch (Exception ex) { Log.Error("Failed to load configuration: {0}", ex.Message); CliUtil.Exit(1, true); } }
public static async Task Main(string[] args) { CliUtil.WriteHeader("Game & Stream", ConsoleColor.DarkGreen); CliUtil.LoadingTitle(); Initialization(); if (FileManager.FileExists(FileManager.AppPath + "Config.json")) { Configuration(args); } else { _log.Error($"{FileManager.AppPath}Config.json doesn't exist!"); return; } _log.Info("{0} version {1}", Name, Version); var connection = MySQL.CreateConnection(); if (connection == null) { LogManager.Flush(); return; } connection.Close(); // Check if there are any updates CheckDatabaseUpdates(); var builder = new HostBuilder() .ConfigureAppConfiguration((hostingContext, config) => { config.AddEnvironmentVariables(); if (args != null) { config.AddCommandLine(args); } }) .ConfigureServices((hostContext, services) => { services.AddOptions(); services.AddSingleton <IHostedService, GameService>(); }); await builder.RunConsoleAsync(); }
/// <summary> /// 加载配置文件 /// </summary> /// <param name="conf"></param> public void LoadConf(BaseConf conf) { Log.Info("读取配置..."); try { conf.Load(); } catch (Exception ex) { Log.Exception(ex, "读取错误. ({0})", ex.Message); CliUtil.Exit(1); } }
/// <summary> /// Tries to initialize database with the information from conf, /// exits on error. /// </summary> public virtual void InitDatabase(AuraDb db, BaseConf conf) { Log.Info("Initializing database..."); try { db.Init(conf.Database.Host, conf.Database.User, conf.Database.Pass, conf.Database.Db); } catch (Exception ex) { Log.Error("Unable to open database connection. ({0})", ex.Message); CliUtil.Exit(1); } }
/// <summary> /// Tries to call conf's load method, exits on error. /// </summary> public void LoadConf(BaseConf conf) { Log.Info("Reading configuration..."); try { conf.Load(); } catch (Exception ex) { Log.Exception(ex, "Unable to read configuration. ({0})", ex.Message); CliUtil.Exit(1); } }
public void Run() { if (_running) { throw new Exception("Server is already running."); } //标题栏 CliUtil.WriteHeader("Channel Server" + DateTime.Now.ToString(), ConsoleColor.DarkGreen); CliUtil.LoadingTitle(); //配置文件 this.LoadConf(this.Conf = new ChannelConf()); //// Database //this.InitDatabase(this.Database = new ChannelDb(), this.Conf); //// Data //this.LoadData(DataLoad.ChannelServer, false); // Localization //this.LoadLocalization(this.Conf); //// World //this.InitializeWorld(); //// Skills //this.LoadSkills(); //// Scripts //this.LoadScripts(); //// Weather //this.Weather.Initialize(); //// Autoban //if (this.Conf.Autoban.Enabled) // this.Events.SecurityViolation += (e) => Autoban.Incident(e.Client, e.Level, e.Report, e.StackReport); //服务器开启 this.Server.Start(this.Conf.Channel.ChannelPort); //连接登陆服务器 this.ConnectToLogin(true); //this.StartStatusUpdateTimer(); CliUtil.RunningTitle(); _running = true; //GM操作 this.ConsoleCommands.Wait(); }
private static void RenderWorld() { RenderedChunks = 0; GL.Begin(PrimitiveType.Quads); try { //Stack<Chunk> chunks = new Stack<Chunk>(world.Chunks.Values.ToList().FindAll((ch) => true || CliUtil.ShouldRenderChunk(ch))); Stack <Chunk> chunks = new Stack <Chunk>(world.Dimensions[DataStore.Player.DimensionId].Chunks.Values); foreach (Chunk ce in chunks) { if (CliUtil.ShouldRenderChunk(ce) && ce != null && ce.Blocks != null) { foreach (Block bl in ce.Blocks.Values) { RenderCube(ce, bl); } RenderedChunks++; } } ; /*foreach (Chunk cch in chunks) * { * try * { * foreach (Block bl in cch.Blocks.Values.ToList()) * { * RenderCube(world, cch, bl); * } * RenderedChunks++; * } * catch * { * RenderErrors++; * } * }*/ } catch (Exception err) { Logger.PostLog("Exception: " + err.Message + " @ " + err.Source); } _shader.Use(); GL.End(); GL.BindVertexArray(_vertexArrayObject); GL.DrawArrays(PrimitiveType.Quads, 0, 3); }
/// <summary> /// Tries to find aura root folder and changes the working directory to it. /// Exits if not successful. /// </summary> public void NavigateToRoot() { // Go back max 2 folders, the bins should be in [aura]/bin/(Debug|Release) for (int i = 0; i < 3; ++i) { if (Directory.Exists("system")) { return; } Directory.SetCurrentDirectory(".."); } Log.Error("Unable to find root directory."); CliUtil.Exit(1); }
/// <summary> /// Starts listener. /// </summary> /// <param name="endPoint"></param> private void Start(IPEndPoint endPoint) { try { _socket.Bind(endPoint); _socket.Listen(10); _socket.BeginAccept(this.OnAccept, _socket); Log.Status("Server ready, listening on {0}.", _socket.LocalEndPoint); } catch (Exception ex) { Log.Exception(ex, "Unable to set up socket; perhaps you're already running a server?"); CliUtil.Exit(1); } }
/// <summary> /// Starts the server. /// </summary> public override void Run() { base.Run(); CliUtil.WriteHeader("Login", ConsoleColor.Magenta); CliUtil.LoadingTitle(); // Conf this.LoadConf(); // Database this.Database = new LoginDb(); this.InitDatabase(this.Database); // Check if there are any updates this.CheckDatabaseUpdates(); // Data this.LoadData(DataToLoad.Jobs | DataToLoad.Maps | DataToLoad.Barracks | DataToLoad.Servers | DataToLoad.StartingCities, true); // Packet handlers LoginPacketHandler.Instance.RegisterMethods(); // Get server data var serverId = 1; var serverData = this.Data.ServerDb.FindLogin(serverId); if (serverData == null) { Log.Error("Server data not found. ({0})", serverId); CliUtil.Exit(1); } // Server var mgr = new ConnectionManager <LoginConnection>(serverData.Port); mgr.Start(); // Ready CliUtil.RunningTitle(); Log.Status("Server ready, listening on {0}.", mgr.Address); // Commands this.ConsoleCommands = new LoginConsoleCommands(); this.ConsoleCommands.Wait(); }
/// <summary> /// Starts the server. /// </summary> public override void Run() { base.Run(); CliUtil.WriteHeader("Channel", ConsoleColor.DarkGreen); CliUtil.LoadingTitle(); // Conf this.LoadConf(); // Database this.Database = new ChannelDb(); this.InitDatabase(this.Database); SessionFactory.Init(this.Database._connectionString); // Data this.ClientData = new ClientData(); // GM Commands this.GmCommands = new GmCommands(); // Packet handlers ChannelPacketHandler.Instance.RegisterMethods(); // World Log.Info("Initializing world..."); this.World.Initialize(); Log.Info(" done loading {0} maps.", this.World.Count); // Script manager this.ScriptManager.Initialize(); this.ScriptManager.Load(); // Server this.ConnectionManager = new ConnectionManager <ChannelConnection>(Int32.Parse(Settings.Default.ZoneServerPort)); this.ConnectionManager.Start(); // Ready CliUtil.RunningTitle(); Log.Status("Server ready, listening on {0}.", this.ConnectionManager.Address); // Commands this.ConsoleCommands = new ConsoleCommands(); this.ConsoleCommands.Wait(); }