Esempio n. 1
0
 public void Read(Stream stream)
 {
     using (var reader = PooledBitReader.Get(stream))
     {
         playerId = reader.ReadInt32Packed();
         motion   = reader.ReadVector2Packed();
     }
 }
Esempio n. 2
0
 public override void NetworkStart(Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         string name = reader.ReadString().ToString();
         gameObject.name = name;
     }
 }
Esempio n. 3
0
 internal static void HandleTimeSync(ulong clientId, Stream stream, float receiveTime)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         float netTime = reader.ReadSinglePacked();
         NetworkingManager.Singleton.UpdateNetworkTime(clientId, netTime, receiveTime);
     }
 }
 internal static void HandleDestroyPoolObject(uint clientId, Stream stream, int channelId)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         uint netId = reader.ReadUInt32Packed();
         SpawnManager.SpawnedObjects[netId].gameObject.SetActive(false);
     }
 }
Esempio n. 5
0
 private void ApplyRotation(ulong clientID, Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         float rotation = reader.ReadSinglePacked();
         transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, rotation);
     }
 }
 internal static void HandleClientDisconnect(uint clientId, Stream stream, int channelId)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         uint disconnectedClientId = reader.ReadUInt32Packed();
         netManager.OnClientDisconnectFromServer(disconnectedClientId);
     }
 }
 private void HandleNetworkLog(ulong sendingClientID, Stream stream, float receiveTime)
 {
     //DO NOT* CALL Debug.Log or other log functions in this function. *See onReceivedNetworkLog summary comments.
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         m_OnReceivedNetworkLog?.Invoke(sendingClientID, reader.ReadString().ToString(), reader.ReadBool() ? reader.ReadString().ToString() : string.Empty, (LogType)reader.ReadByte());
     }
 }
Esempio n. 8
0
 internal static void HandleDestroyObject(ulong clientId, Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         ulong networkId = reader.ReadUInt64Packed();
         SpawnManager.OnDestroyObject(networkId, true);
     }
 }
 internal static void HandleDestroyObject(uint clientId, Stream stream, int channelId)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         uint netId = reader.ReadUInt32Packed();
         SpawnManager.OnDestroyObject(netId, true);
     }
 }
Esempio n. 10
0
 private void HandleTimeSync(ulong sendingClientID, Stream stream, float receiveTime)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         float netTime = reader.ReadSinglePacked();
         UpdateNetworkTime(sendingClientID, netTime, receiveTime);
     }
 }
Esempio n. 11
0
 public void ReadSyncTeamSlots(PooledBitReader reader, int count)
 {
     for (int i = 0; i < count; i++)
     {
         int   slot  = reader.ReadInt32Packed();
         ulong netID = reader.ReadUInt64Packed();
         teamSlots[slot] = GameManager.GetPlayerByNetworkID(netID);
     }
 }
Esempio n. 12
0
        /// <inheritdoc />
        public void ReadDelta(Stream stream)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                ushort deltaCount = reader.ReadUInt16Packed();
                for (int i = 0; i < deltaCount; i++)
                {
                    NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType eventType = (NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType)reader.ReadBits(3);
                    switch (eventType)
                    {
                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add:
                    {
                        TKey   key   = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue));
                        dictionary.Add(key, value);
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Remove:
                    {
                        TKey key = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        dictionary.Remove(key);
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.RemovePair:
                    {
                        TKey   key   = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue));
                        dictionary.Remove(new KeyValuePair <TKey, TValue>(key, value));
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Clear:
                    {
                        //read nothing
                        dictionary.Clear();
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Value:
                    {
                        TKey   key   = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue));
                        if (dictionary.ContainsKey(key))
                        {
                            dictionary[key] = value;
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
            }
        }
Esempio n. 13
0
        internal void ReadValue(Stream stream)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                value = reader.ReadObjectPacked(field.FieldType);

                field.SetValue(fieldInstance, value);
            }
        }
Esempio n. 14
0
    public bool PullFilesFromPacket(PooledBitReader reader)
    {
        bool packetEndHit = false;

        while (!packetEndHit)
        {
            int id = reader.ReadInt32();

            byte[] data = reader.ReadByteArray(null);
            packetEndHit = reader.ReadBit();

            float progress = (float)fileBytesReceived / (float)DownloadSize;

            //Debug.LogError("file packet received: " + id + " " + data.Length + "    packet finished: " + packetEndHit.ToString());

            fileBytesReceived += data.Length;
            //Debug.LogWarning("internal prog: " + progress + "     -     " + fileBytesReceived + "/" + DownloadSize);
            if (OnProgressUpdated != null)
            {
                OnProgressUpdated(progress, "Receiving file: " + Headers[id].path);
            }

            numFilesReceived++;
            //Debug.Log(fileBytesReceived + "   /   " + DownloadSize);
            bool allFilesProcessed = fileBytesReceived >= DownloadSize;

            if (id != previousFileID)
            {
                if (receptionFileStream != null)
                {
                    receptionFileStreamWriter.Dispose();
                    receptionFileStream.Dispose();
                }

                string filePath = Paths.GetDownloadPath(Headers[id]);

                receptionFileStream       = File.Open(filePath, FileMode.Append);
                receptionFileStreamWriter = new BinaryWriter(receptionFileStream);
            }


            receptionFileStreamWriter.Write(data);


            if (allFilesProcessed)
            {
                receptionFileStreamWriter.Dispose();
                receptionFileStream.Dispose();
                return(true);
            }


            previousFileID = id;
        }

        return(false);
    }
Esempio n. 15
0
 public void ClientSyncTeamSlots(Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         int teamid = reader.ReadInt32Packed();
         int count  = reader.ReadInt32Packed();
         teams[teamid].ReadSyncTeamSlots(reader, count);
     }
 }
Esempio n. 16
0
 public void Read(Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         LocationIndex = reader.ReadByte();
         Question      = reader.ReadString().ToString();
         reader.ReadIntArrayPacked(Answers, ANSWER_COUNT);
     }
 }
Esempio n. 17
0
 public void ReadPlayerFromServer(Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         isInsideThree = reader.ReadBool();
         isInbounds    = reader.ReadBool();
         HasBall       = reader.ReadBool();
     }
 }
Esempio n. 18
0
 public CustomMessages()
 {
     CustomMessagingManager.RegisterNamedMessageHandler(MessageName, (sender, payload) => {
         Debug.Log("MESSAGE HANDLER");
         using (var reader = PooledBitReader.Get(payload)) {
             ChatReceived?.Invoke(this, reader.ReadString().ToString());
         }
     });
 }
    public static AnimationPacket FromStream(Stream stream)
    {
        using (PooledBitReader reader = PooledBitReader.Get(stream)) {
            bool groundstate = reader.ReadBool();
            bool hangstate   = reader.ReadBool();

            return(new AnimationPacket(groundstate, hangstate));
        }
    }
Esempio n. 20
0
 //In the lobby i want to send a name, outside of that i just want to send an id and find it. It would make a lot of code much nicer.
 //Maybe register/deregister a custom serializer?
 public void Read(Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         //TODO: ID could very often be inferred by who sent it?
         ID   = reader.ReadUInt64();
         Name = reader.ReadString().ToString();
     }
 }
 internal static void HandleSwitchScene(uint clientId, Stream stream, int channelId)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         uint sceneIndex      = reader.ReadUInt32Packed();
         Guid switchSceneGuid = new Guid(reader.ReadByteArray());
         NetworkSceneManager.OnSceneSwitch(sceneIndex, switchSceneGuid);
     }
 }
Esempio n. 22
0
        internal static void HandleNamedMessage(ulong clientId, Stream stream)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                ulong hash = reader.ReadUInt64Packed();

                CustomMessagingManager.InvokeNamedMessage(hash, clientId, stream);
            }
        }
Esempio n. 23
0
        internal static void HandleAddObject(ulong clientId, Stream stream)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                bool  isPlayerObject  = reader.ReadBool();
                ulong networkId       = reader.ReadUInt64Packed();
                ulong ownerId         = reader.ReadUInt64Packed();
                bool  hasParent       = reader.ReadBool();
                ulong?parentNetworkId = null;

                if (hasParent)
                {
                    parentNetworkId = reader.ReadUInt64Packed();
                }

                ulong prefabHash;
                ulong instanceId;
                bool  softSync;

                if (NetworkingManager.Singleton.NetworkConfig.UsePrefabSync)
                {
                    softSync   = false;
                    instanceId = 0;
                    prefabHash = reader.ReadUInt64Packed();
                }
                else
                {
                    softSync = reader.ReadBool();

                    if (softSync)
                    {
                        instanceId = reader.ReadUInt64Packed();
                        prefabHash = 0;
                    }
                    else
                    {
                        prefabHash = reader.ReadUInt64Packed();
                        instanceId = 0;
                    }
                }

                Vector3?   pos = null;
                Quaternion?rot = null;
                if (reader.ReadBool())
                {
                    pos = new Vector3(reader.ReadSinglePacked(), reader.ReadSinglePacked(), reader.ReadSinglePacked());
                    rot = Quaternion.Euler(reader.ReadSinglePacked(), reader.ReadSinglePacked(), reader.ReadSinglePacked());
                }

                bool hasPayload    = reader.ReadBool();
                int  payLoadLength = hasPayload ? reader.ReadInt32Packed() : 0;

                NetworkedObject netObject = SpawnManager.CreateLocalNetworkedObject(softSync, instanceId, prefabHash, parentNetworkId, pos, rot);
                SpawnManager.SpawnNetworkedObjectLocally(netObject, networkId, softSync, isPlayerObject, ownerId, stream, hasPayload, payLoadLength, true, false);
            }
        }
Esempio n. 24
0
        internal static void HandleTimeSync(ulong clientId, Stream stream)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                float netTime = reader.ReadSinglePacked();
                ulong msDelay = NetworkingManager.Singleton.NetworkConfig.NetworkTransport.GetCurrentRtt(clientId);

                NetworkingManager.Singleton.NetworkTime = netTime + (msDelay / 1000f);
            }
        }
Esempio n. 25
0
 public void Read(Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         GameMode      = (BallersGamemode)reader.ReadByte();
         TeamSize      = reader.ReadByte();
         QuarterLength = reader.ReadByte();
         QuartersCount = reader.ReadByte();
     }
 }
Esempio n. 26
0
 public void Read(Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         ImposterCount = reader.ReadByte();
         MovementSpeed = reader.ReadSinglePacked();
         VoteDuration  = reader.ReadSinglePacked();
         TaskCount     = reader.ReadUInt16Packed();
     }
 }
Esempio n. 27
0
 internal void SetNetworkedVarData(Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         foreach (var NetworkedVarsList in dummyNetworkedVars.Values)
         {
             NetworkedBehaviour.SetNetworkedVarData(NetworkedVarsList, reader, stream);
         }
     }
 }
Esempio n. 28
0
 private void WinRPC(ulong clientId, Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         left           = reader.ReadInt32();
         right          = reader.ReadInt32();
         leftText.text  = left.ToString();
         rightText.text = right.ToString();
     }
 }
Esempio n. 29
0
        private void ApplyTransform(ulong clientId, Stream stream)
        {
            if (!enabled)
            {
                return;
            }

            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                Vector3    position = Vector3.zero;
                Quaternion rotation = Quaternion.identity;
                if (SyncPosition)
                {
                    position = reader.ReadVector3Packed();
                }
                if (SyncRotation)
                {
                    if (FullRotation)
                    {
                        Quaternion.Euler(reader.ReadVector3Packed());
                    }
                    else
                    {
                        Quaternion.Euler(0, reader.ReadSinglePacked(), 0);
                    }
                }

                if (InterpolatePosition && !IsServer)
                {
                    lastReceiveTime = Time.unscaledTime;
                    if (SyncPosition)
                    {
                        lerpStartPos = transform.position;
                        lerpEndPos   = position;
                    }
                    if (SyncRotation)
                    {
                        lerpStartRot = transform.rotation;
                        lerpEndRot   = rotation;
                    }
                    lerpT = 0;
                }
                else
                {
                    if (SyncPosition)
                    {
                        transform.position = position;
                    }
                    if (SyncRotation)
                    {
                        transform.rotation = rotation;
                    }
                }
            }
        }
Esempio n. 30
0
 internal void SetNetworkedVarData(Stream stream)
 {
     using (PooledBitReader reader = PooledBitReader.Get(stream))
     {
         for (int i = 0; i < childNetworkedBehaviours.Count; i++)
         {
             childNetworkedBehaviours[i].NetworkedVarInit();
             NetworkedBehaviour.SetNetworkedVarData(childNetworkedBehaviours[i].networkedVarFields, reader, stream);
         }
     }
 }