More changes...

This commit is contained in:
2026-02-27 19:30:49 -08:00
parent 20fdf60665
commit b64e257b9a
36 changed files with 553 additions and 63 deletions

View File

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

View File

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

View File

@@ -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);
}
}
}

View File

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

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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
{

View File

@@ -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
});
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;

View File

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

View File

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