From d5a07bd2633006a840adbf743758cab24bf56b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Wed, 26 Aug 2020 21:11:48 +0200 Subject: [PATCH] feat(example): add option for more accounts --- NostaleGfless.Example/Options.cs | 3 +- NostaleGfless.Example/Program.cs | 51 +++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/NostaleGfless.Example/Options.cs b/NostaleGfless.Example/Options.cs index 822eeeb..8085226 100644 --- a/NostaleGfless.Example/Options.cs +++ b/NostaleGfless.Example/Options.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using CommandLine; using Newtonsoft.Json; @@ -11,7 +12,7 @@ namespace NostaleGfless.Example [Option('n', "nostale", Required = true, HelpText = "Path to nostale folder or NostaleClientX.exe")] public string NostalePath { get; set; } - [Option('a', "account", Required = false, HelpText = "Name of the account to connect to. Otherwise the first one will be used.")] + [Option('a', "account", Required = false, HelpText = "Name of the account to connect to. Otherwise the first one will be used. For more accounts split them using coma")] public string AccountName { get; set; } [Value(0, MetaName = "Email", Required = true, HelpText = "Gameforge account email")] diff --git a/NostaleGfless.Example/Program.cs b/NostaleGfless.Example/Program.cs index 5393e12..2009db4 100644 --- a/NostaleGfless.Example/Program.cs +++ b/NostaleGfless.Example/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using CommandLine; @@ -33,41 +34,55 @@ namespace NostaleGfless.Example var authenticator = new GameforgeAuthenticator(); authenticator.InstallationId = installationId; var launcher = await authenticator.Authenticate(options.Email, options.Password); - - GameforgeAccount account = launcher.Accounts.FirstOrDefault(); - if (account == null) + if (launcher.Accounts.Count == 0) { throw new InvalidOperationException("There are no nostale account on the gameforge account"); } + List accounts = new List(); + if (options.AccountName != null) { - account = launcher.Accounts.FirstOrDefault(x => x.Name == options.AccountName); - - if (account == null) + foreach (string accountName in options.AccountName.Split(',')) { - account = launcher.Accounts.FirstOrDefault(x => x.Name.Contains(options.AccountName)); + GameforgeAccount account = launcher.Accounts.FirstOrDefault(x => x.Name == accountName); if (account == null) { - throw new InvalidOperationException("Account not found"); + account = launcher.Accounts.FirstOrDefault(x => x.Name.Contains(accountName)); + + if (account == null) + { + throw new InvalidOperationException($"Account {accountName} not found"); + } } + + accounts.Add(account); } } - - Console.WriteLine($"Selected account: {account.Name}"); - Console.WriteLine("Launching nostale with the selected account ..."); - - Console.WriteLine("Waiting for nostale ..."); - var result = await launcher.Launch(account, options.NostalePath); - if (result != null && result.Initialized) + if (accounts.Count == 0) { - Console.WriteLine($"Nostale launched successfully. Process id: {result.ProcessId}, Session id: {result.SessionId}"); + accounts.Add(launcher.Accounts.FirstOrDefault()); } - else + + foreach (GameforgeAccount account in accounts) { - Console.WriteLine("There was an error launching nostale"); + Console.WriteLine($"Selected account: {account.Name}"); + Console.WriteLine("Launching nostale with the selected account ..."); + + Console.WriteLine("Waiting for nostale ..."); + var result = await launcher.Launch(account, options.NostalePath); + + if (result != null && result.Initialized) + { + Console.WriteLine( + $"Nostale launched successfully. Process id: {result.ProcessId}, Session id: {result.SessionId}"); + } + else + { + Console.WriteLine("There was an error launching nostale"); + } } ewh.Set(); -- 2.49.0