mirror of
https://github.com/Impostor/Impostor.git
synced 2026-10-20 01:46:11 +00:00
Add support for PackedGameDataTo
This commit is contained in:
1 parent
b30775c2fc
commit
2cb9c648f3
3 files changed
+67
No files matched your search
@@ -29,6 +29,7 @@ namespace Impostor.Api.Net.Messages
|
||||
public const byte QueryPlatformIds = 22;
|
||||
public const byte QueryLobbyInfo = 23;
|
||||
public const byte EndGameHostMigration = 24;
|
||||
public const byte PackedGameDataTo = 26;
|
||||
|
||||
private static readonly Dictionary<byte, string> FlagCache;
|
||||
|
||||
|
||||
@@ -259,6 +259,47 @@ namespace Impostor.Server.Net
|
||||
break;
|
||||
}
|
||||
|
||||
case MessageFlags.PackedGameDataTo:
|
||||
{
|
||||
if (!IsPackedGameDataToAllowed(reader))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (reader.Position < reader.Length)
|
||||
{
|
||||
using var packed = reader.ReadMessage();
|
||||
|
||||
if (packed.Tag != MessageFlags.GameDataTo)
|
||||
{
|
||||
_logger.LogWarning("PackedGameDataTo contained non-GameDataTo flag {0}.", packed.Tag);
|
||||
return;
|
||||
}
|
||||
|
||||
if (packed.ReadInt32() != Player!.Game.Code)
|
||||
{
|
||||
_logger.LogWarning("PackedGameDataTo contained GameDataTo for the wrong game.");
|
||||
return;
|
||||
}
|
||||
|
||||
var position = packed.Position;
|
||||
var verified = await Player.Game.HandleGameDataAsync(packed, Player, true);
|
||||
packed.Seek(position);
|
||||
|
||||
if (!verified || Player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var writer = MessageWriter.Get(messageType);
|
||||
var target = packed.ReadPackedInt32();
|
||||
packed.CopyTo(writer);
|
||||
await Player.Game.SendToAsync(writer, target);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case MessageFlags.EndGame:
|
||||
{
|
||||
if (!IsPacketAllowed(reader, true))
|
||||
@@ -344,6 +385,7 @@ namespace Impostor.Server.Net
|
||||
#if DEBUG
|
||||
if (flag != MessageFlags.GameData &&
|
||||
flag != MessageFlags.GameDataTo &&
|
||||
flag != MessageFlags.PackedGameDataTo &&
|
||||
flag != MessageFlags.EndGame &&
|
||||
reader.Position < reader.Length)
|
||||
{
|
||||
@@ -407,6 +449,29 @@ namespace Impostor.Server.Net
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsPackedGameDataToAllowed(IMessageReader message)
|
||||
{
|
||||
if (Player == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var game = Player.Game;
|
||||
|
||||
if (message.ReadPackedInt32() != game.Code)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (game.HostId == Id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.LogWarning("[{0}] Client sent PackedGameDataTo only allowed by the host ({1}).", Id, game.HostId);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the connected client requests the PlatformSpecificData.
|
||||
/// </summary>
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace Impostor.Tools.Proxy
|
||||
{ 13, "Redirect" },
|
||||
{ 14, "ReselectServer" },
|
||||
{ 16, "GetGameListV2" },
|
||||
{ 26, "PackedGameDataTo" },
|
||||
};
|
||||
|
||||
private static IServiceProvider _serviceProvider;
|
||||
|
||||
Reference in new issue
Block a user