]> git.deb.at Git - rhonda/impostor.git/commitdiff
Add QueryPlatformIds
authorminiduikboot <mini@duikbo.at>
Wed, 2 Feb 2022 21:07:17 +0000 (22:07 +0100)
committerminiduikboot <mini@duikbo.at>
Wed, 2 Feb 2022 21:17:47 +0000 (22:17 +0100)
Some platforms (notable the Microsoft Store version) ask for this before connecting.

src/Impostor.Api/Net/Messages/C2S/Message22QueryPlatformIdsC2S.cs [new file with mode: 0644]
src/Impostor.Api/Net/Messages/S2C/Message22QueryPlatformIdsS2C.cs [new file with mode: 0644]
src/Impostor.Server/Net/Client.cs

diff --git a/src/Impostor.Api/Net/Messages/C2S/Message22QueryPlatformIdsC2S.cs b/src/Impostor.Api/Net/Messages/C2S/Message22QueryPlatformIdsC2S.cs
new file mode 100644 (file)
index 0000000..dca404f
--- /dev/null
@@ -0,0 +1,18 @@
+using System;
+using Impostor.Api.Games;
+
+namespace Impostor.Api.Net.Messages.C2S
+{
+    public class Message22QueryPlatformIdsC2S
+    {
+        public static void Serialize(IMessageWriter writer)
+        {
+            throw new NotImplementedException();
+        }
+
+        public static void Deserialize(IMessageReader reader, out GameCode gameCode)
+        {
+            gameCode = reader.ReadInt32();
+        }
+    }
+}
diff --git a/src/Impostor.Api/Net/Messages/S2C/Message22QueryPlatformIdsS2C.cs b/src/Impostor.Api/Net/Messages/S2C/Message22QueryPlatformIdsS2C.cs
new file mode 100644 (file)
index 0000000..c3e8594
--- /dev/null
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using Impostor.Api.Games;
+using Impostor.Api.Innersloth;
+
+namespace Impostor.Api.Net.Messages.S2C
+{
+    public class Message22QueryPlatformIdsS2C
+    {
+        public static void Serialize(IMessageWriter writer, GameCode gameCode, IEnumerable<PlatformSpecificData> playerSpecificDatas)
+        {
+            writer.StartMessage(MessageFlags.QueryPlatformIds);
+            writer.Write(gameCode);
+            foreach (var playerSpecificData in playerSpecificDatas)
+            {
+                playerSpecificData.Serialize(writer);
+            }
+
+            writer.EndMessage();
+        }
+
+        public static void Deserialize(IMessageReader reader)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}
index a8e744c0a0040bd09fb7bd1cb72e15b24d487e88..b3daed708ba3d5b568d2a37eee8b5174b0d33205 100644 (file)
@@ -1,4 +1,5 @@
 using System;
+using System.Linq;
 using System.Threading.Tasks;
 using Impostor.Api;
 using Impostor.Api.Games;
@@ -263,6 +264,13 @@ namespace Impostor.Server.Net
                     break;
                 }
 
+                case MessageFlags.QueryPlatformIds:
+                {
+                    Message22QueryPlatformIdsC2S.Deserialize(reader, out var gameCode);
+                    await OnQueryPlatformIds(gameCode);
+                    break;
+                }
+
                 default:
                     if (_customMessageManager.TryGet(flag, out var customRootMessage))
                     {
@@ -354,5 +362,22 @@ namespace Impostor.Server.Net
 
             return Connection.SendAsync(message);
         }
+
+        /// <summary>
+        ///     Triggered when the connected client requests the PlatformSpecificData.
+        /// </summary>
+        /// <param name="code">
+        ///     The GameCode of the game whose platform id's are checked.
+        /// </param>
+        private ValueTask OnQueryPlatformIds(GameCode code)
+        {
+            using var message = MessageWriter.Get(MessageType.Reliable);
+
+            var playerSpecificData = _gameManager.Find(code)?.Players.Select(p => p.Client.PlatformSpecificData) ?? Enumerable.Empty<PlatformSpecificData>();
+
+            Message22QueryPlatformIdsS2C.Serialize(message, code, playerSpecificData);
+
+            return Connection.SendAsync(message);
+        }
     }
 }