diff --git a/MBBSEmu/Program.cs b/MBBSEmu/Program.cs index 5c484488..e68e5399 100644 --- a/MBBSEmu/Program.cs +++ b/MBBSEmu/Program.cs @@ -80,6 +80,11 @@ public class Program /// private bool _doResetDatabase; + /// + /// Specified if -PWRESET Command Line Argument was Passed + /// + private bool _doResetPassword; + /// /// New Sysop Password specified by the -DBRESET Command Line Argument /// @@ -254,6 +259,17 @@ private void Run(string[] args) _isConsoleSession = true; break; } + case "-PWRESET": + { + _doResetPassword = true; + if (i + 1 < args.Length && args[i + 1][0] != '-') + { + _newSysopPassword = args[i + 1]; + i++; + } + + break; + } default: Console.WriteLine($"Unknown Command Line Argument: {args[i]}"); return; @@ -295,28 +311,6 @@ private void Run(string[] args) return; } - //If the user specified CLI mode, don't start the UI - if (!_cliMode) - { - var mainMBBSEmuWindow = new MainView(_serviceResolver); - - //Start UI in a Task as to not block this thread - Task.Run(() => - { - mainMBBSEmuWindow.Setup(); - mainMBBSEmuWindow.Run(); - }); - - //Wait for the UI to be running before continuing - Console.Write("Waiting for MBBSEmu GUI to start..."); - while (!mainMBBSEmuWindow.isRunning) - { - Thread.Sleep(500); - Console.Write("."); - } - Console.WriteLine(); - } - var configuration = _serviceResolver.GetService(); var textVariableService = _serviceResolver.GetService(); var resourceManager = _serviceResolver.GetService(); @@ -343,6 +337,10 @@ private void Run(string[] args) if (_doResetDatabase) DatabaseReset(); + //Password Reset + if (_doResetPassword) + PasswordReset(); + //Database Sanity Checks var databaseFile = configuration.DatabaseFile; if (!File.Exists($"{databaseFile}")) @@ -433,6 +431,28 @@ private void Run(string[] args) return; } + //If the user specified CLI mode, don't start the UI + if (!_cliMode && !_isConsoleSession) + { + var mainMBBSEmuWindow = new MainView(_serviceResolver); + + //Start UI in a Task as to not block this thread + Task.Run(() => + { + mainMBBSEmuWindow.Setup(); + mainMBBSEmuWindow.Run(); + }); + + //Wait for the UI to be running before continuing + Console.Write("Waiting for MBBSEmu GUI to start..."); + while (!mainMBBSEmuWindow.isRunning) + { + Thread.Sleep(500); + Console.Write("."); + } + Console.WriteLine(); + } + //Setup and Run Host var host = _serviceResolver.GetService(); host.Start(_moduleConfigurations); @@ -519,7 +539,7 @@ private void CancelKeyPressHandler(object sender, ConsoleCancelEventArgs args) _cancellationRequests++; - _logger.Warn("BBS Shutting down"); + _logger.Warn("MBBSEmu Shutting down..."); foreach (var runningService in _runningServices) { @@ -536,27 +556,8 @@ private void DatabaseReset() { _logger.Info("Resetting Database..."); - if (string.IsNullOrEmpty(_newSysopPassword)) - { - var bPasswordMatch = false; - while (!bPasswordMatch) - { - Console.Write("Enter New Sysop Password: "); - var password1 = Console.ReadLine(); - Console.Write("Re-Enter New Sysop Password: "); - var password2 = Console.ReadLine(); - if (password1 == password2) - { - bPasswordMatch = true; - _newSysopPassword = password1; - } - else - { - Console.WriteLine("Password mismatch, please try again."); - } - } - } + _newSysopPassword = PasswordPrompt("sysop"); var acct = _serviceResolver.GetService(); acct.Reset(_newSysopPassword); @@ -576,5 +577,45 @@ private void DatabaseReset() _logger.Info("Database Reset!"); } + + /// + /// Prompts the user via the CLI to enter a new password for the specified username + /// + /// + /// + /// + private string PasswordPrompt(string username) + { + while (true) + { + Console.Write($"Enter New Password for {username}: "); + var password1 = Console.ReadLine(); + Console.Write($"Re-Enter New Password for {username}: "); + var password2 = Console.ReadLine(); + + //If they match, return the password + if (password1 == password2) + return password1; + + //Otherwise infinite loop until they match + Console.WriteLine("Password mismatch, please try again."); + } + } + + /// + /// Reset the Sysop Password to the specified value via the console + /// + private void PasswordReset() + { + //Interactive Password Reset via Console if one wasn't specified in the command line + if (string.IsNullOrEmpty(_newSysopPassword)) + _newSysopPassword = PasswordPrompt("sysop"); + + var acct = _serviceResolver.GetService(); + var sysopAccount = acct.GetAccountByUsername("sysop"); + acct.UpdateAccountById(sysopAccount.accountId, sysopAccount.userName, _newSysopPassword, sysopAccount.email); + _logger.Info("Sysop Password Reset!"); + _doResetPassword = false; + } } }