More changes...

This commit is contained in:
splootybean
2026-02-27 19:30:49 -08:00
parent 20fdf60665
commit b64e257b9a
36 changed files with 553 additions and 63 deletions
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Mvc;
namespace RecRoomArchive.Controllers.API.Equipment.V1
{
[Route(template: "api/[controller]/v1")]
[ApiController]
public class EquipmentController : ControllerBase
{
[HttpGet(template: "getUnlocked")]
public async Task<ActionResult<List<object>>> GetEquipment()
{
return new List<object>();
}
}
}
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Mvc;
namespace RecRoomArchive.Controllers.API.Events.V3
{
[Route(template: "api/[controller]/v3")]
[ApiController]
public class EventsController : ControllerBase
{
[HttpGet(template: "list")]
public async Task<ActionResult<List<object>>> GetActiveEventsList()
{
return new List<object>();
}
}
}
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Models.API.GameSessions;
using System.Text.Json;
namespace RecRoomArchive.Controllers.API.GameSessions.V2
{
[Route("api/[controller]/v2")]
[ApiController]
public class GameSessionsController : ControllerBase
{
[HttpPost(template: "joinRandom")]
public async Task<ActionResult<JoinGameSessionResponse>> JoinRandomGameSession([FromBody] JoinRandomGameSessionRequest request)
{
Console.WriteLine(JsonSerializer.Serialize(request));
var session = new JoinGameSessionResponse()
{
GameSession = new GameSession()
};
Console.WriteLine(JsonSerializer.Serialize(session));
return Ok(session);
}
}
}
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Controllers.API.Notification;
using RecRoomArchive.Models.API.Notification;
using RecRoomArchive.Models.API.Players;
using RecRoomArchive.Services;
using System.Text.Json;
@@ -25,6 +27,8 @@ namespace RecRoomArchive.Controllers.API.Images.V2
fileService.SetData("profile.json", JsonSerializer.Serialize(profile));
await NotificationController.Notify(profile.Id, PushNotificationId.SubscriptionUpdateProfile, profile);
return Ok();
}
}
@@ -0,0 +1,87 @@
using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Models.API.Notification;
using System.Net.WebSockets;
using System.Text;
using System.Text.Json;
namespace RecRoomArchive.Controllers.API.Notification
{
[Route("api/[controller]")]
[ApiController]
public class NotificationController : ControllerBase
{
private static readonly Dictionary<ulong, WebSocket> Clients = [];
[HttpGet("v2")]
public async Task Get()
{
if (!HttpContext.WebSockets.IsWebSocketRequest)
{
HttpContext.Response.StatusCode = 400;
return;
}
var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
var buffer = new byte[1024 * 4];
var result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
var handshakeJson = Encoding.UTF8.GetString(buffer, 0, result.Count);
var handshakeData = JsonSerializer.Deserialize<Dictionary<string, string>>(handshakeJson)!;
var playerId = ulong.Parse(handshakeData["PlayerId"]);
Clients[playerId] = webSocket;
var sessionResponse = JsonSerializer.Serialize(new { SessionId = playerId });
await webSocket.SendAsync(Encoding.UTF8.GetBytes(sessionResponse), WebSocketMessageType.Text, true, CancellationToken.None);
await Echo(playerId, webSocket);
Clients.Remove(playerId);
}
private static async Task Echo(ulong playerId, WebSocket webSocket)
{
var buffer = new byte[1024 * 4];
var receiveResult = await webSocket.ReceiveAsync(
new ArraySegment<byte>(buffer), CancellationToken.None);
while (!receiveResult.CloseStatus.HasValue)
{
var response = JsonSerializer.Serialize(new { SessionId = playerId }); // i think?? only for analytics tho lolololool
await webSocket.SendAsync(new ArraySegment<byte>(Encoding.UTF8.GetBytes(response)),
WebSocketMessageType.Text, true, CancellationToken.None);
/*await webSocket.SendAsync(
new ArraySegment<byte>(buffer, 0, receiveResult.Count),
receiveResult.MessageType,
receiveResult.EndOfMessage,
CancellationToken.None);*/
receiveResult = await webSocket.ReceiveAsync(
new ArraySegment<byte>(buffer), CancellationToken.None);
}
await webSocket.CloseAsync(
receiveResult.CloseStatus.Value,
receiveResult.CloseStatusDescription,
CancellationToken.None);
Clients.Remove(playerId);
}
public static async Task Notify(ulong playerId, PushNotificationId id, object msg)
{
if (!Clients.TryGetValue(playerId, out var socket))
return;
if (socket.State != WebSocketState.Open)
return;
var notification = new
{
Id = (int)id,
Msg = msg
};
var json = JsonSerializer.Serialize(notification);
var bytes = Encoding.UTF8.GetBytes(json);
await socket.SendAsync(bytes, WebSocketMessageType.Text, true, CancellationToken.None);
}
}
}
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Models.API.Platform;
using RecRoomArchive.Models.API.Players;
using RecRoomArchive.Services;
namespace RecRoomArchive.Controllers.API.PlatformLogin.V1
{
[Route("api/[controller]/v1")]
[ApiController]
public class PlatformLoginController(AccountService accountService) : ControllerBase
{
[HttpPost(template: "profiles")]
public async Task<ActionResult<List<BaseProfile>>> GetProfiles([FromForm(Name = "Platform")] PlatformType platform, [FromForm(Name = "PlatformId")] ulong platformId)
{
if (!accountService.AccountExists())
{
accountService.CreateAccount();
}
var profile = accountService.GetSelfAccount();
if (profile == null)
return BadRequest("Please relaunch RRAC and re-run setup");
List<BaseProfile> profiles = [profile];
return Ok(profiles);
}
}
}
@@ -34,7 +34,7 @@ namespace RecRoomArchive.Controllers.API.PlatformLogin.V2
accountService.CreateAccount(username);
}
var accountId = accountService.GetSelfAccount()!.Id;
var accountId = accountService.GetSelfAccountId()!.Value;
return Ok(new BaseLoginResponse
{
@@ -0,0 +1,44 @@
using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Models.API.PlatformLogin.Requests;
using RecRoomArchive.Models.API.PlatformLogin.Responses;
using RecRoomArchive.Services;
namespace RecRoomArchive.Controllers.API.PlatformLogin.V5
{
/// <summary>
/// Used to login to accounts on Rec Room
/// </summary>
[Route(template: "api/[controller]/v5")]
[ApiController]
public class PlatformLoginController(AppVersionService appVersionService, AccountService accountService, AuthorizationService authorizationService) : ControllerBase
{
/// <summary>
/// Checks if the appVersion provided is allowed to play (which it most certainly will be unless its a weird build or someone messed with it)
/// </summary>
/// <returns>An Ok response if the version is valid, Forbid if it is not. Forbid will yield the client displaying "Rec Room Update Required" soo maybe don't</returns>
[HttpPost]
public async Task<ActionResult> Login([FromForm] BaseLoginRequest loginRequest)
{
var username = loginRequest.Name ?? string.Empty;
var buildTimestamp = loginRequest.BuildTimestamp;
await appVersionService.StoreBuildTimestamp(buildTimestamp);
// See if a profile exists yet...
if (!accountService.AccountExists())
{
// ...if not, create it!
accountService.CreateAccount(username);
}
var accountId = accountService.GetSelfAccountId()!.Value;
return Ok(new BaseLoginResponse
{
Token = authorizationService.GenerateToken(accountId),
PlayerId = accountId
});
}
}
}
@@ -69,7 +69,13 @@ namespace RecRoomArchive.Controllers.API.Players
[HttpPut(template: "{profileId:long}")]
public async Task<ActionResult<AugustProfile>> UpdateProfile([Required] ulong profileId, [FromBody] AugustProfile model)
{
return (AugustProfile)accountService.GetSelfAccount()!;
var baseProfile = accountService.GetSelfAccount();
if (baseProfile == null)
return NotFound();
var profile = new AugustProfile(baseProfile);
return profile;
}
}
}
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Models.API.Config;
using RecRoomArchive.Models.API.Platform;
using RecRoomArchive.Models.API.Players;
using RecRoomArchive.Services;
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Controllers.API.Notification;
using RecRoomArchive.Models.API.Notification;
using RecRoomArchive.Models.API.Players;
using RecRoomArchive.Models.Common;
using RecRoomArchive.Services;
@@ -31,6 +33,8 @@ namespace RecRoomArchive.Controllers.API.Players.V2
fileService.SetData("profile.json", JsonSerializer.Serialize(profile));
await NotificationController.Notify(profile.Id, PushNotificationId.SubscriptionUpdateProfile, profile);
return Ok(OkResponse.Ok());
}
}
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Models.API.VersionCheck;
using RecRoomArchive.Services;
namespace RecRoomArchive.Controllers.API.VersionCheck.V3
{
/// <summary>
/// Endpoints used to check if the version the player is playing on is up to date enough to play Rec Room, due to this being a custom server, it doesn't really matter
/// </summary>
[Route(template: "api/[controller]/v3")]
[ApiController]
public class VersionCheckController(AppVersionService appVersionService) : ControllerBase
{
/// <summary>
/// Checks if the appVersion provided is allowed to play (which it most certainly will be unless its a weird build or someone messed with it)
/// </summary>
/// <returns>A valid VersionCheckResponse if the version is valid, an invalid VersionCheckResponse if it is not. Forbid will yield the client displaying "Rec Room Update Required" soo maybe don't</returns>
[HttpGet]
public async Task<ActionResult> CheckVersion([FromQuery(Name = "v")] string appVersion)
{
if (appVersion == null)
return BadRequest(new VersionCheckResponse(VersionStatus.UpdateRequired));
await appVersionService.StoreAppVersion(appVersion);
return Ok(new VersionCheckResponse());
}
}
}
+24 -5
View File
@@ -1,5 +1,6 @@
using RecRoomArchive.Models.Common;
using RecRoomArchive.Services;
using Serilog;
namespace RecRoomArchive
{
@@ -8,11 +9,15 @@ namespace RecRoomArchive
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseKestrel();
Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger();
#region Services
builder.Services.AddControllers();
builder.Services.AddOpenApi();
builder.Services.AddHttpContextAccessor();
builder.Services.AddSerilog();
builder.Services.AddScoped<AccountService>();
builder.Services.AddScoped<AppVersionService>();
@@ -21,17 +26,31 @@ namespace RecRoomArchive
builder.Services.AddScoped<FileService>();
builder.Services.AddScoped<ImageService>();
builder.Services.AddScoped<MessageOfTheDayService>();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
#endregion
Console.Title = $"RRAC {Constants.Version}";
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.MapOpenApi();
app.UseSwagger();
app.UseSwaggerUI();
app.UseSerilogRequestLogging();
app.UseAuthorization();
var webSocketOptions = new WebSocketOptions
{
KeepAliveInterval = TimeSpan.FromMinutes(2)
};
app.UseWebSockets(webSocketOptions);
app.MapControllers();
app.Run();
@@ -20,4 +20,4 @@
}
}
}
}
}
+4 -1
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
@@ -8,6 +8,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="10.1.4" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />
</ItemGroup>
+17 -27
View File
@@ -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);
}
}
}
}
}
+5 -1
View File
@@ -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)),
+4 -3
View File
@@ -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 =
[
+14 -2
View File
@@ -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;
}
}
}