Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 42 additions & 19 deletions Application/OasisBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class CommandLineOptions
[Option('p', "profile", Required = false, HelpText = "Set the profile name to use.")]
public string Profile { get; set; }

[Option('a', "account", Required = false, HelpText = "Set the account name to use.")]
public string Account { get; set; }

[Option("launch-client", Required = false, HelpText = "Start with client")]
public bool LaunchClient { get; set; }

Expand All @@ -50,20 +53,30 @@ public class CommandLineOptions

[Option("headless", Required = false, HelpText = "Start the bot without graphical user interface")]
public bool Headless { get; set; }

[Option('h', "help", Required = false, HelpText = "Show help message.")]
public bool Help { get; set; }
}

private static void DisplayHelp(ParserResult<CommandLineOptions> result)
{
var helpText = HelpText.AutoBuild(
result,
h =>
{
h.AdditionalNewLineAfterOption = false;
h.AddDashesToOption = true;
return HelpText.DefaultParsingErrorsHandler(result, h);
}
var helpText = new HelpText
{
Heading = new HeadingInfo(AssemblyTitle, AssemblyVersion),
AdditionalNewLineAfterOption = false,
AddDashesToOption = true,
};
helpText.AddPreOptionsLine(
"Copyright (C) 2017-2021 ngoedde; 2021-2026 RSBot Team; 2026 Silkroad Developer Community"
);
helpText.AddOptions(result);

var lines = helpText.ToString().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
var filteredLines = lines.Where(line =>
!line.TrimStart().StartsWith("--help") && !line.TrimStart().StartsWith("--version")
);
Console.WriteLine(helpText);

Console.WriteLine(string.Join(Environment.NewLine, filteredLines));
}

[STAThread]
Expand All @@ -77,16 +90,19 @@ private static void Main(string[] args)
parserResult
.WithParsed(options =>
{
if (options.Help)
{
DisplayHelp(parserResult);
Environment.Exit(0);
}

RunOptions(options);
isHeadless = options.Headless;
})
.WithNotParsed(errs =>
{
DisplayHelp(parserResult);
var isHelp = errs.Any(e =>
e.Tag == ErrorType.HelpRequestedError || e.Tag == ErrorType.VersionRequestedError
);
Environment.Exit(isHelp ? 0 : 1);
Environment.Exit(1);
});

//CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
Expand Down Expand Up @@ -174,13 +190,20 @@ private static void RunOptions(CommandLineOptions options)

ProfileManager.IsProfileLoadedByArgs = true;
Log.Debug($"Selected profile by args: {profile}");
}

if (!string.IsNullOrEmpty(options.Character))
{
var character = options.Character;
ProfileManager.SelectedCharacter = character;
Log.Debug($"Selected character by args: {character}");
if (!string.IsNullOrEmpty(options.Account))
{
var account = options.Account;
ProfileManager.SelectedAccount = account;
Log.Debug($"Selected account by args: {account}");

if (!string.IsNullOrEmpty(options.Character))
{
var character = options.Character;
ProfileManager.SelectedCharacter = character;
Log.Debug($"Selected character by args: {character}");
}
}
}
}
}
5 changes: 5 additions & 0 deletions Library/RSBot.Core/Components/ProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ static ProfileManager()
/// </summary>
public static string SelectedCharacter { get; set; }

/// <summary>
/// The selected account
/// </summary>
public static string SelectedAccount { get; set; }

/// <summary>
/// The selected profile
/// </summary>
Expand Down
10 changes: 6 additions & 4 deletions Plugins/RSBot.General/Components/AutoLogin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -51,9 +51,11 @@ public static async void Handle()
return;
}

var selectedAccount = Accounts.SavedAccounts?.Find(p =>
p.Username == GlobalConfig.Get<string>("RSBot.General.AutoLoginAccountUsername")
);
var autoLoginUsername = !string.IsNullOrEmpty(ProfileManager.SelectedAccount)
? ProfileManager.SelectedAccount
: GlobalConfig.Get<string>("RSBot.General.AutoLoginAccountUsername");

var selectedAccount = Accounts.SavedAccounts?.Find(p => p.Username == autoLoginUsername);
if (selectedAccount == null)
{
_busy = false;
Expand Down
Loading