using RecRoomArchive.Models.API.Players; using System.Security.Cryptography; using System.Text.Json; namespace RecRoomArchive.Services { public class AccountService { public static ulong? AccountId { get; private set; } public bool AccountExists() { return File.Exists("data/profile.json"); } public bool CreateAccount(string? username = null) { 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")); } public ulong? GetSelfAccountId() { if (AccountId.HasValue) return AccountId; var profile = JsonSerializer.Deserialize(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}"; } } }