]> git.deb.at Git - rhonda/impostor.git/commitdiff
Log MessageFlag name instead of numbers
authorAeonLucid <aeonlucid@gmail.com>
Sun, 18 Dec 2022 22:52:01 +0000 (23:52 +0100)
committerAeonLucid <aeonlucid@gmail.com>
Sun, 18 Dec 2022 22:52:01 +0000 (23:52 +0100)
src/Impostor.Api/Net/Messages/MessageFlags.cs
src/Impostor.Server/Net/Client.cs

index a7f5272a5c504525fba308c43250e6b585488e22..d945305c70a96b89528912c9e6c6f5384666912a 100644 (file)
@@ -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
     {
         public const byte SetActivePodType = 21;
         public const byte QueryPlatformIds = 22;
         public const byte QueryLobbyInfo = 23;
+
+        private static readonly Dictionary<byte, string> 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];
+        }
     }
 }
index 49488e83d5cd975b0bade479164495857f56d76f..b6c056f69360de0a2f5d91460dd13048b99b9d67 100644 (file)
@@ -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)
             {