1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-10-30 05:42:47 +01:00
Minecraft-Phantom-Panel/Server/Phantom.Server/Variables.cs

42 lines
1.2 KiB
C#

using Npgsql;
using Phantom.Common.Logging;
using Phantom.Utils.Runtime;
namespace Phantom.Server;
sealed record Variables(
string WebServerHost,
ushort WebServerPort,
string RpcServerHost,
ushort RpcServerPort,
string SqlConnectionString
) {
private static Variables LoadOrThrow() {
var connectionStringBuilder = new NpgsqlConnectionStringBuilder {
Host = EnvironmentVariables.GetString("PG_HOST").OrThrow,
Port = EnvironmentVariables.GetPortNumber("PG_PORT").OrThrow,
Username = EnvironmentVariables.GetString("PG_USER").OrThrow,
Password = EnvironmentVariables.GetString("PG_PASS").OrThrow,
Database = EnvironmentVariables.GetString("PG_DATABASE").OrThrow
};
return new Variables(
EnvironmentVariables.GetString("WEB_SERVER_HOST").OrDefault("0.0.0.0"),
EnvironmentVariables.GetPortNumber("WEB_SERVER_PORT").OrDefault(9400),
EnvironmentVariables.GetString("RPC_SERVER_HOST").OrDefault("0.0.0.0"),
EnvironmentVariables.GetPortNumber("RPC_SERVER_PORT").OrDefault(9401),
connectionStringBuilder.ToString()
);
}
public static Variables LoadOrExit() {
try {
return LoadOrThrow();
} catch (Exception e) {
PhantomLogger.Root.Fatal(e.Message);
Environment.Exit(1);
throw;
}
}
}