Merge pull request #460 from miniduikboot/feature/queryplatformids

Add QueryPlatformIds
This commit is contained in:
miniduikboot authored and GitHub committed 2022-02-14 22:12:47 +01:00
commit b252bf2ee7
3 files changed
+70

No files matched your search

@@ -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();
}
}
}
@@ -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();
}
}
}
+25
View 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);
}
}
}