Skip to content

Commit

Permalink
Merge pull request #213 from stayintarkov/network-crash-fixes
Browse files Browse the repository at this point in the history
Network crash fixes
  • Loading branch information
Plootie authored Apr 27, 2024
2 parents 92f6886 + 528480f commit 851c26b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion SIT.Manager/Localization/en-US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@
<system:String x:Key="DirectConnectViewEnterPasswordPlaceholder">Enter Password...</system:String>
<system:String x:Key="DirectConnectViewRememberMeCheckBoxTitle">Remember Me</system:String>
<system:String x:Key="DirectConnectViewConnectButtonTitle">Connect</system:String>
<system:String x:Key="CDirectConnectViewonnectButtonTitleToolTip">Connect to the server</system:String>
<system:String x:Key="DirectConnectViewConnectButtonTitleToolTip">Connect to the server</system:String>
<system:String x:Key="DirectConnectViewStartServerAndConnectButtonTitleToolTip">Start the Aki server and connect to the server</system:String>

<!-- LoginDialogView -->
Expand Down
30 changes: 20 additions & 10 deletions SIT.Manager/ViewModels/Play/CharacterSelectionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace SIT.Manager.ViewModels.Play;
Expand Down Expand Up @@ -89,20 +90,29 @@ private async Task CreateCharacter()
private async Task ReloadCharacterList()
{
CharacterList.Clear();
List<AkiMiniProfile> miniProfiles = await _serverService.GetMiniProfilesAsync(_connectedServer);
foreach (AkiMiniProfile profile in miniProfiles)
try
{
CharacterSummaryViewModel characterSummaryViewModel = ActivatorUtilities.CreateInstance<CharacterSummaryViewModel>(_serviceProvider, _connectedServer, profile);
if (_connectedServer.Characters.Any(x => x.Username == profile.Username) == true)
{
SavedCharacterList.Add(characterSummaryViewModel);
}
else
//TODO: This is currently listing *all* server characters. We should narrow this to saved only
List<AkiMiniProfile> miniProfiles = await _serverService.GetMiniProfilesAsync(_connectedServer);
foreach (AkiMiniProfile profile in miniProfiles)
{
CharacterList.Add(characterSummaryViewModel);
CharacterSummaryViewModel characterSummaryViewModel = ActivatorUtilities.CreateInstance<CharacterSummaryViewModel>(_serviceProvider, _connectedServer, profile);
if (_connectedServer.Characters.Any(x => x.Username == profile.Username) == true)
{
SavedCharacterList.Add(characterSummaryViewModel);
}
else
{
CharacterList.Add(characterSummaryViewModel);
}
}

_logger.LogDebug("{profileCount} mini profiles retrieved from {name}", miniProfiles.Count, _connectedServer.Name);
}
catch(HttpRequestException ex)
{
_logger.LogError(ex, "An error occured while fetching characters");
}
_logger.LogDebug("{profileCount} mini profiles retrieved from {name}", miniProfiles.Count, _connectedServer.Name);
}

protected override async void OnActivated()
Expand Down
12 changes: 11 additions & 1 deletion SIT.Manager/ViewModels/Play/DirectConnectViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

namespace SIT.Manager.ViewModels.Play;
Expand Down Expand Up @@ -124,7 +125,7 @@ private async Task ConnectToServer(bool launchServer = false)

if (serverAddress != null)
{
AkiServer server = await _serverRequestingService.GetAkiServerAsync(serverAddress);
AkiServer server = await _serverRequestingService.GetAkiServerAsync(serverAddress, false);
AkiCharacter character = new(server, Username, Password);

try
Expand All @@ -149,6 +150,15 @@ private async Task ConnectToServer(bool launchServer = false)
}
}
}
catch(HttpRequestException ex)
{
await new ContentDialog()
{
Title = _localizationService.TranslateSource("DirectConnectViewModelLoginErrorTitle"),
Content = _localizationService.TranslateSource("DirectConnectViewModelLoginErrorDescription", ex.Message),
CloseButtonText = _localizationService.TranslateSource("DirectConnectViewModelButtonOk")
}.ShowAsync();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion SIT.Manager/Views/Play/DirectConnectView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<Button Name="ConnectButton"
Command="{Binding ConnectToServerCommand}"
Content="{DynamicResource DirectConnectViewConnectButtonTitle}"
ToolTip.Tip="{DynamicResource DirectConnectViewonnectButtonTitleToolTip}"
ToolTip.Tip="{DynamicResource DirectConnectViewConnectButtonTitleToolTip}"
Margin="0,0,4,0"/>
<Button Name="QuickPlayButton"
Command="{Binding QuickPlayCommand}"
Expand Down

0 comments on commit 851c26b

Please sign in to comment.