Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
122 lines
3.9 KiB
Text
122 lines
3.9 KiB
Text
@page "/Settings/Integrations/Steam"
|
|
@using LANCommander.Server.Services.Enums
|
|
@using LANCommander.Server.Settings
|
|
@using LANCommander.Server.Settings.Models
|
|
@using LANCommander.Server.UI.Pages.Settings.Components
|
|
@using Microsoft.Extensions.Options
|
|
@inject SteamCMDService SteamCmdService
|
|
@inject IOptions<Settings> Settings
|
|
@inject SettingsProvider<Settings> SettingsProvider
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Beacon> Logger
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
<PageHeader Title="Steam">
|
|
<PageHeaderExtra>
|
|
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<PageContent>
|
|
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
|
|
<FormItem Label="SteamCMD Path">
|
|
<FilePicker @bind-Value="context.Server.SteamCMD.Path" Title="Choose SteamCMD Executable Path" Root="@_rootPath" />
|
|
</FormItem>
|
|
</Form>
|
|
|
|
<h2>Profiles</h2>
|
|
|
|
<Flex Direction="FlexDirection.Vertical" Gap="FlexGap.Large">
|
|
<Collapse>
|
|
@foreach (var profile in Settings.Value.Server.SteamCMD.Profiles)
|
|
{
|
|
<Panel Header="@(String.IsNullOrWhiteSpace(profile.Username) ? "New Profile" : profile.Username)">
|
|
<ExtraTemplate>
|
|
<Flex Gap="FlexGap.Small">
|
|
<Button Type="ButtonType.Text" Icon="@IconType.Outline.Close" Size="ButtonSize.Small" Danger OnClick="() => RemoveProfile(profile)"/>
|
|
</Flex>
|
|
</ExtraTemplate>
|
|
<ChildContent>
|
|
<SteamProfileEditor
|
|
@bind-Username="profile.Username"
|
|
@bind-InstallDirectory="profile.InstallDirectory"
|
|
OnAuthenticated="Save"/>
|
|
</ChildContent>
|
|
</Panel>
|
|
}
|
|
</Collapse>
|
|
|
|
<Flex Justify="FlexJustify.End">
|
|
<Button OnClick="AddProfile">Add Profile</Button>
|
|
</Flex>
|
|
</Flex>
|
|
</PageContent>
|
|
|
|
@code {
|
|
string _rootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
|
|
|
|
SteamCmdConnectionStatus _connectionStatus;
|
|
|
|
string _username;
|
|
string _password;
|
|
|
|
bool _processingLogin;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (!Settings.Value.Server.SteamCMD.Profiles.Any())
|
|
AddProfile();
|
|
}
|
|
|
|
void AddProfile()
|
|
{
|
|
Settings.Value.Server.SteamCMD.Profiles.Add(new SteamCmdProfile());
|
|
}
|
|
|
|
async Task RemoveProfile(SteamCmdProfile profile)
|
|
{
|
|
Settings.Value.Server.SteamCMD.Profiles.Remove(profile);
|
|
|
|
if (!String.IsNullOrWhiteSpace(profile.Username))
|
|
{
|
|
var logoutMessage = new MessageConfig
|
|
{
|
|
Content = "Logging out of Steam...",
|
|
Duration = 0,
|
|
Key = Guid.NewGuid().ToString()
|
|
};
|
|
|
|
MessageService.Loading(logoutMessage);
|
|
|
|
await SteamCmdService.LogoutAsync(profile.Username);
|
|
|
|
logoutMessage.Content = "Successfully logged out from Steam!";
|
|
logoutMessage.Duration = 3;
|
|
|
|
MessageService.Success(logoutMessage);
|
|
}
|
|
|
|
if (!Settings.Value.Server.SteamCMD.Profiles.Any())
|
|
AddProfile();
|
|
}
|
|
|
|
async Task Save()
|
|
{
|
|
try
|
|
{
|
|
Settings.Value.Server.SteamCMD.Profiles = Settings.Value.Server.SteamCMD.Profiles.Where(p => !String.IsNullOrWhiteSpace(p.Username)).ToList();
|
|
|
|
SettingsProvider.Update(s =>
|
|
{
|
|
s.Server.SteamCMD = Settings.Value.Server.SteamCMD;
|
|
});
|
|
|
|
MessageService.Success("Settings saved!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("An unknown error occurred.");
|
|
Logger.LogError(ex, "An unknown error occurred.");
|
|
}
|
|
}
|
|
}
|