]> git.deb.at Git - rhonda/impostor.git/commitdiff
Do not add ProductUserId/Friendcode on <2.24
authorminiduikboot <mini@duikbo.at>
Sat, 2 Apr 2022 08:41:37 +0000 (10:41 +0200)
committerminiduikboot <mini@duikbo.at>
Tue, 5 Apr 2022 18:05:06 +0000 (20:05 +0200)
Because it is fine to add data to the end of messages the new fields
could be added to Message 1 just fine, but because Message 7 contains a
loop, we need to send a different message to old clients there.

src/Impostor.Api/Net/IClient.cs
src/Impostor.Api/Net/Messages/S2C/Message07JoinedGameS2CPre20220202.cs [new file with mode: 0644]
src/Impostor.Server/Net/State/Game.Outgoing.cs

index b7a446780c315ce84535c9b357fb3cba77fb0993..ceb8f2d6e4196c33c3810605e50db72d5456794a 100644 (file)
@@ -65,6 +65,11 @@ namespace Impostor.Api.Net
         /// </summary>
         IClientPlayer? Player { get; }
 
+        /// <summary>
+        /// Gets the version of the game the client is using.
+        /// </summary>
+        int GameVersion { get; }
+
         /// <summary>
         /// Gets platform specific data of the <see cref="IClient" />.
         /// </summary>
diff --git a/src/Impostor.Api/Net/Messages/S2C/Message07JoinedGameS2CPre20220202.cs b/src/Impostor.Api/Net/Messages/S2C/Message07JoinedGameS2CPre20220202.cs
new file mode 100644 (file)
index 0000000..65faac4
--- /dev/null
@@ -0,0 +1,36 @@
+using System;
+
+namespace Impostor.Api.Net.Messages.S2C
+{
+    public static class Message07JoinedGameS2CPre20220202
+    {
+        public static void Serialize(IMessageWriter writer, bool clear, int gameCode, int playerId, int hostId, IClientPlayer[] otherPlayers)
+        {
+            if (clear)
+            {
+                writer.Clear(MessageType.Reliable);
+            }
+
+            writer.StartMessage(MessageFlags.JoinedGame);
+            writer.Write(gameCode);
+            writer.Write(playerId);
+            writer.Write(hostId);
+            writer.WritePacked(otherPlayers.Length);
+
+            foreach (var ply in otherPlayers)
+            {
+                writer.WritePacked(ply.Client.Id);
+                writer.Write(ply.Client.Name);
+                ply.Client.PlatformSpecificData.Serialize(writer);
+                writer.WritePacked(ply.Character?.PlayerInfo.PlayerLevel ?? 1);
+            }
+
+            writer.EndMessage();
+        }
+
+        public static void Deserialize(IMessageReader reader)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}
index 8e5ab9b73239c9011bbbc886fafc347a7079dd1c..b7c808babce7954b064a55f3526c0351efd4fda1 100644 (file)
@@ -83,7 +83,15 @@ namespace Impostor.Server.Net.State
                 .Select(x => x.Value)
                 .ToArray();
 
-            Message07JoinedGameS2C.Serialize(message, clear, Code, player.Client.Id, HostId, players);
+            // TODO: clean up Pre20220202 when versions before it are no longer supported.
+            if (player.Client.GameVersion >= GameVersion.GetVersion(2022, 2, 2))
+            {
+                Message07JoinedGameS2C.Serialize(message, clear, Code, player.Client.Id, HostId, players);
+            }
+            else
+            {
+                Message07JoinedGameS2CPre20220202.Serialize(message, clear, Code, player.Client.Id, HostId, players);
+            }
         }
 
         private void WriteAlterGameMessage(IMessageWriter message, bool clear, bool isPublic)