//callback from SteamClient. Read the data and decide how to process it.
    public void ReceiveP2PData(ulong steamID, byte[] bytes, int length, int channel)
    {
        readStream = new UdpKit.UdpStream(bytes, length);
        //Debug.Log("rec message");
        //string s = stream.ReadString();
        while (readStream.CanRead() && readStream.CanRead(8))
        {
            int msgCode = (int)SerializerUtils.ReadInt(readStream, 0, 255);
            //Debug.Log("[REC] MessageCode: " + msgCode);
            if (msgCode == GetMessageCode("Empty"))
            {
                break; //no more data, the rest of this packet is junk
            }

            if (MessageDeserializers[msgCode] != null)
            {
                MessageDeserializers[msgCode](steamID, msgCode, readStream);
                //entity messages deserialize is called internally (MessageCodes.SpawnPrefab.Deserialize  calles entity.Deserialize)
            }
            else
            {
                MessageProcessors[msgCode](steamID); //process is usually called within the deserializer, but since we have no deserializer (because we have no data, just a msgCode), call it here.
            }
        }
    }
Beispiel #2
0
    //callback from SteamClient. Read the data and decide how to process it.
    public void ReceiveP2PData(ulong steamID, byte[] bytes, int length, int channel)
    {
        readStream = new UdpKit.UdpStream(bytes, length);
        //Debug.Log("rec message");
        //string s = stream.ReadString();
        while (readStream.CanRead() && readStream.CanRead(SerializerUtils.RequiredBitsInt(0, maxMessageTypes)))
        {
            int msgCode = (int)SerializerUtils.ReadInt(readStream, 0, maxMessageTypes);
            //Debug.Log("[REC] MessageCode: " + msgCode);
            if (msgCode == GetMessageCode("Empty"))
            {
                AddToBandwidthInBuffer(-8);
                break; //no more data, the rest of this packet is junk
            }
            //can we ignore all state data here if we're not in the same zone?
            //we don't know what kind of entity it's from..so...
            //maybe all zoneless data should just go through events?
            //or we can check the prefab to find out if it's zoneless?

            if (MessageDeserializers[msgCode] != null)
            {
                MessageDeserializers[msgCode](steamID, msgCode, readStream);
                //entity messages deserialize is called internally (MessageCodes.SpawnPrefab.Deserialize  calles entity.Deserialize)
            }
            else
            {
                MessageProcessors[msgCode](steamID); //process is usually called within the deserializer, but since we have no deserializer (because we have no data, just a msgCode), call it here.
            }
        }
    }