]> git.deb.at Git - rhonda/impostor.git/commitdiff
Handle all handshake versions
authorjs6pak <kubastaron@hotmail.com>
Tue, 27 Jul 2021 15:42:11 +0000 (17:42 +0200)
committerjs6pak <kubastaron@hotmail.com>
Tue, 27 Jul 2021 15:42:11 +0000 (17:42 +0200)
src/Impostor.Api/Net/Messages/C2S/HandshakeC2S.cs

index 1a456881612a322fc04543711f867895ccf7574f..83fd647a586cd50c0208a1306f419fde798a97c4 100644 (file)
@@ -4,27 +4,37 @@ namespace Impostor.Api.Net.Messages.C2S
 {
     public static class HandshakeC2S
     {
-        private static readonly int ExtendedHandshakeMinVersion = GameVersion.GetVersion(2021, 6, 30);
-
-        public static void Deserialize(IMessageReader reader, out int clientVersion, out string name, out uint lastNonceReceived, out Language language, out QuickChatModes chatMode)
+        public static void Deserialize(IMessageReader reader, out int clientVersion, out string name, out uint? lastNonceReceived, out Language language, out QuickChatModes chatMode)
         {
             clientVersion = reader.ReadInt32();
             name = reader.ReadString();
-            lastNonceReceived = reader.ReadUInt32();
 
-            // Version 2021.6.30 (aka 50537300) is the first version that includes language and chat modes
-            // In case the game is older than that, stop reading here.
-            if (clientVersion >= ExtendedHandshakeMinVersion)
+            if (clientVersion >= Version.V1)
+            {
+                lastNonceReceived = reader.ReadUInt32();
+            }
+            else
+            {
+                lastNonceReceived = null;
+            }
+
+            if (clientVersion >= Version.V2)
             {
                 language = (Language)reader.ReadUInt32();
                 chatMode = (QuickChatModes)reader.ReadByte();
             }
             else
             {
-                // This is an old version of Among Us and will fail later in the handshake due to a version mismatch
                 language = Language.English;
                 chatMode = QuickChatModes.FreeChatOrQuickChat;
             }
         }
+
+        private static class Version
+        {
+            public static readonly int V1 = GameVersion.GetVersion(2021, 4, 25);
+
+            public static readonly int V2 = GameVersion.GetVersion(2021, 6, 30);
+        }
     }
 }