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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace RecRoomArchive.Services
|
||||
using RecRoomArchive.Models.Common;
|
||||
|
||||
namespace RecRoomArchive.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to get the appVersion from the client to determine how to run the server
|
||||
@@ -63,6 +65,8 @@
|
||||
FullBuildTimestamp = buildTimestamp;
|
||||
BuildTimestamp = buildTimestampDateTime;
|
||||
|
||||
Console.Title = $"RRAC {Constants.Version} - ({BuildTimestamp.Value.Year}) {BuildTimestamp.Value}";
|
||||
Console.WriteLine ($"RRAC {Constants.Version} - ({BuildTimestamp.Value.Year}) {BuildTimestamp.Value}");
|
||||
Console.WriteLine($"buildTimestamp: {FullBuildTimestamp}, buildTimestampDateTime: {BuildTimestamp}");
|
||||
|
||||
return true;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace RecRoomArchive.Services
|
||||
new(ClaimTypes.Role, "gameClient")
|
||||
};
|
||||
|
||||
SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor()
|
||||
SecurityTokenDescriptor tokenDescriptor = new()
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
Expires = DateTime.UtcNow.Add(TimeSpan.FromHours(12)),
|
||||
|
||||
@@ -17,12 +17,13 @@ namespace RecRoomArchive.Services
|
||||
public async Task<RecRoomConfig> GetRecRoomConfig()
|
||||
{
|
||||
var request = _httpContextAccessor.HttpContext?.Request;
|
||||
var host = $"{request!.Scheme}://{request.Host}";
|
||||
var cdnHost = $"{request!.Scheme}://{request.Host}";
|
||||
var motd = await _motdService.GetMessageOfTheDay();
|
||||
|
||||
return new RecRoomConfig()
|
||||
{
|
||||
MessageOfTheDay = await _motdService.GetMessageOfTheDay(),
|
||||
CdnBaseUri = host,
|
||||
MessageOfTheDay = motd,
|
||||
CdnBaseUri = cdnHost,
|
||||
MatchmakingParams = new MatchmakingParams(),
|
||||
LevelProgressionMaps =
|
||||
[
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Xml.Linq;
|
||||
using RecRoomArchive.Models.RRA;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace RecRoomArchive.Services
|
||||
{
|
||||
@@ -9,7 +10,7 @@ namespace RecRoomArchive.Services
|
||||
string basePath = "data";
|
||||
|
||||
string[] directories = ["rooms", "images", "blobs"];
|
||||
string[] files = ["rooms.json", "avatar.json", "settings.json", "profile.json"];
|
||||
string[] files = ["rooms.json", "avatar.json", "settings.json", "profile.json", "avatarItems.json", "serverPreferences.json"];
|
||||
|
||||
Directory.CreateDirectory(basePath);
|
||||
|
||||
@@ -28,6 +29,17 @@ namespace RecRoomArchive.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteServerPrefs(bool isComplete)
|
||||
{
|
||||
var preferences = new ServerPreferences
|
||||
{
|
||||
CompletedSetup = isComplete
|
||||
};
|
||||
|
||||
SetData("serverPreferences.json", JsonSerializer.Serialize(preferences));
|
||||
}
|
||||
|
||||
public string? GetData(string name)
|
||||
{
|
||||
var path = $"data/{name}";
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace RecRoomArchive.Services
|
||||
/// <summary>
|
||||
/// HttpClient for making requests to Gitea
|
||||
/// </summary>
|
||||
private static readonly HttpClient httpClient = new HttpClient();
|
||||
private static readonly HttpClient httpClient = new();
|
||||
|
||||
/// <summary>
|
||||
/// MessageOfTheDay reference
|
||||
@@ -22,16 +22,18 @@ namespace RecRoomArchive.Services
|
||||
/// Gets the message of the day from Gitea. If the URL cannot be resolved, it will fall back to "Welcome to RecRoomArchive!"
|
||||
/// </summary>
|
||||
/// <returns>String related to the Message of the Day</returns>
|
||||
public async Task<string> GetMessageOfTheDay(string? version = null)
|
||||
public async Task<string> GetMessageOfTheDay()
|
||||
{
|
||||
// I wouldn't want to re-request the MOTD from the server a bunch of times...
|
||||
if (string.IsNullOrEmpty(MessageOfTheDay))
|
||||
{
|
||||
var motd = await httpClient.GetAsync($"https://git.recroomarchive.org/RecRoomArchive/RRAC/raw/branch/main/MOTD");
|
||||
if (!motd.IsSuccessStatusCode)
|
||||
return "Welcome to RecRoomArchive!";
|
||||
//var motd = await httpClient.GetAsync($"https://git.recroomarchive.org/RecRoomArchive/RRAC/raw/branch/main/MOTD");
|
||||
//if (!motd.IsSuccessStatusCode)
|
||||
// return "Welcome to RecRoomArchive!";
|
||||
|
||||
MessageOfTheDay = await motd.Content.ReadAsStringAsync();
|
||||
//MessageOfTheDay = await motd.Content.ReadAsStringAsync();
|
||||
|
||||
MessageOfTheDay = "Welcome to RecRoomArchive!";
|
||||
}
|
||||
|
||||
return MessageOfTheDay;
|
||||
@@ -46,17 +48,19 @@ namespace RecRoomArchive.Services
|
||||
if (CharadesWordsLastFetchedAt - DateTime.UtcNow > TimeSpan.FromMinutes(30))
|
||||
return CachedCharadesWords;
|
||||
|
||||
var request = await httpClient.GetAsync("https://git.recroomarchive.org/RecRoomArchive/RRAC/raw/branch/main/CharadesWords");
|
||||
if (!request.IsSuccessStatusCode)
|
||||
return [];
|
||||
//var request = await httpClient.GetAsync("https://git.recroomarchive.org/RecRoomArchive/RRAC/raw/branch/main/CharadesWords");
|
||||
//if (!request.IsSuccessStatusCode)
|
||||
// return [];
|
||||
|
||||
var words = await request.Content.ReadAsStringAsync();
|
||||
if (words == null)
|
||||
return [];
|
||||
//var words = await request.Content.ReadAsStringAsync();
|
||||
//if (words == null)
|
||||
// return [];
|
||||
|
||||
CachedCharadesWords = JsonSerializer.Deserialize<List<CharadesWord>>(words)!;
|
||||
return [];
|
||||
|
||||
return CachedCharadesWords;
|
||||
//CachedCharadesWords = JsonSerializer.Deserialize<List<CharadesWord>>(words)!;
|
||||
|
||||
//return CachedCharadesWords;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user