Răsfoiți Sursa

Ensure we set packetWrite.Position to 0 after all the data has been sent. This avoids corruption.

Dominique Louis 3 săptămâni în urmă
părinte
comite
72e6fea554
1 a modificat fișierele cu 12 adăugiri și 14 ștergeri
  1. 12 14
      MonoGame.Xna.Framework.Net/Net/NetworkGamer.cs

+ 12 - 14
MonoGame.Xna.Framework.Net/Net/NetworkGamer.cs

@@ -223,11 +223,12 @@ namespace Microsoft.Xna.Framework.Net
         }
 
         /// <summary>
-        /// Sends data using PacketWriter.
+        /// Sends data using PacketWriter to specific recipients.
         /// </summary>
         /// <param name="data">The data to send.</param>
         /// <param name="options">Send options.</param>
-        public void SendData(PacketWriter data, SendDataOptions options)
+        /// <param name="recipients">The gamers to send to.</param>
+        public void SendData(PacketWriter data, SendDataOptions options, IEnumerable<NetworkGamer> recipients)
         {
             if (data == null)
                 throw new ArgumentNullException(nameof(data), "PacketWriter cannot be null.");
@@ -235,26 +236,23 @@ namespace Microsoft.Xna.Framework.Net
             if (!Enum.IsDefined(typeof(SendDataOptions), options))
                 throw new ArgumentOutOfRangeException(nameof(options), "Invalid send data option.");
 
+            if (recipients == null)
+                throw new ArgumentNullException(nameof(recipients));
+
             byte[] serializedData = data.GetData();
-            SendDataInternal(serializedData, options, session.AllGamers);
+            SendDataInternal(serializedData, options, recipients);
+
+            data.Position = 0; // Reset position after sending
         }
 
         /// <summary>
-        /// Sends data using PacketWriter to specific recipients.
+        /// Sends data using PacketWriter.
         /// </summary>
         /// <param name="data">The data to send.</param>
         /// <param name="options">Send options.</param>
-        /// <param name="recipients">The gamers to send to.</param>
-        public void SendData(PacketWriter data, SendDataOptions options, IEnumerable<NetworkGamer> recipients)
+        public void SendData(PacketWriter data, SendDataOptions options)
         {
-            if (data == null)
-                throw new ArgumentNullException(nameof(data), "PacketWriter cannot be null.");
-
-            if (recipients == null)
-                throw new ArgumentNullException(nameof(recipients));
-
-            byte[] serializedData = data.GetData();
-            SendDataInternal(serializedData, options, recipients);
+            SendData(data, options, session.AllGamers);
         }
 
         /// <summary>