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..b6f35b27 100644 --- a/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/MatchingEndpoints.cs @@ -5,10 +5,10 @@ using Bunkum.Listener.Protocol; using Bunkum.Protocols.Http; using Refresh.GameServer.Authentication; -using Refresh.GameServer.Database; +using Refresh.GameServer.Configuration; using Refresh.GameServer.Services; +using Refresh.GameServer.Types.Data; using Refresh.GameServer.Types.Matching; -using Refresh.GameServer.Types.UserData; namespace Refresh.GameServer.Endpoints.Game; @@ -17,7 +17,11 @@ 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, + string body, + DataContext dataContext, + GameServerConfig gameServerConfig) { (string method, string jsonBody) = MatchService.ExtractMethodAndBodyFromJson(body); context.Logger.LogInfo(BunkumCategory.Matching, $"Received {method} match request, data: {jsonBody}"); @@ -35,7 +39,7 @@ public Response Match(RequestContext context, GameDatabaseContext database, Game return BadRequest; } - return service.ExecuteMethod(method, roomData, database, user, token); + 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 3feca210..0ecd9601 100644 --- a/Refresh.GameServer/Services/MatchService.cs +++ b/Refresh.GameServer/Services/MatchService.cs @@ -6,7 +6,8 @@ using Bunkum.Core.Responses; using Bunkum.Listener.Protocol; using Refresh.GameServer.Authentication; -using Refresh.GameServer.Database; +using Refresh.GameServer.Configuration; +using Refresh.GameServer.Types.Data; using Refresh.GameServer.Types.Matching; using Refresh.GameServer.Types.Matching.MatchMethods; using Refresh.GameServer.Types.Matching.Responses; @@ -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, 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); + 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 349e53d6..7e0fe2b6 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/CreateRoomMethod.cs @@ -1,10 +1,7 @@ using Bunkum.Core; using Bunkum.Core.Responses; -using NotEnoughLogs; -using Refresh.GameServer.Authentication; -using Refresh.GameServer.Database; -using Refresh.GameServer.Services; -using Refresh.GameServer.Types.UserData; +using Refresh.GameServer.Configuration; +using Refresh.GameServer.Types.Data; namespace Refresh.GameServer.Types.Matching.MatchMethods; @@ -12,21 +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) + 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; } @@ -34,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; } @@ -48,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 027a782b..65683a58 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs @@ -4,8 +4,11 @@ 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.Data; +using Refresh.GameServer.Types.Levels; using Refresh.GameServer.Types.Matching.Responses; using Refresh.GameServer.Types.UserData; @@ -15,50 +18,60 @@ public class FindRoomMethod : IMatchMethod { public IEnumerable MethodNames => new[] { "FindBestRoom" }; - public Response Execute(MatchService service, Logger logger, GameDatabaseContext database, - GameUser user, - Token token, - SerializedRoomData body) + 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. - 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) { 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; } + + 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 (dataContext.Game == TokenGame.LittleBigPlanetVita && userLevelIds.Count > 1) + userLevelIds = []; //TODO: Add user option to filter rooms by language + + List allRooms = dataContext.Match.RoomAccessor + .GetRoomsByGameAndPlatform(dataContext.Game, dataContext.Platform) + .Where(r => r.RoomId != usersRoom.RoomId).ToList(); - IEnumerable rooms = service.RoomAccessor - // Get all the available rooms - .GetRoomsByGameAndPlatform(token.TokenGame, token.TokenPlatform) - .Where(r => - // Make sure we don't match the user into their own room - r.RoomId != usersRoom.RoomId && + 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()) @@ -74,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) @@ -84,18 +97,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 && gameServerConfig.PrintRoomStateWhenNoFoundRooms) { -#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) + { + 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.", + dataContext.User.Username, dataContext.Game, dataContext.Platform); + } + else + { + dataContext.Logger.LogDebug(BunkumCategory.Matching, + "Room search by {0} on {1} ({2}) returned no results, dumping list of possible rooms.", + dataContext.User.Username, dataContext.Game, dataContext.Platform); + + foreach (GameRoom logRoom in allRooms) + 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); + } // Return a 404 status code if there's no rooms to match them to return new Response(new List { new SerializedStatusCodeMatchResponse(404), }, ContentType.Json); @@ -105,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, @@ -116,9 +138,9 @@ 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); + 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() { @@ -134,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 613852c7..aaa3974e 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/IMatchMethod.cs @@ -1,10 +1,7 @@ using Bunkum.Core.Responses; using JetBrains.Annotations; -using NotEnoughLogs; -using Refresh.GameServer.Authentication; -using Refresh.GameServer.Database; -using Refresh.GameServer.Services; -using Refresh.GameServer.Types.UserData; +using Refresh.GameServer.Configuration; +using Refresh.GameServer.Types.Data; namespace Refresh.GameServer.Types.Matching.MatchMethods; @@ -13,6 +10,5 @@ public interface IMatchMethod { IEnumerable MethodNames { get; } - Response Execute(MatchService service, Logger logger, - GameDatabaseContext database, GameUser user, Token token, SerializedRoomData body); + 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 c74ad1a4..dbb79c28 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/UpdatePlayersInRoomMethod.cs @@ -1,8 +1,6 @@ using Bunkum.Core.Responses; -using NotEnoughLogs; -using Refresh.GameServer.Authentication; -using Refresh.GameServer.Database; -using Refresh.GameServer.Services; +using Refresh.GameServer.Configuration; +using Refresh.GameServer.Types.Data; using Refresh.GameServer.Types.UserData; namespace Refresh.GameServer.Types.Matching.MatchMethods; @@ -11,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) + 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 c5368da1..c1d8ccdf 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/UpdateRoomDataMethod.cs @@ -1,10 +1,7 @@ using Bunkum.Core; using Bunkum.Core.Responses; -using NotEnoughLogs; -using Refresh.GameServer.Authentication; -using Refresh.GameServer.Database; -using Refresh.GameServer.Services; -using Refresh.GameServer.Types.UserData; +using Refresh.GameServer.Configuration; +using Refresh.GameServer.Types.Data; namespace Refresh.GameServer.Types.Matching.MatchMethods; @@ -12,18 +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) + 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; } @@ -31,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; } @@ -50,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 01b70eab..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); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + 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); + 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); + }, 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); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + 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); + 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); - match.ExecuteMethod("CreateRoom", roomData2, context.Database, user2, token2); + 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); + }, 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); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + 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); + }, 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); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + 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); + 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); - match.ExecuteMethod("CreateRoom", roomData, context.Database, user2, token2); + 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); + 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); + 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);