Esempio n. 1
0
 public void Deserialize(ref NetworkReader reader, IEntityReferenceSerializer refSerializer, int tick)
 {
     checkTick     = reader.ReadInt32();
     renderTick    = reader.ReadInt32();
     moveYaw       = reader.ReadFloatQ();
     moveMagnitude = reader.ReadFloatQ();
     lookYaw       = reader.ReadFloat();
     lookPitch     = reader.ReadFloat();
     jump          = reader.ReadBoolean();
     boost         = reader.ReadBoolean();
     sprint        = reader.ReadBoolean();
     primaryFire   = reader.ReadBoolean();
     secondaryFire = reader.ReadBoolean();
     abilityA      = reader.ReadBoolean();
     reload        = reader.ReadBoolean();
     melee         = reader.ReadBoolean();
     use           = reader.ReadBoolean();
     emote         = (CharacterEmote)reader.ReadByte();
     //VR controls
     rightControllerPos = reader.ReadVector3Q();
     leftControllerPos  = reader.ReadVector3Q();
     headsetPos         = reader.ReadVector3Q();
     rightControllerRot = reader.ReadQuaternion();
     leftControllerRot  = reader.ReadQuaternion();
     headsetRot         = reader.ReadQuaternion();
 }
Esempio n. 2
0
 public override void Deserialize(ref NetworkReader reader)
 {
     base.Deserialize(ref reader);
     position         = reader.ReadVector3();
     health           = reader.ReadInt32();
     flag             = reader.ReadBoolean();
     message          = reader.ReadString();
     predictedData    = reader.ReadFloat();
     nonpredictedData = reader.ReadFloat();
 }
Esempio n. 3
0
 public void Deserialize(ref SerializeContext context, ref NetworkReader networkReader)
 {
     checkTick     = networkReader.ReadInt32();
     renderTick    = networkReader.ReadInt32();
     moveYaw       = networkReader.ReadFloatQ();
     moveMagnitude = networkReader.ReadFloatQ();
     lookYaw       = networkReader.ReadFloat();
     lookPitch     = networkReader.ReadFloat();
     buttons.flags = networkReader.ReadUInt32();
 }
Esempio n. 4
0
File: Plane.cs Progetto: kdada/plane
    public object Translate(NetworkReader reader)
    {
        var x = reader.ReadFloat();
        var y = reader.ReadFloat();

        return(new Position()
        {
            x = x.Value, y = y.Value
        });
    }
 public static MyGenericStruct <float> ReadItem(this NetworkReader reader)
 {
     return(new MyGenericStruct <float>()
     {
         genericpotato = reader.ReadFloat()
     });
 }
Esempio n. 6
0
 public override void Deserialize(ref NetworkReader reader)
 {
     intValue    = reader.ReadInt32();
     boolValue   = reader.ReadBoolean();
     floatValue  = reader.ReadFloat();
     stringValue = reader.ReadString();
 }
Esempio n. 7
0
 public void Deserialize(ref NetworkReader networkReader, IEntityReferenceSerializer refSerializer, int tick)
 {
     checkTick     = networkReader.ReadInt32();
     renderTick    = networkReader.ReadInt32();
     moveYaw       = networkReader.ReadFloatQ();
     moveMagnitude = networkReader.ReadFloatQ();
     lookYaw       = networkReader.ReadFloat();
     lookPitch     = networkReader.ReadFloat();
     jump          = networkReader.ReadBoolean();
     boost         = networkReader.ReadBoolean();
     sprint        = networkReader.ReadBoolean();
     primaryFire   = networkReader.ReadBoolean();
     secondaryFire = networkReader.ReadBoolean();
     abilityA      = networkReader.ReadBoolean();
     reload        = networkReader.ReadBoolean();
     melee         = networkReader.ReadBoolean();
     use           = networkReader.ReadBoolean();
 }
        public static DataBase ReadData(this NetworkReader reader)
        {
            int id = reader.ReadInt();

            int      someField = reader.ReadInt();
            DataBase data      = null;

            if (data.id == 1)
            {
                SomeData someData = new SomeData()
                {
                    someField = someField
                };
                // read extra stuff depending on id here

                someData.anotherField = reader.ReadFloat();

                data = someData;
            }
            return(data);
        }
Esempio n. 9
0
 public void Deserialize(ref SerializeContext context, ref NetworkReader reader)
 {
     health = reader.ReadFloat();
 }
Esempio n. 10
0
        unsafe public static void ReadAndAssertValues(List <object> values, uint[] buffer, NetworkSchema schema)
        {
            fixed(uint *buf = buffer)
            {
                NetworkReader reader = new NetworkReader(buf, schema);

                for (int j = 0; j < schema.numFields; ++j)
                {
                    var value = values[j];
                    var field = schema.fields[j];
                    if (value is bool)
                    {
                        Assert.AreEqual(value, reader.ReadBoolean());
                    }
                    else if (value is byte)
                    {
                        Assert.AreEqual(value, reader.ReadByte());
                    }
                    else if (value is ushort)
                    {
                        Assert.AreEqual(value, reader.ReadUInt16());
                    }
                    else if (value is short)
                    {
                        Assert.AreEqual(value, reader.ReadInt16());
                    }
                    else if (value is uint)
                    {
                        Assert.AreEqual(value, reader.ReadUInt32());
                    }
                    else if (value is int)
                    {
                        Assert.AreEqual(value, reader.ReadInt32());
                    }
                    else if (value is float)
                    {
                        var expected = (float)value;
                        if (field.delta)
                        {
                            var actual = reader.ReadFloatQ();
                            Assert.IsTrue(Math.Abs(actual - expected) < Math.Pow(10, -field.precision));
                        }
                        else
                        {
                            var actual = reader.ReadFloat();
                            Assert.AreEqual(expected, actual);
                        }
                    }
                    else if (value is Vector2)
                    {
                        var expected = (Vector2)value;
                        if (field.delta)
                        {
                            var actual = reader.ReadVector2Q();
                            Assert.IsTrue(Math.Abs(actual.x - expected.x) < Math.Pow(10, -field.precision));
                            Assert.IsTrue(Math.Abs(actual.y - expected.y) < Math.Pow(10, -field.precision));
                        }
                        else
                        {
                            var actual = reader.ReadVector2();
                            Assert.AreEqual(expected.x, actual.x);
                            Assert.AreEqual(expected.y, actual.y);
                        }
                    }
                    else if (value is Vector3)
                    {
                        var expected = (Vector3)value;
                        if (field.delta)
                        {
                            var actual = reader.ReadVector3Q();
                            Assert.IsTrue(Math.Abs(actual.x - expected.x) < Math.Pow(10, -field.precision));
                            Assert.IsTrue(Math.Abs(actual.y - expected.y) < Math.Pow(10, -field.precision));
                            Assert.IsTrue(Math.Abs(actual.z - expected.z) < Math.Pow(10, -field.precision));
                        }
                        else
                        {
                            var actual = reader.ReadVector3();
                            Assert.AreEqual(expected.x, actual.x);
                            Assert.AreEqual(expected.y, actual.y);
                            Assert.AreEqual(expected.z, actual.z);
                        }
                    }
                    else if (value is Quaternion)
                    {
                        var expected = (Quaternion)value;

                        if (field.delta)
                        {
                            var actual = reader.ReadQuaternionQ();
                            Assert.IsTrue(Math.Abs(actual.x - expected.x) < Math.Pow(10, -field.precision));
                            Assert.IsTrue(Math.Abs(actual.y - expected.y) < Math.Pow(10, -field.precision));
                            Assert.IsTrue(Math.Abs(actual.z - expected.z) < Math.Pow(10, -field.precision));
                            Assert.IsTrue(Math.Abs(actual.w - expected.w) < Math.Pow(10, -field.precision));
                        }
                        else
                        {
                            var actual = reader.ReadQuaternion();
                            Assert.AreEqual(expected.x, actual.x);
                            Assert.AreEqual(expected.y, actual.y);
                            Assert.AreEqual(expected.z, actual.z);
                            Assert.AreEqual(expected.w, actual.w);
                        }
                    }
                    else if (value is string)
                    {
                        var actual = reader.ReadString(1024);
                        if (value != null)
                        {
                            Assert.AreEqual(value, actual);
                        }
                        else
                        {
                            Assert.AreEqual("", actual);
                        }
                    }
                    else if (value is byte[])
                    {
                        var expected = (byte[])value;
                        var actual   = new byte[10];
                        var length   = reader.ReadBytes(actual, 0, 1024);
                        Assert.AreEqual(10, length);
                        for (int b = 0; b < 10; ++b)
                        {
                            Assert.AreEqual(expected[b], actual[b]);
                        }
                    }
                    else if (value == null && field.fieldType == NetworkSchema.FieldType.String)
                    {
                        var actual = reader.ReadString(1024);
                        Assert.AreEqual("", actual);
                    }
                    else
                    {
                        Assert.Fail();
                    }
                }
            }
        }
Esempio n. 11
0
 public void Deserialize(ref NetworkReader reader, IEntityReferenceSerializer refSerializer, int tick)
 {
     health = reader.ReadFloat();
     armor  = reader.ReadFloat();
 }
Esempio n. 12
0
 public override void OnDeserialize(NetworkReader reader, bool initialState)
 {
     customSerializeField = reader.ReadFloat();
     base.OnDeserialize(reader, initialState);
 }
Esempio n. 13
0
    private void OnReceivedClientMovementData(ulong guid)
    {
        playerObject tempObj = clients[guid];

        tempObj.m_x        = m_NetworkReader.ReadFloat();
        tempObj.m_y        = m_NetworkReader.ReadFloat();
        tempObj.m_z        = m_NetworkReader.ReadFloat();
        tempObj.rotation_x = m_NetworkReader.ReadFloat();
        tempObj.rotation_y = m_NetworkReader.ReadFloat();
        tempObj.rotation_z = m_NetworkReader.ReadFloat();
        tempObj.velocity_X = m_NetworkReader.ReadFloat();
        tempObj.velocity_Y = m_NetworkReader.ReadFloat();
        tempObj.velocity_Z = m_NetworkReader.ReadFloat();

        clients[guid] = tempObj;

        if (m_NetworkWriter.StartWritting())
        {
            m_NetworkWriter.WritePacketID((byte)Packets_ID.ID_MOVEMENT);
            m_NetworkWriter.Write(tempObj.id);
            m_NetworkWriter.Write(tempObj.m_x);
            m_NetworkWriter.Write(tempObj.m_y);
            m_NetworkWriter.Write(tempObj.m_z);
            m_NetworkWriter.Write(tempObj.rotation_x);
            m_NetworkWriter.Write(tempObj.rotation_y);
            m_NetworkWriter.Write(tempObj.rotation_z);
            m_NetworkWriter.Write(tempObj.velocity_X);
            m_NetworkWriter.Write(tempObj.velocity_Y);
            m_NetworkWriter.Write(tempObj.velocity_Z);

            SendToAll(guid, m_NetworkWriter, true);
        }
    }
Esempio n. 14
0
    /// <summary>
    /// Parsing packet
    /// </summary>
    /// <param name="packet_id">PACKET ID  - SEE Packets_ID.cs</param>

    private void OnReceivedPacket(byte packet_id)
    {
        bool IsInternalNetworkPackets = packet_id <= 134;

        if (IsInternalNetworkPackets)
        {
            if (packet_id == (byte)Peer.RakNet_Packets_ID.CONNECTION_REQUEST_ACCEPTED)
            {
                OnConnected(peer.incomingAddress);
            }

            if (packet_id == (byte)Peer.RakNet_Packets_ID.CONNECTION_ATTEMPT_FAILED)
            {
                OnDisconnected("Connection attempt failed");
            }

            if (packet_id == (byte)Peer.RakNet_Packets_ID.INCOMPATIBLE_PROTOCOL_VERSION)
            {
                OnDisconnected("Incompatible protocol version");
            }

            if (packet_id == (byte)Peer.RakNet_Packets_ID.CONNECTION_LOST)
            {
                OnDisconnected("Time out");
            }

            if (packet_id == (byte)Peer.RakNet_Packets_ID.NO_FREE_INCOMING_CONNECTIONS)
            {
                OnDisconnected("Server is full.");
            }

            if (packet_id == (byte)Peer.RakNet_Packets_ID.DISCONNECTION_NOTIFICATION && !tmp_Banned && !tmp_Fake)
            {
                OnDisconnected("You are kicked!");
            }
        }
        else
        {
            switch (packet_id)
            {
            case (byte)Packets_ID.CL_INFO:
                if (m_NetworkWriter.StartWritting())
                {
                    GameObject playerObj = Instantiate(playerReference);
                    int        playerNum = playerObj.GetComponentInChildren <PlayerMovement>().Init(true);
                    playerObj.GetComponent <PlayerManager>().SetPlayer(true);;
                    playersList.Add(playerObj.GetComponent <PlayerManager>());

                    m_NetworkWriter.WritePacketID((byte)Packets_ID.CL_INFO);
                    m_NetworkWriter.Write(m_ClientNetInfo.name);
                    m_NetworkWriter.WritePackedUInt64(m_ClientNetInfo.local_id);
                    m_NetworkWriter.Write(m_ClientNetInfo.client_hwid);
                    m_NetworkWriter.Write(m_ClientNetInfo.client_version);
                    m_NetworkWriter.Write(playerNum);
                    serveruid = peer.incomingGUID;
                    m_NetworkWriter.Send(peer.incomingGUID, Peer.Priority.Immediate, Peer.Reliability.Reliable, 0);    //sending
                }
                break;

            case (byte)Packets_ID.NET_REGISTER:
            {
                bool success = m_NetworkReader.ReadBoolean();

                if (success)
                {
                    GameObject obj = GameObject.FindGameObjectWithTag("UIMaster");
                    obj.GetComponent <UIController>().SetToLogin();
                }
                else
                {
                    Debug.Log("Username Already Exists");
                }
            }
            break;

            case (byte)Packets_ID.CL_ACCEPTED:
                m_ClientNetInfo.net_id = m_NetworkReader.ReadPackedUInt64();
                Debug.Log("[Client] Accepted connection by server... [ID: " + m_ClientNetInfo.net_id + "]");
                break;

            case (byte)Packets_ID.ID_WELCOME:
                Debug.Log("welcome!!");
                uint          id  = m_NetworkReader.ReadUInt32();
                PlayerManager mgr = playersList[0];
                mgr.pid = id;
                int playerCount = m_NetworkReader.ReadInt32();

                for (int i = 0; i < playerCount; ++i)
                {
                    GameObject    otherPlayer  = Instantiate(playerReference);
                    PlayerManager otherManager = otherPlayer.GetComponent <PlayerManager>();
                    otherManager.pid       = m_NetworkReader.ReadUInt32();
                    otherManager.position  = new Vector3(m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat());
                    otherManager.pRotation = new Vector3(m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat());
                    otherManager.pName     = m_NetworkReader.ReadString();
                    playersList.Add(otherManager);
                }
                SendInitialStats();

                break;

            case (byte)Packets_ID.ID_MOVEMENT:
                uint playerID = m_NetworkReader.ReadUInt32();

                foreach (PlayerManager player in playersList)
                {
                    if (player.pid == playerID)
                    {
                        //  ship.position = new Vector3(m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat(), 0);
                        //  ship.pRotation = m_NetworkReader.ReadFloat();

                        // Step 8 : Instead of using ship.position, use server_pos and serverRotation
                        // set server position, server rotation
                        player.server_pos     = new Vector3(m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat());
                        player.serverRotation = new Vector3(m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat());
                        Debug.Log("Server rotation: " + player.serverRotation);
                        // Lab 7 Task 1 : Read Extrapolation Data velocity x, velocity y & angular velocity
                        // set velocity and rotation velocity of ship (look at ship Manager)

                        player.velocity = new Vector3(m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat());
                    }
                }
                break;

            case (byte)Packets_ID.ID_NEWPLAYER:
            {
                GameObject    playerObj    = Instantiate(playerReference);
                PlayerManager otherManager = playerObj.GetComponent <PlayerManager>();
                otherManager.pid = m_NetworkReader.ReadUInt32();
                playerObj.GetComponentInChildren <PlayerMovement>().Init(false);
                otherManager.pName     = m_NetworkReader.ReadString();
                otherManager.position  = new Vector3(m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat());
                otherManager.pRotation = new Vector3(m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat(), m_NetworkReader.ReadFloat());

                playersList.Add(otherManager);
            }
            break;

            case (byte)Packets_ID.ID_CHANGESCENE:
            {
                string sceneName = m_NetworkReader.ReadString();
                if (Application.CanStreamedLevelBeLoaded(sceneName))
                {
                    Scene nextScene = SceneManager.GetSceneByName(sceneName);
                    SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
                    SceneManager.MoveGameObjectToScene(this.gameObject, nextScene);

                    //foreach (PlayerManager player in playersList)
                    //{
                    //    SceneManager.MoveGameObjectToScene(player.gameObject, nextScene);
                    //}
                }
                else
                {
                    // load another scene?
                }
            }
            break;
            }
        }
    }