mirror of
https://git.recroomarchive.org/RecRoomArchive/RRAC.git
synced 2026-09-09 15:11:25 -07:00
Initialize repository
Added basic info to get in game for like...August 2016 ;-; It's not much but it's a start
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user