From 19e84a70f244818b67c13cb273d1af4cb6a3568b Mon Sep 17 00:00:00 2001 From: jvyden Date: Sat, 10 Aug 2024 21:25:54 -0400 Subject: [PATCH] Add ability for admins to ask users for verification codes --- Refresh.GameServer/CommandLineManager.cs | 13 +++++++++++++ Refresh.GameServer/RefreshGameServer.cs | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Refresh.GameServer/CommandLineManager.cs b/Refresh.GameServer/CommandLineManager.cs index 05e64263..0d8493ac 100644 --- a/Refresh.GameServer/CommandLineManager.cs +++ b/Refresh.GameServer/CommandLineManager.cs @@ -70,6 +70,9 @@ private class Options [Option("mark-all-reuploads", HelpText = "Marks all levels uploaded by a user as re-uploaded. Username or Email options are required if this is set.")] public bool MarkAllReuploads { get; set; } + + [Option("ask-for-verification", HelpText = "Sends a verification code to confirm a user's identity over an untrusted channel. Username or Email options are required if this is set.")] + public bool AskUserForVerification { get; set; } } internal void StartWithArgs(string[] args) @@ -203,5 +206,15 @@ private void StartWithOptions(Options options) GameUser user = this.GetUserOrFail(options); this._server.MarkAllReuploads(user); } + else if (options.AskUserForVerification) + { + GameUser user = this.GetUserOrFail(options); + string code = this._server.AskUserForVerification(user); + Console.WriteLine($"The code has been sent to {user.Username}'s notifications."); + Console.WriteLine(); + Console.WriteLine($"\tCode: {code}"); + Console.WriteLine(); + Console.WriteLine("If the user does not reply to you with *exactly* this code, assume the worst."); + } } } \ No newline at end of file diff --git a/Refresh.GameServer/RefreshGameServer.cs b/Refresh.GameServer/RefreshGameServer.cs index 157ea8d6..879fe910 100644 --- a/Refresh.GameServer/RefreshGameServer.cs +++ b/Refresh.GameServer/RefreshGameServer.cs @@ -11,6 +11,7 @@ using Bunkum.HealthChecks.RealmDatabase; using Bunkum.Protocols.Http; using Refresh.Common; +using Refresh.Common.Verification; using Refresh.GameServer.Authentication; using Refresh.GameServer.Configuration; using Refresh.GameServer.Database; @@ -261,6 +262,20 @@ public void MarkAllReuploads(GameUser user) context.MarkAllReuploads(user); } + public string AskUserForVerification(GameUser user) + { + using GameDatabaseContext context = this.GetContext(); + string code = CodeHelper.GenerateDigitCode(); + + string text = $"An admin is requesting a code to verify that you currently have access to your account. " + + $"Please share the code '{code}' with the admin you're currently speaking with. " + + "If you're not in contact with any such staff member, please report this immediately."; + + context.AddNotification("Admin Verification Request (Action Required)", text, user, "shield"); + + return code; + } + public override void Dispose() { this._databaseProvider.Dispose();