feat: add new matchmake routes for player, event, club, and code

This commit is contained in:
Alexa
2026-07-02 10:11:05 +03:00
parent 1272768e16
commit 56b8d4285d
2 changed files with 50 additions and 3 deletions
@@ -28,6 +28,10 @@ public sealed class MatchmakePullInviteTests : IClassFixture<DorkNetServerFactor
[InlineData("/matchmake/instance/999")] [InlineData("/matchmake/instance/999")]
[InlineData("/matchmake/invite/999")] [InlineData("/matchmake/invite/999")]
[InlineData("/matchmake/chatinvite/2/16777216")] // {accountId}/{roomInstanceId} [InlineData("/matchmake/chatinvite/2/16777216")] // {accountId}/{roomInstanceId}
[InlineData("/matchmake/player/2")]
[InlineData("/matchmake/event/999")]
[InlineData("/matchmake/club/999")]
[InlineData("/matchmake/code/5/ABCDEF")] // {roomId}/{code}
public async Task Matchmake_pull_routes_exist(string path) public async Task Matchmake_pull_routes_exist(string path)
{ {
using var client = ApiClient(); using var client = ApiClient();
@@ -44,6 +48,10 @@ public sealed class MatchmakePullInviteTests : IClassFixture<DorkNetServerFactor
[InlineData("/matchmake/invite/999")] [InlineData("/matchmake/invite/999")]
[InlineData("/matchmake/chatinvite/2/16777216")] [InlineData("/matchmake/chatinvite/2/16777216")]
[InlineData("/matchmake/room/5")] [InlineData("/matchmake/room/5")]
[InlineData("/matchmake/player/2")]
[InlineData("/matchmake/event/999")]
[InlineData("/matchmake/club/999")]
[InlineData("/matchmake/code/5/ABCDEF")]
public void Matchmake_paths_route_to_same_service_as_goto(string path) public void Matchmake_paths_route_to_same_service_as_goto(string path)
{ {
const string apex = "dork.test"; const string apex = "dork.test";
@@ -410,14 +410,32 @@ public class GoToController(
}; };
[HttpPost("/goto/event/{eventId:long}")] [HttpPost("/goto/event/{eventId:long}")]
// 2023 rename goto/event → matchmake/event (RecNet.Matchmaking HHDMGIMLBKF).
[HttpPost("/matchmake/event/{eventId:long}")]
public async Task<ActionResult<MatchmakingResponseDto>> GoToEvent(long eventId) public async Task<ActionResult<MatchmakingResponseDto>> GoToEvent(long eventId)
{ {
var resp = await BuildResponseAsync("DormRoom"); // Matchmake the caller into the event's host room. Falls back to
// the dorm if the event is unknown or has no room set.
var roomId = await db.PlayerEvents.AsNoTracking()
.Where(e => e.Id == eventId)
.Select(e => (long?)e.RoomId)
.FirstOrDefaultAsync();
string? roomName = null;
if (roomId is long rid && rid > 0)
roomName = await db.Rooms.AsNoTracking()
.Where(r => r.Id == rid)
.Select(r => r.Name)
.FirstOrDefaultAsync();
var resp = await BuildResponseAsync(
string.IsNullOrWhiteSpace(roomName) ? "DormRoom" : roomName);
await RecordResponseAsync(resp); await RecordResponseAsync(resp);
return Ok(resp); return Ok(resp);
} }
[HttpPost("/goto/club/{clubId:long}")] [HttpPost("/goto/club/{clubId:long}")]
// 2023 rename goto/club → matchmake/club (RecNet.Matchmaking KPAIGCCHIBN).
[HttpPost("/matchmake/club/{clubId:long}")]
public async Task<ActionResult<MatchmakingResponseDto>> GoToClub(long clubId) public async Task<ActionResult<MatchmakingResponseDto>> GoToClub(long clubId)
{ {
var club = await db.Clubs.AsNoTracking().FirstOrDefaultAsync(c => c.Id == clubId); var club = await db.Clubs.AsNoTracking().FirstOrDefaultAsync(c => c.Id == clubId);
@@ -430,7 +448,20 @@ public class GoToController(
}); });
} }
var resp = await BuildResponseAsync("RecCenter"); // Land in the club's clubhouse room when it has one set; otherwise
// fall back to the Rec Center. Either way the response carries the
// ClubId so the watch's club UI knows which club it matchmade for.
string roomName = "RecCenter";
if (club.ClubhouseRoomId is long clubhouseId && clubhouseId > 0)
{
var name = await db.Rooms.AsNoTracking()
.Where(r => r.Id == clubhouseId)
.Select(r => r.Name)
.FirstOrDefaultAsync();
if (!string.IsNullOrWhiteSpace(name)) roomName = name;
}
var resp = await BuildResponseAsync(roomName);
resp.RoomInstance!.ClubId = club.Id; resp.RoomInstance!.ClubId = club.Id;
await RecordResponseAsync(resp); await RecordResponseAsync(resp);
return Ok(resp); return Ok(resp);
@@ -438,7 +469,12 @@ public class GoToController(
[HttpPost("/goto/code")] [HttpPost("/goto/code")]
[HttpPost("/goto/code/{code}")] [HttpPost("/goto/code/{code}")]
public async Task<ActionResult<MatchmakingResponseDto>> GoToCode(string? code = null) // 2023 sends the room code as the second segment behind the room id
// (RecNet.Matchmaking CPINEGCODMD → "matchmake/code/{roomId}/{code}").
// The code alone resolves the private instance, so the roomId is just
// routing context we don't need — resolve by code either way.
[HttpPost("/matchmake/code/{roomId:long}/{code}")]
public async Task<ActionResult<MatchmakingResponseDto>> GoToCode(string? code = null, long roomId = 0)
{ {
code ??= Request.HasFormContentType code ??= Request.HasFormContentType
? (await Request.ReadFormAsync())["code"].FirstOrDefault() ? (await Request.ReadFormAsync())["code"].FirstOrDefault()
@@ -807,6 +843,9 @@ public class GoToController(
/// or on the invite list per <see cref="PrivateInstanceService.CanJoin"/>; /// or on the invite list per <see cref="PrivateInstanceService.CanJoin"/>;
/// otherwise we refuse with errorCode=9 (RoomNotJoinable).</summary> /// otherwise we refuse with errorCode=9 (RoomNotJoinable).</summary>
[HttpPost("/goto/player/{playerId:long}")] [HttpPost("/goto/player/{playerId:long}")]
// 2023 rename goto/player → matchmake/player (RecNet.Matchmaking
// FJAFOJHHKPO). Follow a friend into their current room/instance.
[HttpPost("/matchmake/player/{playerId:long}")]
public async Task<ActionResult<MatchmakingResponseDto>> GoToPlayer(long playerId) public async Task<ActionResult<MatchmakingResponseDto>> GoToPlayer(long playerId)
{ {
var theirRoom = presence.GetRoom(playerId); var theirRoom = presence.GetRoom(playerId);