From cd26a7284ae4dce277e3c43789e78e3c2f218aa5 Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Sat, 26 Sep 2020 20:37:09 +0200 Subject: [PATCH] Fix game list filter --- .../Net/Manager/GameManager.cs | 20 +++++++++++++------ .../Net/State/ClientPlayer.Events.cs | 3 ++- .../Innersloth/Data/MapFlags.cs | 12 +++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/Impostor.Shared/Innersloth/Data/MapFlags.cs diff --git a/src/Impostor.Server/Net/Manager/GameManager.cs b/src/Impostor.Server/Net/Manager/GameManager.cs index 515ae5b..0ad8fe5 100644 --- a/src/Impostor.Server/Net/Manager/GameManager.cs +++ b/src/Impostor.Server/Net/Manager/GameManager.cs @@ -9,6 +9,7 @@ using Impostor.Shared.Innersloth; using Impostor.Shared.Innersloth.Data; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Serilog; namespace Impostor.Server.Net.Manager { @@ -53,7 +54,7 @@ namespace Impostor.Server.Net.Manager return game; } - public IEnumerable FindListings(byte mapId, int impostorCount, GameKeywords language, int count = 10) + public IEnumerable FindListings(MapFlags map, int impostorCount, GameKeywords language, int count = 10) { var results = 0; @@ -61,13 +62,20 @@ namespace Impostor.Server.Net.Manager foreach (var (code, game) in _games.Where(x => x.Value.IsPublic && x.Value.GameState == GameStates.NotStarted && - x.Value.PlayerCount < 10)) // TODO: Do "< x.Value.Options.MaxPlayers" when GameData packets are done. + x.Value.PlayerCount < x.Value.Options.MaxPlayers)) { // Check for options. - // TODO: Re-enable map filter when GameData packets are done. - if (/* game.Options.MapId != mapId || */ - game.Options.Keywords != language || - (impostorCount != 0 && game.Options.NumImpostors != impostorCount)) + if (!map.HasFlag((MapFlags) (1 << game.Options.MapId))) + { + continue; + } + + if (!language.HasFlag(game.Options.Keywords)) + { + continue; + } + + if (impostorCount != 0 && game.Options.NumImpostors != impostorCount) { continue; } diff --git a/src/Impostor.Server/Net/State/ClientPlayer.Events.cs b/src/Impostor.Server/Net/State/ClientPlayer.Events.cs index 4404862..41c1b0e 100644 --- a/src/Impostor.Server/Net/State/ClientPlayer.Events.cs +++ b/src/Impostor.Server/Net/State/ClientPlayer.Events.cs @@ -1,6 +1,7 @@ using Hazel; using Impostor.Server.Net.Messages; using Impostor.Shared.Innersloth; +using Impostor.Shared.Innersloth.Data; namespace Impostor.Server.Net.State { @@ -17,7 +18,7 @@ namespace Impostor.Server.Net.State { using (var message = MessageWriter.Get(SendOption.Reliable)) { - var games = _gameManager.FindListings(options.MapId, options.NumImpostors, options.Keywords); + var games = _gameManager.FindListings((MapFlags) options.MapId, options.NumImpostors, options.Keywords); Message16GetGameListV2.Serialize(message, games); diff --git a/src/Impostor.Shared/Innersloth/Data/MapFlags.cs b/src/Impostor.Shared/Innersloth/Data/MapFlags.cs new file mode 100644 index 0000000..49d730c --- /dev/null +++ b/src/Impostor.Shared/Innersloth/Data/MapFlags.cs @@ -0,0 +1,12 @@ +using System; + +namespace Impostor.Shared.Innersloth.Data +{ + [Flags] + public enum MapFlags + { + Skeld = 1, + MiraHQ = 2, + Polus = 4 + } +} \ No newline at end of file -- 2.39.5