feat(headless): complete portable single-session host
This commit is contained in:
parent
fbebb91848
commit
f8cb840fb1
30 changed files with 3571 additions and 32 deletions
|
|
@ -556,7 +556,10 @@ public sealed class LiveSessionController
|
|||
|
||||
CharacterList.Parsed? characters = _operations.GetCharacters(session);
|
||||
if (characters is null
|
||||
|| !CharacterList.TrySelectFirstAvailable(characters, out CharacterList.Selection selected))
|
||||
|| !TrySelectCharacter(
|
||||
characters,
|
||||
options.Character,
|
||||
out CharacterList.Selection selected))
|
||||
{
|
||||
Console.WriteLine("live: no available characters on account; disconnecting");
|
||||
StopCore();
|
||||
|
|
@ -755,6 +758,62 @@ public sealed class LiveSessionController
|
|||
private LiveSessionStartResult ConnectedResult()
|
||||
=> new(LiveSessionStartStatus.Connected, _activeSelection);
|
||||
|
||||
private static bool TrySelectCharacter(
|
||||
CharacterList.Parsed characters,
|
||||
LiveSessionCharacterSelector? selector,
|
||||
out CharacterList.Selection selection)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(characters);
|
||||
if (selector is null)
|
||||
{
|
||||
return CharacterList.TrySelectFirstAvailable(
|
||||
characters,
|
||||
out selection);
|
||||
}
|
||||
|
||||
int selectorCount =
|
||||
(selector.ActiveIndex.HasValue ? 1 : 0)
|
||||
+ (selector.CharacterId.HasValue ? 1 : 0)
|
||||
+ (!string.IsNullOrWhiteSpace(selector.CharacterName) ? 1 : 0);
|
||||
if (selectorCount != 1)
|
||||
{
|
||||
selection = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int index = 0; index < characters.Characters.Count; index++)
|
||||
{
|
||||
CharacterList.Character character =
|
||||
characters.Characters[index];
|
||||
if (!CharacterList.IsAvailableActiveIdentity(character))
|
||||
continue;
|
||||
if (selector.ActiveIndex is { } requestedIndex
|
||||
&& requestedIndex != index)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (selector.CharacterId is { } requestedId
|
||||
&& requestedId != character.Id)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (selector.CharacterName is { } requestedName
|
||||
&& !string.Equals(
|
||||
requestedName,
|
||||
character.Name,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
selection = new CharacterList.Selection(index, character);
|
||||
return true;
|
||||
}
|
||||
|
||||
selection = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ThrowIfDisposing()
|
||||
{
|
||||
if (_disposeRequested || _disposed)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue