rework server responsibilities (#18)

* rework server responsibilities
add remote configuration

* start metrics only when compiled as not debug

* add some more logging to discord bot

* fixes of some casts

* make metrics port configurable, minor fixes

* add docker bullshit

* md formatting

* adjustments to docker stuff

* fix docker json files, fix some stuff in discord bot, add /useradd for Discord bot

* adjust docker configs and fix sharded.bat

* fixes for logs, cache file provider repeat trying to open filestream

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
rootdarkarchon
2022-12-27 13:48:05 +01:00
committed by GitHub
parent 7ee7fdaf48
commit 9eb5967935
101 changed files with 2470 additions and 585 deletions

View File

@@ -1,32 +1,46 @@
using System.Text;
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Text.Json;
namespace MareSynchronosShared.Utils;
public class MareConfigurationBase
public class MareConfigurationBase : IMareConfiguration
{
public int DbContextPoolSize { get; set; } = 100;
public string ShardName { get; set; } = string.Empty;
public int MetricsPort { get; set; } = 4981;
public T GetValue<T>(string key)
{
var prop = GetType().GetProperty(key);
if (prop == null) throw new KeyNotFoundException(key);
if (prop.PropertyType != typeof(T)) throw new ArgumentException($"Requested {key} with T:{typeof(T)}, where {key} is {prop.PropertyType}");
return (T)prop.GetValue(this);
}
public T GetValueOrDefault<T>(string key, T defaultValue)
{
var prop = GetType().GetProperty(key);
if (prop.PropertyType != typeof(T)) throw new ArgumentException($"Requested {key} with T:{typeof(T)}, where {key} is {prop.PropertyType}");
if (prop == null) return defaultValue;
return (T)prop.GetValue(this);
}
public string SerializeValue(string key, string defaultValue)
{
var prop = GetType().GetProperty(key);
if (prop == null) return defaultValue;
if (prop.GetCustomAttribute<RemoteConfigurationAttribute>() == null) return defaultValue;
return JsonSerializer.Serialize(prop.GetValue(this), prop.PropertyType);
}
public override string ToString()
{
StringBuilder sb = new();
sb.AppendLine(base.ToString());
sb.AppendLine($"{nameof(ShardName)} => {ShardName}");
sb.AppendLine($"{nameof(DbContextPoolSize)} => {DbContextPoolSize}");
return sb.ToString();
}
}
public class MareConfigurationAuthBase : MareConfigurationBase
{
public int DbContextPoolSize { get; set; } = 100;
public int FailedAuthForTempBan { get; set; } = 5;
public int TempBanDurationInMinutes { get; set; } = 5;
public List<string> WhitelistedIps { get; set; } = new();
public override string ToString()
{
StringBuilder sb = new();
sb.AppendLine($"{nameof(FailedAuthForTempBan)} => {FailedAuthForTempBan}");
sb.AppendLine($"{nameof(TempBanDurationInMinutes)} => {TempBanDurationInMinutes}");
sb.AppendLine($"{nameof(WhitelistedIps)} => {string.Join(", ", WhitelistedIps)}");
return sb.ToString();
}
}