From: miniduikboot Date: Wed, 2 Feb 2022 21:07:17 +0000 (+0100) Subject: Add QueryPlatformIds X-Git-Tag: v1.7.0~12^2 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=9b5a63e030a6daf605c18573e215387a04f9dd3c;p=rhonda%2Fimpostor.git Add QueryPlatformIds Some platforms (notable the Microsoft Store version) ask for this before connecting. --- diff --git a/src/Impostor.Api/Net/Messages/C2S/Message22QueryPlatformIdsC2S.cs b/src/Impostor.Api/Net/Messages/C2S/Message22QueryPlatformIdsC2S.cs new file mode 100644 index 0000000..dca404f --- /dev/null +++ b/src/Impostor.Api/Net/Messages/C2S/Message22QueryPlatformIdsC2S.cs @@ -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 index 0000000..c3e8594 --- /dev/null +++ b/src/Impostor.Api/Net/Messages/S2C/Message22QueryPlatformIdsS2C.cs @@ -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 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(); + } + } +} diff --git a/src/Impostor.Server/Net/Client.cs b/src/Impostor.Server/Net/Client.cs index a8e744c..b3daed7 100644 --- a/src/Impostor.Server/Net/Client.cs +++ b/src/Impostor.Server/Net/Client.cs @@ -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); } + + /// + /// Triggered when the connected client requests the PlatformSpecificData. + /// + /// + /// The GameCode of the game whose platform id's are checked. + /// + 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(); + + Message22QueryPlatformIdsS2C.Serialize(message, code, playerSpecificData); + + return Connection.SendAsync(message); + } } }