Stop hardcoding the GameOptions in GameListingV2

To prevent needing to pull in Impostor.Hazel, use an extension method
instead.

Thanks Niko for researching this part

Co-Authored-By: Niko233 <139348239+NikoCat233@users.noreply.github.com>
This commit is contained in:
miniduikbootandNiko233 committed 2025-03-30 20:35:03 +02:00
1 parent 06289d46c0
commit 28e933092a
2 files changed
+26 -3

No files matched your search

@@ -0,0 +1,24 @@
using System;
using Impostor.Api.Innersloth.GameOptions;
using Impostor.Hazel;
namespace Impostor.Server.Extensions;
public static class IGameOptionsExtensions
{
public static byte[] ToBytes(this IGameOptions gameOptions)
{
using var writer = MessageWriter.Get(MessageType.Unreliable);
writer.Write(gameOptions.Version);
writer.StartMessage(0);
writer.Write((byte)gameOptions.GameMode);
gameOptions.Serialize(writer);
writer.EndMessage();
return writer.ToByteArray(false);
}
public static string ToBase64String(this IGameOptions gameOptions)
{
return Convert.ToBase64String(gameOptions.ToBytes());
}
}
+2 -3
View File
@@ -9,6 +9,7 @@ using Impostor.Api.Config;
using Impostor.Api.Games;
using Impostor.Api.Games.Managers;
using Impostor.Api.Innersloth;
using Impostor.Server.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
@@ -308,9 +309,7 @@ public sealed class GamesController : ControllerBase
NumImpostors = game.Options.NumImpostors,
MapId = game.Options.Map,
Language = game.Options.Keywords,
// TODO don't hardcode
Options = "CXQAAAEAAA8AAQAAAgAAwD8AAEA/AAAAQAAAoEECAgQCAAAAAgEtAAAALQAAAAAPAAABAQAHBQABZAMAAAAKHgIAAWQCAAAKDwQAAkYDAAAjDwADAAFkAgAADw8IAAJkAgAACgEJAAFkAgAACh4KAAFkAwAADxQB",
Options = game.Options.ToBase64String(),
};
}
}