Example #1
0
        public void Serialize(NetDataWriter writer)
        {
            writer.Put(classFullName);
            writer.Put(methodName);
            {
                string[] keys = new List <string>(paramNameValues.Keys).ToArray();
                writer.PutArray(keys);

                string[] values = new List <string>(paramNameValues.Values).ToArray();
                writer.PutArray(values);
            }
        }
 public void Write(NetDataWriter writer)
 {
     writer.Put(origin);
     writer.Put(force);
     writer.Put(forceFallof);
     writer.PutArray(bodyPartFactor);
 }
Example #3
0
 public void Serialize(NetDataWriter writer)
 {
     writer.Put(descriptionName);
     writer.Put(paraName);
     writer.Put(paraTypeFullName);
     writer.Put(defaultValueStr);
     writer.PutArray(selectItemValues);
 }
Example #4
0
 public static void PutArray(this NetDataWriter netDataWriter, List <NetworkedObject> objects)
 {
     int[] ids = new int[objects.Count];
     for (int i = 0; i < objects.Count; i++)
     {
         ids[i] = objects[i].id;
     }
     netDataWriter.PutArray(ids);
 }
Example #5
0
        public static void SendCommand(string command, string[] param)
        {
            NetDataWriter writer = new NetDataWriter();

            writer.Put((int)NetworkedEvent.RemoteCommand);
            writer.Put(command);
            writer.PutArray(param);
            client.FirstPeer.Send(writer, DeliveryMethod.ReliableOrdered);
        }
Example #6
0
 public static void SendDestroyedObjects(List <NetPeer> peers, NetDataWriter writer)
 {
     writer.Reset();
     writer.Put(GameServer.MESSAGE_OBJECT_DESTROY);
     writer.PutArray(destroyedObjects.ToArray());
     foreach (NetPeer peer in peers)
     {
         peer.Send(writer, DeliveryMethod.ReliableOrdered);
     }
     destroyedObjects.Clear();
 }
Example #7
0
        public void WriteReadLongArray()
        {
            var ndw = new NetDataWriter();

            ndw.PutArray(new[] { 1L, 2L, 3L, 4L, long.MaxValue, long.MinValue });

            var ndr           = new NetDataReader(ndw.Data);
            var readLongArray = ndr.GetLongArray();

            Assert.That(new[] { 1L, 2L, 3L, 4L, long.MaxValue, long.MinValue }, Is.EqualTo(readLongArray).AsCollection);
        }
Example #8
0
        public void WriteReadIntArray()
        {
            var ndw = new NetDataWriter();

            ndw.PutArray(new[] { 1, 2, 3, 4, 5, 6, 7, int.MaxValue, int.MinValue });

            var ndr          = new NetDataReader(ndw.Data);
            var readIntArray = ndr.GetIntArray();

            Assert.That(new[] { 1, 2, 3, 4, 5, 6, 7, int.MaxValue, int.MinValue }, Is.EqualTo(readIntArray).AsCollection);
        }
Example #9
0
        public void WriteReadBoolArray()
        {
            var ndw = new NetDataWriter();

            ndw.PutArray(new[] { true, false, true, false, false });

            var ndr           = new NetDataReader(ndw.Data);
            var readBoolArray = ndr.GetBoolArray();

            Assert.That(new[] { true, false, true, false, false }, Is.EqualTo(readBoolArray).AsCollection);
        }
Example #10
0
        public void WriteReadStringArray()
        {
            var ndw = new NetDataWriter();

            ndw.PutArray(new[] { "First", "Second", "Third", "Fourth" });

            var ndr             = new NetDataReader(ndw.Data);
            var readStringArray = ndr.GetStringArray(10);

            Assert.That(new[] { "First", "Second", "Third", "Fourth" }, Is.EqualTo(readStringArray).AsCollection);
        }
Example #11
0
        /// <summary>
        /// Sends one message to all connected clients.
        /// </summary>
        /// <param name="type">The type of message [INFO, CMD, DATA]</param>
        /// <param name="topic">The topic of this message.</param>
        /// <param name="data">Any number of strings</param>
        private void Broadcast(string type, string topic, params string[] data)
        {
            NetDataWriter output  = new NetDataWriter();
            List <string> message = new List <string>();

            message.Add(type);
            message.Add(topic);
            message.AddRange(data);

            output.PutArray(message.ToArray());
            Manager?.SendToAll(output, DeliveryMethod.ReliableOrdered);
        }
Example #12
0
        public void WriteReadUIntArray()
        {
            var ndw = new NetDataWriter();

            ndw.PutArray(new[] { 1U, 2U, 3U, 4U, 5U, 6U, uint.MaxValue, uint.MinValue });

            var ndr           = new NetDataReader(ndw.Data);
            var readUIntArray = ndr.GetUIntArray();

            Assert.That(
                new[] { 1U, 2U, 3U, 4U, 5U, 6U, uint.MaxValue, uint.MinValue },
                Is.EqualTo(readUIntArray).AsCollection);
        }
Example #13
0
        public void WriteReadDoubleArray()
        {
            var ndw = new NetDataWriter();

            ndw.PutArray(new[] { 1.1, 2.2, 3.3, 4.4, double.MaxValue, double.MinValue });

            var ndr             = new NetDataReader(ndw.Data);
            var readDoubleArray = ndr.GetDoubleArray();

            Assert.That(
                new[] { 1.1, 2.2, 3.3, 4.4, double.MaxValue, double.MinValue },
                Is.EqualTo(readDoubleArray).AsCollection);
        }
Example #14
0
        public void WriteReadFloatArray()
        {
            var ndw = new NetDataWriter();

            ndw.PutArray(new[] { 1.1f, 2.2f, 3.3f, 4.4f, float.MaxValue, float.MinValue });

            var ndr            = new NetDataReader(ndw.Data);
            var readFloatArray = ndr.GetFloatArray();

            Assert.That(
                new[] { 1.1f, 2.2f, 3.3f, 4.4f, float.MaxValue, float.MinValue },
                Is.EqualTo(readFloatArray).AsCollection);
        }
Example #15
0
        /// <summary>
        /// Execute command on server.
        /// </summary>
        /// <param name="command">Command name.</param>
        /// <param name="arguments">Command arguments.</param>
        public void ExecuteCommand(string command, List <string> arguments)
        {
            NetDataWriter writer = new NetDataWriter();

            writer.Put(command);
            writer.PutArray(arguments.ToArray());
            PacketProcessor.Send <ServerInteractPacket>(Peer,
                                                        new ServerInteractPacket()
            {
                AddonId = Assembly.GetCallingAssembly().GetAddonId(),
                Type    = (byte)ServerInteractionType.ExecuteCommand,
                Data    = writer.Data,
            }, DeliveryMethod.ReliableOrdered);
        }
Example #16
0
        /// <summary>
        /// Sends one message to a specific connected peer.
        /// </summary>
        /// <param name="peer">The connection information required to identify the player.</param>
        /// <param name="type">The type of message [INFO, CMD, DATA]</param>
        /// <param name="topic">The topic of this message.</param>
        /// <param name="data">Any number of strings</param>
        private void SendMessage(NetPeer peer, string type, string topic, params string[] data)
        {
            NetDataWriter output  = new NetDataWriter();
            List <string> message = new List <string>();

            message.Add(type);
            message.Add(topic);
            message.AddRange(data);

            output.PutArray(message.ToArray());
            if ((peer?.ConnectionState & ConnectionState.Connected) != 0)
            {
                peer?.Send(output, DeliveryMethod.ReliableOrdered);
            }
        }
Example #17
0
    IEnumerator SendAudio()
    {
        NetDataWriter writer = new NetDataWriter();

        while (true)
        {
            AudioClip audioClip = Microphone.Start("", false, 1, 125);
            yield return(new WaitForSecondsRealtime(125f / 44100f));

            float[] sendData = new float[125];
            audioClip.GetData(sendData, 0);
            writer.Reset();
            writer.PutArray(sendData);
            netManager.SendToAll(writer, DeliveryMethod.ReliableSequenced);
        }
    }
 public void SerializeParameters(NetDataWriter writer)
 {
     if (Parameters == null || Parameters.Length == 0)
     {
         return;
     }
     for (int i = 0; i < Parameters.Length; ++i)
     {
         if (ParameterTypes[i].IsArray)
         {
             writer.PutArray(ParameterTypes[i].GetElementType(), Parameters[i]);
         }
         else
         {
             writer.PutValue(ParameterTypes[i], Parameters[i]);
         }
     }
 }
Example #19
0
 public void CreateDefaultConnectionData()
 {
     defaultdata = new NetDataWriter();
     defaultdata.Put(plugin.Config.HostConnectionKey);
     defaultdata.Put(plugin.Version.ToString(3));
     defaultdata.Put(Server.Port);
     defaultdata.Put(CustomNetworkManager.slots);
     defaultdata.PutArray(ClientAddons.Select(p => p.Key).ToArray());
     if (File.Exists(tokenPath))
     {
         var bytes = File.ReadAllBytes(tokenPath);
         defaultdata.PutBytesWithLength(bytes, 0, bytes.Length);
     }
     else
     {
         var bytes = Encoding.UTF8.GetBytes(string.Empty);
         defaultdata.PutBytesWithLength(bytes, 0, bytes.Length);
     }
 }
 private void DataWriterTest(NetDataWriter netDataWriter, Stopwatch stopwatch, SamplePacket samplePacket)
 {
     netDataWriter.Reset();
     stopwatch.Restart();
     for (int i = 0; i < LoopLength; i++)
     {
         netDataWriter.Put(samplePacket.SomeString);
         netDataWriter.Put(samplePacket.SomeFloat);
         netDataWriter.PutArray(samplePacket.SomeIntArray);
         SomeVector2.Serialize(netDataWriter, samplePacket.SomeVector2);
         netDataWriter.Put((ushort)samplePacket.SomeVectors.Length);
         for (int j = 0; j < samplePacket.SomeVectors.Length; j++)
         {
             SomeVector2.Serialize(netDataWriter, samplePacket.SomeVectors[j]);
         }
         netDataWriter.Put(samplePacket.EmptyString);
         netDataWriter.Put(samplePacket.TestObj);
     }
     stopwatch.Stop();
     Console.WriteLine($"Raw time: {stopwatch.ElapsedMilliseconds} ms, size: { netDataWriter.Length / LoopLength} bytes");
 }
Example #21
0
 public void WriteContents(NetDataWriter msg) => msg.PutArray(RTCs);
 internal override void SerializeValue(NetDataWriter writer)
 {
     writer.PutArray(Value);
 }
Example #23
0
 public void WriteContents(NetDataWriter message)
 {
     message.Put(Base);
     Ship.Put(message);
     message.PutArray(RTCs);
 }
Example #24
0
 public void Serialize(NetDataWriter writer)
 {
     writer.Put(Nbits);
     writer.PutArray(words);
 }
 public void PutArray(int[] array)
 {
     _networkWriterImplementation.PutArray(array);
 }
Example #26
0
 public void Serialize(NetDataWriter writer)
 {
     writer.PutArray(PlayersArray);
 }
Example #27
0
        private void TestPerformance()
        {
            const int LoopLength = 100000;
            //Test serializer performance
            Stopwatch       stopwatch       = new Stopwatch();
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            MemoryStream    memoryStream    = new MemoryStream();
            NetDataWriter   netDataWriter   = new NetDataWriter();

            SamplePacket samplePacket = new SamplePacket
            {
                SomeFloat    = 0.3f,
                SomeString   = "TEST",
                SomeIntArray = new [] { 1, 2, 3 },
                SomeVector2  = new SomeVector2(1, 2),
                SomeVectors  = new [] { new SomeVector2(3, 4), new SomeVector2(5, 6) }
            };

            NetSerializer netSerializer = new NetSerializer();

            netSerializer.RegisterCustomType <SampleNetSerializable>();
            netSerializer.RegisterCustomType(SomeVector2.Serialize, SomeVector2.Deserialize);

            //Prewarm cpu
            for (int i = 0; i < 10000000; i++)
            {
                double c = Math.Sin(i);
            }

            //Test binary formatter
            stopwatch.Start();
            for (int i = 0; i < LoopLength; i++)
            {
                binaryFormatter.Serialize(memoryStream, samplePacket);
            }
            stopwatch.Stop();
            Console.WriteLine("BinaryFormatter time: " + stopwatch.ElapsedMilliseconds + " ms");

            //Test NetSerializer
            stopwatch.Restart();
            for (int i = 0; i < LoopLength; i++)
            {
                netSerializer.Serialize(netDataWriter, samplePacket);
            }
            stopwatch.Stop();
            Console.WriteLine("NetSerializer first run time: " + stopwatch.ElapsedMilliseconds + " ms");

            //Test NetSerializer
            netDataWriter.Reset();
            stopwatch.Restart();
            for (int i = 0; i < LoopLength; i++)
            {
                netSerializer.Serialize(netDataWriter, samplePacket);
            }
            stopwatch.Stop();
            Console.WriteLine("NetSerializer second run time: " + stopwatch.ElapsedMilliseconds + " ms");

            //Test RAW
            netDataWriter.Reset();
            stopwatch.Restart();
            for (int i = 0; i < LoopLength; i++)
            {
                netDataWriter.Put(samplePacket.SomeFloat);
                netDataWriter.Put(samplePacket.SomeString);
                netDataWriter.PutArray(samplePacket.SomeIntArray);
                netDataWriter.Put(samplePacket.SomeVector2.X);
                netDataWriter.Put(samplePacket.SomeVector2.Y);
                netDataWriter.Put(samplePacket.SomeVectors.Length);
                for (int j = 0; j < samplePacket.SomeVectors.Length; j++)
                {
                    netDataWriter.Put(samplePacket.SomeVectors[j].X);
                    netDataWriter.Put(samplePacket.SomeVectors[j].Y);
                }
                netDataWriter.Put(samplePacket.EmptyString);
                netDataWriter.Put(samplePacket.TestObj.Value);
            }
            stopwatch.Stop();
            Console.WriteLine("DataWriter (raw put method calls) time: " + stopwatch.ElapsedMilliseconds + " ms");
        }