Random findBestRoom list, clear recent dive-in list if rooms are unavailable

This commit is contained in:
jvyden 2022-07-25 20:29:06 -04:00
commit b30195c5ba
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 11 additions and 2 deletions

View file

@ -36,6 +36,8 @@ public static class MatchHelper
return recentlyDivedIn.Contains(otherUserId); return recentlyDivedIn.Contains(otherUserId);
} }
public static bool ClearUserRecentDiveIns(int userId) => UserRecentlyDivedIn.Remove(userId);
// This is the function used to show people how laughably awful LBP's protocol is. Beware. // This is the function used to show people how laughably awful LBP's protocol is. Beware.
public static IMatchCommand? Deserialize(string data) public static IMatchCommand? Deserialize(string data)
{ {

View file

@ -1,4 +1,5 @@
#nullable enable #nullable enable
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
@ -47,10 +48,10 @@ public class RoomHelper
return null; return null;
} }
IEnumerable<Room> rooms = Rooms; Random random = new();
IEnumerable<Room> rooms = Rooms.OrderBy(_ => random.Next());
rooms = rooms.OrderBy(r => r.IsLookingForPlayers); rooms = rooms.OrderBy(r => r.IsLookingForPlayers);
rooms = rooms.Where(r => r.RoomVersion == roomVersion).ToList(); rooms = rooms.Where(r => r.RoomVersion == roomVersion).ToList();
if (platform != null) rooms = rooms.Where(r => r.RoomPlatform == platform).ToList(); if (platform != null) rooms = rooms.Where(r => r.RoomPlatform == platform).ToList();
@ -137,6 +138,12 @@ public class RoomHelper
return response; return response;
} }
if (user != null)
{
MatchHelper.ClearUserRecentDiveIns(user.UserId);
Logger.Info($"Cleared {user.Username} (id: {user.UserId})'s recent dive-ins", LogArea.Match);
}
return null; return null;
} }