private static IConfiguration CreateConfig(bool keepHealthChecksValue) { return(ConfigGenerator.GetConfigWithASingleValue( "PluginsConfiguration:ApachePlugin:IncludeGatewayChecks", keepHealthChecksValue.ToString())); }
public override async Task <int> Main() { this.Location = Path.GetFullPath(this.Location); Console.WriteLine("This utility will walk you through setting up a new FiveM server with NFive installed."); Console.WriteLine(); Console.WriteLine($"The server will be installed at {this.Location}"); Console.WriteLine(); Console.WriteLine("Press ", "Ctrl+C".Yellow(), " at any time to quit."); Console.WriteLine(); if (this.FiveM.HasValue && this.FiveM.Value || !this.FiveM.HasValue && Input.Bool("Install FiveM server?", true)) { if (!this.FiveM.HasValue) { Console.WriteLine(); } Console.WriteLine("FiveM server configuration..."); var config = new ConfigGenerator { Hostname = string.IsNullOrWhiteSpace(this.ServerName) ? Input.String("server name", "NFive") : this.ServerName, MaxPlayers = this.MaxPlayers ?? Convert.ToUInt16(Input.Int("server max players", 1, 128, 32)), Locale = string.IsNullOrWhiteSpace(this.Locale) ? Input.String("server locale", "en-US", s => { if (Regex.IsMatch(s, @"[a-z]{2}-[A-Z]{2}")) { return(true); } Console.Write("Please enter a valid locale (xx-XX format): "); return(false); }) : this.Locale, OneSync = this.OneSync ?? Input.Bool("enable OneSync", true), Tags = (string.IsNullOrWhiteSpace(this.Tags) ? Input.String("server tags (separate with space)", "NFive") : this.Tags).Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(), LicenseKey = string.IsNullOrWhiteSpace(this.LicenseKey) ? Input.String("server license key (https://keymaster.fivem.net/)", s => { if (Regex.IsMatch(s, @"[\d\w]{32}")) { return(true); } Console.Write("Please enter a valid license key: "); return(false); }).ToLowerInvariant() : this.LicenseKey, SteamKey = string.IsNullOrWhiteSpace(this.SteamKey) ? Regex.Replace(Input.String("Steam API license key (https://steamcommunity.com/dev/apikey)", "<disabled>", s => { if (s == "<disabled>") { return(true); } if (s == "none") { return(true); } if (Regex.IsMatch(s, @"[0-9a-fA-F]{32}")) { return(true); } Console.Write("Please enter a valid Steam API license key: "); return(false); }), "^<disabled>$", "none") : this.SteamKey, RconPassword = string.IsNullOrWhiteSpace(this.RconPassword) ? Regex.Replace(Input.Password("RCON password", "<disabled>"), "^<disabled>$", string.Empty) : this.RconPassword }; Directory.CreateDirectory(RuntimeEnvironment.IsWindows ? this.Location : Path.Combine(this.Location, "alpine", "opt", "cfx-server")); config.Serialize(Path.Combine(this.Location, RuntimeEnvironment.IsWindows ? PathManager.ConfigFile : Path.Combine("alpine", "opt", "cfx-server", PathManager.ConfigFile))); if (!this.FiveM.HasValue) { Console.WriteLine(); } await InstallFiveM(this.Location, this.FiveMSource); if (!RuntimeEnvironment.IsWindows) { this.Location = Path.Combine(this.Location, "alpine", "opt", "cfx-server"); } this.Location = Path.Combine(this.Location, "resources", "nfive"); } if (this.NFive.HasValue && this.NFive.Value || !this.NFive.HasValue && Input.Bool("Install NFive?", true)) { if (!this.FiveM.HasValue) { Console.WriteLine(); } Console.WriteLine("NFive database configuration..."); var dbHost = string.IsNullOrWhiteSpace(this.DatabaseHost) ? Input.String("database host", "localhost") : this.DatabaseHost; var dbPort = this.DatabasePort ?? Input.Int("database port", 1, ushort.MaxValue, 3306); var dbUser = string.IsNullOrWhiteSpace(this.DatabaseUser) ? Input.String("database user", "root") : this.DatabaseUser; var dbPass = string.IsNullOrWhiteSpace(this.DatabasePassword) ? Regex.Replace(Input.Password("database password", "<blank>"), "^<blank>$", string.Empty) : this.DatabasePassword; var dbName = string.IsNullOrWhiteSpace(this.DatabaseName) ? Input.String("database name", "fivem", s => { if (Regex.IsMatch(s, "^[^\\/?%*:|\"<>.]{1,64}$")) { return(true); } Console.Write("Please enter a valid database name: "); return(false); }) : this.DatabaseName; if (!this.FiveM.HasValue) { Console.WriteLine(); } await InstallNFive(this.Location); File.WriteAllText(Path.Combine(this.Location, ConfigurationManager.DefinitionFile), Yaml.Serialize(new { Name = "local/nfive-install", Version = new Version { Major = 1, Minor = 0, Patch = 0 } })); var dbYml = File.ReadAllText(Path.Combine(this.Location, "config", "database.yml")); // TODO: Handle as YAML? dbYml = Regex.Replace(dbYml, "(\\s*host\\: ).+", $"${{1}}{dbHost}"); dbYml = Regex.Replace(dbYml, "(\\s*port\\: ).+", $"${{1}}{dbPort}"); dbYml = Regex.Replace(dbYml, "(\\s*database\\: ).+", $"${{1}}{dbName}"); dbYml = Regex.Replace(dbYml, "(\\s*user\\: ).+", $"${{1}}{dbUser}"); dbYml = Regex.Replace(dbYml, "(\\s*password\\: ).+", $"${{1}}{dbPass}"); File.WriteAllText(Path.Combine(this.Location, "config", "database.yml"), dbYml); // TODO: Ask to include stock plugins? } Console.WriteLine("Installation is complete, you can now start the server with `nfpm start`!"); return(0); }
public void AddConfig(ConfigGenerator config) { Apns.Add(config); Save(); }