@using LANCommander.Server.Services.Enums
@inject SteamCMDService SteamCmdService
@inject IMessageService MessageService
@code {
[Parameter] public string Username { get; set; }
[Parameter] public EventCallback UsernameChanged { get; set; }
[Parameter] public string InstallDirectory { get; set; }
[Parameter] public EventCallback InstallDirectoryChanged { get; set; }
[Parameter] public EventCallback OnAuthenticated { get; set; }
string _rootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
SteamCmdConnectionStatus _connectionStatus = SteamCmdConnectionStatus.Unknown;
bool _processingLogin = false;
string _password = String.Empty;
MessageConfig _loginMessage = new MessageConfig();
protected override async Task OnInitializedAsync()
{
if (!String.IsNullOrWhiteSpace(Username))
_connectionStatus = await SteamCmdService.GetConnectionStatusAsync(Username);
else
_connectionStatus = SteamCmdConnectionStatus.Unauthenticated;
}
async Task Authenticate()
{
_processingLogin = true;
await InvokeAsync(StateHasChanged);
_loginMessage.Content = "Logging into Steam...";
_loginMessage.Key = Guid.NewGuid().ToString();
_loginMessage.Duration = 0;
MessageService.Loading(_loginMessage);
MessageService.Info("Check the Steam mobile app to confirm this login", 10);
var status = await SteamCmdService.LoginToSteamAsync(Username, _password);
if (status == SteamCmdStatus.Success)
{
_connectionStatus = await SteamCmdService.GetConnectionStatusAsync(Username);
_loginMessage.Content = "Successfully authenticated to Steam!";
_loginMessage.Duration = 3;
MessageService.Success(_loginMessage);
_password = String.Empty;
if (UsernameChanged.HasDelegate)
await UsernameChanged.InvokeAsync(Username);
if (InstallDirectoryChanged.HasDelegate)
await InstallDirectoryChanged.InvokeAsync(InstallDirectory);
if (OnAuthenticated.HasDelegate)
await OnAuthenticated.InvokeAsync();
}
else
{
switch (status)
{
case SteamCmdStatus.InvalidUsername:
case SteamCmdStatus.InvalidPassword:
_loginMessage.Content = "Invalid username or password";
break;
case SteamCmdStatus.ExecutableNotFound:
_loginMessage.Content = "SteamCMD executable not found";
break;
case SteamCmdStatus.PathNotConfigured:
_loginMessage.Content = "SteamCMD path not configured";
break;
case SteamCmdStatus.Error:
_loginMessage.Content = "SteamCMD returned an error, check logs for info.";
break;
case SteamCmdStatus.UnknownError:
default:
_loginMessage.Content = "An unknown error occurred, check logs for more info";
break;
}
_loginMessage.Duration = 8;
MessageService.Error(_loginMessage);
}
_processingLogin = false;
await InvokeAsync(StateHasChanged);
}
}