Merge branch 'main' of https://github.com/Penumbra-Sync/server
This commit is contained in:
@@ -1,220 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronosServer.Data;
|
||||
using MareSynchronosServer.Metrics;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace MareSynchronosServer.Authentication
|
||||
{
|
||||
public class FailedAuthorization : IDisposable
|
||||
{
|
||||
private int failedAttempts = 1;
|
||||
public int FailedAttempts => failedAttempts;
|
||||
public Task ResetTask { get; set; }
|
||||
public CancellationTokenSource? ResetCts { get; set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetCts?.Cancel();
|
||||
ResetCts?.Dispose();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public void IncreaseFailedAttempts()
|
||||
{
|
||||
Interlocked.Increment(ref failedAttempts);
|
||||
}
|
||||
}
|
||||
|
||||
public class SecretKeyAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
||||
{
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly MareDbContext _mareDbContext;
|
||||
private readonly IConfiguration _configuration;
|
||||
public const string AuthScheme = "SecretKeyAuth";
|
||||
private const string unauthorized = "Unauthorized";
|
||||
public static readonly Dictionary<string, string> Authentications = new();
|
||||
private static readonly Dictionary<string, FailedAuthorization> FailedAuthorizations = new();
|
||||
private static readonly object authDictLock = new();
|
||||
private static readonly object failedAuthLock = new();
|
||||
private readonly int failedAttemptsForTempBan;
|
||||
private readonly int tempBanMinutes;
|
||||
|
||||
public static void ClearUnauthorizedUsers()
|
||||
{
|
||||
lock (authDictLock)
|
||||
{
|
||||
foreach (var item in Authentications.ToArray())
|
||||
{
|
||||
if (item.Value == unauthorized)
|
||||
{
|
||||
Authentications[item.Key] = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveAuthentication(string uid)
|
||||
{
|
||||
lock (authDictLock)
|
||||
{
|
||||
var auth = Authentications.Where(u => u.Value == uid);
|
||||
if (auth.Any())
|
||||
{
|
||||
Authentications.Remove(auth.First().Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
{
|
||||
MareMetrics.AuthenticationRequests.Inc();
|
||||
|
||||
if (!Request.Headers.ContainsKey("Authorization"))
|
||||
{
|
||||
MareMetrics.AuthenticationFailures.Inc();
|
||||
return AuthenticateResult.Fail("Failed Authorization");
|
||||
}
|
||||
|
||||
var authHeader = Request.Headers["Authorization"].ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader))
|
||||
{
|
||||
MareMetrics.AuthenticationFailures.Inc();
|
||||
return AuthenticateResult.Fail("Failed Authorization");
|
||||
}
|
||||
|
||||
var ip = _accessor.GetIpAddress();
|
||||
|
||||
lock (failedAuthLock)
|
||||
{
|
||||
if (FailedAuthorizations.TryGetValue(ip, out var failedAuth) && failedAuth.FailedAttempts > failedAttemptsForTempBan)
|
||||
{
|
||||
MareMetrics.AuthenticationFailures.Inc();
|
||||
|
||||
failedAuth.ResetCts?.Cancel();
|
||||
failedAuth.ResetCts?.Dispose();
|
||||
failedAuth.ResetCts = new CancellationTokenSource();
|
||||
var token = failedAuth.ResetCts.Token;
|
||||
failedAuth.ResetTask = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromMinutes(tempBanMinutes), token);
|
||||
if (token.IsCancellationRequested) return;
|
||||
FailedAuthorization fauth;
|
||||
lock (failedAuthLock)
|
||||
{
|
||||
FailedAuthorizations.Remove(ip, out fauth);
|
||||
}
|
||||
fauth.Dispose();
|
||||
}, token);
|
||||
|
||||
Logger.LogWarning("TempBan " + ip + " for authorization spam");
|
||||
return AuthenticateResult.Fail("Failed Authorization");
|
||||
}
|
||||
}
|
||||
|
||||
using var sha256 = SHA256.Create();
|
||||
var hashedHeader = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(authHeader))).Replace("-", "");
|
||||
|
||||
string uid;
|
||||
lock (authDictLock)
|
||||
{
|
||||
if (Authentications.TryGetValue(hashedHeader, out uid))
|
||||
{
|
||||
if (uid == unauthorized)
|
||||
{
|
||||
MareMetrics.AuthenticationFailures.Inc();
|
||||
|
||||
lock (failedAuthLock)
|
||||
{
|
||||
Logger.LogWarning("Failed authorization from " + ip);
|
||||
if (FailedAuthorizations.TryGetValue(ip, out var auth))
|
||||
{
|
||||
auth.IncreaseFailedAttempts();
|
||||
}
|
||||
else
|
||||
{
|
||||
FailedAuthorizations[ip] = new FailedAuthorization();
|
||||
}
|
||||
}
|
||||
|
||||
return AuthenticateResult.Fail("Failed Authorization");
|
||||
}
|
||||
|
||||
MareMetrics.AuthenticationCacheHits.Inc();
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(uid))
|
||||
{
|
||||
uid = (await _mareDbContext.Auth.AsNoTracking()
|
||||
.FirstOrDefaultAsync(m => m.HashedKey == hashedHeader))?.UserUID;
|
||||
|
||||
if (uid == null)
|
||||
{
|
||||
lock (authDictLock)
|
||||
{
|
||||
Authentications[hashedHeader] = unauthorized;
|
||||
}
|
||||
|
||||
Logger.LogWarning("Failed authorization from " + ip);
|
||||
lock (failedAuthLock)
|
||||
{
|
||||
if (FailedAuthorizations.TryGetValue(ip, out var auth))
|
||||
{
|
||||
auth.IncreaseFailedAttempts();
|
||||
}
|
||||
else
|
||||
{
|
||||
FailedAuthorizations[ip] = new FailedAuthorization();
|
||||
}
|
||||
}
|
||||
|
||||
MareMetrics.AuthenticationFailures.Inc();
|
||||
return AuthenticateResult.Fail("Failed Authorization");
|
||||
}
|
||||
else
|
||||
{
|
||||
Authentications[hashedHeader] = uid;
|
||||
}
|
||||
}
|
||||
|
||||
var claims = new List<Claim> {
|
||||
new Claim(ClaimTypes.NameIdentifier, uid)
|
||||
};
|
||||
|
||||
var identity = new ClaimsIdentity(claims, nameof(SecretKeyAuthenticationHandler));
|
||||
var principal = new ClaimsPrincipal(identity);
|
||||
var ticket = new AuthenticationTicket(principal, Scheme.Name);
|
||||
|
||||
MareMetrics.AuthenticationSuccesses.Inc();
|
||||
|
||||
return AuthenticateResult.Success(ticket);
|
||||
}
|
||||
|
||||
public SecretKeyAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, IHttpContextAccessor accessor,
|
||||
MareDbContext mareDbContext, IConfiguration configuration, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
|
||||
{
|
||||
_accessor = accessor;
|
||||
_mareDbContext = mareDbContext;
|
||||
_configuration = configuration;
|
||||
failedAttemptsForTempBan = _configuration.GetValue<int>("FailedAuthForTempBan", 5);
|
||||
tempBanMinutes = _configuration.GetValue<int>("TempBanDurationInMinutes", 30);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronosServer.Authentication;
|
||||
using MareSynchronosServer.Data;
|
||||
using MareSynchronosServer.Metrics;
|
||||
using MareSynchronosServer.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MareSynchronosServer
|
||||
{
|
||||
public class CleanupService : IHostedService, IDisposable
|
||||
{
|
||||
private readonly ILogger<CleanupService> _logger;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IConfiguration _configuration;
|
||||
private Timer _timer;
|
||||
|
||||
public CleanupService(ILogger<CleanupService> logger, IServiceProvider services, IConfiguration configuration)
|
||||
{
|
||||
_logger = logger;
|
||||
_services = services;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Cleanup Service started");
|
||||
|
||||
_timer = new Timer(CleanUp, null, TimeSpan.Zero, TimeSpan.FromMinutes(10));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void CleanUp(object state)
|
||||
{
|
||||
if (!int.TryParse(_configuration["UnusedFileRetentionPeriodInDays"], out var filesOlderThanDays))
|
||||
{
|
||||
filesOlderThanDays = 7;
|
||||
}
|
||||
|
||||
using var scope = _services.CreateScope();
|
||||
using var dbContext = scope.ServiceProvider.GetService<MareDbContext>()!;
|
||||
|
||||
_logger.LogInformation($"Cleaning up files older than {filesOlderThanDays} days");
|
||||
|
||||
try
|
||||
{
|
||||
var prevTime = DateTime.Now.Subtract(TimeSpan.FromDays(filesOlderThanDays));
|
||||
|
||||
var allFiles = dbContext.Files.ToList();
|
||||
foreach (var file in allFiles.Where(f => f.Uploaded))
|
||||
{
|
||||
var fileName = Path.Combine(_configuration["CacheDirectory"], file.Hash);
|
||||
var fi = new FileInfo(fileName);
|
||||
if (!fi.Exists)
|
||||
{
|
||||
_logger.LogInformation("File does not exist anymore: " + fileName);
|
||||
dbContext.Files.Remove(file);
|
||||
}
|
||||
else if (fi.LastAccessTime < prevTime)
|
||||
{
|
||||
MareMetrics.FilesTotalSize.Dec(fi.Length);
|
||||
_logger.LogInformation("File outdated: " + fileName);
|
||||
dbContext.Files.Remove(file);
|
||||
fi.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error during file cleanup");
|
||||
}
|
||||
|
||||
var cacheSizeLimitInGiB = _configuration.GetValue<double>("CacheSizeHardLimitInGiB", -1);
|
||||
|
||||
try
|
||||
{
|
||||
if (cacheSizeLimitInGiB > 0)
|
||||
{
|
||||
_logger.LogInformation("Cleaning up files beyond the cache size limit");
|
||||
var allLocalFiles = Directory.EnumerateFiles(_configuration["CacheDirectory"]).Select(f => new FileInfo(f)).ToList().OrderBy(f => f.LastAccessTimeUtc).ToList();
|
||||
var totalCacheSizeInBytes = allLocalFiles.Sum(s => s.Length);
|
||||
long cacheSizeLimitInBytes = (long)(cacheSizeLimitInGiB * 1024 * 1024 * 1024);
|
||||
HashSet<string> removedHashes = new();
|
||||
while (totalCacheSizeInBytes > cacheSizeLimitInBytes && allLocalFiles.Any())
|
||||
{
|
||||
var oldestFile = allLocalFiles.First();
|
||||
removedHashes.Add(oldestFile.Name.ToLower());
|
||||
allLocalFiles.Remove(oldestFile);
|
||||
totalCacheSizeInBytes -= oldestFile.Length;
|
||||
MareMetrics.FilesTotal.Dec();
|
||||
MareMetrics.FilesTotalSize.Dec(oldestFile.Length);
|
||||
oldestFile.Delete();
|
||||
}
|
||||
|
||||
dbContext.Files.RemoveRange(dbContext.Files.Where(f => removedHashes.Contains(f.Hash.ToLower())));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error during cache size limit cleanup");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_logger.LogInformation($"Cleaning up expired lodestone authentications");
|
||||
var lodestoneAuths = dbContext.LodeStoneAuth.Include(u => u.User).Where(a => a.StartedAt != null).ToList();
|
||||
List<LodeStoneAuth> expiredAuths = new List<LodeStoneAuth>();
|
||||
foreach (var auth in lodestoneAuths)
|
||||
{
|
||||
if (auth.StartedAt < DateTime.UtcNow - TimeSpan.FromMinutes(15))
|
||||
{
|
||||
expiredAuths.Add(auth);
|
||||
}
|
||||
}
|
||||
|
||||
dbContext.RemoveRange(expiredAuths.Select(a => a.User));
|
||||
dbContext.RemoveRange(expiredAuths);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error during expired auths cleanup");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!bool.TryParse(_configuration["PurgeUnusedAccounts"], out var purgeUnusedAccounts))
|
||||
{
|
||||
purgeUnusedAccounts = false;
|
||||
}
|
||||
|
||||
if (purgeUnusedAccounts)
|
||||
{
|
||||
if (!int.TryParse(_configuration["PurgeUnusedAccountsPeriodInDays"], out var usersOlderThanDays))
|
||||
{
|
||||
usersOlderThanDays = 14;
|
||||
}
|
||||
|
||||
_logger.LogInformation($"Cleaning up users older than {usersOlderThanDays} days");
|
||||
|
||||
var allUsers = dbContext.Users.ToList();
|
||||
List<User> usersToRemove = new();
|
||||
foreach (var user in allUsers)
|
||||
{
|
||||
if (user.LastLoggedIn < (DateTime.UtcNow - TimeSpan.FromDays(usersOlderThanDays)))
|
||||
{
|
||||
_logger.LogInformation("User outdated: " + user.UID);
|
||||
usersToRemove.Add(user);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var user in usersToRemove)
|
||||
{
|
||||
PurgeUser(user, dbContext, _configuration);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Cleaning up unauthorized users");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error during user purge");
|
||||
}
|
||||
|
||||
SecretKeyAuthenticationHandler.ClearUnauthorizedUsers();
|
||||
|
||||
_logger.LogInformation($"Cleanup complete");
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public static void PurgeUser(User user, MareDbContext dbContext, IConfiguration _configuration)
|
||||
{
|
||||
var lodestone = dbContext.LodeStoneAuth.SingleOrDefault(a => a.User.UID == user.UID);
|
||||
|
||||
if (lodestone != null)
|
||||
{
|
||||
dbContext.Remove(lodestone);
|
||||
}
|
||||
|
||||
SecretKeyAuthenticationHandler.RemoveAuthentication(user.UID);
|
||||
|
||||
var auth = dbContext.Auth.Single(a => a.UserUID == user.UID);
|
||||
|
||||
var userFiles = dbContext.Files.Where(f => f.Uploaded && f.Uploader.UID == user.UID).ToList();
|
||||
foreach (var file in userFiles)
|
||||
{
|
||||
var fi = new FileInfo(Path.Combine(_configuration["CacheDirectory"], file.Hash));
|
||||
if (fi.Exists)
|
||||
{
|
||||
MareMetrics.FilesTotalSize.Dec(fi.Length);
|
||||
MareMetrics.FilesTotal.Dec();
|
||||
fi.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
dbContext.Files.RemoveRange(userFiles);
|
||||
|
||||
var ownPairData = dbContext.ClientPairs.Where(u => u.User.UID == user.UID).ToList();
|
||||
|
||||
dbContext.RemoveRange(ownPairData);
|
||||
var otherPairData = dbContext.ClientPairs.Include(u => u.User)
|
||||
.Where(u => u.OtherUser.UID == user.UID).ToList();
|
||||
|
||||
MareMetrics.Pairs.Dec(ownPairData.Count);
|
||||
MareMetrics.PairsPaused.Dec(ownPairData.Count(c => c.IsPaused));
|
||||
MareMetrics.Pairs.Dec(otherPairData.Count);
|
||||
MareMetrics.PairsPaused.Dec(otherPairData.Count(c => c.IsPaused));
|
||||
MareMetrics.UsersRegistered.Dec();
|
||||
|
||||
dbContext.RemoveRange(otherPairData);
|
||||
dbContext.Remove(auth);
|
||||
dbContext.Remove(user);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_timer?.Change(Timeout.Infinite, 0);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_timer?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using MareSynchronosServer.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MareSynchronosServer.Data
|
||||
{
|
||||
public class MareDbContext : DbContext
|
||||
{
|
||||
public MareDbContext(DbContextOptions<MareDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<FileCache> Files { get; set; }
|
||||
public DbSet<ClientPair> ClientPairs { get; set; }
|
||||
public DbSet<ForbiddenUploadEntry> ForbiddenUploadEntries { get; set; }
|
||||
public DbSet<Banned> BannedUsers { get; set; }
|
||||
public DbSet<Auth> Auth { get; set; }
|
||||
public DbSet<LodeStoneAuth> LodeStoneAuth { get; set; }
|
||||
public DbSet<BannedRegistrations> BannedRegistrations { get; set; }
|
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Auth>().ToTable("auth");
|
||||
modelBuilder.Entity<User>().ToTable("users");
|
||||
modelBuilder.Entity<User>().HasIndex(c => c.CharacterIdentification);
|
||||
modelBuilder.Entity<FileCache>().ToTable("file_caches");
|
||||
modelBuilder.Entity<FileCache>().HasIndex(c => c.UploaderUID);
|
||||
modelBuilder.Entity<ClientPair>().ToTable("client_pairs");
|
||||
modelBuilder.Entity<ClientPair>().HasKey(u => new { u.UserUID, u.OtherUserUID });
|
||||
modelBuilder.Entity<ClientPair>().HasIndex(c => c.UserUID);
|
||||
modelBuilder.Entity<ClientPair>().HasIndex(c => c.OtherUserUID);
|
||||
modelBuilder.Entity<ForbiddenUploadEntry>().ToTable("forbidden_upload_entries");
|
||||
modelBuilder.Entity<Banned>().ToTable("banned_users");
|
||||
modelBuilder.Entity<LodeStoneAuth>().ToTable("lodestone_auth");
|
||||
modelBuilder.Entity<BannedRegistrations>().ToTable("banned_registrations");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,431 +0,0 @@
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using MareSynchronosServer.Data;
|
||||
using MareSynchronosServer.Hubs;
|
||||
using MareSynchronosServer.Metrics;
|
||||
using MareSynchronosServer.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MareSynchronosServer.Discord
|
||||
{
|
||||
public class DiscordBot : IHostedService
|
||||
{
|
||||
private readonly IServiceProvider services;
|
||||
private readonly IConfiguration configuration;
|
||||
private readonly ILogger<DiscordBot> logger;
|
||||
private readonly Random random;
|
||||
private string authToken = string.Empty;
|
||||
DiscordSocketClient discordClient;
|
||||
ConcurrentDictionary<ulong, string> DiscordLodestoneMapping = new();
|
||||
private CancellationTokenSource verificationTaskCts;
|
||||
private CancellationTokenSource updateStatusCts;
|
||||
private readonly string[] LodestoneServers = new[] { "eu", "na", "jp", "fr", "de" };
|
||||
private readonly ConcurrentQueue<SocketSlashCommand> verificationQueue = new();
|
||||
|
||||
private SemaphoreSlim semaphore;
|
||||
|
||||
public DiscordBot(IServiceProvider services, IConfiguration configuration, ILogger<DiscordBot> logger)
|
||||
{
|
||||
this.services = services;
|
||||
this.configuration = configuration;
|
||||
this.logger = logger;
|
||||
this.verificationQueue = new ConcurrentQueue<SocketSlashCommand>();
|
||||
this.semaphore = new SemaphoreSlim(1);
|
||||
|
||||
random = new();
|
||||
authToken = configuration.GetValue<string>("DiscordBotToken");
|
||||
|
||||
discordClient = new(new DiscordSocketConfig()
|
||||
{
|
||||
DefaultRetryMode = RetryMode.AlwaysRetry
|
||||
});
|
||||
|
||||
discordClient.Log += Log;
|
||||
}
|
||||
|
||||
private async Task DiscordClient_SlashCommandExecuted(SocketSlashCommand arg)
|
||||
{
|
||||
await semaphore.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (arg.Data.Name == "register")
|
||||
{
|
||||
if (arg.Data.Options.FirstOrDefault(f => f.Name == "overwrite_old_account") != null)
|
||||
{
|
||||
await DeletePreviousUserAccount(arg.User.Id);
|
||||
}
|
||||
|
||||
var modal = new ModalBuilder();
|
||||
modal.WithTitle("Verify with Lodestone");
|
||||
modal.WithCustomId("register_modal");
|
||||
modal.AddTextInput("Enter the Lodestone URL of your Character", "lodestoneurl", TextInputStyle.Short, "https://*.finalfantasyxiv.com/lodestone/character/<CHARACTERID>/", required: true);
|
||||
await arg.RespondWithModalAsync(modal.Build());
|
||||
}
|
||||
else if (arg.Data.Name == "verify")
|
||||
{
|
||||
EmbedBuilder eb = new();
|
||||
if (verificationQueue.Any(u => u.User.Id == arg.User.Id))
|
||||
{
|
||||
eb.WithTitle("Already queued for verfication");
|
||||
eb.WithDescription("You are already queued for verification. Please wait.");
|
||||
await arg.RespondAsync(embeds: new[] { eb.Build() }, ephemeral: true);
|
||||
}
|
||||
else if (!DiscordLodestoneMapping.ContainsKey(arg.User.Id))
|
||||
{
|
||||
eb.WithTitle("Cannot verify registration");
|
||||
eb.WithDescription("You need to **/register** first before you can **/verify**");
|
||||
await arg.RespondAsync(embeds: new[] { eb.Build() }, ephemeral: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
await arg.DeferAsync(ephemeral: true);
|
||||
verificationQueue.Enqueue(arg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await arg.RespondAsync("idk what you did to get here to start, just follow the instructions as provided.", ephemeral: true);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeletePreviousUserAccount(ulong id)
|
||||
{
|
||||
using var scope = services.CreateScope();
|
||||
using var db = scope.ServiceProvider.GetService<MareDbContext>();
|
||||
var discordAuthedUser = await db.LodeStoneAuth.Include(u => u.User).FirstOrDefaultAsync(u => u.DiscordId == id);
|
||||
if (discordAuthedUser != null)
|
||||
{
|
||||
if (discordAuthedUser.User != null)
|
||||
{
|
||||
CleanupService.PurgeUser(discordAuthedUser.User, db, configuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
db.Remove(discordAuthedUser);
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DiscordClient_ModalSubmitted(SocketModal arg)
|
||||
{
|
||||
if (arg.Data.CustomId == "register_modal")
|
||||
{
|
||||
var embed = await HandleRegisterModalAsync(arg);
|
||||
await arg.RespondAsync(embeds: new Embed[] { embed }, ephemeral: true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Embed> HandleVerifyAsync(ulong id)
|
||||
{
|
||||
var embedBuilder = new EmbedBuilder();
|
||||
|
||||
using var scope = services.CreateScope();
|
||||
var req = new HttpClient();
|
||||
using var db = scope.ServiceProvider.GetService<MareDbContext>();
|
||||
|
||||
var lodestoneAuth = db.LodeStoneAuth.SingleOrDefault(u => u.DiscordId == id);
|
||||
if (lodestoneAuth != null && DiscordLodestoneMapping.ContainsKey(id))
|
||||
{
|
||||
var randomServer = LodestoneServers[random.Next(LodestoneServers.Length)];
|
||||
var response = await req.GetAsync($"https://{randomServer}.finalfantasyxiv.com/lodestone/character/{DiscordLodestoneMapping[id]}");
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
if (content.Contains(lodestoneAuth.LodestoneAuthString))
|
||||
{
|
||||
DiscordLodestoneMapping.TryRemove(id, out _);
|
||||
|
||||
using var sha256 = SHA256.Create();
|
||||
var user = new User();
|
||||
|
||||
var hasValidUid = false;
|
||||
while (!hasValidUid)
|
||||
{
|
||||
var uid = MareHub.GenerateRandomString(10);
|
||||
if (db.Users.Any(u => u.UID == uid)) continue;
|
||||
user.UID = uid;
|
||||
hasValidUid = true;
|
||||
}
|
||||
|
||||
// make the first registered user on the service to admin
|
||||
if (!await db.Users.AnyAsync())
|
||||
{
|
||||
user.IsAdmin = true;
|
||||
}
|
||||
|
||||
if (configuration.GetValue<bool>("PurgeUnusedAccounts"))
|
||||
{
|
||||
var purgedDays = configuration.GetValue<int>("PurgeUnusedAccountsPeriodInDays");
|
||||
user.LastLoggedIn = DateTime.UtcNow - TimeSpan.FromDays(purgedDays) + TimeSpan.FromDays(1);
|
||||
}
|
||||
|
||||
var computedHash = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(MareHub.GenerateRandomString(64)))).Replace("-", "");
|
||||
var auth = new Auth()
|
||||
{
|
||||
HashedKey = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(computedHash)))
|
||||
.Replace("-", ""),
|
||||
User = user,
|
||||
};
|
||||
|
||||
db.Users.Add(user);
|
||||
db.Auth.Add(auth);
|
||||
|
||||
logger.LogInformation("User registered: " + user.UID);
|
||||
|
||||
MareMetrics.UsersRegistered.Inc();
|
||||
|
||||
lodestoneAuth.StartedAt = null;
|
||||
lodestoneAuth.User = user;
|
||||
lodestoneAuth.LodestoneAuthString = null;
|
||||
|
||||
embedBuilder.WithTitle("Registration successful");
|
||||
embedBuilder.WithDescription("This is your private secret key. Do not share this private secret key with anyone. **If you lose it, it is irrevocably lost.**"
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ $"**{computedHash}**"
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ "Enter this key in Mare Synchronos and hit save to connect to the service."
|
||||
+ Environment.NewLine
|
||||
+ "You should connect as soon as possible to not get caught by the automatic cleanup process."
|
||||
+ Environment.NewLine
|
||||
+ "Have fun.");
|
||||
}
|
||||
else
|
||||
{
|
||||
embedBuilder.WithTitle("Failed to verify your character");
|
||||
embedBuilder.WithDescription("Did not find requested authentication key on your profile. Make sure you have saved *twice*, then do **/verify** again.");
|
||||
lodestoneAuth.StartedAt = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
embedBuilder.WithTitle("Your auth has expired or something else went wrong");
|
||||
embedBuilder.WithDescription("Start again with **/register**");
|
||||
DiscordLodestoneMapping.TryRemove(id, out _);
|
||||
}
|
||||
|
||||
return embedBuilder.Build();
|
||||
}
|
||||
|
||||
private async Task<Embed> HandleRegisterModalAsync(SocketModal arg)
|
||||
{
|
||||
var embed = new EmbedBuilder();
|
||||
|
||||
var lodestoneId = ParseCharacterIdFromLodestoneUrl(arg.Data.Components.Single(c => c.CustomId == "lodestoneurl").Value);
|
||||
if (lodestoneId == null)
|
||||
{
|
||||
embed.WithTitle("Invalid Lodestone URL");
|
||||
embed.WithDescription("The lodestone URL was not valid. It should have following format:" + Environment.NewLine
|
||||
+ "https://eu.finalfantasyxiv.com/lodestone/character/YOUR_LODESTONE_ID/");
|
||||
}
|
||||
else
|
||||
{
|
||||
// check if userid is already in db
|
||||
using var scope = services.CreateScope();
|
||||
using var sha256 = SHA256.Create();
|
||||
|
||||
var hashedLodestoneId = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(lodestoneId.ToString()))).Replace("-", "");
|
||||
|
||||
using var db = scope.ServiceProvider.GetService<MareDbContext>();
|
||||
|
||||
// check if discord id or lodestone id is banned
|
||||
if (db.BannedRegistrations.Any(a => a.DiscordIdOrLodestoneAuth == arg.User.Id.ToString() || a.DiscordIdOrLodestoneAuth == hashedLodestoneId))
|
||||
{
|
||||
embed.WithTitle("no");
|
||||
embed.WithDescription("your account is banned");
|
||||
}
|
||||
else if (db.LodeStoneAuth.Any(a => a.DiscordId == arg.User.Id))
|
||||
{
|
||||
// user already in db
|
||||
embed.WithTitle("Registration failed");
|
||||
embed.WithDescription("You cannot register more than one lodestone character to your discord account.");
|
||||
}
|
||||
else if (db.LodeStoneAuth.Any(a => a.HashedLodestoneId == hashedLodestoneId))
|
||||
{
|
||||
// character already in db
|
||||
embed.WithTitle("Registration failed");
|
||||
embed.WithDescription("This lodestone character already exists in the Database. If you are the rightful owner for this character and lost your secret key generated with it, contact the developer.");
|
||||
}
|
||||
else
|
||||
{
|
||||
string lodestoneAuth = await GenerateLodestoneAuth(arg.User.Id, hashedLodestoneId, db);
|
||||
// check if lodestone id is already in db
|
||||
embed.WithTitle("Authorize your character");
|
||||
embed.WithDescription("Add following key to your character profile at https://na.finalfantasyxiv.com/lodestone/my/setting/profile/"
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ $"**{lodestoneAuth}**"
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ $"**! THIS IS NOT THE KEY YOU HAVE TO ENTER IN MARE !**"
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ "Once added and saved, use command **/verify** to finish registration and receive a secret key to use for Mare Synchronos."
|
||||
+ Environment.NewLine
|
||||
+ "You can delete the entry from your profile after verification."
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ "The verification will expire in approximately 15 minutes. If you fail to **/verify** the registration will be invalidated and you have to **/register** again.");
|
||||
DiscordLodestoneMapping[arg.User.Id] = lodestoneId.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return embed.Build();
|
||||
}
|
||||
|
||||
private async Task<string> GenerateLodestoneAuth(ulong discordid, string hashedLodestoneId, MareDbContext dbContext)
|
||||
{
|
||||
var auth = MareHub.GenerateRandomString(32);
|
||||
LodeStoneAuth lsAuth = new LodeStoneAuth()
|
||||
{
|
||||
DiscordId = discordid,
|
||||
HashedLodestoneId = hashedLodestoneId,
|
||||
LodestoneAuthString = auth,
|
||||
StartedAt = DateTime.UtcNow
|
||||
};
|
||||
|
||||
dbContext.Add(lsAuth);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
return auth;
|
||||
}
|
||||
|
||||
private int? ParseCharacterIdFromLodestoneUrl(string lodestoneUrl)
|
||||
{
|
||||
var regex = new Regex(@"https:\/\/(na|eu|de|fr|jp)\.finalfantasyxiv\.com\/lodestone\/character\/\d+");
|
||||
var matches = regex.Match(lodestoneUrl);
|
||||
var isLodestoneUrl = matches.Success;
|
||||
if (!isLodestoneUrl || matches.Groups.Count < 1) return null;
|
||||
|
||||
lodestoneUrl = matches.Groups[0].ToString();
|
||||
var stringId = lodestoneUrl.Split('/', StringSplitOptions.RemoveEmptyEntries).Last();
|
||||
if (!int.TryParse(stringId, out int lodestoneId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return lodestoneId;
|
||||
}
|
||||
|
||||
private async Task DiscordClient_Ready()
|
||||
{
|
||||
var register = new SlashCommandBuilder()
|
||||
.WithName("register")
|
||||
.WithDescription("Registration for the Mare Synchronos server of this Discord")
|
||||
.AddOption(new SlashCommandOptionBuilder()
|
||||
.WithName("new_account")
|
||||
.WithDescription("Starts the registration process for the Mare Synchronos server of this Discord")
|
||||
.WithType(ApplicationCommandOptionType.SubCommand))
|
||||
.AddOption(new SlashCommandOptionBuilder()
|
||||
.WithName("overwrite_old_account")
|
||||
.WithDescription("Will forcefully overwrite your current character on the service, if present")
|
||||
.WithType(ApplicationCommandOptionType.SubCommand));
|
||||
|
||||
var verify = new SlashCommandBuilder();
|
||||
verify.WithName("verify");
|
||||
verify.WithDescription("Finishes the registration process for the Mare Synchronos server of this Discord");
|
||||
|
||||
try
|
||||
{
|
||||
await discordClient.CreateGlobalApplicationCommandAsync(register.Build());
|
||||
await discordClient.CreateGlobalApplicationCommandAsync(verify.Build());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to create command");
|
||||
}
|
||||
}
|
||||
|
||||
private Task Log(LogMessage msg)
|
||||
{
|
||||
logger.LogInformation(msg.ToString());
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(authToken))
|
||||
{
|
||||
authToken = configuration.GetValue<string>("DiscordBotToken");
|
||||
|
||||
await discordClient.LoginAsync(TokenType.Bot, authToken);
|
||||
await discordClient.StartAsync();
|
||||
|
||||
discordClient.Ready += DiscordClient_Ready;
|
||||
discordClient.SlashCommandExecuted += DiscordClient_SlashCommandExecuted;
|
||||
discordClient.ModalSubmitted += DiscordClient_ModalSubmitted;
|
||||
|
||||
_ = ProcessQueueWork();
|
||||
_ = UpdateStatusAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ProcessQueueWork()
|
||||
{
|
||||
verificationTaskCts = new CancellationTokenSource();
|
||||
while (!verificationTaskCts.IsCancellationRequested)
|
||||
{
|
||||
if (verificationQueue.TryDequeue(out var queueitem))
|
||||
{
|
||||
try
|
||||
{
|
||||
var dataEmbed = await HandleVerifyAsync(queueitem.User.Id);
|
||||
await queueitem.FollowupAsync(embed: dataEmbed, ephemeral: true);
|
||||
|
||||
logger.LogInformation("Sent login information to user");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
await Task.Delay(TimeSpan.FromSeconds(2), verificationTaskCts.Token);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateStatusAsync()
|
||||
{
|
||||
updateStatusCts = new();
|
||||
while (!updateStatusCts.IsCancellationRequested)
|
||||
{
|
||||
using var scope = services.CreateScope();
|
||||
using var db = scope.ServiceProvider.GetService<MareDbContext>();
|
||||
|
||||
var users = db.Users.Count(c => c.CharacterIdentification != null);
|
||||
|
||||
await discordClient.SetActivityAsync(new Game("Mare for " + users + " Users"));
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(15));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
verificationTaskCts?.Cancel();
|
||||
updateStatusCts?.Cancel();
|
||||
|
||||
await discordClient.LogoutAsync();
|
||||
await discordClient.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Linq;
|
||||
|
||||
namespace MareSynchronosServer
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace MareSynchronosServer.Authentication
|
||||
namespace MareSynchronosServer.Hubs
|
||||
{
|
||||
public class IdBasedUserIdProvider : IUserIdProvider
|
||||
{
|
||||
@@ -2,8 +2,8 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronosServer.Authentication;
|
||||
using MareSynchronosServer.Models;
|
||||
using MareSynchronosShared.Authentication;
|
||||
using MareSynchronosShared.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -18,58 +18,58 @@ namespace MareSynchronosServer.Hubs
|
||||
|
||||
private List<string> OnlineAdmins => _dbContext.Users.Where(u => !string.IsNullOrEmpty(u.CharacterIdentification) && (u.IsModerator || u.IsAdmin))
|
||||
.Select(u => u.UID).ToList();
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendAdminChangeModeratorStatus)]
|
||||
public async Task ChangeModeratorStatus(string uid, bool isModerator)
|
||||
{
|
||||
if (!IsAdmin) return;
|
||||
var user = await _dbContext.Users.SingleOrDefaultAsync(u => u.UID == uid);
|
||||
var user = await _dbContext.Users.SingleOrDefaultAsync(u => u.UID == uid).ConfigureAwait(false);
|
||||
|
||||
if (user == null) return;
|
||||
|
||||
user.IsModerator = isModerator;
|
||||
_dbContext.Update(user);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await Clients.Users(user.UID).SendAsync(Api.OnAdminForcedReconnect);
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
await Clients.Users(user.UID).SendAsync(Api.OnAdminForcedReconnect).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendAdminDeleteBannedUser)]
|
||||
public async Task DeleteBannedUser(BannedUserDto dto)
|
||||
{
|
||||
if (!IsModerator || string.IsNullOrEmpty(dto.CharacterHash)) return;
|
||||
|
||||
var existingUser =
|
||||
await _dbContext.BannedUsers.SingleOrDefaultAsync(b => b.CharacterIdentification == dto.CharacterHash);
|
||||
await _dbContext.BannedUsers.SingleOrDefaultAsync(b => b.CharacterIdentification == dto.CharacterHash).ConfigureAwait(false);
|
||||
if (existingUser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_dbContext.Remove(existingUser);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminDeleteBannedUser, dto);
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminDeleteBannedUser, dto).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendAdminDeleteForbiddenFile)]
|
||||
public async Task DeleteForbiddenFile(ForbiddenFileDto dto)
|
||||
{
|
||||
if (!IsAdmin || string.IsNullOrEmpty(dto.Hash)) return;
|
||||
|
||||
var existingFile =
|
||||
await _dbContext.ForbiddenUploadEntries.SingleOrDefaultAsync(b => b.Hash == dto.Hash);
|
||||
await _dbContext.ForbiddenUploadEntries.SingleOrDefaultAsync(b => b.Hash == dto.Hash).ConfigureAwait(false);
|
||||
if (existingFile == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_dbContext.Remove(existingFile);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminDeleteForbiddenFile, dto);
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminDeleteForbiddenFile, dto).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeAdminGetBannedUsers)]
|
||||
public async Task<List<BannedUserDto>> GetBannedUsers()
|
||||
{
|
||||
@@ -79,10 +79,10 @@ namespace MareSynchronosServer.Hubs
|
||||
{
|
||||
CharacterHash = b.CharacterIdentification,
|
||||
Reason = b.Reason
|
||||
}).ToListAsync();
|
||||
}).ToListAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeAdminGetForbiddenFiles)]
|
||||
public async Task<List<ForbiddenFileDto>> GetForbiddenFiles()
|
||||
{
|
||||
@@ -92,10 +92,10 @@ namespace MareSynchronosServer.Hubs
|
||||
{
|
||||
Hash = b.Hash,
|
||||
ForbiddenBy = b.ForbiddenBy
|
||||
}).ToListAsync();
|
||||
}).ToListAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeAdminGetOnlineUsers)]
|
||||
public async Task<List<OnlineUserDto>> AdminGetOnlineUsers()
|
||||
{
|
||||
@@ -107,17 +107,17 @@ namespace MareSynchronosServer.Hubs
|
||||
UID = b.UID,
|
||||
IsModerator = b.IsModerator,
|
||||
IsAdmin = b.IsAdmin
|
||||
}).ToListAsync();
|
||||
}).ToListAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendAdminUpdateOrAddBannedUser)]
|
||||
public async Task UpdateOrAddBannedUser(BannedUserDto dto)
|
||||
{
|
||||
if (!IsModerator || string.IsNullOrEmpty(dto.CharacterHash)) return;
|
||||
|
||||
var existingUser =
|
||||
await _dbContext.BannedUsers.SingleOrDefaultAsync(b => b.CharacterIdentification == dto.CharacterHash);
|
||||
await _dbContext.BannedUsers.SingleOrDefaultAsync(b => b.CharacterIdentification == dto.CharacterHash).ConfigureAwait(false);
|
||||
if (existingUser != null)
|
||||
{
|
||||
existingUser.Reason = dto.Reason;
|
||||
@@ -129,27 +129,27 @@ namespace MareSynchronosServer.Hubs
|
||||
{
|
||||
CharacterIdentification = dto.CharacterHash,
|
||||
Reason = dto.Reason
|
||||
});
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminUpdateOrAddBannedUser, dto);
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminUpdateOrAddBannedUser, dto).ConfigureAwait(false);
|
||||
var bannedUser =
|
||||
await _dbContext.Users.SingleOrDefaultAsync(u => u.CharacterIdentification == dto.CharacterHash);
|
||||
await _dbContext.Users.SingleOrDefaultAsync(u => u.CharacterIdentification == dto.CharacterHash).ConfigureAwait(false);
|
||||
if (bannedUser != null)
|
||||
{
|
||||
await Clients.User(bannedUser.UID).SendAsync(Api.OnAdminForcedReconnect);
|
||||
await Clients.User(bannedUser.UID).SendAsync(Api.OnAdminForcedReconnect).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendAdminUpdateOrAddForbiddenFile)]
|
||||
public async Task UpdateOrAddForbiddenFile(ForbiddenFileDto dto)
|
||||
{
|
||||
if (!IsAdmin || string.IsNullOrEmpty(dto.Hash)) return;
|
||||
|
||||
var existingForbiddenFile =
|
||||
await _dbContext.ForbiddenUploadEntries.SingleOrDefaultAsync(b => b.Hash == dto.Hash);
|
||||
await _dbContext.ForbiddenUploadEntries.SingleOrDefaultAsync(b => b.Hash == dto.Hash).ConfigureAwait(false);
|
||||
if (existingForbiddenFile != null)
|
||||
{
|
||||
existingForbiddenFile.ForbiddenBy = dto.ForbiddenBy;
|
||||
@@ -161,12 +161,12 @@ namespace MareSynchronosServer.Hubs
|
||||
{
|
||||
Hash = dto.Hash,
|
||||
ForbiddenBy = dto.ForbiddenBy
|
||||
});
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
|
||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminUpdateOrAddForbiddenFile, dto);
|
||||
await Clients.Users(OnlineAdmins).SendAsync(Api.OnAdminUpdateOrAddForbiddenFile, dto).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@ using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronosServer.Authentication;
|
||||
using MareSynchronosServer.Metrics;
|
||||
using MareSynchronosServer.Models;
|
||||
using MareSynchronosShared.Authentication;
|
||||
using MareSynchronosShared.Metrics;
|
||||
using MareSynchronosShared.Models;
|
||||
using MareSynchronosShared.Protos;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -21,45 +22,47 @@ namespace MareSynchronosServer.Hubs
|
||||
{
|
||||
private string BasePath => _configuration["CacheDirectory"];
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendFileAbortUpload)]
|
||||
public async Task AbortUpload()
|
||||
{
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " aborted upload");
|
||||
_logger.LogInformation("User {AuthenticatedUserId} aborted upload", AuthenticatedUserId);
|
||||
var userId = AuthenticatedUserId;
|
||||
var notUploadedFiles = _dbContext.Files.Where(f => !f.Uploaded && f.Uploader.UID == userId).ToList();
|
||||
_dbContext.RemoveRange(notUploadedFiles);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendFileDeleteAllFiles)]
|
||||
public async Task DeleteAllFiles()
|
||||
{
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " deleted all their files");
|
||||
_logger.LogInformation("User {AuthenticatedUserId} deleted all their files", AuthenticatedUserId);
|
||||
|
||||
var ownFiles = await _dbContext.Files.Where(f => f.Uploaded && f.Uploader.UID == AuthenticatedUserId).ToListAsync();
|
||||
var ownFiles = await _dbContext.Files.Where(f => f.Uploaded && f.Uploader.UID == AuthenticatedUserId).ToListAsync().ConfigureAwait(false);
|
||||
foreach (var file in ownFiles)
|
||||
{
|
||||
var fi = new FileInfo(Path.Combine(BasePath, file.Hash));
|
||||
if (fi.Exists)
|
||||
{
|
||||
MareMetrics.FilesTotalSize.Dec(fi.Length);
|
||||
MareMetrics.FilesTotal.Dec();
|
||||
await _metricsClient.DecGaugeAsync(new GaugeRequest()
|
||||
{GaugeName = MetricsAPI.GaugeFilesTotalSize, Value = fi.Length}).ConfigureAwait(false);
|
||||
await _metricsClient.DecGaugeAsync(new GaugeRequest()
|
||||
{ GaugeName = MetricsAPI.GaugeFilesTotal, Value = 1}).ConfigureAwait(false);
|
||||
fi.Delete();
|
||||
}
|
||||
}
|
||||
_dbContext.Files.RemoveRange(ownFiles);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeGetFilesSizes)]
|
||||
public async Task<List<DownloadFileDto>> GetFilesSizes(List<string> hashes)
|
||||
{
|
||||
var allFiles = await _dbContext.Files.Where(f => hashes.Contains(f.Hash)).ToListAsync();
|
||||
var allFiles = await _dbContext.Files.Where(f => hashes.Contains(f.Hash)).ToListAsync().ConfigureAwait(false);
|
||||
var forbiddenFiles = await _dbContext.ForbiddenUploadEntries.
|
||||
Where(f => hashes.Contains(f.Hash)).ToListAsync();
|
||||
Where(f => hashes.Contains(f.Hash)).ToListAsync().ConfigureAwait(false);
|
||||
List<DownloadFileDto> response = new();
|
||||
foreach (var hash in hashes)
|
||||
{
|
||||
@@ -90,33 +93,32 @@ namespace MareSynchronosServer.Hubs
|
||||
if (!fileInfo.Exists && downloadFile != null)
|
||||
{
|
||||
_dbContext.Files.Remove(downloadFile);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeFileIsUploadFinished)]
|
||||
public async Task<bool> IsUploadFinished()
|
||||
{
|
||||
var userUid = AuthenticatedUserId;
|
||||
return await _dbContext.Files.AsNoTracking()
|
||||
.AnyAsync(f => f.Uploader.UID == userUid && !f.Uploaded);
|
||||
.AnyAsync(f => f.Uploader.UID == userUid && !f.Uploaded).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeFileSendFiles)]
|
||||
public async Task<List<UploadFileDto>> SendFiles(List<string> fileListHashes)
|
||||
{
|
||||
var userSentHashes = new HashSet<string>(fileListHashes.Distinct());
|
||||
_logger.LogInformation($"User {AuthenticatedUserId} sending files: {userSentHashes.Count}");
|
||||
_logger.LogInformation("User {AuthenticatedUserId} sending files: {count}", AuthenticatedUserId, userSentHashes.Count);
|
||||
var notCoveredFiles = new Dictionary<string, UploadFileDto>();
|
||||
// Todo: Check if a select can directly transform to hashset
|
||||
var forbiddenFiles = await _dbContext.ForbiddenUploadEntries.AsNoTracking().Where(f => userSentHashes.Contains(f.Hash)).ToDictionaryAsync(f => f.Hash, f => f);
|
||||
var existingFiles = await _dbContext.Files.AsNoTracking().Where(f => userSentHashes.Contains(f.Hash)).ToDictionaryAsync(f => f.Hash, f => f);
|
||||
var uploader = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId);
|
||||
var forbiddenFiles = await _dbContext.ForbiddenUploadEntries.AsNoTracking().Where(f => userSentHashes.Contains(f.Hash)).ToDictionaryAsync(f => f.Hash, f => f).ConfigureAwait(false);
|
||||
var existingFiles = await _dbContext.Files.AsNoTracking().Where(f => userSentHashes.Contains(f.Hash)).ToDictionaryAsync(f => f.Hash, f => f).ConfigureAwait(false);
|
||||
var uploader = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
||||
|
||||
List<FileCache> fileCachesToUpload = new();
|
||||
foreach (var file in userSentHashes)
|
||||
@@ -137,7 +139,7 @@ namespace MareSynchronosServer.Hubs
|
||||
}
|
||||
if (existingFiles.ContainsKey(file)) { continue; }
|
||||
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " needs upload: " + file);
|
||||
_logger.LogInformation("User {AuthenticatedUserId} needs upload: {file}", AuthenticatedUserId, file);
|
||||
var userId = AuthenticatedUserId;
|
||||
fileCachesToUpload.Add(new FileCache()
|
||||
{
|
||||
@@ -152,16 +154,16 @@ namespace MareSynchronosServer.Hubs
|
||||
};
|
||||
}
|
||||
//Save bulk
|
||||
await _dbContext.Files.AddRangeAsync(fileCachesToUpload);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.Files.AddRangeAsync(fileCachesToUpload).ConfigureAwait(false);
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
return notCoveredFiles.Values.ToList();
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendFileUploadFileStreamAsync)]
|
||||
public async Task UploadFileStreamAsync(string hash, IAsyncEnumerable<byte[]> fileContent)
|
||||
{
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " uploading file: " + hash);
|
||||
_logger.LogInformation("User {AuthenticatedUserId} uploading file: {hash}", AuthenticatedUserId, hash);
|
||||
|
||||
var relatedFile = _dbContext.Files.SingleOrDefault(f => f.Hash == hash && f.Uploader.UID == AuthenticatedUserId && f.Uploaded == false);
|
||||
if (relatedFile == null) return;
|
||||
@@ -173,23 +175,23 @@ namespace MareSynchronosServer.Hubs
|
||||
long length = 0;
|
||||
try
|
||||
{
|
||||
await foreach (var chunk in fileContent)
|
||||
await foreach (var chunk in fileContent.ConfigureAwait(false))
|
||||
{
|
||||
length += chunk.Length;
|
||||
await fileStream.WriteAsync(chunk);
|
||||
await fileStream.WriteAsync(chunk).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await fileStream.FlushAsync();
|
||||
await fileStream.DisposeAsync();
|
||||
await fileStream.FlushAsync().ConfigureAwait(false);
|
||||
await fileStream.DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
await fileStream.FlushAsync();
|
||||
await fileStream.DisposeAsync();
|
||||
await fileStream.FlushAsync().ConfigureAwait(false);
|
||||
await fileStream.DisposeAsync().ConfigureAwait(false);
|
||||
_dbContext.Files.Remove(relatedFile);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -203,20 +205,20 @@ namespace MareSynchronosServer.Hubs
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " upload finished: " + hash + ", size: " + length);
|
||||
_logger.LogInformation("User {AuthenticatedUserId} upload finished: {hash}, size: {length}", AuthenticatedUserId, hash, length);
|
||||
|
||||
try
|
||||
{
|
||||
var decodedFile = LZ4.LZ4Codec.Unwrap(await File.ReadAllBytesAsync(tempFileName));
|
||||
var decodedFile = LZ4.LZ4Codec.Unwrap(await File.ReadAllBytesAsync(tempFileName).ConfigureAwait(false));
|
||||
using var sha1 = SHA1.Create();
|
||||
using var ms = new MemoryStream(decodedFile);
|
||||
var computedHash = await sha1.ComputeHashAsync(ms);
|
||||
var computedHash = await sha1.ComputeHashAsync(ms).ConfigureAwait(false);
|
||||
var computedHashString = BitConverter.ToString(computedHash).Replace("-", "");
|
||||
if (hash != computedHashString)
|
||||
{
|
||||
_logger.LogWarning($"Computed file hash was not expected file hash. Computed: {computedHashString}, Expected {hash}");
|
||||
_logger.LogWarning("Computed file hash was not expected file hash. Computed: {computedHashString}, Expected {hash}", computedHashString, hash);
|
||||
_dbContext.Remove(relatedFile);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -225,17 +227,19 @@ namespace MareSynchronosServer.Hubs
|
||||
relatedFile = _dbContext.Files.Single(f => f.Hash == hash);
|
||||
relatedFile.Uploaded = true;
|
||||
|
||||
MareMetrics.FilesTotal.Inc();
|
||||
MareMetrics.FilesTotalSize.Inc(length);
|
||||
await _metricsClient.IncGaugeAsync(new GaugeRequest()
|
||||
{ GaugeName = MetricsAPI.GaugeFilesTotalSize, Value = length }).ConfigureAwait(false);
|
||||
await _metricsClient.IncGaugeAsync(new GaugeRequest()
|
||||
{ GaugeName = MetricsAPI.GaugeFilesTotal, Value = 1 }).ConfigureAwait(false);
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
_logger.LogInformation("File " + hash + " added to DB");
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
_logger.LogInformation("File {hash} added to DB", hash);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Upload failed");
|
||||
_dbContext.Remove(relatedFile);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronosServer.Authentication;
|
||||
using MareSynchronosServer.Metrics;
|
||||
using MareSynchronosServer.Models;
|
||||
using MareSynchronosShared.Authentication;
|
||||
using MareSynchronosShared.Metrics;
|
||||
using MareSynchronosShared.Models;
|
||||
using MareSynchronosShared.Protos;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -14,18 +15,18 @@ namespace MareSynchronosServer.Hubs
|
||||
{
|
||||
public partial class MareHub
|
||||
{
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendUserDeleteAccount)]
|
||||
public async Task DeleteAccount()
|
||||
{
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " deleted their account");
|
||||
_logger.LogInformation("User {AuthenticatedUserId} deleted their account", AuthenticatedUserId);
|
||||
|
||||
|
||||
string userid = AuthenticatedUserId;
|
||||
var userEntry = await _dbContext.Users.SingleAsync(u => u.UID == userid);
|
||||
var ownPairData = await _dbContext.ClientPairs.Where(u => u.User.UID == userid).ToListAsync();
|
||||
var auth = await _dbContext.Auth.SingleAsync(u => u.UserUID == userid);
|
||||
var lodestone = await _dbContext.LodeStoneAuth.SingleOrDefaultAsync(a => a.User.UID == userid);
|
||||
var userEntry = await _dbContext.Users.SingleAsync(u => u.UID == userid).ConfigureAwait(false);
|
||||
var ownPairData = await _dbContext.ClientPairs.Where(u => u.User.UID == userid).ToListAsync().ConfigureAwait(false);
|
||||
var auth = await _dbContext.Auth.SingleAsync(u => u.UserUID == userid).ConfigureAwait(false);
|
||||
var lodestone = await _dbContext.LodeStoneAuth.SingleOrDefaultAsync(a => a.User.UID == userid).ConfigureAwait(false);
|
||||
|
||||
if (lodestone != null)
|
||||
{
|
||||
@@ -34,18 +35,16 @@ namespace MareSynchronosServer.Hubs
|
||||
|
||||
while (_dbContext.Files.Any(f => f.Uploader == userEntry))
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
SecretKeyAuthenticationHandler.RemoveAuthentication(userid);
|
||||
await _authServiceClient.RemoveAuthAsync(new RemoveAuthRequest() { Uid = userid }).ConfigureAwait(false);
|
||||
|
||||
MareMetrics.Pairs.Dec(ownPairData.Count);
|
||||
MareMetrics.PairsPaused.Dec(ownPairData.Count(c => c.IsPaused));
|
||||
|
||||
_dbContext.RemoveRange(ownPairData);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
var otherPairData = await _dbContext.ClientPairs.Include(u => u.User)
|
||||
.Where(u => u.OtherUser.UID == userid).ToListAsync();
|
||||
.Where(u => u.OtherUser.UID == userid).ToListAsync().ConfigureAwait(false);
|
||||
foreach (var pair in otherPairData)
|
||||
{
|
||||
await Clients.User(pair.User.UID)
|
||||
@@ -53,42 +52,45 @@ namespace MareSynchronosServer.Hubs
|
||||
{
|
||||
OtherUID = userid,
|
||||
IsRemoved = true
|
||||
}, userEntry.CharacterIdentification);
|
||||
}, userEntry.CharacterIdentification).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
MareMetrics.Pairs.Dec(otherPairData.Count());
|
||||
MareMetrics.PairsPaused.Dec(otherPairData.Count(c => c.IsPaused));
|
||||
MareMetrics.UsersRegistered.Dec();
|
||||
await _metricsClient.DecGaugeAsync(new GaugeRequest()
|
||||
{ GaugeName = MetricsAPI.GaugePairs, Value = ownPairData.Count + otherPairData.Count }).ConfigureAwait(false);
|
||||
await _metricsClient.DecGaugeAsync(new GaugeRequest()
|
||||
{ GaugeName = MetricsAPI.GaugePairsPaused, Value = ownPairData.Count(c => c.IsPaused) }).ConfigureAwait(false);
|
||||
await _metricsClient.DecGaugeAsync(new GaugeRequest()
|
||||
{ GaugeName = MetricsAPI.GaugeUsersRegistered, Value = 1 }).ConfigureAwait(false);
|
||||
|
||||
_dbContext.RemoveRange(otherPairData);
|
||||
_dbContext.Remove(userEntry);
|
||||
_dbContext.Remove(auth);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeUserGetOnlineCharacters)]
|
||||
public async Task<List<string>> GetOnlineCharacters()
|
||||
{
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " requested online characters");
|
||||
_logger.LogInformation("User {AuthenticatedUserId} requested online characters", AuthenticatedUserId);
|
||||
|
||||
var ownUser = await GetAuthenticatedUserUntrackedAsync();
|
||||
var ownUser = await GetAuthenticatedUserUntrackedAsync().ConfigureAwait(false);
|
||||
|
||||
var otherUsers = await _dbContext.ClientPairs.AsNoTracking()
|
||||
.Include(u => u.User)
|
||||
.Include(u => u.OtherUser)
|
||||
.Where(w => w.User.UID == ownUser.UID && !w.IsPaused)
|
||||
.Where(w => !string.IsNullOrEmpty(w.OtherUser.CharacterIdentification))
|
||||
.Select(e => e.OtherUser).ToListAsync();
|
||||
.Include(u => u.User)
|
||||
.Include(u => u.OtherUser)
|
||||
.Where(w => w.User.UID == ownUser.UID && !w.IsPaused)
|
||||
.Where(w => !string.IsNullOrEmpty(w.OtherUser.CharacterIdentification))
|
||||
.Select(e => e.OtherUser).ToListAsync().ConfigureAwait(false);
|
||||
var otherEntries = await _dbContext.ClientPairs.AsNoTracking()
|
||||
.Include(u => u.User)
|
||||
.Where(u => otherUsers.Any(e => e == u.User) && u.OtherUser == ownUser && !u.IsPaused).ToListAsync();
|
||||
.Where(u => otherUsers.Any(e => e == u.User) && u.OtherUser == ownUser && !u.IsPaused).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
await Clients.Users(otherEntries.Select(e => e.User.UID)).SendAsync(Api.OnUserAddOnlinePairedPlayer, ownUser.CharacterIdentification);
|
||||
await Clients.Users(otherEntries.Select(e => e.User.UID)).SendAsync(Api.OnUserAddOnlinePairedPlayer, ownUser.CharacterIdentification).ConfigureAwait(false);
|
||||
return otherEntries.Select(e => e.User.CharacterIdentification).Distinct().ToList();
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeUserGetPairedClients)]
|
||||
public async Task<List<ClientPairDto>> GetPairedClients()
|
||||
{
|
||||
@@ -117,7 +119,7 @@ namespace MareSynchronosServer.Hubs
|
||||
IsSynced = otherEntry != null
|
||||
};
|
||||
|
||||
return (await query.ToListAsync()).Select(f => new ClientPairDto()
|
||||
return (await query.ToListAsync().ConfigureAwait(false)).Select(f => new ClientPairDto()
|
||||
{
|
||||
IsPaused = f.IsPaused,
|
||||
OtherUID = f.OtherUserUID,
|
||||
@@ -126,13 +128,13 @@ namespace MareSynchronosServer.Hubs
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeUserPushCharacterDataToVisibleClients)]
|
||||
public async Task PushCharacterDataToVisibleClients(CharacterCacheDto characterCache, List<string> visibleCharacterIds)
|
||||
{
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " pushing character data to " + visibleCharacterIds.Count + " visible clients");
|
||||
_logger.LogInformation("User {AuthenticatedUserId} pushing character data to {visibleCharacterIds} visible clients", AuthenticatedUserId, visibleCharacterIds.Count);
|
||||
|
||||
var user = await GetAuthenticatedUserUntrackedAsync();
|
||||
var user = await GetAuthenticatedUserUntrackedAsync().ConfigureAwait(false);
|
||||
|
||||
var query =
|
||||
from userToOther in _dbContext.ClientPairs
|
||||
@@ -154,38 +156,40 @@ namespace MareSynchronosServer.Hubs
|
||||
&& visibleCharacterIds.Contains(userToOther.OtherUser.CharacterIdentification)
|
||||
select otherToUser.UserUID;
|
||||
|
||||
var otherEntries = await query.ToListAsync();
|
||||
var otherEntries = await query.ToListAsync().ConfigureAwait(false);
|
||||
|
||||
await Clients.Users(otherEntries).SendAsync(Api.OnUserReceiveCharacterData, characterCache, user.CharacterIdentification);
|
||||
await Clients.Users(otherEntries).SendAsync(Api.OnUserReceiveCharacterData, characterCache, user.CharacterIdentification).ConfigureAwait(false);
|
||||
|
||||
MareMetrics.UserPushData.Inc();
|
||||
MareMetrics.UserPushDataTo.Inc(otherEntries.Count);
|
||||
await _metricsClient.IncreaseCounterAsync(new IncreaseCounterRequest()
|
||||
{ CounterName = MetricsAPI.CounterUserPushData, Value = 1 }).ConfigureAwait(false);
|
||||
await _metricsClient.IncreaseCounterAsync(new IncreaseCounterRequest()
|
||||
{ CounterName = MetricsAPI.CounterUserPushDataTo, Value = otherEntries.Count }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendUserPairedClientAddition)]
|
||||
public async Task SendPairedClientAddition(string uid)
|
||||
{
|
||||
if (uid == AuthenticatedUserId) return;
|
||||
uid = uid.Trim();
|
||||
var user = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId);
|
||||
var user = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
||||
|
||||
var otherUser = await _dbContext.Users
|
||||
.SingleOrDefaultAsync(u => u.UID == uid);
|
||||
.SingleOrDefaultAsync(u => u.UID == uid).ConfigureAwait(false);
|
||||
var existingEntry =
|
||||
await _dbContext.ClientPairs.AsNoTracking()
|
||||
.FirstOrDefaultAsync(p =>
|
||||
p.User.UID == AuthenticatedUserId && p.OtherUser.UID == uid);
|
||||
p.User.UID == AuthenticatedUserId && p.OtherUser.UID == uid).ConfigureAwait(false);
|
||||
if (otherUser == null || existingEntry != null) return;
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " adding " + uid + " to whitelist");
|
||||
_logger.LogInformation("User {AuthenticatedUserId} adding {uid} to whitelist", AuthenticatedUserId, uid);
|
||||
ClientPair wl = new ClientPair()
|
||||
{
|
||||
IsPaused = false,
|
||||
OtherUser = otherUser,
|
||||
User = user
|
||||
};
|
||||
await _dbContext.ClientPairs.AddAsync(wl);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.ClientPairs.AddAsync(wl).ConfigureAwait(false);
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
var otherEntry = OppositeEntry(uid);
|
||||
await Clients.User(user.UID)
|
||||
.SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
||||
@@ -194,7 +198,7 @@ namespace MareSynchronosServer.Hubs
|
||||
IsPaused = false,
|
||||
IsPausedFromOthers = otherEntry?.IsPaused ?? false,
|
||||
IsSynced = otherEntry != null
|
||||
}, string.Empty);
|
||||
}, string.Empty).ConfigureAwait(false);
|
||||
if (otherEntry != null)
|
||||
{
|
||||
await Clients.User(uid).SendAsync(Api.OnUserUpdateClientPairs,
|
||||
@@ -204,34 +208,34 @@ namespace MareSynchronosServer.Hubs
|
||||
IsPaused = otherEntry.IsPaused,
|
||||
IsPausedFromOthers = false,
|
||||
IsSynced = true
|
||||
}, user.CharacterIdentification);
|
||||
}, user.CharacterIdentification).ConfigureAwait(false);
|
||||
|
||||
if (!string.IsNullOrEmpty(otherUser.CharacterIdentification))
|
||||
{
|
||||
await Clients.User(user.UID)
|
||||
.SendAsync(Api.OnUserAddOnlinePairedPlayer, otherUser.CharacterIdentification);
|
||||
.SendAsync(Api.OnUserAddOnlinePairedPlayer, otherUser.CharacterIdentification).ConfigureAwait(false);
|
||||
await Clients.User(otherUser.UID)
|
||||
.SendAsync(Api.OnUserAddOnlinePairedPlayer, user.CharacterIdentification);
|
||||
.SendAsync(Api.OnUserAddOnlinePairedPlayer, user.CharacterIdentification).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
MareMetrics.Pairs.Inc();
|
||||
await _metricsClient.IncGaugeAsync(new GaugeRequest() {GaugeName = MetricsAPI.GaugePairs, Value = 1}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendUserPairedClientPauseChange)]
|
||||
public async Task SendPairedClientPauseChange(string otherUserUid, bool isPaused)
|
||||
{
|
||||
if (otherUserUid == AuthenticatedUserId) return;
|
||||
ClientPair pair = await _dbContext.ClientPairs.SingleOrDefaultAsync(w => w.UserUID == AuthenticatedUserId && w.OtherUserUID == otherUserUid);
|
||||
ClientPair pair = await _dbContext.ClientPairs.SingleOrDefaultAsync(w => w.UserUID == AuthenticatedUserId && w.OtherUserUID == otherUserUid).ConfigureAwait(false);
|
||||
if (pair == null) return;
|
||||
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " changed pause status with " + otherUserUid + " to " + isPaused);
|
||||
_logger.LogInformation("User {AuthenticatedUserId} changed pause status with {otherUserUid} to {isPaused}", AuthenticatedUserId, otherUserUid, isPaused);
|
||||
pair.IsPaused = isPaused;
|
||||
_dbContext.Update(pair);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
var selfCharaIdent = (await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId)).CharacterIdentification;
|
||||
var otherCharaIdent = (await _dbContext.Users.SingleAsync(u => u.UID == otherUserUid)).CharacterIdentification;
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
var selfCharaIdent = (await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false)).CharacterIdentification;
|
||||
var otherCharaIdent = (await _dbContext.Users.SingleAsync(u => u.UID == otherUserUid).ConfigureAwait(false)).CharacterIdentification;
|
||||
var otherEntry = OppositeEntry(otherUserUid);
|
||||
|
||||
await Clients.User(AuthenticatedUserId)
|
||||
@@ -241,7 +245,7 @@ namespace MareSynchronosServer.Hubs
|
||||
IsPaused = isPaused,
|
||||
IsPausedFromOthers = otherEntry?.IsPaused ?? false,
|
||||
IsSynced = otherEntry != null
|
||||
}, otherCharaIdent);
|
||||
}, otherCharaIdent).ConfigureAwait(false);
|
||||
if (otherEntry != null)
|
||||
{
|
||||
await Clients.User(otherUserUid).SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
||||
@@ -250,60 +254,60 @@ namespace MareSynchronosServer.Hubs
|
||||
IsPaused = otherEntry.IsPaused,
|
||||
IsPausedFromOthers = isPaused,
|
||||
IsSynced = true
|
||||
}, selfCharaIdent);
|
||||
}, selfCharaIdent).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (isPaused)
|
||||
{
|
||||
MareMetrics.PairsPaused.Inc();
|
||||
await _metricsClient.IncGaugeAsync(new GaugeRequest() { GaugeName = MetricsAPI.GaugePairsPaused, Value = 1 }).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
MareMetrics.PairsPaused.Dec();
|
||||
await _metricsClient.DecGaugeAsync(new GaugeRequest() { GaugeName = MetricsAPI.GaugePairsPaused, Value = 1 }).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendUserPairedClientRemoval)]
|
||||
public async Task SendPairedClientRemoval(string uid)
|
||||
{
|
||||
if (uid == AuthenticatedUserId) return;
|
||||
|
||||
var sender = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId);
|
||||
var otherUser = await _dbContext.Users.SingleOrDefaultAsync(u => u.UID == uid);
|
||||
var sender = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
||||
var otherUser = await _dbContext.Users.SingleOrDefaultAsync(u => u.UID == uid).ConfigureAwait(false);
|
||||
if (otherUser == null) return;
|
||||
_logger.LogInformation("User " + AuthenticatedUserId + " removed " + uid + " from whitelist");
|
||||
_logger.LogInformation("User {AuthenticatedUserId} removed {uid} from whitelist", AuthenticatedUserId, uid);
|
||||
ClientPair wl =
|
||||
await _dbContext.ClientPairs.SingleOrDefaultAsync(w => w.User == sender && w.OtherUser == otherUser);
|
||||
await _dbContext.ClientPairs.SingleOrDefaultAsync(w => w.User == sender && w.OtherUser == otherUser).ConfigureAwait(false);
|
||||
if (wl == null) return;
|
||||
_dbContext.ClientPairs.Remove(wl);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
var otherEntry = OppositeEntry(uid);
|
||||
await Clients.User(sender.UID)
|
||||
.SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
||||
{
|
||||
OtherUID = otherUser.UID,
|
||||
IsRemoved = true
|
||||
}, otherUser.CharacterIdentification);
|
||||
}, otherUser.CharacterIdentification).ConfigureAwait(false);
|
||||
if (otherEntry != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(otherUser.CharacterIdentification))
|
||||
{
|
||||
await Clients.User(sender.UID)
|
||||
.SendAsync(Api.OnUserRemoveOnlinePairedPlayer, otherUser.CharacterIdentification);
|
||||
.SendAsync(Api.OnUserRemoveOnlinePairedPlayer, otherUser.CharacterIdentification).ConfigureAwait(false);
|
||||
await Clients.User(otherUser.UID)
|
||||
.SendAsync(Api.OnUserRemoveOnlinePairedPlayer, sender.CharacterIdentification);
|
||||
.SendAsync(Api.OnUserRemoveOnlinePairedPlayer, sender.CharacterIdentification).ConfigureAwait(false);
|
||||
await Clients.User(otherUser.UID).SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
||||
{
|
||||
OtherUID = sender.UID,
|
||||
IsPaused = otherEntry.IsPaused,
|
||||
IsPausedFromOthers = false,
|
||||
IsSynced = false
|
||||
}, sender.CharacterIdentification);
|
||||
}, sender.CharacterIdentification).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
MareMetrics.Pairs.Dec();
|
||||
await _metricsClient.DecGaugeAsync(new GaugeRequest() { GaugeName = MetricsAPI.GaugePairs, Value = 1 }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private ClientPair OppositeEntry(string otherUID) =>
|
||||
|
||||
@@ -4,9 +4,11 @@ using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronosServer.Authentication;
|
||||
using MareSynchronosServer.Data;
|
||||
using MareSynchronosServer.Metrics;
|
||||
using MareSynchronosShared.Authentication;
|
||||
using MareSynchronosShared.Data;
|
||||
using MareSynchronosShared.Metrics;
|
||||
using MareSynchronosShared.Models;
|
||||
using MareSynchronosShared.Protos;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
@@ -18,14 +20,19 @@ namespace MareSynchronosServer.Hubs
|
||||
{
|
||||
public partial class MareHub : Hub
|
||||
{
|
||||
private readonly MetricsService.MetricsServiceClient _metricsClient;
|
||||
private readonly AuthService.AuthServiceClient _authServiceClient;
|
||||
private readonly SystemInfoService _systemInfoService;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IHttpContextAccessor contextAccessor;
|
||||
private readonly ILogger<MareHub> _logger;
|
||||
private readonly MareDbContext _dbContext;
|
||||
|
||||
public MareHub(MareDbContext mareDbContext, ILogger<MareHub> logger, SystemInfoService systemInfoService, IConfiguration configuration, IHttpContextAccessor contextAccessor)
|
||||
public MareHub(MetricsService.MetricsServiceClient metricsClient, AuthService.AuthServiceClient authServiceClient,
|
||||
MareDbContext mareDbContext, ILogger<MareHub> logger, SystemInfoService systemInfoService, IConfiguration configuration, IHttpContextAccessor contextAccessor)
|
||||
{
|
||||
_metricsClient = metricsClient;
|
||||
_authServiceClient = authServiceClient;
|
||||
_systemInfoService = systemInfoService;
|
||||
_configuration = configuration;
|
||||
this.contextAccessor = contextAccessor;
|
||||
@@ -34,22 +41,22 @@ namespace MareSynchronosServer.Hubs
|
||||
}
|
||||
|
||||
[HubMethodName(Api.InvokeHeartbeat)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[Authorize(AuthenticationSchemes = SecretKeyGrpcAuthenticationHandler.AuthScheme)]
|
||||
public async Task<ConnectionDto> Heartbeat(string characterIdentification)
|
||||
{
|
||||
MareMetrics.InitializedConnections.Inc();
|
||||
await _metricsClient.IncreaseCounterAsync(new() { CounterName = MetricsAPI.CounterInitializedConnections, Value = 1 }).ConfigureAwait(false);
|
||||
|
||||
var userId = Context.User!.Claims.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
_logger.LogInformation("Connection from " + userId + ", CI: " + characterIdentification);
|
||||
_logger.LogInformation("Connection from {userId}, CI: {characterIdentification}", userId, characterIdentification);
|
||||
|
||||
await Clients.Caller.SendAsync(Api.OnUpdateSystemInfo, _systemInfoService.SystemInfoDto);
|
||||
await Clients.Caller.SendAsync(Api.OnUpdateSystemInfo, _systemInfoService.SystemInfoDto).ConfigureAwait(false);
|
||||
|
||||
var isBanned = await _dbContext.BannedUsers.AsNoTracking().AnyAsync(u => u.CharacterIdentification == characterIdentification);
|
||||
var isBanned = await _dbContext.BannedUsers.AsNoTracking().AnyAsync(u => u.CharacterIdentification == characterIdentification).ConfigureAwait(false);
|
||||
|
||||
if (!string.IsNullOrEmpty(userId) && !isBanned && !string.IsNullOrEmpty(characterIdentification))
|
||||
{
|
||||
var user = (await _dbContext.Users.SingleAsync(u => u.UID == userId));
|
||||
var user = (await _dbContext.Users.SingleAsync(u => u.UID == userId).ConfigureAwait(false));
|
||||
if (!string.IsNullOrEmpty(user.CharacterIdentification) && characterIdentification != user.CharacterIdentification)
|
||||
{
|
||||
return new ConnectionDto()
|
||||
@@ -59,12 +66,12 @@ namespace MareSynchronosServer.Hubs
|
||||
}
|
||||
else if (string.IsNullOrEmpty(user.CharacterIdentification))
|
||||
{
|
||||
MareMetrics.AuthorizedConnections.Inc();
|
||||
await _metricsClient.IncGaugeAsync(new GaugeRequest() { GaugeName = MetricsAPI.GaugeAuthorizedConnections, Value = 1 }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
user.LastLoggedIn = DateTime.UtcNow;
|
||||
user.CharacterIdentification = characterIdentification;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
return new ConnectionDto
|
||||
{
|
||||
ServerVersion = Api.Version,
|
||||
@@ -80,32 +87,34 @@ namespace MareSynchronosServer.Hubs
|
||||
};
|
||||
}
|
||||
|
||||
public override Task OnConnectedAsync()
|
||||
public override async Task OnConnectedAsync()
|
||||
{
|
||||
_logger.LogInformation("Connection from " + contextAccessor.GetIpAddress());
|
||||
MareMetrics.Connections.Inc();
|
||||
return base.OnConnectedAsync();
|
||||
_logger.LogInformation("Connection from {ip}", contextAccessor.GetIpAddress());
|
||||
await _metricsClient.IncGaugeAsync(new GaugeRequest() { GaugeName = MetricsAPI.GaugeConnections, Value = 1 }).ConfigureAwait(false);
|
||||
await base.OnConnectedAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override async Task OnDisconnectedAsync(Exception exception)
|
||||
{
|
||||
MareMetrics.Connections.Dec();
|
||||
await _metricsClient.DecGaugeAsync(new GaugeRequest() { GaugeName = MetricsAPI.GaugeConnections, Value = 1 }).ConfigureAwait(false);
|
||||
|
||||
var user = await _dbContext.Users.SingleOrDefaultAsync(u => u.UID == AuthenticatedUserId);
|
||||
var user = await _dbContext.Users.SingleOrDefaultAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
||||
if (user != null && !string.IsNullOrEmpty(user.CharacterIdentification))
|
||||
{
|
||||
MareMetrics.AuthorizedConnections.Dec();
|
||||
await _metricsClient.DecGaugeAsync(new GaugeRequest() { GaugeName = MetricsAPI.GaugeAuthorizedConnections, Value = 1 }).ConfigureAwait(false);
|
||||
|
||||
_logger.LogInformation("Disconnect from " + AuthenticatedUserId);
|
||||
_logger.LogInformation("Disconnect from {id}", AuthenticatedUserId);
|
||||
|
||||
var query =
|
||||
from userToOther in _dbContext.ClientPairs
|
||||
join otherToUser in _dbContext.ClientPairs
|
||||
on new {
|
||||
on new
|
||||
{
|
||||
user = userToOther.UserUID,
|
||||
other = userToOther.OtherUserUID
|
||||
|
||||
} equals new {
|
||||
} equals new
|
||||
{
|
||||
user = otherToUser.OtherUserUID,
|
||||
other = otherToUser.UserUID
|
||||
}
|
||||
@@ -114,42 +123,24 @@ namespace MareSynchronosServer.Hubs
|
||||
&& !userToOther.IsPaused
|
||||
&& !otherToUser.IsPaused
|
||||
select otherToUser.UserUID;
|
||||
var otherEntries = await query.ToListAsync();
|
||||
var otherEntries = await query.ToListAsync().ConfigureAwait(false);
|
||||
|
||||
await Clients.Users(otherEntries).SendAsync(Api.OnUserRemoveOnlinePairedPlayer, user.CharacterIdentification).ConfigureAwait(false);
|
||||
|
||||
await Clients.Users(otherEntries).SendAsync(Api.OnUserRemoveOnlinePairedPlayer, user.CharacterIdentification);
|
||||
|
||||
_dbContext.RemoveRange(_dbContext.Files.Where(f => !f.Uploaded && f.UploaderUID == user.UID));
|
||||
|
||||
user.CharacterIdentification = null;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await base.OnDisconnectedAsync(exception);
|
||||
}
|
||||
|
||||
public static string GenerateRandomString(int length, string allowableChars = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(allowableChars))
|
||||
allowableChars = @"ABCDEFGHJKLMNPQRSTUVWXYZ0123456789";
|
||||
|
||||
// Generate random data
|
||||
var rnd = RandomNumberGenerator.GetBytes(length);
|
||||
|
||||
// Generate the output string
|
||||
var allowable = allowableChars.ToCharArray();
|
||||
var l = allowable.Length;
|
||||
var chars = new char[length];
|
||||
for (var i = 0; i < length; i++)
|
||||
chars[i] = allowable[rnd[i] % l];
|
||||
|
||||
return new string(chars);
|
||||
await base.OnDisconnectedAsync(exception).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
protected string AuthenticatedUserId => Context.User?.Claims?.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value ?? "Unknown";
|
||||
|
||||
protected async Task<Models.User> GetAuthenticatedUserUntrackedAsync()
|
||||
protected async Task<User> GetAuthenticatedUserUntrackedAsync()
|
||||
{
|
||||
return await _dbContext.Users.AsNoTrackingWithIdentityResolution().SingleAsync(u => u.UID == AuthenticatedUserId);
|
||||
return await _dbContext.Users.AsNoTrackingWithIdentityResolution().SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
using AspNetCoreRateLimit;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AspNetCoreRateLimit;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace MareSynchronosServer.Throttling;
|
||||
namespace MareSynchronosServer.Hubs;
|
||||
public class SignalRLimitFilter : IHubFilter
|
||||
{
|
||||
private readonly IRateLimitProcessor _processor;
|
||||
private readonly IHttpContextAccessor accessor;
|
||||
private readonly ILogger<SignalRLimitFilter> logger;
|
||||
private static SemaphoreSlim ConnectionLimiterSemaphore = new(20);
|
||||
private static SemaphoreSlim DisconnectLimiterSemaphore = new(20);
|
||||
private static readonly SemaphoreSlim ConnectionLimiterSemaphore = new(20);
|
||||
private static readonly SemaphoreSlim DisconnectLimiterSemaphore = new(20);
|
||||
|
||||
public SignalRLimitFilter(
|
||||
IOptions<IpRateLimitOptions> options, IProcessingStrategy processing, IIpPolicyStore policyStore, IHttpContextAccessor accessor, ILogger<SignalRLimitFilter> logger)
|
||||
@@ -37,25 +37,25 @@ public class SignalRLimitFilter : IHubFilter
|
||||
HttpVerb = "ws",
|
||||
ClientId = invocationContext.Context.UserIdentifier
|
||||
};
|
||||
foreach (var rule in await _processor.GetMatchingRulesAsync(client))
|
||||
foreach (var rule in await _processor.GetMatchingRulesAsync(client).ConfigureAwait(false))
|
||||
{
|
||||
var counter = await _processor.ProcessRequestAsync(client, rule);
|
||||
var counter = await _processor.ProcessRequestAsync(client, rule).ConfigureAwait(false);
|
||||
if (counter.Count > rule.Limit)
|
||||
{
|
||||
var authUserId = invocationContext.Context.User.Claims?.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value ?? "Unknown";
|
||||
var retry = counter.Timestamp.RetryAfterFrom(rule);
|
||||
logger.LogWarning($"Method rate limit triggered from {ip}/{authUserId}: {invocationContext.HubMethodName}");
|
||||
logger.LogWarning("Method rate limit triggered from {ip}/{authUserId}: {method}", ip, authUserId, invocationContext.HubMethodName);
|
||||
throw new HubException($"call limit {retry}");
|
||||
}
|
||||
}
|
||||
|
||||
return await next(invocationContext);
|
||||
return await next(invocationContext).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// Optional method
|
||||
public async Task OnConnectedAsync(HubLifetimeContext context, Func<HubLifetimeContext, Task> next)
|
||||
{
|
||||
await ConnectionLimiterSemaphore.WaitAsync();
|
||||
await ConnectionLimiterSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
var ip = accessor.GetIpAddress();
|
||||
var client = new ClientRequestIdentity
|
||||
{
|
||||
@@ -63,13 +63,13 @@ public class SignalRLimitFilter : IHubFilter
|
||||
Path = "Connect",
|
||||
HttpVerb = "ws",
|
||||
};
|
||||
foreach (var rule in await _processor.GetMatchingRulesAsync(client))
|
||||
foreach (var rule in await _processor.GetMatchingRulesAsync(client).ConfigureAwait(false))
|
||||
{
|
||||
var counter = await _processor.ProcessRequestAsync(client, rule);
|
||||
var counter = await _processor.ProcessRequestAsync(client, rule).ConfigureAwait(false);
|
||||
if (counter.Count > rule.Limit)
|
||||
{
|
||||
var retry = counter.Timestamp.RetryAfterFrom(rule);
|
||||
logger.LogWarning($"Connection rate limit triggered from {ip}");
|
||||
logger.LogWarning("Connection rate limit triggered from {ip}", ip);
|
||||
ConnectionLimiterSemaphore.Release();
|
||||
throw new HubException($"Connection rate limit {retry}");
|
||||
}
|
||||
@@ -77,8 +77,8 @@ public class SignalRLimitFilter : IHubFilter
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(250);
|
||||
await next(context);
|
||||
await Task.Delay(250).ConfigureAwait(false);
|
||||
await next(context).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -93,7 +93,7 @@ public class SignalRLimitFilter : IHubFilter
|
||||
public async Task OnDisconnectedAsync(
|
||||
HubLifetimeContext context, Exception exception, Func<HubLifetimeContext, Exception, Task> next)
|
||||
{
|
||||
await DisconnectLimiterSemaphore.WaitAsync();
|
||||
await DisconnectLimiterSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
if (exception != null)
|
||||
{
|
||||
logger.LogWarning(exception, "InitialException on OnDisconnectedAsync");
|
||||
@@ -101,8 +101,8 @@ public class SignalRLimitFilter : IHubFilter
|
||||
|
||||
try
|
||||
{
|
||||
await next(context, exception);
|
||||
await Task.Delay(250);
|
||||
await next(context, exception).ConfigureAwait(false);
|
||||
await Task.Delay(250).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -10,10 +10,15 @@
|
||||
<PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" />
|
||||
<PackageReference Include="Bazinga.AspNetCore.Authentication.Basic" Version="2.0.1" />
|
||||
<PackageReference Include="Ben.BlockingDetector" Version="0.0.4" />
|
||||
<PackageReference Include="Discord.Net" Version="3.7.2" />
|
||||
<PackageReference Include="EFCore.NamingConventions" Version="6.0.0" />
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.40.0" />
|
||||
<PackageReference Include="Grpc.Net.Client" Version="2.47.0" />
|
||||
<PackageReference Include="Karambolo.Extensions.Logging.File" Version="3.3.1" />
|
||||
<PackageReference Include="lz4net" Version="1.0.15.93" />
|
||||
<PackageReference Include="Meziantou.Analyzer" Version="1.0.715">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.8" />
|
||||
@@ -22,18 +27,12 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.6" />
|
||||
<PackageReference Include="prometheus-net" Version="6.0.0" />
|
||||
<PackageReference Include="prometheus-net.AspNetCore" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MareAPI\MareSynchronosAPI\MareSynchronos.API.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Migrations\" />
|
||||
<ProjectReference Include="..\MareSynchronosShared\MareSynchronosShared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Prometheus;
|
||||
|
||||
namespace MareSynchronosServer.Metrics
|
||||
{
|
||||
public class MareMetrics
|
||||
{
|
||||
public static readonly Counter InitializedConnections =
|
||||
Prometheus.Metrics.CreateCounter("mare_initialized_connections", "Initialized Connections");
|
||||
public static readonly Gauge Connections =
|
||||
Prometheus.Metrics.CreateGauge("mare_unauthorized_connections", "Unauthorized Connections");
|
||||
public static readonly Gauge AuthorizedConnections =
|
||||
Prometheus.Metrics.CreateGauge("mare_authorized_connections", "Authorized Connections");
|
||||
public static readonly Gauge AvailableWorkerThreads = Prometheus.Metrics.CreateGauge("mare_available_threadpool", "Available Threadpool Workers");
|
||||
public static readonly Gauge AvailableIOWorkerThreads = Prometheus.Metrics.CreateGauge("mare_available_threadpool_io", "Available Threadpool IO Workers");
|
||||
|
||||
public static readonly Gauge UsersRegistered = Prometheus.Metrics.CreateGauge("mare_users_registered", "Total Registrations");
|
||||
|
||||
public static readonly Gauge Pairs = Prometheus.Metrics.CreateGauge("mare_pairs", "Total Pairs");
|
||||
public static readonly Gauge PairsPaused = Prometheus.Metrics.CreateGauge("mare_pairs_paused", "Total Paused Pairs");
|
||||
|
||||
public static readonly Gauge FilesTotal = Prometheus.Metrics.CreateGauge("mare_files", "Total uploaded files");
|
||||
public static readonly Gauge FilesTotalSize =
|
||||
Prometheus.Metrics.CreateGauge("mare_files_size", "Total uploaded files (bytes)");
|
||||
|
||||
public static readonly Counter UserPushData = Prometheus.Metrics.CreateCounter("mare_user_push", "Users pushing data");
|
||||
public static readonly Counter UserPushDataTo =
|
||||
Prometheus.Metrics.CreateCounter("mare_user_push_to", "Users Receiving Data");
|
||||
|
||||
public static readonly Counter UserDownloadedFiles =
|
||||
Prometheus.Metrics.CreateCounter("mare_user_downloaded_files", "Total Downloaded Files by Users");
|
||||
public static readonly Counter UserDownloadedFilesSize =
|
||||
Prometheus.Metrics.CreateCounter("mare_user_downloaded_files_size", "Total Downloaded Files Size by Users");
|
||||
|
||||
public static readonly Gauge
|
||||
CPUUsage = Prometheus.Metrics.CreateGauge("mare_cpu_usage", "Total calculated CPU usage in %");
|
||||
public static readonly Gauge RAMUsage =
|
||||
Prometheus.Metrics.CreateGauge("mare_ram_usage", "Total calculated RAM usage in bytes for Mare + MSSQL");
|
||||
public static readonly Gauge NetworkOut = Prometheus.Metrics.CreateGauge("mare_network_out", "Network out in byte/s");
|
||||
public static readonly Gauge NetworkIn = Prometheus.Metrics.CreateGauge("mare_network_in", "Network in in byte/s");
|
||||
public static readonly Counter AuthenticationRequests = Prometheus.Metrics.CreateCounter("mare_auth_requests", "Mare Authentication Requests");
|
||||
public static readonly Counter AuthenticationCacheHits = Prometheus.Metrics.CreateCounter("mare_auth_requests_cachehit", "Mare Authentication Requests Cache Hits");
|
||||
public static readonly Counter AuthenticationFailures = Prometheus.Metrics.CreateCounter("mare_auth_requests_fail", "Mare Authentication Requests Failed");
|
||||
public static readonly Counter AuthenticationSuccesses = Prometheus.Metrics.CreateCounter("mare_auth_requests_success", "Mare Authentication Requests Success");
|
||||
|
||||
public static void InitializeMetrics(MareDbContext dbContext, IConfiguration configuration)
|
||||
{
|
||||
UsersRegistered.IncTo(dbContext.Users.Count());
|
||||
Pairs.IncTo(dbContext.ClientPairs.Count());
|
||||
PairsPaused.IncTo(dbContext.ClientPairs.Count(p => p.IsPaused));
|
||||
FilesTotal.IncTo(dbContext.Files.Count());
|
||||
FilesTotalSize.IncTo(Directory.EnumerateFiles(configuration["CacheDirectory"]).Sum(f => new FileInfo(f).Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
[DbContext(typeof(MareDbContext))]
|
||||
[Migration("20220731210149_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.Property<string>("HashedKey")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("hashed_key");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("HashedKey")
|
||||
.HasName("pk_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_auth_user_uid");
|
||||
|
||||
b.ToTable("Auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Banned", b =>
|
||||
{
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("reason");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("CharacterIdentification")
|
||||
.HasName("pk_banned_users");
|
||||
|
||||
b.ToTable("BannedUsers", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.Property<string>("UserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.Property<string>("OtherUserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("other_user_uid");
|
||||
|
||||
b.Property<bool>("AllowReceivingMessages")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("allow_receiving_messages");
|
||||
|
||||
b.Property<bool>("IsPaused")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_paused");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UserUID", "OtherUserUID")
|
||||
.HasName("pk_client_pairs");
|
||||
|
||||
b.HasIndex("OtherUserUID")
|
||||
.HasDatabaseName("ix_client_pairs_other_user_uid");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_client_pairs_user_uid");
|
||||
|
||||
b.ToTable("ClientPairs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.Property<bool>("Uploaded")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("uploaded");
|
||||
|
||||
b.Property<string>("UploaderUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uploader_uid");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_file_caches");
|
||||
|
||||
b.HasIndex("UploaderUID")
|
||||
.HasDatabaseName("ix_file_caches_uploader_uid");
|
||||
|
||||
b.ToTable("FileCaches", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ForbiddenUploadEntry", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<string>("ForbiddenBy")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("forbidden_by");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_forbidden_upload_entries");
|
||||
|
||||
b.ToTable("ForbiddenUploadEntries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
||||
{
|
||||
b.Property<string>("UID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uid");
|
||||
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<bool>("IsAdmin")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_admin");
|
||||
|
||||
b.Property<bool>("IsModerator")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_moderator");
|
||||
|
||||
b.Property<DateTime>("LastLoggedIn")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_logged_in");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UID")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("CharacterIdentification")
|
||||
.HasDatabaseName("ix_users_character_identification");
|
||||
|
||||
b.ToTable("Users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_auth_users_user_uid");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("OtherUserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_other_user_uid");
|
||||
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_user_uid");
|
||||
|
||||
b.Navigation("OtherUser");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "Uploader")
|
||||
.WithMany()
|
||||
.HasForeignKey("UploaderUID")
|
||||
.HasConstraintName("fk_file_caches_users_uploader_uid");
|
||||
|
||||
b.Navigation("Uploader");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BannedUsers",
|
||||
columns: table => new
|
||||
{
|
||||
character_identification = table.Column<string>(type: "text", nullable: false),
|
||||
reason = table.Column<string>(type: "text", nullable: true),
|
||||
timestamp = table.Column<byte[]>(type: "bytea", rowVersion: true, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_banned_users", x => x.character_identification);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ForbiddenUploadEntries",
|
||||
columns: table => new
|
||||
{
|
||||
hash = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
|
||||
forbidden_by = table.Column<string>(type: "text", nullable: true),
|
||||
timestamp = table.Column<byte[]>(type: "bytea", rowVersion: true, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_forbidden_upload_entries", x => x.hash);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
uid = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: false),
|
||||
character_identification = table.Column<string>(type: "text", nullable: true),
|
||||
timestamp = table.Column<byte[]>(type: "bytea", rowVersion: true, nullable: true),
|
||||
is_moderator = table.Column<bool>(type: "boolean", nullable: false),
|
||||
is_admin = table.Column<bool>(type: "boolean", nullable: false),
|
||||
last_logged_in = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_users", x => x.uid);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Auth",
|
||||
columns: table => new
|
||||
{
|
||||
hashed_key = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
user_uid = table.Column<string>(type: "character varying(10)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_auth", x => x.hashed_key);
|
||||
table.ForeignKey(
|
||||
name: "fk_auth_users_user_uid",
|
||||
column: x => x.user_uid,
|
||||
principalTable: "Users",
|
||||
principalColumn: "uid");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ClientPairs",
|
||||
columns: table => new
|
||||
{
|
||||
user_uid = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: false),
|
||||
other_user_uid = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: false),
|
||||
is_paused = table.Column<bool>(type: "boolean", nullable: false),
|
||||
allow_receiving_messages = table.Column<bool>(type: "boolean", nullable: false),
|
||||
timestamp = table.Column<byte[]>(type: "bytea", rowVersion: true, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_client_pairs", x => new { x.user_uid, x.other_user_uid });
|
||||
table.ForeignKey(
|
||||
name: "fk_client_pairs_users_other_user_uid",
|
||||
column: x => x.other_user_uid,
|
||||
principalTable: "Users",
|
||||
principalColumn: "uid",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_client_pairs_users_user_uid",
|
||||
column: x => x.user_uid,
|
||||
principalTable: "Users",
|
||||
principalColumn: "uid",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "FileCaches",
|
||||
columns: table => new
|
||||
{
|
||||
hash = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
|
||||
uploader_uid = table.Column<string>(type: "character varying(10)", nullable: true),
|
||||
uploaded = table.Column<bool>(type: "boolean", nullable: false),
|
||||
timestamp = table.Column<byte[]>(type: "bytea", rowVersion: true, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_file_caches", x => x.hash);
|
||||
table.ForeignKey(
|
||||
name: "fk_file_caches_users_uploader_uid",
|
||||
column: x => x.uploader_uid,
|
||||
principalTable: "Users",
|
||||
principalColumn: "uid");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_auth_user_uid",
|
||||
table: "Auth",
|
||||
column: "user_uid");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_client_pairs_other_user_uid",
|
||||
table: "ClientPairs",
|
||||
column: "other_user_uid");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_client_pairs_user_uid",
|
||||
table: "ClientPairs",
|
||||
column: "user_uid");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_file_caches_uploader_uid",
|
||||
table: "FileCaches",
|
||||
column: "uploader_uid");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_users_character_identification",
|
||||
table: "Users",
|
||||
column: "character_identification");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Auth");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BannedUsers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ClientPairs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "FileCaches");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ForbiddenUploadEntries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
[DbContext(typeof(MareDbContext))]
|
||||
[Migration("20220731211419_RenameLowerSnakeCase")]
|
||||
partial class RenameLowerSnakeCase
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.Property<string>("HashedKey")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("hashed_key");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("HashedKey")
|
||||
.HasName("pk_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_auth_user_uid");
|
||||
|
||||
b.ToTable("auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Banned", b =>
|
||||
{
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("reason");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("CharacterIdentification")
|
||||
.HasName("pk_banned_users");
|
||||
|
||||
b.ToTable("banned_users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.Property<string>("UserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.Property<string>("OtherUserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("other_user_uid");
|
||||
|
||||
b.Property<bool>("AllowReceivingMessages")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("allow_receiving_messages");
|
||||
|
||||
b.Property<bool>("IsPaused")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_paused");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UserUID", "OtherUserUID")
|
||||
.HasName("pk_client_pairs");
|
||||
|
||||
b.HasIndex("OtherUserUID")
|
||||
.HasDatabaseName("ix_client_pairs_other_user_uid");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_client_pairs_user_uid");
|
||||
|
||||
b.ToTable("client_pairs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.Property<bool>("Uploaded")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("uploaded");
|
||||
|
||||
b.Property<string>("UploaderUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uploader_uid");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_file_caches");
|
||||
|
||||
b.HasIndex("UploaderUID")
|
||||
.HasDatabaseName("ix_file_caches_uploader_uid");
|
||||
|
||||
b.ToTable("file_caches", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ForbiddenUploadEntry", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<string>("ForbiddenBy")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("forbidden_by");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_forbidden_upload_entries");
|
||||
|
||||
b.ToTable("forbidden_upload_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
||||
{
|
||||
b.Property<string>("UID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uid");
|
||||
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<bool>("IsAdmin")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_admin");
|
||||
|
||||
b.Property<bool>("IsModerator")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_moderator");
|
||||
|
||||
b.Property<DateTime>("LastLoggedIn")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_logged_in");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UID")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("CharacterIdentification")
|
||||
.HasDatabaseName("ix_users_character_identification");
|
||||
|
||||
b.ToTable("users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_auth_users_user_temp_id");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("OtherUserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_other_user_temp_id1");
|
||||
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_user_temp_id2");
|
||||
|
||||
b.Navigation("OtherUser");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "Uploader")
|
||||
.WithMany()
|
||||
.HasForeignKey("UploaderUID")
|
||||
.HasConstraintName("fk_file_caches_users_uploader_uid");
|
||||
|
||||
b.Navigation("Uploader");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
public partial class RenameLowerSnakeCase : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_auth_users_user_uid",
|
||||
table: "Auth");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_client_pairs_users_other_user_uid",
|
||||
table: "ClientPairs");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_client_pairs_users_user_uid",
|
||||
table: "ClientPairs");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "Users",
|
||||
newName: "users");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "Auth",
|
||||
newName: "auth");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ForbiddenUploadEntries",
|
||||
newName: "forbidden_upload_entries");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "FileCaches",
|
||||
newName: "file_caches");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "ClientPairs",
|
||||
newName: "client_pairs");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "BannedUsers",
|
||||
newName: "banned_users");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_auth_users_user_temp_id",
|
||||
table: "auth",
|
||||
column: "user_uid",
|
||||
principalTable: "users",
|
||||
principalColumn: "uid");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_client_pairs_users_other_user_temp_id1",
|
||||
table: "client_pairs",
|
||||
column: "other_user_uid",
|
||||
principalTable: "users",
|
||||
principalColumn: "uid",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_client_pairs_users_user_temp_id2",
|
||||
table: "client_pairs",
|
||||
column: "user_uid",
|
||||
principalTable: "users",
|
||||
principalColumn: "uid",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_auth_users_user_temp_id",
|
||||
table: "auth");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_client_pairs_users_other_user_temp_id1",
|
||||
table: "client_pairs");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_client_pairs_users_user_temp_id2",
|
||||
table: "client_pairs");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "users",
|
||||
newName: "Users");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "auth",
|
||||
newName: "Auth");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "forbidden_upload_entries",
|
||||
newName: "ForbiddenUploadEntries");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "file_caches",
|
||||
newName: "FileCaches");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "client_pairs",
|
||||
newName: "ClientPairs");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "banned_users",
|
||||
newName: "BannedUsers");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_auth_users_user_uid",
|
||||
table: "Auth",
|
||||
column: "user_uid",
|
||||
principalTable: "Users",
|
||||
principalColumn: "uid");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_client_pairs_users_other_user_uid",
|
||||
table: "ClientPairs",
|
||||
column: "other_user_uid",
|
||||
principalTable: "Users",
|
||||
principalColumn: "uid",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_client_pairs_users_user_uid",
|
||||
table: "ClientPairs",
|
||||
column: "user_uid",
|
||||
principalTable: "Users",
|
||||
principalColumn: "uid",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
[DbContext(typeof(MareDbContext))]
|
||||
[Migration("20220801121419_AddLodestoneAuth")]
|
||||
partial class AddLodestoneAuth
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.Property<string>("HashedKey")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("hashed_key");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("HashedKey")
|
||||
.HasName("pk_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_auth_user_uid");
|
||||
|
||||
b.ToTable("auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Banned", b =>
|
||||
{
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("reason");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("CharacterIdentification")
|
||||
.HasName("pk_banned_users");
|
||||
|
||||
b.ToTable("banned_users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.Property<string>("UserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.Property<string>("OtherUserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("other_user_uid");
|
||||
|
||||
b.Property<bool>("AllowReceivingMessages")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("allow_receiving_messages");
|
||||
|
||||
b.Property<bool>("IsPaused")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_paused");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UserUID", "OtherUserUID")
|
||||
.HasName("pk_client_pairs");
|
||||
|
||||
b.HasIndex("OtherUserUID")
|
||||
.HasDatabaseName("ix_client_pairs_other_user_uid");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_client_pairs_user_uid");
|
||||
|
||||
b.ToTable("client_pairs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.Property<bool>("Uploaded")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("uploaded");
|
||||
|
||||
b.Property<string>("UploaderUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uploader_uid");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_file_caches");
|
||||
|
||||
b.HasIndex("UploaderUID")
|
||||
.HasDatabaseName("ix_file_caches_uploader_uid");
|
||||
|
||||
b.ToTable("file_caches", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ForbiddenUploadEntry", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<string>("ForbiddenBy")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("forbidden_by");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_forbidden_upload_entries");
|
||||
|
||||
b.ToTable("forbidden_upload_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.Property<decimal>("DiscordId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("discord_id");
|
||||
|
||||
b.Property<string>("HashedLodestoneId")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("hashed_lodestone_id");
|
||||
|
||||
b.Property<string>("LodestoneAuthString")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("lodestone_auth_string");
|
||||
|
||||
b.Property<DateTime>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("started_at");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("DiscordId")
|
||||
.HasName("pk_lodestone_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_lodestone_auth_user_uid");
|
||||
|
||||
b.ToTable("lodestone_auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
||||
{
|
||||
b.Property<string>("UID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uid");
|
||||
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<bool>("IsAdmin")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_admin");
|
||||
|
||||
b.Property<bool>("IsModerator")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_moderator");
|
||||
|
||||
b.Property<DateTime>("LastLoggedIn")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_logged_in");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UID")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("CharacterIdentification")
|
||||
.HasDatabaseName("ix_users_character_identification");
|
||||
|
||||
b.ToTable("users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_auth_users_user_temp_id");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("OtherUserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_other_user_temp_id1");
|
||||
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_user_temp_id2");
|
||||
|
||||
b.Navigation("OtherUser");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "Uploader")
|
||||
.WithMany()
|
||||
.HasForeignKey("UploaderUID")
|
||||
.HasConstraintName("fk_file_caches_users_uploader_uid");
|
||||
|
||||
b.Navigation("Uploader");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_lodestone_auth_users_user_uid");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
public partial class AddLodestoneAuth : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "lodestone_auth",
|
||||
columns: table => new
|
||||
{
|
||||
discord_id = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
||||
hashed_lodestone_id = table.Column<string>(type: "text", nullable: true),
|
||||
lodestone_auth_string = table.Column<string>(type: "text", nullable: true),
|
||||
user_uid = table.Column<string>(type: "character varying(10)", nullable: true),
|
||||
started_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_lodestone_auth", x => x.discord_id);
|
||||
table.ForeignKey(
|
||||
name: "fk_lodestone_auth_users_user_uid",
|
||||
column: x => x.user_uid,
|
||||
principalTable: "users",
|
||||
principalColumn: "uid");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_lodestone_auth_user_uid",
|
||||
table: "lodestone_auth",
|
||||
column: "user_uid");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "lodestone_auth");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
[DbContext(typeof(MareDbContext))]
|
||||
[Migration("20220801122103_AddNullableLodestoneAuthProperties")]
|
||||
partial class AddNullableLodestoneAuthProperties
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.Property<string>("HashedKey")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("hashed_key");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("HashedKey")
|
||||
.HasName("pk_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_auth_user_uid");
|
||||
|
||||
b.ToTable("auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Banned", b =>
|
||||
{
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("reason");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("CharacterIdentification")
|
||||
.HasName("pk_banned_users");
|
||||
|
||||
b.ToTable("banned_users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.Property<string>("UserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.Property<string>("OtherUserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("other_user_uid");
|
||||
|
||||
b.Property<bool>("AllowReceivingMessages")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("allow_receiving_messages");
|
||||
|
||||
b.Property<bool>("IsPaused")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_paused");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UserUID", "OtherUserUID")
|
||||
.HasName("pk_client_pairs");
|
||||
|
||||
b.HasIndex("OtherUserUID")
|
||||
.HasDatabaseName("ix_client_pairs_other_user_uid");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_client_pairs_user_uid");
|
||||
|
||||
b.ToTable("client_pairs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.Property<bool>("Uploaded")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("uploaded");
|
||||
|
||||
b.Property<string>("UploaderUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uploader_uid");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_file_caches");
|
||||
|
||||
b.HasIndex("UploaderUID")
|
||||
.HasDatabaseName("ix_file_caches_uploader_uid");
|
||||
|
||||
b.ToTable("file_caches", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ForbiddenUploadEntry", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<string>("ForbiddenBy")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("forbidden_by");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_forbidden_upload_entries");
|
||||
|
||||
b.ToTable("forbidden_upload_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.Property<decimal>("DiscordId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("discord_id");
|
||||
|
||||
b.Property<string>("HashedLodestoneId")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("hashed_lodestone_id");
|
||||
|
||||
b.Property<string>("LodestoneAuthString")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("lodestone_auth_string");
|
||||
|
||||
b.Property<DateTime?>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("started_at");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("DiscordId")
|
||||
.HasName("pk_lodestone_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_lodestone_auth_user_uid");
|
||||
|
||||
b.ToTable("lodestone_auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
||||
{
|
||||
b.Property<string>("UID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uid");
|
||||
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<bool>("IsAdmin")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_admin");
|
||||
|
||||
b.Property<bool>("IsModerator")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_moderator");
|
||||
|
||||
b.Property<DateTime>("LastLoggedIn")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_logged_in");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UID")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("CharacterIdentification")
|
||||
.HasDatabaseName("ix_users_character_identification");
|
||||
|
||||
b.ToTable("users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_auth_users_user_temp_id");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("OtherUserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_other_user_temp_id1");
|
||||
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_user_temp_id2");
|
||||
|
||||
b.Navigation("OtherUser");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "Uploader")
|
||||
.WithMany()
|
||||
.HasForeignKey("UploaderUID")
|
||||
.HasConstraintName("fk_file_caches_users_uploader_uid");
|
||||
|
||||
b.Navigation("Uploader");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_lodestone_auth_users_user_uid");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
public partial class AddNullableLodestoneAuthProperties : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "started_at",
|
||||
table: "lodestone_auth",
|
||||
type: "timestamp with time zone",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "timestamp with time zone");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "started_at",
|
||||
table: "lodestone_auth",
|
||||
type: "timestamp with time zone",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "timestamp with time zone",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,295 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
[DbContext(typeof(MareDbContext))]
|
||||
[Migration("20220806103053_AddBannedRegistrations")]
|
||||
partial class AddBannedRegistrations
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.Property<string>("HashedKey")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("hashed_key");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("HashedKey")
|
||||
.HasName("pk_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_auth_user_uid");
|
||||
|
||||
b.ToTable("auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Banned", b =>
|
||||
{
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("reason");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("CharacterIdentification")
|
||||
.HasName("pk_banned_users");
|
||||
|
||||
b.ToTable("banned_users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.BannedRegistrations", b =>
|
||||
{
|
||||
b.Property<string>("DiscordIdOrLodestoneAuth")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("discord_id_or_lodestone_auth");
|
||||
|
||||
b.HasKey("DiscordIdOrLodestoneAuth")
|
||||
.HasName("pk_banned_registrations");
|
||||
|
||||
b.ToTable("banned_registrations", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.Property<string>("UserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.Property<string>("OtherUserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("other_user_uid");
|
||||
|
||||
b.Property<bool>("AllowReceivingMessages")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("allow_receiving_messages");
|
||||
|
||||
b.Property<bool>("IsPaused")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_paused");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UserUID", "OtherUserUID")
|
||||
.HasName("pk_client_pairs");
|
||||
|
||||
b.HasIndex("OtherUserUID")
|
||||
.HasDatabaseName("ix_client_pairs_other_user_uid");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_client_pairs_user_uid");
|
||||
|
||||
b.ToTable("client_pairs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.Property<bool>("Uploaded")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("uploaded");
|
||||
|
||||
b.Property<string>("UploaderUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uploader_uid");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_file_caches");
|
||||
|
||||
b.HasIndex("UploaderUID")
|
||||
.HasDatabaseName("ix_file_caches_uploader_uid");
|
||||
|
||||
b.ToTable("file_caches", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ForbiddenUploadEntry", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<string>("ForbiddenBy")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("forbidden_by");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_forbidden_upload_entries");
|
||||
|
||||
b.ToTable("forbidden_upload_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.Property<decimal>("DiscordId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("discord_id");
|
||||
|
||||
b.Property<string>("HashedLodestoneId")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("hashed_lodestone_id");
|
||||
|
||||
b.Property<string>("LodestoneAuthString")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("lodestone_auth_string");
|
||||
|
||||
b.Property<DateTime?>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("started_at");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("DiscordId")
|
||||
.HasName("pk_lodestone_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_lodestone_auth_user_uid");
|
||||
|
||||
b.ToTable("lodestone_auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
||||
{
|
||||
b.Property<string>("UID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uid");
|
||||
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<bool>("IsAdmin")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_admin");
|
||||
|
||||
b.Property<bool>("IsModerator")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_moderator");
|
||||
|
||||
b.Property<DateTime>("LastLoggedIn")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_logged_in");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UID")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("CharacterIdentification")
|
||||
.HasDatabaseName("ix_users_character_identification");
|
||||
|
||||
b.ToTable("users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_auth_users_user_temp_id");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("OtherUserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_other_user_temp_id1");
|
||||
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_user_temp_id2");
|
||||
|
||||
b.Navigation("OtherUser");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "Uploader")
|
||||
.WithMany()
|
||||
.HasForeignKey("UploaderUID")
|
||||
.HasConstraintName("fk_file_caches_users_uploader_uid");
|
||||
|
||||
b.Navigation("Uploader");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_lodestone_auth_users_user_uid");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
public partial class AddBannedRegistrations : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "banned_registrations",
|
||||
columns: table => new
|
||||
{
|
||||
discord_id_or_lodestone_auth = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_banned_registrations", x => x.discord_id_or_lodestone_auth);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "banned_registrations");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,302 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
[DbContext(typeof(MareDbContext))]
|
||||
[Migration("20220816170426_SetMaxLimitForStrings")]
|
||||
partial class SetMaxLimitForStrings
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.Property<string>("HashedKey")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("hashed_key");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("HashedKey")
|
||||
.HasName("pk_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_auth_user_uid");
|
||||
|
||||
b.ToTable("auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Banned", b =>
|
||||
{
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("reason");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("CharacterIdentification")
|
||||
.HasName("pk_banned_users");
|
||||
|
||||
b.ToTable("banned_users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.BannedRegistrations", b =>
|
||||
{
|
||||
b.Property<string>("DiscordIdOrLodestoneAuth")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("discord_id_or_lodestone_auth");
|
||||
|
||||
b.HasKey("DiscordIdOrLodestoneAuth")
|
||||
.HasName("pk_banned_registrations");
|
||||
|
||||
b.ToTable("banned_registrations", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.Property<string>("UserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.Property<string>("OtherUserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("other_user_uid");
|
||||
|
||||
b.Property<bool>("AllowReceivingMessages")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("allow_receiving_messages");
|
||||
|
||||
b.Property<bool>("IsPaused")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_paused");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UserUID", "OtherUserUID")
|
||||
.HasName("pk_client_pairs");
|
||||
|
||||
b.HasIndex("OtherUserUID")
|
||||
.HasDatabaseName("ix_client_pairs_other_user_uid");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_client_pairs_user_uid");
|
||||
|
||||
b.ToTable("client_pairs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.Property<bool>("Uploaded")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("uploaded");
|
||||
|
||||
b.Property<string>("UploaderUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uploader_uid");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_file_caches");
|
||||
|
||||
b.HasIndex("UploaderUID")
|
||||
.HasDatabaseName("ix_file_caches_uploader_uid");
|
||||
|
||||
b.ToTable("file_caches", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ForbiddenUploadEntry", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<string>("ForbiddenBy")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("forbidden_by");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_forbidden_upload_entries");
|
||||
|
||||
b.ToTable("forbidden_upload_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.Property<decimal>("DiscordId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("discord_id");
|
||||
|
||||
b.Property<string>("HashedLodestoneId")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("hashed_lodestone_id");
|
||||
|
||||
b.Property<string>("LodestoneAuthString")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("lodestone_auth_string");
|
||||
|
||||
b.Property<DateTime?>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("started_at");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("DiscordId")
|
||||
.HasName("pk_lodestone_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_lodestone_auth_user_uid");
|
||||
|
||||
b.ToTable("lodestone_auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
||||
{
|
||||
b.Property<string>("UID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uid");
|
||||
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<bool>("IsAdmin")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_admin");
|
||||
|
||||
b.Property<bool>("IsModerator")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_moderator");
|
||||
|
||||
b.Property<DateTime>("LastLoggedIn")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_logged_in");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UID")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("CharacterIdentification")
|
||||
.HasDatabaseName("ix_users_character_identification");
|
||||
|
||||
b.ToTable("users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_auth_users_user_temp_id");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("OtherUserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_other_user_temp_id1");
|
||||
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_user_temp_id2");
|
||||
|
||||
b.Navigation("OtherUser");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "Uploader")
|
||||
.WithMany()
|
||||
.HasForeignKey("UploaderUID")
|
||||
.HasConstraintName("fk_file_caches_users_uploader_uid");
|
||||
|
||||
b.Navigation("Uploader");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_lodestone_auth_users_user_uid");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
public partial class SetMaxLimitForStrings : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "character_identification",
|
||||
table: "users",
|
||||
type: "character varying(100)",
|
||||
maxLength: 100,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "lodestone_auth_string",
|
||||
table: "lodestone_auth",
|
||||
type: "character varying(100)",
|
||||
maxLength: 100,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "hashed_lodestone_id",
|
||||
table: "lodestone_auth",
|
||||
type: "character varying(100)",
|
||||
maxLength: 100,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "forbidden_by",
|
||||
table: "forbidden_upload_entries",
|
||||
type: "character varying(100)",
|
||||
maxLength: 100,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "character_identification",
|
||||
table: "banned_users",
|
||||
type: "character varying(100)",
|
||||
maxLength: 100,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "discord_id_or_lodestone_auth",
|
||||
table: "banned_registrations",
|
||||
type: "character varying(100)",
|
||||
maxLength: 100,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "character_identification",
|
||||
table: "users",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(100)",
|
||||
oldMaxLength: 100,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "lodestone_auth_string",
|
||||
table: "lodestone_auth",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(100)",
|
||||
oldMaxLength: 100,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "hashed_lodestone_id",
|
||||
table: "lodestone_auth",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(100)",
|
||||
oldMaxLength: 100,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "forbidden_by",
|
||||
table: "forbidden_upload_entries",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(100)",
|
||||
oldMaxLength: 100,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "character_identification",
|
||||
table: "banned_users",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(100)",
|
||||
oldMaxLength: 100);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "discord_id_or_lodestone_auth",
|
||||
table: "banned_registrations",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(100)",
|
||||
oldMaxLength: 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
[DbContext(typeof(MareDbContext))]
|
||||
partial class MareDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.Property<string>("HashedKey")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("hashed_key");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("HashedKey")
|
||||
.HasName("pk_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_auth_user_uid");
|
||||
|
||||
b.ToTable("auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Banned", b =>
|
||||
{
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("reason");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("CharacterIdentification")
|
||||
.HasName("pk_banned_users");
|
||||
|
||||
b.ToTable("banned_users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.BannedRegistrations", b =>
|
||||
{
|
||||
b.Property<string>("DiscordIdOrLodestoneAuth")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("discord_id_or_lodestone_auth");
|
||||
|
||||
b.HasKey("DiscordIdOrLodestoneAuth")
|
||||
.HasName("pk_banned_registrations");
|
||||
|
||||
b.ToTable("banned_registrations", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.Property<string>("UserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.Property<string>("OtherUserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("other_user_uid");
|
||||
|
||||
b.Property<bool>("AllowReceivingMessages")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("allow_receiving_messages");
|
||||
|
||||
b.Property<bool>("IsPaused")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_paused");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UserUID", "OtherUserUID")
|
||||
.HasName("pk_client_pairs");
|
||||
|
||||
b.HasIndex("OtherUserUID")
|
||||
.HasDatabaseName("ix_client_pairs_other_user_uid");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_client_pairs_user_uid");
|
||||
|
||||
b.ToTable("client_pairs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.Property<bool>("Uploaded")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("uploaded");
|
||||
|
||||
b.Property<string>("UploaderUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uploader_uid");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_file_caches");
|
||||
|
||||
b.HasIndex("UploaderUID")
|
||||
.HasDatabaseName("ix_file_caches_uploader_uid");
|
||||
|
||||
b.ToTable("file_caches", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ForbiddenUploadEntry", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("hash");
|
||||
|
||||
b.Property<string>("ForbiddenBy")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("forbidden_by");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("Hash")
|
||||
.HasName("pk_forbidden_upload_entries");
|
||||
|
||||
b.ToTable("forbidden_upload_entries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.Property<decimal>("DiscordId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("discord_id");
|
||||
|
||||
b.Property<string>("HashedLodestoneId")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("hashed_lodestone_id");
|
||||
|
||||
b.Property<string>("LodestoneAuthString")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("lodestone_auth_string");
|
||||
|
||||
b.Property<DateTime?>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("started_at");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("user_uid");
|
||||
|
||||
b.HasKey("DiscordId")
|
||||
.HasName("pk_lodestone_auth");
|
||||
|
||||
b.HasIndex("UserUID")
|
||||
.HasDatabaseName("ix_lodestone_auth_user_uid");
|
||||
|
||||
b.ToTable("lodestone_auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
||||
{
|
||||
b.Property<string>("UID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("uid");
|
||||
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("character_identification");
|
||||
|
||||
b.Property<bool>("IsAdmin")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_admin");
|
||||
|
||||
b.Property<bool>("IsModerator")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_moderator");
|
||||
|
||||
b.Property<DateTime>("LastLoggedIn")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_logged_in");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("timestamp");
|
||||
|
||||
b.HasKey("UID")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("CharacterIdentification")
|
||||
.HasDatabaseName("ix_users_character_identification");
|
||||
|
||||
b.ToTable("users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_auth_users_user_temp_id");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("OtherUserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_other_user_temp_id1");
|
||||
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_client_pairs_users_user_temp_id2");
|
||||
|
||||
b.Navigation("OtherUser");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "Uploader")
|
||||
.WithMany()
|
||||
.HasForeignKey("UploaderUID")
|
||||
.HasConstraintName("fk_file_caches_users_uploader_uid");
|
||||
|
||||
b.Navigation("Uploader");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.LodeStoneAuth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.HasConstraintName("fk_lodestone_auth_users_user_uid");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MareSynchronosServer.Models
|
||||
{
|
||||
public class Auth
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(64)]
|
||||
public string HashedKey { get; set; }
|
||||
|
||||
public string UserUID { get; set; }
|
||||
public User User { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MareSynchronosServer.Models
|
||||
{
|
||||
public class Banned
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(100)]
|
||||
public string CharacterIdentification { get; set; }
|
||||
public string Reason { get; set; }
|
||||
[Timestamp]
|
||||
public byte[] Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MareSynchronosServer.Models
|
||||
{
|
||||
public class BannedRegistrations
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(100)]
|
||||
public string DiscordIdOrLodestoneAuth { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MareSynchronosServer.Models
|
||||
{
|
||||
public class ClientPair
|
||||
{
|
||||
[MaxLength(10)]
|
||||
public string UserUID { get; set; }
|
||||
public User User { get; set; }
|
||||
[MaxLength(10)]
|
||||
public string OtherUserUID { get; set; }
|
||||
public User OtherUser { get; set; }
|
||||
public bool IsPaused { get; set; }
|
||||
public bool AllowReceivingMessages { get; set; } = false;
|
||||
[Timestamp]
|
||||
public byte[] Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MareSynchronosServer.Models
|
||||
{
|
||||
public class FileCache
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(40)]
|
||||
public string Hash { get; set; }
|
||||
[MaxLength(10)]
|
||||
public string UploaderUID { get; set; }
|
||||
public User Uploader { get; set; }
|
||||
public bool Uploaded { get; set; }
|
||||
[Timestamp]
|
||||
public byte[] Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MareSynchronosServer.Models
|
||||
{
|
||||
public class ForbiddenUploadEntry
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(40)]
|
||||
public string Hash { get; set; }
|
||||
[MaxLength(100)]
|
||||
public string ForbiddenBy { get; set; }
|
||||
[Timestamp]
|
||||
public byte[] Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MareSynchronosServer.Models
|
||||
{
|
||||
public class LodeStoneAuth
|
||||
{
|
||||
[Key]
|
||||
public ulong DiscordId { get; set; }
|
||||
[MaxLength(100)]
|
||||
public string HashedLodestoneId { get; set; }
|
||||
[MaxLength(100)]
|
||||
public string? LodestoneAuthString { get; set; }
|
||||
public User? User { get; set; }
|
||||
public DateTime? StartedAt { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MareSynchronosServer.Models
|
||||
{
|
||||
public class User
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(10)]
|
||||
public string UID { get; set; }
|
||||
[MaxLength(100)]
|
||||
public string CharacterIdentification { get; set; }
|
||||
[Timestamp]
|
||||
public byte[] Timestamp { get; set; }
|
||||
|
||||
public bool IsModerator { get; set; } = false;
|
||||
|
||||
public bool IsAdmin { get; set; } = false;
|
||||
|
||||
public DateTime LastLoggedIn { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,12 @@ using System;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Linq;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MareSynchronosServer.Metrics;
|
||||
using MareSynchronosServer.Models;
|
||||
using System.Collections.Generic;
|
||||
using MareSynchronosShared.Data;
|
||||
|
||||
namespace MareSynchronosServer
|
||||
{
|
||||
@@ -38,8 +36,6 @@ namespace MareSynchronosServer
|
||||
context.RemoveRange(unfinishedRegistrations);
|
||||
context.RemoveRange(looseFiles);
|
||||
context.SaveChanges();
|
||||
|
||||
MareMetrics.InitializeMetrics(context, services.GetRequiredService<IConfiguration>());
|
||||
}
|
||||
|
||||
if (args.Length == 0 || args[0] != "dry")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using MareSynchronos.API;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@@ -5,19 +6,16 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using MareSynchronosServer.Authentication;
|
||||
using MareSynchronosServer.Data;
|
||||
using MareSynchronosServer.Hubs;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Http.Connections;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Prometheus;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using MareSynchronosServer.Discord;
|
||||
using AspNetCoreRateLimit;
|
||||
using MareSynchronosServer.Throttling;
|
||||
using Ben.Diagnostics;
|
||||
using MareSynchronosShared.Authentication;
|
||||
using MareSynchronosShared.Data;
|
||||
using MareSynchronosShared.Protos;
|
||||
|
||||
namespace MareSynchronosServer
|
||||
{
|
||||
@@ -47,6 +45,15 @@ namespace MareSynchronosServer
|
||||
services.AddSingleton<IUserIdProvider, IdBasedUserIdProvider>();
|
||||
services.AddTransient(_ => Configuration);
|
||||
|
||||
services.AddGrpcClient<AuthService.AuthServiceClient>(c =>
|
||||
{
|
||||
c.Address = new Uri(Configuration.GetValue<string>("ServiceAddress"));
|
||||
});
|
||||
services.AddGrpcClient<MetricsService.MetricsServiceClient>(c =>
|
||||
{
|
||||
c.Address = new Uri(Configuration.GetValue<string>("ServiceAddress"));
|
||||
});
|
||||
|
||||
services.AddDbContextPool<MareDbContext>(options =>
|
||||
{
|
||||
options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"), builder =>
|
||||
@@ -56,15 +63,13 @@ namespace MareSynchronosServer
|
||||
options.EnableThreadSafetyChecks(false);
|
||||
}, Configuration.GetValue("DbContextPoolSize", 1024));
|
||||
|
||||
services.AddHostedService<CleanupService>();
|
||||
services.AddHostedService(provider => provider.GetService<SystemInfoService>());
|
||||
services.AddHostedService<DiscordBot>();
|
||||
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultScheme = SecretKeyAuthenticationHandler.AuthScheme;
|
||||
options.DefaultScheme = SecretKeyGrpcAuthenticationHandler.AuthScheme;
|
||||
})
|
||||
.AddScheme<AuthenticationSchemeOptions, SecretKeyAuthenticationHandler>(SecretKeyAuthenticationHandler.AuthScheme, options => { });
|
||||
.AddScheme<AuthenticationSchemeOptions, SecretKeyGrpcAuthenticationHandler>(SecretKeyGrpcAuthenticationHandler.AuthScheme, options => { });
|
||||
services.AddAuthorization(options => options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build());
|
||||
|
||||
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
|
||||
@@ -98,27 +103,13 @@ namespace MareSynchronosServer
|
||||
|
||||
app.UseIpRateLimiting();
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseHttpLogging();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseHttpMetrics();
|
||||
app.UseWebSockets();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
var metricServer = new KestrelMetricServer(4980);
|
||||
metricServer.Start();
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions()
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(Configuration["CacheDirectory"]),
|
||||
RequestPath = "/cache",
|
||||
ServeUnknownFileTypes = true
|
||||
});
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapHub<MareHub>(Api.Path, options =>
|
||||
|
||||
@@ -3,9 +3,10 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronosServer.Data;
|
||||
using MareSynchronosServer.Hubs;
|
||||
using MareSynchronosServer.Metrics;
|
||||
using MareSynchronosShared.Data;
|
||||
using MareSynchronosShared.Metrics;
|
||||
using MareSynchronosShared.Protos;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -40,12 +41,16 @@ public class SystemInfoService : IHostedService, IDisposable
|
||||
private void PushSystemInfo(object state)
|
||||
{
|
||||
ThreadPool.GetAvailableThreads(out int workerThreads, out int ioThreads);
|
||||
_logger.LogInformation($"ThreadPool: {workerThreads} workers available, {ioThreads} IO workers available");
|
||||
MareMetrics.AvailableWorkerThreads.Set(workerThreads);
|
||||
MareMetrics.AvailableIOWorkerThreads.Set(ioThreads);
|
||||
_logger.LogInformation("ThreadPool: {workerThreads} workers available, {ioThreads} IO workers available", workerThreads, ioThreads);
|
||||
|
||||
using var scope = _services.CreateScope();
|
||||
using var db = scope.ServiceProvider.GetService<MareDbContext>();
|
||||
using var db = scope.ServiceProvider.GetService<MareDbContext>()!;
|
||||
|
||||
var metricsServiceClient = scope.ServiceProvider.GetService<MetricsService.MetricsServiceClient>()!;
|
||||
_ = metricsServiceClient.SetGauge(new SetGaugeRequest()
|
||||
{ GaugeName = MetricsAPI.GaugeAvailableWorkerThreads, Value = workerThreads });
|
||||
_ = metricsServiceClient.SetGauge(new SetGaugeRequest()
|
||||
{ GaugeName = MetricsAPI.GaugeAvailableIOWorkerThreads, Value = ioThreads });
|
||||
|
||||
var users = db.Users.Count(c => c.CharacterIdentification != null);
|
||||
|
||||
|
||||
@@ -25,14 +25,9 @@
|
||||
},
|
||||
"DbContextPoolSize": 2000,
|
||||
"CdnFullUrl": "https://<url or ip to your server>/cache/",
|
||||
"FailedAuthForTempBan": 5,
|
||||
"TempBanDurationInMinutes": 30,
|
||||
"DiscordBotToken": "",
|
||||
"UnusedFileRetentionPeriodInDays": 7,
|
||||
"PurgeUnusedAccounts": true,
|
||||
"PurgeUnusedAccountsPeriodInDays": 14,
|
||||
"CacheDirectory": "G:\\ServerTest", // do not delete this key and set it to the path where the files will be stored
|
||||
"CacheSizeHardLimitInGiB": -1,
|
||||
"ServicesUrl": "http://localhost:5002",
|
||||
|
||||
"AllowedHosts": "*",
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
|
||||
Reference in New Issue
Block a user