* 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>
28 lines
911 B
C#
28 lines
911 B
C#
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace MareSynchronosShared;
|
|
|
|
public static class Extensions
|
|
{
|
|
public static string GetIpAddress(this IHttpContextAccessor accessor)
|
|
{
|
|
if (!string.IsNullOrEmpty(accessor.HttpContext.Request.Headers["CF-CONNECTING-IP"]))
|
|
return accessor.HttpContext.Request.Headers["CF-CONNECTING-IP"];
|
|
|
|
if (!string.IsNullOrEmpty(accessor.HttpContext.Request.Headers["X-Forwarded-For"]))
|
|
{
|
|
return accessor.HttpContext.Request.Headers["X-Forwarded-For"];
|
|
}
|
|
|
|
var ipAddress = accessor.HttpContext.GetServerVariable("HTTP_X_FORWARDED_FOR");
|
|
|
|
if (!string.IsNullOrEmpty(ipAddress))
|
|
{
|
|
var addresses = ipAddress.Split(',');
|
|
if (addresses.Length != 0)
|
|
return addresses.Last();
|
|
}
|
|
|
|
return accessor.HttpContext.Connection.RemoteIpAddress.ToString();
|
|
}
|
|
} |