Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic persistance #24

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Fuyu.Launcher/Fuyu.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../Fuyu.Platform.Common/Fuyu.Platform.Common.csproj" />
<ProjectReference Include="../Fuyu.Platform.Launcher/Fuyu.Platform.Launcher.csproj" />
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions Fuyu.Launcher/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<FluentDesignTheme Mode="DesignThemeModes.Dark"></FluentDesignTheme>

<FluentStack Orientation="Orientation.Horizontal" Width="100%">
<FluentNavMenu Width="250" Collapsible="false" Class="height-100vh nav-bg">
<FluentNavLink Href="/account">Account</FluentNavLink>
<FluentStack Orientation="Orientation.Horizontal" Width="100%" Class="height-100vh">
<FluentNavMenu Width="200" Collapsible="false">
<FluentNavLink Href="/login">Login</FluentNavLink>
<FluentNavLink Href="/settings">Settings</FluentNavLink>
</FluentNavMenu>

Expand Down
21 changes: 11 additions & 10 deletions Fuyu.Launcher/Pages/Account.razor
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
@using Fuyu.Launcher.Services;
@using Fuyu.Platform.Common.Models.Fuyu.Accounts
@using Fuyu.Platform.Launcher.Services

@page "/"
@page "/account"

<FluentStack Orientation="Orientation.Vertical">

<FluentButton Appearance="Appearance.Accent" IconStart="@(new Icons.Regular.Size24.Play())" OnClick="StartServer">Start Server</FluentButton>
<FluentButton Appearance="Appearance.Accent" IconStart="@(new Icons.Regular.Size24.Play())" OnClick="StartEft">Start Game</FluentButton>
<FluentButton Appearance="Appearance.Accent" IconStart="@(new Icons.Regular.Size24.Play())" OnClick="StartEft_Clicked">Start EFT</FluentButton>
<FluentButton Appearance="Appearance.Accent" IconStart="@(new Icons.Regular.Size24.Play())" OnClick="StartArena_Clicked">Start Arena</FluentButton>

</FluentStack>

@code
{
private void StartServer()
[SupplyParameterFromQuery(Name = "sessionid")]
private string sessionId { get; set; }

private void StartEft_Clicked()
{
using (var process = ProcessService.StartServer(SettingsService.ServerDirectory))
using (var process = ProcessService.StartEft(SettingsService.EftDirectory, sessionId, SettingsService.EftAddress))
{
process.Start();
}
}

private void StartEft()
private void StartArena_Clicked()
{
var sessionId = "test";

using (var process = ProcessService.StartEft(SettingsService.ClientDirectory, sessionId, SettingsService.Address))
using (var process = ProcessService.StartArena(SettingsService.ArenaDirectory, sessionId, SettingsService.ArenaAddress))
{
process.Start();
}
Expand Down
45 changes: 45 additions & 0 deletions Fuyu.Launcher/Pages/Login.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@using Fuyu.Platform.Launcher.Services;

@inject NavigationManager Navigation

@page "/"
@page "/login"

<FluentStack Orientation="Orientation.Vertical">

<!-- server settings -->
<FluentAccordionItem Heading="Login" Expanded=true Style="width: 100%;">
<FluentLabel>Username:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Text" @bind-Value="username" Style="width: 100%;"></FluentTextField>
<FluentLabel>Password:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Password" @bind-Value="password" Style="width: 100%;"></FluentTextField>
<br />
<br />
<FluentButton Appearance="Appearance.Accent" OnClick="Login_Clicked">Login</FluentButton>
<a href="/register"><FluentLabel>Register</FluentLabel></a>
</FluentAccordionItem>

</FluentStack>

@code
{
string username = string.Empty;
string password = string.Empty;

private void Login_Clicked(EventArgs e)
{
var hashedPassword = HashService.GetSHA256(password);
var sessionId = RequestService.LoginAccount(username, hashedPassword);

if (sessionId == string.Empty)
{
// TODO:
// * show error
// -- seionmoya, 2024/09/02
}
else
{
Navigation.NavigateTo($"/account?sessionid={sessionId}");
}
}
}
50 changes: 50 additions & 0 deletions Fuyu.Launcher/Pages/Register.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@using Fuyu.Platform.Common.Models.Fuyu.Accounts
@using Fuyu.Platform.Launcher.Services;

@inject NavigationManager Navigation

@page "/register"

<FluentStack Orientation="Orientation.Vertical">

<!-- server settings -->
<FluentAccordionItem Heading="Register" Expanded=true Style="width: 100%;">
<FluentLabel>Username:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Text" @bind-Value="username" Style="width: 100%;"></FluentTextField>
<FluentLabel>Password:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Text" @bind-Value="password" Style="width: 100%;"></FluentTextField>
<FluentLabel>Edition:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Text" @bind-Value="edition" Style="width: 100%;"></FluentTextField>
<br />
<br />
<FluentButton Appearance="Appearance.Accent" OnClick="Register_Clicked">Register</FluentButton>
<a href="/login"><FluentLabel>Login</FluentLabel></a>
</FluentAccordionItem>

</FluentStack>

@code
{
string username = string.Empty;
string password = string.Empty;
string edition = "unheard";

private void Register_Clicked(EventArgs e)
{
var hashedPassword = HashService.GetSHA256(password);
var registerStatus = RequestService.RegisterAccount(username, hashedPassword, edition);

switch (registerStatus)
{
case ERegisterStatus.Success:
Navigation.NavigateTo("/login");
break;

case ERegisterStatus.AlreadyExists:
// TODO:
// * show error
// -- seionmoya, 2024/09/02
break;
}
}
}
58 changes: 39 additions & 19 deletions Fuyu.Launcher/Pages/Settings.razor
Original file line number Diff line number Diff line change
@@ -1,43 +1,63 @@
@using Fuyu.Launcher.Services;
@using Fuyu.Platform.Launcher.Services;

@page "/settings"

<FluentStack Orientation="Orientation.Vertical">

<!-- server settings -->
<FluentAccordionItem Heading="Server" Style="width: 100%;">
<FluentLabel>Path to installation:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Text" @oninput="ServerDirectory_TextChanged" @bind-Value="serverDirectory" Style="width: 100%;"></FluentTextField>
<!-- fuyu -->
<FluentAccordionItem Heading="Fuyu" Style="width: 100%;">
<FluentLabel>Server address:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Url" @oninput="FuyuAddress_TextChanged" @bind-Value="fuyuAddress" Style="width: 100%;"></FluentTextField>
</FluentAccordionItem>

<!-- client settings -->
<FluentAccordionItem Heading="Client" Style="width: 100%;">
<FluentLabel>Path to installation:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Text" @oninput="ClientDirectory_TextChanged" @bind-Value="clientDirectory" Style="width: 100%;"></FluentTextField>
<!-- eft -->
<FluentAccordionItem Heading="Escape From Tarkov" Style="width: 100%;">
<FluentLabel>Server address:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Url" @oninput="Address_TextChanged" @bind-Value="address" Style="width: 100%;"></FluentTextField>
<FluentTextField TextFieldType="TextFieldType.Url" @oninput="EftAddress_TextChanged" @bind-Value="eftAddress" Style="width: 100%;"></FluentTextField>
<FluentLabel>Client location:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Text" @oninput="EftDirectory_TextChanged" @bind-Value="eftDirectory" Style="width: 100%;"></FluentTextField>
</FluentAccordionItem>

<!-- arena -->
<FluentAccordionItem Heading="Escape From Tarkov: Arena" Style="width: 100%;">
<FluentLabel>Server address:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Url" @oninput="ArenaAddress_TextChanged" @bind-Value="arenaAddress" Style="width: 100%;"></FluentTextField>
<FluentLabel>Client location:</FluentLabel>
<FluentTextField TextFieldType="TextFieldType.Text" @oninput="ArenaDirectory_TextChanged" @bind-Value="arenaDirectory" Style="width: 100%;"></FluentTextField>
</FluentAccordionItem>

</FluentStack>

@code
{
string serverDirectory = SettingsService.ServerDirectory;
string clientDirectory = SettingsService.ClientDirectory;
string address = SettingsService.Address;
string fuyuAddress = SettingsService.FuyuAddress;
string eftAddress = SettingsService.EftAddress;
string arenaAddress = SettingsService.ArenaAddress;
string eftDirectory = SettingsService.EftDirectory;
string arenaDirectory = SettingsService.EftDirectory;

private void FuyuAddress_TextChanged(ChangeEventArgs e)
{
SettingsService.FuyuAddress = (string)e.Value;
}

private void EftAddress_TextChanged(ChangeEventArgs e)
{
SettingsService.EftAddress = (string)e.Value;
}

private void ServerDirectory_TextChanged(ChangeEventArgs e)
private void ArenaAddress_TextChanged(ChangeEventArgs e)
{
SettingsService.ServerDirectory = (string)e.Value;
SettingsService.ArenaAddress = (string)e.Value;
}

private void ClientDirectory_TextChanged(ChangeEventArgs e)
private void EftDirectory_TextChanged(ChangeEventArgs e)
{
SettingsService.ClientDirectory = (string)e.Value;
SettingsService.EftDirectory = (string)e.Value;
}

private void Address_TextChanged(ChangeEventArgs e)
private void ArenaDirectory_TextChanged(ChangeEventArgs e)
{
SettingsService.Address = (string)e.Value;
SettingsService.ArenaDirectory = (string)e.Value;
}
}
18 changes: 0 additions & 18 deletions Fuyu.Launcher/Services/SettingsService.cs

This file was deleted.

55 changes: 51 additions & 4 deletions Fuyu.Platform.Common/IO/VFS.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,66 @@
using System;
using System.IO;

namespace Fuyu.Platform.Common.IO
{
public class VFS
{
public static bool Exists(string filepath)
public static bool DirectoryExists(string filepath)
{
return File.Exists(filepath) || Directory.Exists(filepath);
return Directory.Exists(filepath);
}

public static bool FileExists(string filepath)
{
return File.Exists(filepath);
}

public static string[] GetFiles(string path)
{
if (!Directory.Exists(path))
{
throw new DirectoryNotFoundException($"Directory {path} doesn't exist.");
}

return Directory.GetFiles(path);
}

public static void CreateDirectory(string path)
{
Directory.CreateDirectory(path);
}

public static string ReadTextFile(string filepath)
{
var path = Path.GetDirectoryName(filepath);

if (!DirectoryExists(path))
{
throw new DirectoryNotFoundException($"Directory {path} doesn't exist.");
}

if (!File.Exists(filepath))
{
throw new FileNotFoundException($"File {filepath} doesn't exist.");
}

using (var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.None))
{
using (var sr = new StreamReader(fs))
{
var text = sr.ReadToEnd();
return text;
}
}
}

public static void WriteTextFile(string filepath, string text)
{
if (!Exists(filepath))
var path = Path.GetDirectoryName(filepath);

if (!DirectoryExists(path))
{
Directory.CreateDirectory(Path.GetDirectoryName(filepath));
CreateDirectory(path);
}

using (var fs = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
Expand Down
2 changes: 1 addition & 1 deletion Fuyu.Platform.Common/Models/EFT/Common/MongoId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public MongoId([JsonProperty("$value")] string id)
{
if (id == null || id.Length != 24)
{
throw new ArgumentOutOfRangeException("Critical MongoId error: incorrect length. Id: " + id);
throw new ArgumentOutOfRangeException($"Critical MongoId error: incorrect length. Id: {id}");
}

_timeStamp = GetTimestamp(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Runtime.Serialization;
using Fuyu.Platform.Common.Models.Fuyu.Savegame;

namespace Fuyu.Platform.Common.Models.Fuyu
namespace Fuyu.Platform.Common.Models.Fuyu.Accounts
{
[DataContract]
public struct Account
{
[DataMember]
public int Id;

[DataMember]
public string Username;

Expand Down
8 changes: 8 additions & 0 deletions Fuyu.Platform.Common/Models/Fuyu/Accounts/ERegisterStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Fuyu.Platform.Common.Models.Fuyu.Accounts
{
public enum ERegisterStatus
{
AlreadyExists,
Success
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Runtime.Serialization;
using Fuyu.Platform.Common.Models.EFT.Profiles;

namespace Fuyu.Platform.Common.Models.Fuyu.Savegame
namespace Fuyu.Platform.Common.Models.Fuyu.Accounts
{
[DataContract]
public struct EftProfile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;

namespace Fuyu.Platform.Common.Models.Fuyu.Savegame
namespace Fuyu.Platform.Common.Models.Fuyu.Accounts
{
[DataContract]
public struct EftSave
Expand Down
Loading
Loading