diff --git a/src/Impostor.Api/Net/Messages/MessageFlags.cs b/src/Impostor.Api/Net/Messages/MessageFlags.cs index a7f5272a..d945305c 100644 --- a/src/Impostor.Api/Net/Messages/MessageFlags.cs +++ b/src/Impostor.Api/Net/Messages/MessageFlags.cs @@ -1,4 +1,8 @@ -namespace Impostor.Api.Net.Messages +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Impostor.Api.Net.Messages { public static class MessageFlags { @@ -24,5 +28,20 @@ public const byte SetActivePodType = 21; public const byte QueryPlatformIds = 22; public const byte QueryLobbyInfo = 23; + + private static readonly Dictionary FlagCache; + + static MessageFlags() + { + FlagCache = typeof(MessageFlags) + .GetFields(BindingFlags.Public | BindingFlags.Static) + .Where(fi => fi.IsLiteral && !fi.IsInitOnly) + .ToDictionary(x => (byte) x.GetValue(null)!, y => y.Name); + } + + public static string FlagToString(byte flag) + { + return FlagCache[flag]; + } } } diff --git a/src/Impostor.Server/Net/Client.cs b/src/Impostor.Server/Net/Client.cs index 49488e83..b6c056f6 100644 --- a/src/Impostor.Server/Net/Client.cs +++ b/src/Impostor.Server/Net/Client.cs @@ -59,7 +59,7 @@ namespace Impostor.Server.Net { var flag = reader.Tag; - _logger.LogTrace("[{0}] Server got {1}.", Id, flag); + _logger.LogTrace("[{0}] Server got {1}.", Id, MessageFlags.FlagToString(flag)); switch (flag) {