Files
RRAC/RecRoomArchive/Services/AccountService.cs
splootybean 387ec7ba89 Initialize repository
Added basic info to get in game for like...August 2016 ;-;
It's not much but it's a start
2026-02-27 00:58:13 -08:00

72 lines
2.0 KiB
C#

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<BaseProfile>(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);
}
}
}
}
}