Initial Loporrit branding

This commit is contained in:
Loporrit
2023-08-24 18:30:24 +00:00
parent 09a6dbfca0
commit 83eb274bcb
4 changed files with 91 additions and 23 deletions

View File

@@ -208,11 +208,11 @@ public partial class MareHub
} }
var gid = StringUtils.GenerateRandomString(12); 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 = StringUtils.GenerateRandomString(12);
} }
gid = "MSS-" + gid; gid = "LSS-" + gid;
var passwd = StringUtils.GenerateRandomString(16); var passwd = StringUtils.GenerateRandomString(16);
var sha = SHA256.Create(); var sha = SHA256.Create();

View File

@@ -63,7 +63,7 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
dbUser.LastLoggedIn = DateTime.UtcNow; dbUser.LastLoggedIn = DateTime.UtcNow;
await _dbContext.SaveChangesAsync().ConfigureAwait(false); 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); await SendOnlineToAllPairedUsers().ConfigureAwait(false);
return new ConnectionDto(new UserData(dbUser.UID, string.IsNullOrWhiteSpace(dbUser.Alias) ? null : dbUser.Alias)) return new ConnectionDto(new UserData(dbUser.UID, string.IsNullOrWhiteSpace(dbUser.Alias) ? null : dbUser.Alias))

View File

@@ -123,7 +123,7 @@ internal class DiscordBot : IHostedService
builder.WithColor(Color.Green); builder.WithColor(Color.Green);
profile.FlaggedForReport = false; profile.FlaggedForReport = false;
await _mareHubContext.Clients.User(split[1]).SendAsync(nameof(IMareHub.Client_ReceiveServerMessage), 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); .ConfigureAwait(false);
break; break;
@@ -143,7 +143,7 @@ internal class DiscordBot : IHostedService
DiscordIdOrLodestoneAuth = regReporting.DiscordId.ToString() DiscordIdOrLodestoneAuth = regReporting.DiscordId.ToString()
}); });
await _mareHubContext.Clients.User(split[1]).SendAsync(nameof(IMareHub.Client_ReceiveServerMessage), 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); .ConfigureAwait(false);
break; break;
@@ -155,7 +155,7 @@ internal class DiscordBot : IHostedService
profile.ProfileDisabled = true; profile.ProfileDisabled = true;
profile.FlaggedForReport = false; profile.FlaggedForReport = false;
await _mareHubContext.Clients.User(split[1]).SendAsync(nameof(IMareHub.Client_ReceiveServerMessage), 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); .ConfigureAwait(false);
break; break;
@@ -177,7 +177,7 @@ internal class DiscordBot : IHostedService
DiscordIdOrLodestoneAuth = reg.DiscordId.ToString() DiscordIdOrLodestoneAuth = reg.DiscordId.ToString()
}); });
await _mareHubContext.Clients.User(split[1]).SendAsync(nameof(IMareHub.Client_ReceiveServerMessage), 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); .ConfigureAwait(false);
break; break;
} }
@@ -425,8 +425,8 @@ internal class DiscordBot : IHostedService
var endPoint = _connectionMultiplexer.GetEndPoints().First(); var endPoint = _connectionMultiplexer.GetEndPoints().First();
var onlineUsers = await _connectionMultiplexer.GetServer(endPoint).KeysAsync(pattern: "UID:*").CountAsync(); var onlineUsers = await _connectionMultiplexer.GetServer(endPoint).KeysAsync(pattern: "UID:*").CountAsync();
_logger.LogInformation("Users online: " + onlineUsers); //_logger.LogInformation("Users online: " + onlineUsers);
await _discordClient.SetActivityAsync(new Game("Mare for " + onlineUsers + " Users")).ConfigureAwait(false); await _discordClient.SetActivityAsync(new Game("with " + onlineUsers + " Users")).ConfigureAwait(false);
await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(false);
} }
} }

View File

@@ -48,7 +48,7 @@ public class MareModule : InteractionModuleBase
_connectionMultiplexer = connectionMultiplexer; _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) public async Task Register([Summary("overwrite", "Overwrites your old account")] bool overwrite = false)
{ {
_logger.LogInformation("SlashCommand:{userId}:{Method}:{params}", _logger.LogInformation("SlashCommand:{userId}:{Method}:{params}",
@@ -62,7 +62,70 @@ public class MareModule : InteractionModuleBase
await DeletePreviousUserAccount(Context.User.Id).ConfigureAwait(false); await DeletePreviousUserAccount(Context.User.Id).ConfigureAwait(false);
} }
await RespondWithModalAsync<LodestoneModal>("register_modal").ConfigureAwait(false); using var scope = _services.CreateScope();
using var db = scope.ServiceProvider.GetService<MareDbContext>();
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) 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() public async Task Verify()
{ {
_logger.LogInformation("SlashCommand:{userId}:{Method}", _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() public async Task VerifyRelink()
{ {
_logger.LogInformation("SlashCommand:{userId}:{Method}", _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) public async Task Recover([Summary("secondary_uid", "(Optional) Your secondary UID")] string? secondaryUid = null)
{ {
_logger.LogInformation("SlashCommand:{userId}:{Method}", _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() public async Task Relink()
{ {
_logger.LogInformation("SlashCommand:{userId}:{Method}", _logger.LogInformation("SlashCommand:{userId}:{Method}",
@@ -424,7 +491,7 @@ public class MareModule : InteractionModuleBase
if (lodestoneAuth == null) if (lodestoneAuth == null)
{ {
embed.WithTitle("Failed to add secondary user"); 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(); return embed.Build();
} }
@@ -446,7 +513,7 @@ public class MareModule : InteractionModuleBase
var hasValidUid = false; var hasValidUid = false;
while (!hasValidUid) 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; if (await db.Users.AnyAsync(u => u.UID == uid || u.Alias == uid).ConfigureAwait(false)) continue;
newUser.UID = uid; newUser.UID = uid;
hasValidUid = true; hasValidUid = true;
@@ -457,7 +524,8 @@ public class MareModule : InteractionModuleBase
{ {
HashedKey = StringUtils.Sha256String(computedHash), HashedKey = StringUtils.Sha256String(computedHash),
User = newUser, User = newUser,
PrimaryUserUID = lodestoneAuth.User.UID PrimaryUserUID = lodestoneAuth.User.UID,
UserUID = newUser.UID
}; };
await db.Users.AddAsync(newUser).ConfigureAwait(false); await db.Users.AddAsync(newUser).ConfigureAwait(false);
@@ -531,7 +599,7 @@ public class MareModule : InteractionModuleBase
if (primaryUser == null) if (primaryUser == null)
{ {
eb.WithTitle("No account"); 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; return eb;
} }
@@ -558,7 +626,7 @@ public class MareModule : InteractionModuleBase
if (userInDb == null) if (userInDb == null)
{ {
eb.WithTitle("No account"); 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; return eb;
} }
@@ -701,7 +769,7 @@ public class MareModule : InteractionModuleBase
+ Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine
+ $"**{computedHash}**" + $"**{computedHash}**"
+ Environment.NewLine + Environment.NewLine + 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.Auth.AddAsync(auth).ConfigureAwait(false);
await db.SaveChangesAsync().ConfigureAwait(false); await db.SaveChangesAsync().ConfigureAwait(false);
@@ -1130,7 +1198,7 @@ public class MareModule : InteractionModuleBase
var hasValidUid = false; var hasValidUid = false;
while (!hasValidUid) while (!hasValidUid)
{ {
var uid = StringUtils.GenerateRandomString(10); var uid = StringUtils.GenerateRandomString(7);
if (db.Users.Any(u => u.UID == uid || u.Alias == uid)) continue; if (db.Users.Any(u => u.UID == uid || u.Alias == uid)) continue;
user.UID = uid; user.UID = uid;
hasValidUid = true; hasValidUid = true;
@@ -1165,7 +1233,7 @@ public class MareModule : InteractionModuleBase
+ Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine
+ $"**{computedHash}**" + $"**{computedHash}**"
+ Environment.NewLine + Environment.NewLine + 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 + Environment.NewLine
+ "You should connect as soon as possible to not get caught by the automatic cleanup process." + "You should connect as soon as possible to not get caught by the automatic cleanup process."
+ Environment.NewLine + Environment.NewLine