]> git.deb.at Git - rhonda/impostor.git/commitdiff
Fix game list filter
authorAeonLucid <aeonlucid@gmail.com>
Sat, 26 Sep 2020 18:37:09 +0000 (20:37 +0200)
committerAeonLucid <aeonlucid@gmail.com>
Sat, 26 Sep 2020 18:37:09 +0000 (20:37 +0200)
src/Impostor.Server/Net/Manager/GameManager.cs
src/Impostor.Server/Net/State/ClientPlayer.Events.cs
src/Impostor.Shared/Innersloth/Data/MapFlags.cs [new file with mode: 0644]

index 515ae5bda86ce729092d92cfa5ff59d4d8310151..0ad8fe51530447afb367d315632b35c516b8ad64 100644 (file)
@@ -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<Game> FindListings(byte mapId, int impostorCount, GameKeywords language, int count = 10)
+        public IEnumerable<Game> 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;
                 }
index 44048622592b591559737307f43a5372bd6fca47..41c1b0e6cca4fa55aab1b4adeba586b03bb63fc3 100644 (file)
@@ -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 (file)
index 0000000..49d730c
--- /dev/null
@@ -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