From: miniduikboot Date: Wed, 26 Mar 2025 19:52:17 +0000 (+0100) Subject: Stop hardcoding the GameOptions in GameListingV2 X-Git-Tag: v1.10.3~11^2~4 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=28e933092ac2e7cb821a7761194913ff0499bcaf;p=rhonda%2Fimpostor.git 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> --- diff --git a/src/Impostor.Server/Extensions/IGameOptionsExtensions.cs b/src/Impostor.Server/Extensions/IGameOptionsExtensions.cs new file mode 100644 index 0000000..ca54b7d --- /dev/null +++ b/src/Impostor.Server/Extensions/IGameOptionsExtensions.cs @@ -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()); + } +} diff --git a/src/Impostor.Server/Http/GamesController.cs b/src/Impostor.Server/Http/GamesController.cs index 58c3abb..d7310e5 100644 --- a/src/Impostor.Server/Http/GamesController.cs +++ b/src/Impostor.Server/Http/GamesController.cs @@ -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(), }; } }