More changes...

This commit is contained in:
splootybean
2026-02-27 19:30:49 -08:00
parent 20fdf60665
commit b64e257b9a
36 changed files with 553 additions and 63 deletions
+17 -27
View File
@@ -6,6 +6,8 @@ namespace RecRoomArchive.Services
{
public class AccountService
{
public static ulong? AccountId { get; private set; }
public bool AccountExists()
{
return File.Exists("data/profile.json");
@@ -13,8 +15,6 @@ namespace RecRoomArchive.Services
public bool CreateAccount(string? username = null)
{
PopulateServerData();
if (string.IsNullOrEmpty(username))
{
username = GetRandomUsername();
@@ -38,35 +38,25 @@ namespace RecRoomArchive.Services
return JsonSerializer.Deserialize<BaseProfile>(File.ReadAllText("data/profile.json"));
}
public ulong? GetSelfAccountId()
{
if (AccountId.HasValue)
return AccountId;
var profile = JsonSerializer.Deserialize<BaseProfile>(File.ReadAllText("data/profile.json"));
if (profile == null)
return null;
AccountId = profile.Id;
return AccountId;
}
private static string GetRandomUsername()
{
int randomFourDigits = RandomNumberGenerator.GetInt32(1000, 9999);
return $"RRA-User_{randomFourDigits}";
}
private static void PopulateServerData()
{
string basePath = "data";
string[] directories = ["rooms", "images", "blobs"];
string[] files = [];
Directory.CreateDirectory(basePath);
foreach (var directory in directories)
{
Directory.CreateDirectory(Path.Combine(basePath, directory));
}
foreach (var file in files)
{
string fullPath = Path.Combine(basePath, file);
if (!File.Exists(fullPath))
{
File.WriteAllText(fullPath, string.Empty);
}
}
}
}
}