fix: Updates first load configuration (#680)
<img width="814" alt="Screen Shot 2021-08-08 at 11 33 24 PM" src="https://user-images.githubusercontent.com/3953314/128667907-be43bf24-df7b-481b-ab0a-8b9094f01188.png">
This commit is contained in:
parent
b0f8fe0350
commit
f795ab4698
2 changed files with 91 additions and 51 deletions
|
|
@ -27,8 +27,8 @@ namespace Server
|
|||
{
|
||||
private static readonly ILogger logger = LogFactory.GetLogger(typeof(ServerConfiguration));
|
||||
|
||||
private const string m_RelPath = "Configuration/modernuo.json";
|
||||
private static readonly string m_FilePath = Path.Join(Core.BaseDirectory, m_RelPath);
|
||||
private const string _relPath = "Configuration/modernuo.json";
|
||||
private static readonly string m_FilePath = Path.Join(Core.BaseDirectory, _relPath);
|
||||
private static ServerSettings m_Settings;
|
||||
private static bool m_Mocked;
|
||||
|
||||
|
|
@ -181,16 +181,16 @@ namespace Server
|
|||
|
||||
if (File.Exists(m_FilePath))
|
||||
{
|
||||
logger.Information($"Reading server configuration from {m_RelPath}...");
|
||||
logger.Information($"Reading server configuration from {_relPath}...");
|
||||
m_Settings = JsonConfig.Deserialize<ServerSettings>(m_FilePath);
|
||||
|
||||
if (m_Settings == null)
|
||||
{
|
||||
logger.Error($"Reading server configuration failed");
|
||||
logger.Error("Reading server configuration failed");
|
||||
throw new FileNotFoundException($"Failed to deserialize {m_FilePath}.");
|
||||
}
|
||||
|
||||
logger.Information($"Reading server configuration done");
|
||||
logger.Information("Reading server configuration done");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -236,7 +236,10 @@ namespace Server
|
|||
if (updated)
|
||||
{
|
||||
Save();
|
||||
logger.Information($"Server configuration saved to {m_RelPath}.");
|
||||
Console.Write("Server configuration saved to ");
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.WriteLine($"{_relPath}.");
|
||||
Utility.PopColor();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -250,6 +253,9 @@ namespace Server
|
|||
var input = Console.ReadLine();
|
||||
if (string.IsNullOrWhiteSpace(input) || input.InsensitiveStartsWith("n"))
|
||||
{
|
||||
Utility.PushColor(ConsoleColor.Yellow);
|
||||
Console.WriteLine("New Haven chosen with no map diffs.");
|
||||
Utility.PopColor();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -257,10 +263,18 @@ namespace Server
|
|||
{
|
||||
SetSetting("maps.enablePre6000Trammel", true.ToString());
|
||||
SetSetting("maps.enableMapDiffPatches", true.ToString());
|
||||
|
||||
Utility.PushColor(ConsoleColor.Yellow);
|
||||
Console.WriteLine("Old Haven chosen with map diffs.");
|
||||
Utility.PopColor();
|
||||
return;
|
||||
}
|
||||
|
||||
logger.Information($"Invalid option. ({input})");
|
||||
Console.Write("Invalid option ");
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.Write(input);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(". Press y for yes or n for no.");
|
||||
} while (true);
|
||||
}
|
||||
|
||||
|
|
@ -280,25 +294,34 @@ namespace Server
|
|||
|
||||
do
|
||||
{
|
||||
Console.Write("[{0}]> ", maxExpansionName);
|
||||
Console.Write("[enter for {0}]> ", maxExpansionName);
|
||||
var input = Console.ReadLine();
|
||||
Expansion expansion;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
return maxExpansion;
|
||||
expansion = maxExpansion;
|
||||
}
|
||||
|
||||
if (int.TryParse(input, NumberStyles.Integer, null, out var number) && number >= 0 &&
|
||||
number < expansions.Length)
|
||||
else if (int.TryParse(input, NumberStyles.Integer, null, out var number) &&
|
||||
number >= 0 && number < expansions.Length)
|
||||
{
|
||||
return (Expansion)number;
|
||||
expansion = (Expansion)number;
|
||||
}
|
||||
|
||||
if (Enum.TryParse<Expansion>(input, out var expansion))
|
||||
else if (!Enum.TryParse(input, out expansion))
|
||||
{
|
||||
return expansion;
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.Write(input);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(" is an invalid expansion option.");
|
||||
continue;
|
||||
}
|
||||
|
||||
logger.Information($"Invalid expansion. ({input})");
|
||||
Console.Write("Expansion set to ");
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.Write(ExpansionInfo.GetInfo(expansion).Name);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(".");
|
||||
return expansion;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
|
|
@ -310,7 +333,7 @@ namespace Server
|
|||
|
||||
do
|
||||
{
|
||||
Console.Write("{0}> ", directories.Count > 0 ? "[finish] " : " ");
|
||||
Console.Write("{0}> ", directories.Count > 0 ? "[enter to finish]" : " ");
|
||||
var directory = Console.ReadLine();
|
||||
if (string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
|
|
@ -320,11 +343,18 @@ namespace Server
|
|||
if (Directory.Exists(directory))
|
||||
{
|
||||
directories.Add(directory);
|
||||
logger.Information($"Path {directory} added.");
|
||||
Console.Write("Added ");
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.Write(directory);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Information($"Path does not exist. ({directory})");
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.Write(directory);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(" does not exist.");
|
||||
}
|
||||
} while (true);
|
||||
|
||||
|
|
@ -342,33 +372,43 @@ namespace Server
|
|||
do
|
||||
{
|
||||
// IP:Port?
|
||||
Console.Write("[{0}]> ", ips.Count > 0 ? "finish" : "0.0.0.0:2593");
|
||||
Console.Write("[{0}]> ", ips.Count > 0 ? "enter to finish" : "0.0.0.0:2593");
|
||||
var ipStr = Console.ReadLine();
|
||||
|
||||
IPEndPoint ip;
|
||||
if (string.IsNullOrWhiteSpace(ipStr))
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (ips.Count > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ipStr.ContainsOrdinal(':'))
|
||||
{
|
||||
ipStr += ":2593";
|
||||
}
|
||||
|
||||
if (IPEndPoint.TryParse(ipStr, out var ip))
|
||||
{
|
||||
ips.Add(ip);
|
||||
logger.Information($"Core: {ipStr} added.");
|
||||
ip = new IPEndPoint(IPAddress.Any, 2593);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Information($"{ipStr} is not a valid IP or port");
|
||||
}
|
||||
} while (true);
|
||||
if (!ipStr.ContainsOrdinal(':'))
|
||||
{
|
||||
ipStr += ":2593";
|
||||
}
|
||||
|
||||
if (ips.Count == 0)
|
||||
{
|
||||
ips.Add(new IPEndPoint(IPAddress.Any, 2593));
|
||||
}
|
||||
if (!IPEndPoint.TryParse(ipStr, out ip))
|
||||
{
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.Write(ipStr);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(" is not a valid IP or port.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ips.Add(ip);
|
||||
Console.Write("Added ");
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.Write(ip);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(".");
|
||||
} while (true);
|
||||
|
||||
return ips;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ namespace Server
|
|||
|
||||
if (Assembly == null)
|
||||
{
|
||||
throw new Exception("Core: Assembly entry is missing.");
|
||||
throw new Exception("Assembly entry is missing.");
|
||||
}
|
||||
|
||||
if (Thread != null)
|
||||
|
|
@ -417,6 +417,17 @@ namespace Server
|
|||
".TrimMultiline());
|
||||
Utility.PopColor();
|
||||
|
||||
ProcessorCount = Environment.ProcessorCount;
|
||||
|
||||
if (ProcessorCount > 1)
|
||||
{
|
||||
MultiProcessor = true;
|
||||
}
|
||||
|
||||
Console.CancelKeyPress += Console_CancelKeyPressed;
|
||||
|
||||
ServerConfiguration.Load();
|
||||
|
||||
logger.Information($"Running on {RuntimeInformation.FrameworkDescription}");
|
||||
|
||||
var s = Arguments;
|
||||
|
|
@ -426,20 +437,11 @@ namespace Server
|
|||
logger.Information($"Running with arguments: {s}");
|
||||
}
|
||||
|
||||
ProcessorCount = Environment.ProcessorCount;
|
||||
|
||||
if (ProcessorCount > 1)
|
||||
{
|
||||
MultiProcessor = true;
|
||||
}
|
||||
|
||||
if (MultiProcessor)
|
||||
{
|
||||
logger.Information($"Optimizing for {ProcessorCount} processor{(ProcessorCount == 1 ? "" : "s")}");
|
||||
}
|
||||
|
||||
Console.CancelKeyPress += Console_CancelKeyPressed;
|
||||
|
||||
if (GCSettings.IsServerGC)
|
||||
{
|
||||
logger.Information("Server garbage collection mode enabled");
|
||||
|
|
@ -447,8 +449,6 @@ namespace Server
|
|||
|
||||
logger.Information($"High resolution timing ({(Stopwatch.IsHighResolution ? "Supported" : "Unsupported")})");
|
||||
|
||||
ServerConfiguration.Load();
|
||||
|
||||
var assemblyPath = Path.Join(BaseDirectory, AssembliesConfiguration);
|
||||
|
||||
// Load UOContent.dll
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue