Beispiel #1
0
    public void TestSendToAllOthersCorrectPayloadDataRedLight()
    {
        BytePacket p = new BytePacket(10);

        p.Write(750);
        p.Write((ushort)110);
        p.Write((sbyte)-5);
        p.Write(false);
        p.Write((short)short.MinValue);
        p.CurrentSeek = 0;
        transport.SendToAll(p, new VoicePacketInfo(), new List <ulong>()
        {
            1
        });
        Assert.That(ByteManipulator.ReadInt32(workflow.receivedData, 4), Is.Not.EqualTo(0));
    }
Beispiel #2
0
    public void TestSendToAllOthersCorrectPayloadData4()
    {
        BytePacket p = new BytePacket(10);

        p.Write(750);
        p.Write((ushort)110);
        p.Write((sbyte)-5);
        p.Write(false);
        p.Write((short)-32767);
        p.CurrentSeek = 0;
        transport.SendToAll(p, new VoicePacketInfo(), new List <ulong>()
        {
            1
        });
        Assert.That(ByteManipulator.ReadInt16(workflow.receivedData, 12), Is.EqualTo(-32767));
    }
    public override void FromAudioDataToPacketInt16(byte[] audioData, int audioDataOffset, int audioDataCount, ref VoicePacketInfo info, BytePacket output)
    {
        //writes audio data length
        output.Write(audioDataCount);

        //data is written on the output.
        int n = audioDataCount > output.MaxCapacity - output.CurrentSeek ? output.MaxCapacity - output.CurrentSeek : audioDataCount;

        output.WriteByteData(audioData, audioDataOffset, n);
    }
Beispiel #4
0
 public override void FromAudioDataToPacket(float[] audioData, int audioDataOffset, int audioDataCount, ref VoicePacketInfo info, BytePacket output)
 {
     FromAudioToPacket = true;
     for (int i = 0; i < audioDataCount; i++)
     {
         output.Write(audioData[i + audioDataOffset]);
     }
     if (UseInfo)
     {
         info = this.Info;
     }
 }
Beispiel #5
0
    public void TestFromPacketToAudioDataInt16OutputValues3()
    {
        BytePacket packet = new BytePacket(104);

        packet.Write(25);
        for (int i = 0; i < (packet.Data.Length - 4); i++)
        {
            packet.Write((byte)i);
        }
        packet.CurrentSeek   = 0;
        packet.CurrentLength = 104;
        byte[]          output = new byte[100];
        VoicePacketInfo info   = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;

        manipulator.FromPacketToAudioDataInt16(packet, ref info, output, 0);

        Assert.That(output[9], Is.EqualTo(9).Within(0.0001));
    }
Beispiel #6
0
        /// <summary>
        /// Processes audio data in format Single into a GamePacket
        /// </summary>
        /// <param name="audioData">audio data to process</param>
        /// <param name="audioDataOffset">audio data startIndex</param>
        /// <param name="audioDataCount">number of bytes to process</param>
        /// <param name="info">data info</param>
        /// <param name="output">gamepacket on which data will be written</param>
        public override void FromAudioDataToPacket(float[] audioData, int audioDataOffset, int audioDataCount, ref VoicePacketInfo info, BytePacket output)
        {
            int outputAvailableSpace = output.Data.Length - output.CurrentSeek;

            if (outputAvailableSpace < (audioDataCount * sizeof(float)) + sizeof(int))
            {
                audioDataCount = (int)((outputAvailableSpace - sizeof(int)) * ConverterByteSingle);
            }

            if (audioDataCount <= 0)
            {
                info.ValidPacketInfo = false;
                return;
            }

            output.Write(audioDataCount);
            int length = audioDataCount + audioDataOffset;

            for (int i = audioDataOffset; i < length; i++)
            {
                output.Write(audioData[i]);
            }
        }
    //sends to clients the command to instantiate an enemy in a given position, or it takes a random position from an array of randomic given positions if none is specified
    public void InstantiateEnemy(float x = 0, float y = 0, float z = 0)
    {
        int Id = IdDispenser.GetNewNetId();

        int     randomIndex = UnityEngine.Random.Range(0, spawnPoints.Length);
        Vector3 position    = new Vector3(x, y, z);

        if (position == Vector3.zero)
        {
            position = spawnPoints[randomIndex].position;
        }

        idAndPos.CurrentLength = 0;
        idAndPos.CurrentSeek   = 0;

        idAndPos.Write(Id);
        idAndPos.Write(position.x);
        idAndPos.Write(position.y);
        idAndPos.Write(position.z);

        Client.SendPacketToInGameUsers(idAndPos.Data, 0, idAndPos.MaxCapacity, PacketType.EnemySpawn, Client.MyID, Steamworks.EP2PSend.k_EP2PSendReliable);
        //Debug.Log("sent: " + Id);
    }
Beispiel #8
0
        /// <summary>
        /// Processes audio data in format Int16 into a GamePacket
        /// </summary>
        /// <param name="audioData">audio data to process</param>
        /// <param name="audioDataOffset">audio data startIndex</param>
        /// <param name="audioDataCount">number of bytes to process</param>
        /// <param name="info">data info</param>
        /// <param name="output">gamepacket on which data will be written</param>
        public override void FromAudioDataToPacketInt16(byte[] audioData, int audioDataOffset, int audioDataCount, ref VoicePacketInfo info, BytePacket output)
        {
            int outputAvailableSpace = output.Data.Length - output.CurrentSeek;

            if (outputAvailableSpace < audioDataCount + sizeof(int))
            {
                audioDataCount = outputAvailableSpace - sizeof(int);
            }

            if (audioDataCount <= 0)
            {
                info.ValidPacketInfo = false;
                return;
            }

            output.Write(audioDataCount);
            output.WriteByteData(audioData, audioDataOffset, audioDataCount);
        }
Beispiel #9
0
    public void TestFromPacketToAudioDataInt16InvalidPacket3()
    {
        BytePacket packet = new BytePacket(104);

        packet.Write(-1);
        packet.CurrentSeek   = 0;
        packet.CurrentLength = 104;
        byte[]          output = new byte[100];
        VoicePacketInfo info   = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;

        manipulator.FromPacketToAudioDataInt16(packet, ref info, output, 0);

        Assert.That(info.ValidPacketInfo, Is.False);
    }
Beispiel #10
0
    public void TestFromPacketToAudioDataInt16Count2()
    {
        BytePacket packet = new BytePacket(404);

        packet.Write(100);
        packet.CurrentSeek   = 0;
        packet.CurrentLength = 104;
        byte[]          output = new byte[100];
        VoicePacketInfo info   = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;

        int count = manipulator.FromPacketToAudioDataInt16(packet, ref info, output, 0);

        Assert.That(count, Is.EqualTo(100));
    }
Beispiel #11
0
    public void TestFromPacketToAudioDataSingleInvalidPacket2()
    {
        BytePacket packet = new BytePacket(4);

        packet.Write(25);
        packet.CurrentSeek   = 0;
        packet.CurrentLength = 4;
        float[]         output = new float[100];
        VoicePacketInfo info   = new VoicePacketInfo();

        info.ValidPacketInfo = true;
        info.Frequency       = 48000;
        info.Channels        = 1;
        info.Format          = AudioDataTypeFlag.Both;

        manipulator.FromPacketToAudioData(packet, ref info, output, 0);

        Assert.That(info.ValidPacketInfo, Is.False);
    }
Beispiel #12
0
    /// <summary>
    /// Writes the rotation on packet data.
    /// </summary>
    /// <param name="transform">Tranform to write</param>
    /// <param name="resetPacketSeek">If set to <c>true</c> reset packet seek.</param>
    public void WriteTransformOnPacketData(Transform transform, bool resetPacketSeek)
    {
        if (resetPacketSeek)
        {
            Packet.CurrentLength = 0;
            Packet.CurrentSeek   = 0;
        }

        Vector3    pos = transform.position;
        Quaternion rot = transform.rotation;

        Packet.Write(pos.x);
        Packet.Write(pos.y);
        Packet.Write(pos.z);

        Packet.Write(rot.x);
        Packet.Write(rot.y);
        Packet.Write(rot.z);
        Packet.Write(rot.w);
    }