using RecRoomArchive.Models.API.Players; using System.Security.Cryptography; using System.Text.Json; namespace RecRoomArchive.Services { public class AccountService { public bool AccountExists() { return File.Exists("data/profile.json"); } public bool CreateAccount(string? username = null) { PopulateServerData(); if (string.IsNullOrEmpty(username)) { username = GetRandomUsername(); } Console.WriteLine($"Creating account for {username}"); var profile = new BaseProfile { Id = (ulong)RandomNumberGenerator.GetInt32(1000, 9999999), Username = username, DisplayName = username }; File.WriteAllText("data/profile.json", JsonSerializer.Serialize(profile)); return File.Exists("data/profile.json"); } public BaseProfile? GetSelfAccount() { return JsonSerializer.Deserialize(File.ReadAllText("data/profile.json")); } 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); } } } } }