From 83eb274bcbc580728fc8b626153eb3e67ac76a40 Mon Sep 17 00:00:00 2001 From: Loporrit <141286461+loporrit@users.noreply.github.com> Date: Thu, 24 Aug 2023 18:30:24 +0000 Subject: [PATCH] Initial Loporrit branding --- .../Hubs/MareHub.Groups.cs | 4 +- .../MareSynchronosServer/Hubs/MareHub.cs | 2 +- .../Discord/DiscordBot.cs | 12 +-- .../Discord/MareModule.cs | 96 ++++++++++++++++--- 4 files changed, 91 insertions(+), 23 deletions(-) diff --git a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Groups.cs b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Groups.cs index 436ebcf..0291253 100644 --- a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Groups.cs +++ b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Groups.cs @@ -208,11 +208,11 @@ public partial class MareHub } var gid = StringUtils.GenerateRandomString(12); - while (await _dbContext.Groups.AnyAsync(g => g.GID == "MSS-" + gid).ConfigureAwait(false)) + while (await _dbContext.Groups.AnyAsync(g => g.GID == "LSS-" + gid).ConfigureAwait(false)) { gid = StringUtils.GenerateRandomString(12); } - gid = "MSS-" + gid; + gid = "LSS-" + gid; var passwd = StringUtils.GenerateRandomString(16); var sha = SHA256.Create(); diff --git a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.cs b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.cs index 19db0b7..27379bd 100644 --- a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.cs +++ b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.cs @@ -63,7 +63,7 @@ public partial class MareHub : Hub, IMareHub dbUser.LastLoggedIn = DateTime.UtcNow; await _dbContext.SaveChangesAsync().ConfigureAwait(false); - await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Information, "Welcome to Mare Synchronos \"" + _shardName + "\", Current Online Users: " + _systemInfoService.SystemInfoDto.OnlineUsers).ConfigureAwait(false); + await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Information, "Welcome to Loporrit, Current Online Users: " + _systemInfoService.SystemInfoDto.OnlineUsers).ConfigureAwait(false); await SendOnlineToAllPairedUsers().ConfigureAwait(false); return new ConnectionDto(new UserData(dbUser.UID, string.IsNullOrWhiteSpace(dbUser.Alias) ? null : dbUser.Alias)) diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBot.cs b/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBot.cs index 1a8f08f..00dd060 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBot.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBot.cs @@ -123,7 +123,7 @@ internal class DiscordBot : IHostedService builder.WithColor(Color.Green); profile.FlaggedForReport = false; await _mareHubContext.Clients.User(split[1]).SendAsync(nameof(IMareHub.Client_ReceiveServerMessage), - MessageSeverity.Warning, "The Mare profile report against you has been evaluated and your profile re-enabled.") + MessageSeverity.Warning, "The profile report against you has been evaluated and your profile re-enabled.") .ConfigureAwait(false); break; @@ -143,7 +143,7 @@ internal class DiscordBot : IHostedService DiscordIdOrLodestoneAuth = regReporting.DiscordId.ToString() }); await _mareHubContext.Clients.User(split[1]).SendAsync(nameof(IMareHub.Client_ReceiveServerMessage), - MessageSeverity.Warning, "The Mare profile report against you has been evaluated and your profile re-enabled.") + MessageSeverity.Warning, "The profile report against you has been evaluated and your profile re-enabled.") .ConfigureAwait(false); break; @@ -155,7 +155,7 @@ internal class DiscordBot : IHostedService profile.ProfileDisabled = true; profile.FlaggedForReport = false; await _mareHubContext.Clients.User(split[1]).SendAsync(nameof(IMareHub.Client_ReceiveServerMessage), - MessageSeverity.Warning, "The Mare profile report against you has been evaluated and the profile functionality permanently disabled.") + MessageSeverity.Warning, "The profile report against you has been evaluated and the profile functionality permanently disabled.") .ConfigureAwait(false); break; @@ -177,7 +177,7 @@ internal class DiscordBot : IHostedService DiscordIdOrLodestoneAuth = reg.DiscordId.ToString() }); await _mareHubContext.Clients.User(split[1]).SendAsync(nameof(IMareHub.Client_ReceiveServerMessage), - MessageSeverity.Warning, "The Mare profile report against you has been evaluated and your account permanently banned.") + MessageSeverity.Warning, "The profile report against you has been evaluated and your account permanently banned.") .ConfigureAwait(false); break; } @@ -425,8 +425,8 @@ internal class DiscordBot : IHostedService var endPoint = _connectionMultiplexer.GetEndPoints().First(); var onlineUsers = await _connectionMultiplexer.GetServer(endPoint).KeysAsync(pattern: "UID:*").CountAsync(); - _logger.LogInformation("Users online: " + onlineUsers); - await _discordClient.SetActivityAsync(new Game("Mare for " + onlineUsers + " Users")).ConfigureAwait(false); + //_logger.LogInformation("Users online: " + onlineUsers); + await _discordClient.SetActivityAsync(new Game("with " + onlineUsers + " Users")).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(false); } } diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareModule.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareModule.cs index 341d386..3555df9 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareModule.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareModule.cs @@ -48,7 +48,7 @@ public class MareModule : InteractionModuleBase _connectionMultiplexer = connectionMultiplexer; } - [SlashCommand("register", "Starts the registration process for the Mare Synchronos server of this Discord")] + [SlashCommand("register", "Starts the registration process")] public async Task Register([Summary("overwrite", "Overwrites your old account")] bool overwrite = false) { _logger.LogInformation("SlashCommand:{userId}:{Method}:{params}", @@ -62,7 +62,70 @@ public class MareModule : InteractionModuleBase await DeletePreviousUserAccount(Context.User.Id).ConfigureAwait(false); } - await RespondWithModalAsync("register_modal").ConfigureAwait(false); + using var scope = _services.CreateScope(); + using var db = scope.ServiceProvider.GetService(); + + if (db.LodeStoneAuth.Any(a => a.DiscordId == Context.User.Id)) + { + EmbedBuilder eb = new(); + // user already in db + eb.WithTitle("Registration failed"); + eb.WithDescription("You are already registered. Use `/recover overwrite` to delete your old account and create a new one."); + await RespondAsync(embeds: new Embed[] { eb.Build() }, ephemeral: true).ConfigureAwait(false); + } + else + { + // Loporrit - Register immediately + var user = new User(); + + var hasValidUid = false; + while (!hasValidUid) + { + var uid = StringUtils.GenerateRandomString(7); + if (db.Users.Any(u => u.UID == uid || u.Alias == uid)) continue; + user.UID = uid; + hasValidUid = true; + } + + user.LastLoggedIn = DateTime.UtcNow; + + var computedHash = StringUtils.Sha256String(StringUtils.GenerateRandomString(64) + DateTime.UtcNow.ToString()); + + var auth = new Auth() + { + HashedKey = StringUtils.Sha256String(computedHash), + User = user, + }; + + LodeStoneAuth lsAuth = new LodeStoneAuth() + { + DiscordId = Context.User.Id, + HashedLodestoneId = null, + LodestoneAuthString = null, + User = user, + StartedAt = null + }; + + await db.Users.AddAsync(user).ConfigureAwait(false); + await db.Auth.AddAsync(auth).ConfigureAwait(false); + await db.LodeStoneAuth.AddAsync(lsAuth).ConfigureAwait(false); + await db.SaveChangesAsync().ConfigureAwait(false); + + _botServices.Logger.LogInformation("User registered: {userUID}", user.UID); + + EmbedBuilder eb = new(); + + eb.WithTitle("Registration successful"); + eb.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 Loporrit Sync and hit Connect / Reconnect." + + Environment.NewLine + + "Have fun."); + + await RespondAsync(embeds: new Embed[] { eb.Build() }, ephemeral: true).ConfigureAwait(false); + } } catch (Exception ex) { @@ -145,7 +208,8 @@ public class MareModule : InteractionModuleBase } } - [SlashCommand("verify", "Finishes the registration process for the Mare Synchronos server of this Discord")] + // Loporrit - Disable /verify command + //[SlashCommand("verify", "Finishes the registration process for the Mare Synchronos server of this Discord")] public async Task Verify() { _logger.LogInformation("SlashCommand:{userId}:{Method}", @@ -181,7 +245,8 @@ public class MareModule : InteractionModuleBase } } - [SlashCommand("verify_relink", "Finishes the relink process for your user on the Mare Synchronos server of this Discord")] + // Loporrit - Disable /verify command + //[SlashCommand("verify_relink", "Finishes the relink process for your user on the Mare Synchronos server of this Discord")] public async Task VerifyRelink() { _logger.LogInformation("SlashCommand:{userId}:{Method}", @@ -219,7 +284,8 @@ public class MareModule : InteractionModuleBase } - [SlashCommand("recover", "Allows you to recover your account by generating a new secret key")] + // Loporrit -- Disable /recover command + //[SlashCommand("recover", "Allows you to recover your account by generating a new secret key")] public async Task Recover([Summary("secondary_uid", "(Optional) Your secondary UID")] string? secondaryUid = null) { _logger.LogInformation("SlashCommand:{userId}:{Method}", @@ -254,7 +320,8 @@ public class MareModule : InteractionModuleBase } } - [SlashCommand("relink", "Allows you to link a new Discord account to an existing Mare account")] + // Loporrit -- Disable /relink command + //[SlashCommand("relink", "Allows you to link a new Discord account to an existing Mare account")] public async Task Relink() { _logger.LogInformation("SlashCommand:{userId}:{Method}", @@ -424,7 +491,7 @@ public class MareModule : InteractionModuleBase if (lodestoneAuth == null) { embed.WithTitle("Failed to add secondary user"); - embed.WithDescription("You have no registered Mare account yet. Register a Mare account first before trying to add secondary keys."); + embed.WithDescription("You have no registered account yet. Register an account first before trying to add secondary keys."); return embed.Build(); } @@ -446,7 +513,7 @@ public class MareModule : InteractionModuleBase var hasValidUid = false; while (!hasValidUid) { - var uid = StringUtils.GenerateRandomString(10); + var uid = StringUtils.GenerateRandomString(7); if (await db.Users.AnyAsync(u => u.UID == uid || u.Alias == uid).ConfigureAwait(false)) continue; newUser.UID = uid; hasValidUid = true; @@ -457,7 +524,8 @@ public class MareModule : InteractionModuleBase { HashedKey = StringUtils.Sha256String(computedHash), User = newUser, - PrimaryUserUID = lodestoneAuth.User.UID + PrimaryUserUID = lodestoneAuth.User.UID, + UserUID = newUser.UID }; await db.Users.AddAsync(newUser).ConfigureAwait(false); @@ -531,7 +599,7 @@ public class MareModule : InteractionModuleBase if (primaryUser == null) { eb.WithTitle("No account"); - eb.WithDescription("No Mare account was found associated to your Discord user"); + eb.WithDescription("No account was found associated to your Discord user"); return eb; } @@ -558,7 +626,7 @@ public class MareModule : InteractionModuleBase if (userInDb == null) { eb.WithTitle("No account"); - eb.WithDescription("The Discord user has no valid Mare account"); + eb.WithDescription("The Discord user has no valid account"); return eb; } @@ -701,7 +769,7 @@ public class MareModule : InteractionModuleBase + Environment.NewLine + Environment.NewLine + $"**{computedHash}**" + Environment.NewLine + Environment.NewLine - + "Enter this key in Mare Synchronos and hit save to connect to the service."); + + "Enter this key in Loporrit Sync and hit save to connect to the service."); await db.Auth.AddAsync(auth).ConfigureAwait(false); await db.SaveChangesAsync().ConfigureAwait(false); @@ -1130,7 +1198,7 @@ public class MareModule : InteractionModuleBase var hasValidUid = false; while (!hasValidUid) { - var uid = StringUtils.GenerateRandomString(10); + var uid = StringUtils.GenerateRandomString(7); if (db.Users.Any(u => u.UID == uid || u.Alias == uid)) continue; user.UID = uid; hasValidUid = true; @@ -1165,7 +1233,7 @@ public class MareModule : InteractionModuleBase + Environment.NewLine + Environment.NewLine + $"**{computedHash}**" + Environment.NewLine + Environment.NewLine - + "Enter this key in Mare Synchronos and hit save to connect to the service." + + "Enter this key in to the plugin when prompted 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