mirror of
https://git.recroomarchive.org/RecRoomArchive/RRAC.git
synced 2026-09-08 14:41:25 -07:00
More changes...
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user