diff --git a/Refresh.GameServer/Services/MatchService.cs b/Refresh.GameServer/Services/MatchService.cs index 7e6e9685..f6877904 100644 --- a/Refresh.GameServer/Services/MatchService.cs +++ b/Refresh.GameServer/Services/MatchService.cs @@ -141,7 +141,7 @@ public Response ExecuteMethod(string methodStr, SerializedRoomData roomData, Dat return response; // If there's no response body, then we need to make our own using the status code - SerializedStatusCodeMatchResponse status = new((int)response.StatusCode); + SerializedStatusCodeMatchResponse status = new(response.StatusCode); List responseData = [status]; diff --git a/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs b/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs index 572eafc6..62c880a8 100644 --- a/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs +++ b/Refresh.GameServer/Types/Matching/MatchMethods/FindRoomMethod.cs @@ -2,13 +2,9 @@ using Bunkum.Core.Responses; using Bunkum.Listener.Protocol; 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; @@ -20,6 +16,8 @@ public class FindRoomMethod : IMatchMethod public Response Execute(DataContext dataContext, SerializedRoomData body, GameServerConfig gameServerConfig) { + SerializedStatusCodeMatchResponse status = new(OK); + GameRoom? usersRoom = dataContext.Match.RoomAccessor.GetRoomByUser(dataContext.User!, dataContext.Platform, dataContext.Game); if (usersRoom == null) return BadRequest; // user should already have a room. @@ -66,8 +64,8 @@ public Response Execute(DataContext dataContext, SerializedRoomData body, GameSe 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 - (userLevelIds.Count == 0 || r.LevelType != RoomSlotType.Online || userLevelIds.Contains(r.LevelId)) && - (developerLevelIds.Count == 0 || r.LevelType != RoomSlotType.Story || developerLevelIds.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) // Shuffle the rooms around before sorting, this is because the selection is based on a weighted average towards the top of the range, @@ -126,7 +124,8 @@ public Response Execute(DataContext dataContext, SerializedRoomData body, GameSe } // Return a 404 status code if there's no rooms to match them to - return new Response(new List { new SerializedStatusCodeMatchResponse(404), }, ContentType.Json); + status.StatusCode = NotFound; + return new Response(new List {status}, ContentType.Json, status.StatusCode); } // If the user has a forced match and we found a room @@ -174,14 +173,6 @@ public Response Execute(DataContext dataContext, SerializedRoomData body, GameSe roomMatch.Players.Add(new SerializedRoomPlayer(roomUser.Username, 1)); } - SerializedStatusCodeMatchResponse status = new(200); - - List response = - [ - status, - roomMatch, - ]; - - return new Response(response, ContentType.Json); + return new Response(new List {status, roomMatch}, ContentType.Json, status.StatusCode); } } \ No newline at end of file diff --git a/Refresh.GameServer/Types/Matching/Responses/SerializedStatusCodeMatchResponse.cs b/Refresh.GameServer/Types/Matching/Responses/SerializedStatusCodeMatchResponse.cs index be446f48..30c27724 100644 --- a/Refresh.GameServer/Types/Matching/Responses/SerializedStatusCodeMatchResponse.cs +++ b/Refresh.GameServer/Types/Matching/Responses/SerializedStatusCodeMatchResponse.cs @@ -1,17 +1,19 @@ using System.Diagnostics.CodeAnalysis; +using System.Net; +using Bunkum.Core.Responses; namespace Refresh.GameServer.Types.Matching.Responses; [JsonObject(MemberSerialization.OptIn)] -public class SerializedStatusCodeMatchResponse +public class SerializedStatusCodeMatchResponse: IHasResponseCode { [ExcludeFromCodeCoverage] public SerializedStatusCodeMatchResponse() {} - public SerializedStatusCodeMatchResponse(int statusCode) + public SerializedStatusCodeMatchResponse(HttpStatusCode statusCode) { this.StatusCode = statusCode; } - [JsonProperty] public int StatusCode { get; set; } + [JsonProperty] public HttpStatusCode StatusCode { get; set; } } \ No newline at end of file diff --git a/Refresh.GameServer/Types/Matching/SerializedRoomData.cs b/Refresh.GameServer/Types/Matching/SerializedRoomData.cs index b43decc2..bd884def 100644 --- a/Refresh.GameServer/Types/Matching/SerializedRoomData.cs +++ b/Refresh.GameServer/Types/Matching/SerializedRoomData.cs @@ -20,10 +20,10 @@ public class SerializedRoomData // ReSharper disable InconsistentNaming // LBP has two of the same thing sometimes, have both properties to handle both cases [JsonProperty("Slot")] - private List? _Slot { get; set; } + public List? _Slot { private get; set; } [JsonProperty("Slots")] - private List>? _Slots { get; set; } + public List>? _Slots { private get; set; } // ReSharper restore InconsistentNaming [JsonIgnore] diff --git a/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs b/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs index a1ce52b6..3211d560 100644 --- a/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs +++ b/RefreshTests.GameServer/Tests/Matching/MatchingTests.cs @@ -123,8 +123,8 @@ public void DoesntMatchIfNoRooms() //Make sure the only result is a 404 object Assert.That(responseObjects, Has.Count.EqualTo(1)); - Assert.That(response.StatusCode, Is.EqualTo(OK)); - Assert.That(responseObjects[0].StatusCode, Is.EqualTo(404)); + Assert.That(response.StatusCode, Is.EqualTo(NotFound)); + Assert.That(responseObjects[0].StatusCode, Is.EqualTo(NotFound)); } [Test] @@ -185,8 +185,8 @@ public void StrictNatCantJoinStrict() //Make sure the only result is a 404 object Assert.That(responseObjects, Has.Count.EqualTo(1)); - Assert.That(response.StatusCode, Is.EqualTo(OK)); - Assert.That(responseObjects[0].StatusCode, Is.EqualTo(404)); + Assert.That(response.StatusCode, Is.EqualTo(NotFound)); + Assert.That(responseObjects[0].StatusCode, Is.EqualTo(NotFound)); } [Test] @@ -469,4 +469,50 @@ public void PlayersCanLeaveAndSplitIntoNewRoom() } } + + [Test] + public void DoesntMatchIfLookingForLevelWhenPod() + { + using TestContext context = this.GetServer(false); + MatchService match = new(Logger); + match.Initialize(); + + SerializedRoomData roomData = new() + { + Mood = (byte)RoomMood.AllowingAll, // Tells their rooms that they can be matched with each other + NatType = new List + { + NatType.Open, + }, + _Slot = + [ + (int)RoomSlotType.Pod, + 0, + ], + }; + + // Setup rooms + GameUser user1 = context.CreateUser(); + GameUser user2 = context.CreateUser(); + + Token token1 = context.CreateToken(user1); + Token token2 = context.CreateToken(user2); + + match.ExecuteMethod("CreateRoom", roomData, context.GetDataContext(token1), context.Server.Value.GameServerConfig); + match.ExecuteMethod("CreateRoom", roomData, context.GetDataContext(token2), context.Server.Value.GameServerConfig); + + // Tell user2 to try to find a room + Response response = match.ExecuteMethod("FindBestRoom", new SerializedRoomData + { + NatType = new List { + NatType.Open, + }, + _Slot = + [ + (int)RoomSlotType.Online, + 1337, + ], + }, context.GetDataContext(token2), context.Server.Value.GameServerConfig); + Assert.That(response.StatusCode, Is.EqualTo(NotFound)); + } } \ No newline at end of file