From da2f39f38b3b813810e70a1382ef943c5a5a2f94 Mon Sep 17 00:00:00 2001 From: Beyley Thomas Date: Sun, 30 Jun 2024 15:44:33 -0700 Subject: [PATCH 1/3] FindRoomMethod: Fix level ID search & always print room state Printing this out always helps a lot with debugging when people state that "dive in doesn't work". Often by the time someone responds "can you take a capture of the API room output", the room state has changed enough where it's not as helpful. This change makes sure that we can easily see exactly what the server was seeing when it filtered down the rooms. --- .../Matching/MatchMethods/FindRoomMethod.cs | 73 ++++++++++++------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs index 027a782b..ae34068d 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs @@ -6,6 +6,7 @@ using Refresh.GameServer.Authentication; using Refresh.GameServer.Database; using Refresh.GameServer.Services; +using Refresh.GameServer.Types.Levels; using Refresh.GameServer.Types.Matching.Responses; using Refresh.GameServer.Types.UserData; @@ -23,7 +24,9 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext GameRoom? usersRoom = service.RoomAccessor.GetRoomByUser(user, token.TokenPlatform, token.TokenGame); if (usersRoom == null) return BadRequest; // user should already have a room. - List levelIds = new(body.Slots.Count); + // We only really need to match level IDs for user or developer levels + List userLevelIds = []; + List developerLevelIds = []; // Iterate over all sent slots and append their IDs to the list of level IDs to check foreach(List slot in body.Slots) { @@ -32,33 +35,44 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext logger.LogWarning(BunkumCategory.Matching, "Received request with invalid slot, rejecting."); return BadRequest; } + + RoomSlotType slotType = (RoomSlotType)slot[0]; + int slotId = slot[1]; // 0 means "no level specified" - if (slot[1] == 0) + if (slotId == 0) continue; - levelIds.Add(slot[1]); + switch (slotType) + { + case RoomSlotType.Online: + userLevelIds.Add(slotId); + break; + case RoomSlotType.Story: + developerLevelIds.Add(slotId); + break; + } } // If we are on vita and the game specified more than one level ID, then its trying to do dive in only to players in a certain category of levels // This is not how most people expect dive in to work, so let's pretend that the game didn't specify any level IDs whatsoever, so they will get matched with all players - if (token.TokenGame == TokenGame.LittleBigPlanetVita && levelIds.Count > 1) - levelIds = []; + if (token.TokenGame == TokenGame.LittleBigPlanetVita && userLevelIds.Count > 1) + userLevelIds = []; //TODO: Add user option to filter rooms by language - - IEnumerable rooms = service.RoomAccessor - // Get all the available rooms + + List allRooms = service.RoomAccessor .GetRoomsByGameAndPlatform(token.TokenGame, token.TokenPlatform) - .Where(r => - // Make sure we don't match the user into their own room - r.RoomId != usersRoom.RoomId && + .Where(r => r.RoomId != usersRoom.RoomId).ToList(); + + IEnumerable rooms = allRooms.Where(r => // If the level id isn't specified, or is 0, then we don't want to try to match against level IDs, else only match the user to people who are playing that level - (levelIds.Count == 0 || levelIds.Contains(r.LevelId)) && + (userLevelIds.Count == 0 || r.LevelType != RoomSlotType.Online || userLevelIds.Contains(r.LevelId)) && + (developerLevelIds.Count == 0 || r.LevelType != RoomSlotType.Story || developerLevelIds.Contains(r.LevelId)) && // Make sure that we don't try to match the player into a full room, or a room which won't fit the user's current room usersRoom.PlayerIds.Count + r.PlayerIds.Count <= 4 && - // Match the build version of the rooms - (r.BuildVersion ?? 0) == body.BuildVersion) + // Match the build version of the rooms, or dont match build versions if the game doesnt specify it + (body.BuildVersion == null || (r.BuildVersion ?? 0) == body.BuildVersion)) // Shuffle the rooms around before sorting, this is because the selection is based on a weighted average towards the top of the range, // so there would be a bias towards longer lasting rooms without this shuffle .OrderBy(r => Random.Shared.Next()) @@ -84,18 +98,27 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext } // Now that we've done all our filtering, lets convert it to a list, so we can index it quickly. - List roomList = rooms.ToList(); + List foundRooms = rooms.ToList(); - if (roomList.Count <= 0) + // If there's no rooms, dump an "overview" of the global room state, to help debug matching issues + if (foundRooms.Count <= 0) { -#if DEBUG - logger.LogDebug(BunkumCategory.Matching, "Room search by {0} on {1} ({2}) returned no results, dumping list of available rooms.", user.Username, token.TokenGame, token.TokenPlatform); - - // Dump an "overview" of the global room state, to help debug matching issues - rooms = service.RoomAccessor.GetRoomsByGameAndPlatform(token.TokenGame, token.TokenPlatform); - foreach (GameRoom logRoom in rooms) - logger.LogDebug(BunkumCategory.Matching,"Room {0} has NAT type {1} and is on level {2}", logRoom.RoomId, logRoom.NatType, logRoom.LevelId); -#endif + if (allRooms.Count == 0) + { + logger.LogDebug(BunkumCategory.Matching, + "Room search by {0} on {1} ({2}) returned no results due to there being no open rooms on the game/platform.", + user.Username, token.TokenGame, token.TokenPlatform); + } + else + { + logger.LogDebug(BunkumCategory.Matching, + "Room search by {0} on {1} ({2}) returned no results, dumping list of possible rooms.", + user.Username, token.TokenGame, token.TokenPlatform); + + foreach (GameRoom logRoom in allRooms) + logger.LogDebug(BunkumCategory.Matching, "Room {0}: Nat Type {1}, Level {2} ({3}), Build Version {4}", + logRoom.RoomId, logRoom.NatType, logRoom.LevelId, logRoom.LevelType, logRoom.BuildVersion ?? 0); + } // Return a 404 status code if there's no rooms to match them to return new Response(new List { new SerializedStatusCodeMatchResponse(404), }, ContentType.Json); @@ -116,7 +139,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext // Even though NextDouble guarantees the result to be < 1.0, and this mathematically always will check out, // rounding errors may cause this to become roomList.Count (which would crash), so we use a Math.Min to make sure it doesn't - GameRoom room = roomList[Math.Min(roomList.Count - 1, (int)Math.Floor(weightedRandom * roomList.Count))]; + GameRoom room = foundRooms[Math.Min(foundRooms.Count - 1, (int)Math.Floor(weightedRandom * foundRooms.Count))]; logger.LogInfo(BunkumCategory.Matching, "Matched user {0} into {1}'s room (id: {2})", user.Username, room.HostId.Username, room.RoomId); From 4f2e0279a08ee4d2b3944bb0c660a2f53c0dca38 Mon Sep 17 00:00:00 2001 From: Beyley Thomas Date: Sun, 30 Jun 2024 15:52:24 -0700 Subject: [PATCH 2/3] Make debug printing room state a config option --- .../Configuration/GameServerConfig.cs | 6 ++- .../Endpoints/Game/MatchingEndpoints.cs | 12 +++++- Refresh.GameServer/Services/MatchService.cs | 5 ++- .../Matching/MatchMethods/CreateRoomMethod.cs | 6 ++- .../Matching/MatchMethods/FindRoomMethod.cs | 5 ++- .../Matching/MatchMethods/IMatchMethod.cs | 4 +- .../MatchMethods/UpdatePlayersInRoomMethod.cs | 3 +- .../MatchMethods/UpdateRoomDataMethod.cs | 4 +- .../Tests/Matching/MatchingTests.cs | 40 +++++++++---------- 9 files changed, 53 insertions(+), 32 deletions(-) diff --git a/Refresh.GameServer/Configuration/GameServerConfig.cs b/Refresh.GameServer/Configuration/GameServerConfig.cs index 0cc0c1eb..4ee86fab 100644 --- a/Refresh.GameServer/Configuration/GameServerConfig.cs +++ b/Refresh.GameServer/Configuration/GameServerConfig.cs @@ -9,7 +9,7 @@ namespace Refresh.GameServer.Configuration; [SuppressMessage("ReSharper", "RedundantDefaultMemberInitializer")] public class GameServerConfig : Config { - public override int CurrentConfigVersion => 15; + public override int CurrentConfigVersion => 16; public override int Version { get; set; } = 0; protected override void Migrate(int oldVer, dynamic oldConfig) {} @@ -45,4 +45,8 @@ protected override void Migrate(int oldVer, dynamic oldConfig) {} /// The amount of data the user is allowed to upload before all resource uploads get blocked, defaults to 100mb. /// public int UserFilesizeQuota { get; set; } = 100 * 1_048_576; + /// + /// Whether to print the room state whenever a `FindBestRoom` match returns no results + /// + public bool PrintRoomStateWhenNoFoundRooms { get; set; } = true; } \ No newline at end of file diff --git a/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs b/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs index 5ca81c09..55cb86dd 100644 --- a/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs @@ -5,6 +5,7 @@ using Bunkum.Listener.Protocol; using Bunkum.Protocols.Http; using Refresh.GameServer.Authentication; +using Refresh.GameServer.Configuration; using Refresh.GameServer.Database; using Refresh.GameServer.Services; using Refresh.GameServer.Types.Matching; @@ -17,7 +18,14 @@ public class MatchingEndpoints : EndpointGroup // [FindBestRoom,["Players":["VitaGamer128"],"Reservations":["0"],"NAT":[2],"Slots":[[5,0]],"Location":[0x17257bc9,0x17257bf2],"Language":1,"BuildVersion":289,"Search":"","RoomState":3]] [GameEndpoint("match", HttpMethods.Post, ContentType.Json)] [DebugRequestBody, DebugResponseBody] - public Response Match(RequestContext context, GameDatabaseContext database, GameUser user, Token token, MatchService service, string body) + public Response Match( + RequestContext context, + GameDatabaseContext database, + GameUser user, + Token token, + MatchService service, + string body, + GameServerConfig gameServerConfig) { (string method, string jsonBody) = MatchService.ExtractMethodAndBodyFromJson(body); context.Logger.LogInfo(BunkumCategory.Matching, $"Received {method} match request, data: {jsonBody}"); @@ -35,7 +43,7 @@ public Response Match(RequestContext context, GameDatabaseContext database, Game return BadRequest; } - return service.ExecuteMethod(method, roomData, database, user, token); + return service.ExecuteMethod(method, roomData, database, user, token, gameServerConfig); } // Sent by LBP1 to notify the server it has entered a level. diff --git a/Refresh.GameServer/Services/MatchService.cs b/Refresh.GameServer/Services/MatchService.cs index 3feca210..1e22cc33 100644 --- a/Refresh.GameServer/Services/MatchService.cs +++ b/Refresh.GameServer/Services/MatchService.cs @@ -6,6 +6,7 @@ using Bunkum.Core.Responses; using Bunkum.Listener.Protocol; using Refresh.GameServer.Authentication; +using Refresh.GameServer.Configuration; using Refresh.GameServer.Database; using Refresh.GameServer.Types.Matching; using Refresh.GameServer.Types.Matching.MatchMethods; @@ -131,12 +132,12 @@ public override void Initialize() private IMatchMethod? TryGetMatchMethod(string method) => this._matchMethods.FirstOrDefault(m => m.MethodNames.Contains(method)); - public Response ExecuteMethod(string methodStr, SerializedRoomData roomData, GameDatabaseContext database, GameUser user, Token token) + public Response ExecuteMethod(string methodStr, SerializedRoomData roomData, GameDatabaseContext database, GameUser user, Token token, GameServerConfig gameServerConfig) { IMatchMethod? method = this.TryGetMatchMethod(methodStr); if (method == null) return BadRequest; - Response response = method.Execute(this, this.Logger, database, user, token, roomData); + Response response = method.Execute(this, this.Logger, database, user, token, roomData, gameServerConfig); // If there's a response data specified, then there's nothing more we need to do if (response.Data.Length != 0) diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs index 349e53d6..cea50689 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs @@ -2,6 +2,7 @@ using Bunkum.Core.Responses; using NotEnoughLogs; using Refresh.GameServer.Authentication; +using Refresh.GameServer.Configuration; using Refresh.GameServer.Database; using Refresh.GameServer.Services; using Refresh.GameServer.Types.UserData; @@ -12,8 +13,9 @@ public class CreateRoomMethod : IMatchMethod { public IEnumerable MethodNames => new[] { "CreateRoom" }; - public Response Execute(MatchService service, Logger logger, GameDatabaseContext database, GameUser user, Token token, - SerializedRoomData body) + public Response Execute(MatchService service, Logger logger, GameDatabaseContext database, GameUser user, + Token token, + SerializedRoomData body, GameServerConfig gameServerConfig) { NatType natType = body.NatType == null ? NatType.Open : body.NatType[0]; GameRoom room = service.GetOrCreateRoomByPlayer(user, token.TokenPlatform, token.TokenGame, natType, body.BuildVersion, body.PassedNoJoinPoint); diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs index ae34068d..9903d666 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs @@ -4,6 +4,7 @@ using MongoDB.Bson; using NotEnoughLogs; using Refresh.GameServer.Authentication; +using Refresh.GameServer.Configuration; using Refresh.GameServer.Database; using Refresh.GameServer.Services; using Refresh.GameServer.Types.Levels; @@ -19,7 +20,7 @@ public class FindRoomMethod : IMatchMethod public Response Execute(MatchService service, Logger logger, GameDatabaseContext database, GameUser user, Token token, - SerializedRoomData body) + SerializedRoomData body, GameServerConfig gameServerConfig) { GameRoom? usersRoom = service.RoomAccessor.GetRoomByUser(user, token.TokenPlatform, token.TokenGame); if (usersRoom == null) return BadRequest; // user should already have a room. @@ -101,7 +102,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext List foundRooms = rooms.ToList(); // If there's no rooms, dump an "overview" of the global room state, to help debug matching issues - if (foundRooms.Count <= 0) + if (foundRooms.Count <= 0 && gameServerConfig.PrintRoomStateWhenNoFoundRooms) { if (allRooms.Count == 0) { diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs index 613852c7..d2290d7a 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using NotEnoughLogs; using Refresh.GameServer.Authentication; +using Refresh.GameServer.Configuration; using Refresh.GameServer.Database; using Refresh.GameServer.Services; using Refresh.GameServer.Types.UserData; @@ -14,5 +15,6 @@ public interface IMatchMethod IEnumerable MethodNames { get; } Response Execute(MatchService service, Logger logger, - GameDatabaseContext database, GameUser user, Token token, SerializedRoomData body); + GameDatabaseContext database, GameUser user, Token token, SerializedRoomData body, + GameServerConfig gameServerConfig); } \ No newline at end of file diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs index c74ad1a4..df3733ad 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs @@ -1,6 +1,7 @@ using Bunkum.Core.Responses; using NotEnoughLogs; using Refresh.GameServer.Authentication; +using Refresh.GameServer.Configuration; using Refresh.GameServer.Database; using Refresh.GameServer.Services; using Refresh.GameServer.Types.UserData; @@ -14,7 +15,7 @@ public class UpdatePlayersInRoomMethod : IMatchMethod public Response Execute(MatchService service, Logger logger, GameDatabaseContext database, GameUser user, Token token, - SerializedRoomData body) + SerializedRoomData body, GameServerConfig gameServerConfig) { if (body.Players == null) return BadRequest; GameRoom room = service.GetOrCreateRoomByPlayer(user, token.TokenPlatform, token.TokenGame, body.NatType == null ? NatType.Open : body.NatType[0], body.BuildVersion, body.PassedNoJoinPoint); diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs index c5368da1..faa378c2 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs @@ -2,6 +2,7 @@ using Bunkum.Core.Responses; using NotEnoughLogs; using Refresh.GameServer.Authentication; +using Refresh.GameServer.Configuration; using Refresh.GameServer.Database; using Refresh.GameServer.Services; using Refresh.GameServer.Types.UserData; @@ -13,7 +14,8 @@ public class UpdateRoomDataMethod : IMatchMethod public IEnumerable MethodNames => new[] { "UpdateMyPlayerData" }; public Response Execute(MatchService service, Logger logger, - GameDatabaseContext database, GameUser user, Token token, SerializedRoomData body) + GameDatabaseContext database, GameUser user, Token token, SerializedRoomData body, + GameServerConfig gameServerConfig) { GameRoom room = service.GetOrCreateRoomByPlayer(user, token.TokenPlatform, token.TokenGame, body.NatType == null ? NatType.Open : body.NatType[0], body.BuildVersion, body.PassedNoJoinPoint); if (room.HostId.Id != user.UserId) return Unauthorized; diff --git a/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs b/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs index 01b70eab..500dbaa0 100644 --- a/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs +++ b/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs @@ -33,8 +33,8 @@ public void CreatesRooms() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); Assert.Multiple(() => { @@ -73,7 +73,7 @@ public void DoesntMatchIfNoRooms() // Setup room GameUser user1 = context.CreateUser(); Token token1 = context.CreateToken(user1); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); // Tell user1 to try to find a room Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData @@ -82,7 +82,7 @@ public void DoesntMatchIfNoRooms() { NatType.Open, }, - }, context.Database, user1, token1); + }, context.Database, user1, token1, context.Server.Value.GameServerConfig); // Deserialize the result List responseObjects = @@ -117,8 +117,8 @@ public void StrictNatCantJoinStrict() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); // Tell user2 to try to find a room Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData @@ -126,7 +126,7 @@ public void StrictNatCantJoinStrict() NatType = new List { NatType.Strict, }, - }, context.Database, user2, token2); + }, context.Database, user2, token2, context.Server.Value.GameServerConfig); //Deserialize the result List responseObjects = @@ -170,8 +170,8 @@ public void StrictNatCanJoinOpen() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1); - match.ExecuteMethod("CreateRoom", roomData2, context.Database, user2, token2); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData2, context.Database, user2, token2, context.Server.Value.GameServerConfig); // Tell user2 to try to find a room Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData @@ -179,7 +179,7 @@ public void StrictNatCanJoinOpen() NatType = new List { NatType.Strict, }, - }, context.Database, user2, token2); + }, context.Database, user2, token2, context.Server.Value.GameServerConfig); Assert.That(response.StatusCode, Is.EqualTo(OK)); } @@ -206,8 +206,8 @@ public void MatchesPlayersTogether() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); // Tell user2 to try to find a room Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData @@ -215,7 +215,7 @@ public void MatchesPlayersTogether() NatType = new List { NatType.Open, }, - }, context.Database, user2, token2); + }, context.Database, user2, token2, context.Server.Value.GameServerConfig); Assert.That(response.StatusCode, Is.EqualTo(OK)); } @@ -242,8 +242,8 @@ public void HostCanSetPlayersInRoom() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); // Get user1 and user2 in the same room roomData.Players = new List @@ -252,7 +252,7 @@ public void HostCanSetPlayersInRoom() user2.Username, }; - match.ExecuteMethod("UpdatePlayersInRoom", roomData, context.Database, user1, token1); + match.ExecuteMethod("UpdatePlayersInRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); GameRoom? room = match.RoomAccessor.GetRoomByUser(user1); Assert.Multiple(() => { @@ -286,8 +286,8 @@ public void PlayersCanLeaveAndSplitIntoNewRoom() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); // Get user1 and user2 in the same room roomData.Players = new List @@ -297,14 +297,14 @@ public void PlayersCanLeaveAndSplitIntoNewRoom() }; { - match.ExecuteMethod("UpdatePlayersInRoom", roomData, context.Database, user1, token1); + match.ExecuteMethod("UpdatePlayersInRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); GameRoom? user1Room = match.RoomAccessor.GetRoomByUser(user1); Assert.That(user1Room, Is.Not.Null); Assert.That(user1Room!.PlayerIds.FirstOrDefault(r => r.Id == user2.UserId), Is.Not.Null); } { - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); GameRoom? user1Room = match.RoomAccessor.GetRoomByUser(user1); GameRoom? user2Room = match.RoomAccessor.GetRoomByUser(user2); Assert.That(user1Room, Is.Not.Null); From 571829a53083a8e37f8e92c3934a6b92dd1fd06c Mon Sep 17 00:00:00 2001 From: Beyley Thomas Date: Sat, 6 Jul 2024 16:45:23 -0700 Subject: [PATCH 3/3] data con text --- .../Endpoints/Game/MatchingEndpoints.cs | 10 +- Refresh.GameServer/Services/MatchService.cs | 6 +- .../Matching/MatchMethods/CreateRoomMethod.cs | 22 +-- .../Matching/MatchMethods/FindRoomMethod.cs | 36 ++-- .../Matching/MatchMethods/IMatchMethod.cs | 10 +- .../MatchMethods/UpdatePlayersInRoomMethod.cs | 18 +- .../MatchMethods/UpdateRoomDataMethod.cs | 20 +- .../Tests/Matching/MatchingTests.cs | 185 +++++++++++++++--- 8 files changed, 206 insertions(+), 101 deletions(-) diff --git a/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs b/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs index 55cb86dd..b6f35b27 100644 --- a/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs @@ -6,10 +6,9 @@ using Bunkum.Protocols.Http; using Refresh.GameServer.Authentication; using Refresh.GameServer.Configuration; -using Refresh.GameServer.Database; using Refresh.GameServer.Services; +using Refresh.GameServer.Types.Data; using Refresh.GameServer.Types.Matching; -using Refresh.GameServer.Types.UserData; namespace Refresh.GameServer.Endpoints.Game; @@ -20,11 +19,8 @@ public class MatchingEndpoints : EndpointGroup [DebugRequestBody, DebugResponseBody] public Response Match( RequestContext context, - GameDatabaseContext database, - GameUser user, - Token token, - MatchService service, string body, + DataContext dataContext, GameServerConfig gameServerConfig) { (string method, string jsonBody) = MatchService.ExtractMethodAndBodyFromJson(body); @@ -43,7 +39,7 @@ public Response Match( return BadRequest; } - return service.ExecuteMethod(method, roomData, database, user, token, gameServerConfig); + return dataContext.Match.ExecuteMethod(method, roomData, dataContext, gameServerConfig); } // Sent by LBP1 to notify the server it has entered a level. diff --git a/Refresh.GameServer/Services/MatchService.cs b/Refresh.GameServer/Services/MatchService.cs index 1e22cc33..0ecd9601 100644 --- a/Refresh.GameServer/Services/MatchService.cs +++ b/Refresh.GameServer/Services/MatchService.cs @@ -7,7 +7,7 @@ using Bunkum.Listener.Protocol; using Refresh.GameServer.Authentication; using Refresh.GameServer.Configuration; -using Refresh.GameServer.Database; +using Refresh.GameServer.Types.Data; using Refresh.GameServer.Types.Matching; using Refresh.GameServer.Types.Matching.MatchMethods; using Refresh.GameServer.Types.Matching.Responses; @@ -132,12 +132,12 @@ public override void Initialize() private IMatchMethod? TryGetMatchMethod(string method) => this._matchMethods.FirstOrDefault(m => m.MethodNames.Contains(method)); - public Response ExecuteMethod(string methodStr, SerializedRoomData roomData, GameDatabaseContext database, GameUser user, Token token, GameServerConfig gameServerConfig) + public Response ExecuteMethod(string methodStr, SerializedRoomData roomData, DataContext dataContext, GameServerConfig gameServerConfig) { IMatchMethod? method = this.TryGetMatchMethod(methodStr); if (method == null) return BadRequest; - Response response = method.Execute(this, this.Logger, database, user, token, roomData, gameServerConfig); + Response response = method.Execute(dataContext, roomData, gameServerConfig); // If there's a response data specified, then there's nothing more we need to do if (response.Data.Length != 0) diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs index cea50689..7e0fe2b6 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs @@ -1,11 +1,7 @@ using Bunkum.Core; using Bunkum.Core.Responses; -using NotEnoughLogs; -using Refresh.GameServer.Authentication; using Refresh.GameServer.Configuration; -using Refresh.GameServer.Database; -using Refresh.GameServer.Services; -using Refresh.GameServer.Types.UserData; +using Refresh.GameServer.Types.Data; namespace Refresh.GameServer.Types.Matching.MatchMethods; @@ -13,22 +9,20 @@ public class CreateRoomMethod : IMatchMethod { public IEnumerable MethodNames => new[] { "CreateRoom" }; - public Response Execute(MatchService service, Logger logger, GameDatabaseContext database, GameUser user, - Token token, - SerializedRoomData body, GameServerConfig gameServerConfig) + public Response Execute(DataContext dataContext, SerializedRoomData body, GameServerConfig gameServerConfig) { NatType natType = body.NatType == null ? NatType.Open : body.NatType[0]; - GameRoom room = service.GetOrCreateRoomByPlayer(user, token.TokenPlatform, token.TokenGame, natType, body.BuildVersion, body.PassedNoJoinPoint); - if (room.HostId.Id != user.UserId) + GameRoom room = dataContext.Match.GetOrCreateRoomByPlayer(dataContext.User!, dataContext.Platform, dataContext.Game, natType, body.BuildVersion, body.PassedNoJoinPoint); + if (room.HostId.Id != dataContext.User!.UserId) { - room = service.SplitUserIntoNewRoom(user, token.TokenPlatform, token.TokenGame, natType, body.BuildVersion, body.PassedNoJoinPoint); + room = dataContext.Match.SplitUserIntoNewRoom(dataContext.User, dataContext.Platform, dataContext.Game, natType, body.BuildVersion, body.PassedNoJoinPoint); } if (body.RoomState != null) room.RoomState = body.RoomState.Value; if (body.Slots.Count > 1) { - logger.LogWarning(BunkumCategory.Matching, "Received create room request with multiple slots, rejecting"); + dataContext.Logger.LogWarning(BunkumCategory.Matching, "Received create room request with multiple slots, rejecting"); return BadRequest; } @@ -36,7 +30,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext { if (slot.Count != 2) { - logger.LogWarning(BunkumCategory.Matching, "Received request with invalid slot, rejecting."); + dataContext.Logger.LogWarning(BunkumCategory.Matching, "Received request with invalid slot, rejecting."); return BadRequest; } @@ -50,7 +44,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext room.RoomMood = (RoomMood)mood; } - service.RoomAccessor.UpdateRoom(room); + dataContext.Match.RoomAccessor.UpdateRoom(room); return OK; } diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs index 9903d666..65683a58 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs @@ -7,6 +7,7 @@ using Refresh.GameServer.Configuration; using Refresh.GameServer.Database; using Refresh.GameServer.Services; +using Refresh.GameServer.Types.Data; using Refresh.GameServer.Types.Levels; using Refresh.GameServer.Types.Matching.Responses; using Refresh.GameServer.Types.UserData; @@ -17,12 +18,9 @@ public class FindRoomMethod : IMatchMethod { public IEnumerable MethodNames => new[] { "FindBestRoom" }; - public Response Execute(MatchService service, Logger logger, GameDatabaseContext database, - GameUser user, - Token token, - SerializedRoomData body, GameServerConfig gameServerConfig) + public Response Execute(DataContext dataContext, SerializedRoomData body, GameServerConfig gameServerConfig) { - GameRoom? usersRoom = service.RoomAccessor.GetRoomByUser(user, token.TokenPlatform, token.TokenGame); + GameRoom? usersRoom = dataContext.Match.RoomAccessor.GetRoomByUser(dataContext.User!, dataContext.Platform, dataContext.Game); if (usersRoom == null) return BadRequest; // user should already have a room. // We only really need to match level IDs for user or developer levels @@ -33,7 +31,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext { if (slot.Count != 2) { - logger.LogWarning(BunkumCategory.Matching, "Received request with invalid slot, rejecting."); + dataContext.Logger.LogWarning(BunkumCategory.Matching, "Received request with invalid slot, rejecting."); return BadRequest; } @@ -57,13 +55,13 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext // If we are on vita and the game specified more than one level ID, then its trying to do dive in only to players in a certain category of levels // This is not how most people expect dive in to work, so let's pretend that the game didn't specify any level IDs whatsoever, so they will get matched with all players - if (token.TokenGame == TokenGame.LittleBigPlanetVita && userLevelIds.Count > 1) + if (dataContext.Game == TokenGame.LittleBigPlanetVita && userLevelIds.Count > 1) userLevelIds = []; //TODO: Add user option to filter rooms by language - List allRooms = service.RoomAccessor - .GetRoomsByGameAndPlatform(token.TokenGame, token.TokenPlatform) + List allRooms = dataContext.Match.RoomAccessor + .GetRoomsByGameAndPlatform(dataContext.Game, dataContext.Platform) .Where(r => r.RoomId != usersRoom.RoomId).ToList(); IEnumerable rooms = allRooms.Where(r => @@ -89,7 +87,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext rooms = rooms.Where(r => r.NatType == NatType.Open); } - ObjectId? forceMatch = user.ForceMatch; + ObjectId? forceMatch = dataContext.User!.ForceMatch; //If the user has a forced match if (forceMatch != null) @@ -106,18 +104,18 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext { if (allRooms.Count == 0) { - logger.LogDebug(BunkumCategory.Matching, + dataContext.Logger.LogDebug(BunkumCategory.Matching, "Room search by {0} on {1} ({2}) returned no results due to there being no open rooms on the game/platform.", - user.Username, token.TokenGame, token.TokenPlatform); + dataContext.User.Username, dataContext.Game, dataContext.Platform); } else { - logger.LogDebug(BunkumCategory.Matching, + dataContext.Logger.LogDebug(BunkumCategory.Matching, "Room search by {0} on {1} ({2}) returned no results, dumping list of possible rooms.", - user.Username, token.TokenGame, token.TokenPlatform); + dataContext.User.Username, dataContext.Game, dataContext.Platform); foreach (GameRoom logRoom in allRooms) - logger.LogDebug(BunkumCategory.Matching, "Room {0}: Nat Type {1}, Level {2} ({3}), Build Version {4}", + dataContext.Logger.LogDebug(BunkumCategory.Matching, "Room {0}: Nat Type {1}, Level {2} ({3}), Build Version {4}", logRoom.RoomId, logRoom.NatType, logRoom.LevelId, logRoom.LevelType, logRoom.BuildVersion ?? 0); } @@ -129,7 +127,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext if (forceMatch != null) { // Clear the user's force match - database.ClearForceMatch(user); + dataContext.Database.ClearForceMatch(dataContext.User); } // Generate a weighted random number, this is weighted relatively strongly towards lower numbers, @@ -142,7 +140,7 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext // rounding errors may cause this to become roomList.Count (which would crash), so we use a Math.Min to make sure it doesn't GameRoom room = foundRooms[Math.Min(foundRooms.Count - 1, (int)Math.Floor(weightedRandom * foundRooms.Count))]; - logger.LogInfo(BunkumCategory.Matching, "Matched user {0} into {1}'s room (id: {2})", user.Username, room.HostId.Username, room.RoomId); + dataContext.Logger.LogInfo(BunkumCategory.Matching, "Matched user {0} into {1}'s room (id: {2})", dataContext.User.Username, room.HostId.Username, room.RoomId); SerializedRoomMatchResponse roomMatch = new() { @@ -158,13 +156,13 @@ public Response Execute(MatchService service, Logger logger, GameDatabaseContext ], }; - foreach (GameUser? roomUser in room.GetPlayers(database)) + foreach (GameUser? roomUser in room.GetPlayers(dataContext.Database)) { if(roomUser == null) continue; roomMatch.Players.Add(new SerializedRoomPlayer(roomUser.Username, 0)); } - foreach (GameUser? roomUser in usersRoom.GetPlayers(database)) + foreach (GameUser? roomUser in usersRoom.GetPlayers(dataContext.Database)) { if(roomUser == null) continue; roomMatch.Players.Add(new SerializedRoomPlayer(roomUser.Username, 1)); diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs index d2290d7a..aaa3974e 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs @@ -1,11 +1,7 @@ using Bunkum.Core.Responses; using JetBrains.Annotations; -using NotEnoughLogs; -using Refresh.GameServer.Authentication; using Refresh.GameServer.Configuration; -using Refresh.GameServer.Database; -using Refresh.GameServer.Services; -using Refresh.GameServer.Types.UserData; +using Refresh.GameServer.Types.Data; namespace Refresh.GameServer.Types.Matching.MatchMethods; @@ -14,7 +10,5 @@ public interface IMatchMethod { IEnumerable MethodNames { get; } - Response Execute(MatchService service, Logger logger, - GameDatabaseContext database, GameUser user, Token token, SerializedRoomData body, - GameServerConfig gameServerConfig); + Response Execute(DataContext dataContext, SerializedRoomData body, GameServerConfig gameServerConfig); } \ No newline at end of file diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs index df3733ad..dbb79c28 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs @@ -1,9 +1,6 @@ using Bunkum.Core.Responses; -using NotEnoughLogs; -using Refresh.GameServer.Authentication; using Refresh.GameServer.Configuration; -using Refresh.GameServer.Database; -using Refresh.GameServer.Services; +using Refresh.GameServer.Types.Data; using Refresh.GameServer.Types.UserData; namespace Refresh.GameServer.Types.Matching.MatchMethods; @@ -12,22 +9,19 @@ public class UpdatePlayersInRoomMethod : IMatchMethod { public IEnumerable MethodNames => new[] { "UpdatePlayersInRoom" }; - public Response Execute(MatchService service, Logger logger, GameDatabaseContext database, - GameUser user, - Token token, - SerializedRoomData body, GameServerConfig gameServerConfig) + public Response Execute(DataContext dataContext, SerializedRoomData body, GameServerConfig gameServerConfig) { if (body.Players == null) return BadRequest; - GameRoom room = service.GetOrCreateRoomByPlayer(user, token.TokenPlatform, token.TokenGame, body.NatType == null ? NatType.Open : body.NatType[0], body.BuildVersion, body.PassedNoJoinPoint); + GameRoom room = dataContext.Match.GetOrCreateRoomByPlayer(dataContext.User!, dataContext.Platform, dataContext.Game, body.NatType == null ? NatType.Open : body.NatType[0], body.BuildVersion, body.PassedNoJoinPoint); foreach (string playerUsername in body.Players) { - GameUser? player = database.GetUserByUsername(playerUsername); + GameUser? player = dataContext.Database.GetUserByUsername(playerUsername); if (player != null) - service.AddPlayerToRoom(player, room, token.TokenPlatform, token.TokenGame); + dataContext.Match.AddPlayerToRoom(player, room, dataContext.Platform, dataContext.Game); else - service.AddPlayerToRoom(playerUsername, room); + dataContext.Match.AddPlayerToRoom(playerUsername, room); } return OK; diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs index faa378c2..c1d8ccdf 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs @@ -1,11 +1,7 @@ using Bunkum.Core; using Bunkum.Core.Responses; -using NotEnoughLogs; -using Refresh.GameServer.Authentication; using Refresh.GameServer.Configuration; -using Refresh.GameServer.Database; -using Refresh.GameServer.Services; -using Refresh.GameServer.Types.UserData; +using Refresh.GameServer.Types.Data; namespace Refresh.GameServer.Types.Matching.MatchMethods; @@ -13,19 +9,17 @@ public class UpdateRoomDataMethod : IMatchMethod { public IEnumerable MethodNames => new[] { "UpdateMyPlayerData" }; - public Response Execute(MatchService service, Logger logger, - GameDatabaseContext database, GameUser user, Token token, SerializedRoomData body, - GameServerConfig gameServerConfig) + public Response Execute(DataContext dataContext, SerializedRoomData body, GameServerConfig gameServerConfig) { - GameRoom room = service.GetOrCreateRoomByPlayer(user, token.TokenPlatform, token.TokenGame, body.NatType == null ? NatType.Open : body.NatType[0], body.BuildVersion, body.PassedNoJoinPoint); - if (room.HostId.Id != user.UserId) return Unauthorized; + GameRoom room = dataContext.Match.GetOrCreateRoomByPlayer(dataContext.User!, dataContext.Platform, dataContext.Game, body.NatType == null ? NatType.Open : body.NatType[0], body.BuildVersion, body.PassedNoJoinPoint); + if (room.HostId.Id != dataContext.User!.UserId) return Unauthorized; if (body.RoomState != null) room.RoomState = body.RoomState.Value; // Players cannot be in multiple levels at once if (body.Slots.Count > 1) { - logger.LogWarning(BunkumCategory.Matching, "Received update room request with multiple slots, rejecting"); + dataContext.Logger.LogWarning(BunkumCategory.Matching, "Received update room request with multiple slots, rejecting"); return BadRequest; } @@ -33,7 +27,7 @@ public Response Execute(MatchService service, Logger logger, { if (slot.Count != 2) { - logger.LogWarning(BunkumCategory.Matching, "Received request with invalid slot, rejecting."); + dataContext.Logger.LogWarning(BunkumCategory.Matching, "Received request with invalid slot, rejecting."); return BadRequest; } @@ -52,7 +46,7 @@ public Response Execute(MatchService service, Logger logger, room.PassedNoJoinPoint = body.PassedNoJoinPoint.Value; } - service.RoomAccessor.UpdateRoom(room); + dataContext.Match.RoomAccessor.UpdateRoom(room); return OK; } diff --git a/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs b/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs index 500dbaa0..7dc7ba4d 100644 --- a/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs +++ b/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Refresh.GameServer.Authentication; using Refresh.GameServer.Services; +using Refresh.GameServer.Types.Data; using Refresh.GameServer.Types.Matching; using Refresh.GameServer.Types.Matching.Responses; using Refresh.GameServer.Types.UserData; @@ -33,8 +34,22 @@ public void CreatesRooms() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); Assert.Multiple(() => { @@ -73,7 +88,14 @@ public void DoesntMatchIfNoRooms() // Setup room GameUser user1 = context.CreateUser(); Token token1 = context.CreateToken(user1); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); // Tell user1 to try to find a room Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData @@ -82,7 +104,14 @@ public void DoesntMatchIfNoRooms() { NatType.Open, }, - }, context.Database, user1, token1, context.Server.Value.GameServerConfig); + }, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); // Deserialize the result List responseObjects = @@ -117,16 +146,31 @@ public void StrictNatCantJoinStrict() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); // Tell user2 to try to find a room - Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData - { - NatType = new List { - NatType.Strict, - }, - }, context.Database, user2, token2, context.Server.Value.GameServerConfig); + Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData { NatType = [NatType.Strict], }, new DataContext { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); //Deserialize the result List responseObjects = @@ -170,8 +214,22 @@ public void StrictNatCanJoinOpen() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); - match.ExecuteMethod("CreateRoom", roomData2, context.Database, user2, token2, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData2, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); // Tell user2 to try to find a room Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData @@ -179,7 +237,14 @@ public void StrictNatCanJoinOpen() NatType = new List { NatType.Strict, }, - }, context.Database, user2, token2, context.Server.Value.GameServerConfig); + }, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); Assert.That(response.StatusCode, Is.EqualTo(OK)); } @@ -206,8 +271,22 @@ public void MatchesPlayersTogether() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); // Tell user2 to try to find a room Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData @@ -215,7 +294,14 @@ public void MatchesPlayersTogether() NatType = new List { NatType.Open, }, - }, context.Database, user2, token2, context.Server.Value.GameServerConfig); + }, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); Assert.That(response.StatusCode, Is.EqualTo(OK)); } @@ -242,8 +328,22 @@ public void HostCanSetPlayersInRoom() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); // Get user1 and user2 in the same room roomData.Players = new List @@ -252,7 +352,14 @@ public void HostCanSetPlayersInRoom() user2.Username, }; - match.ExecuteMethod("UpdatePlayersInRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); + match.ExecuteMethod("UpdatePlayersInRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); GameRoom? room = match.RoomAccessor.GetRoomByUser(user1); Assert.Multiple(() => { @@ -286,8 +393,22 @@ public void PlayersCanLeaveAndSplitIntoNewRoom() Token token1 = context.CreateToken(user1); Token token2 = context.CreateToken(user2); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); // Get user1 and user2 in the same room roomData.Players = new List @@ -297,14 +418,28 @@ public void PlayersCanLeaveAndSplitIntoNewRoom() }; { - match.ExecuteMethod("UpdatePlayersInRoom", roomData, context.Database, user1, token1, context.Server.Value.GameServerConfig); + match.ExecuteMethod("UpdatePlayersInRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token1, + }, context.Server.Value.GameServerConfig); GameRoom? user1Room = match.RoomAccessor.GetRoomByUser(user1); Assert.That(user1Room, Is.Not.Null); Assert.That(user1Room!.PlayerIds.FirstOrDefault(r => r.Id == user2.UserId), Is.Not.Null); } { - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2, context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, new DataContext + { + Database = context.Database, + Logger = context.Server.Value.Logger, + DataStore = null!, //this isn't accessed by matching + Match = match, + Token = token2, + }, context.Server.Value.GameServerConfig); GameRoom? user1Room = match.RoomAccessor.GetRoomByUser(user1); GameRoom? user2Room = match.RoomAccessor.GetRoomByUser(user2); Assert.That(user1Room, Is.Not.Null);