private unsafe bool ReadP2PPacket(int channel)
        {
            uint DataAvailable = 0;

            if (!networking.IsP2PPacketAvailable(out DataAvailable, channel) || DataAvailable == 0)
            {
                return(false);
            }

            if (ReceiveBuffer.Capacity < DataAvailable)
            {
                ReceiveBuffer.Capacity = (int)DataAvailable;
            }

            ReceiveBuffer.Position = 0;
            ReceiveBuffer.SetLength(DataAvailable);

            fixed(byte *p = ReceiveBuffer.GetBuffer())
            {
                SteamNative.CSteamID steamid = 1;
                if (!networking.ReadP2PPacket((IntPtr)p, (uint)DataAvailable, out DataAvailable, out steamid, channel) || DataAvailable == 0)
                {
                    return(false);
                }

                ReceiveBuffer.SetLength(DataAvailable);

                OnP2PData?.Invoke(steamid, ReceiveBuffer, channel);
                return(true);
            }
        }
        private unsafe bool ReadP2PPacket(MemoryStream ms, int channel = 0)
        {
            uint DataAvailable = 0;

            if (!networking.IsP2PPacketAvailable(out DataAvailable, channel) || DataAvailable == 0)
            {
                return(false);
            }

            if (ms.Capacity < DataAvailable)
            {
                ms.Capacity = (int)DataAvailable;
            }

            ms.Position = 0;
            ms.SetLength(DataAvailable);

            fixed(byte *p = ms.GetBuffer())
            {
                SteamNative.CSteamID steamid = 1;
                if (!networking.ReadP2PPacket((IntPtr)p, (uint)DataAvailable, out DataAvailable, out steamid, channel) || DataAvailable == 0)
                {
                    return(false);
                }

                ms.SetLength(DataAvailable);

                OnP2PData?.Invoke(steamid, ms, channel);
                return(true);
            }
        }
Beispiel #3
0
        private unsafe bool ReadP2PPacket( int channel )
        {
            uint DataAvailable = 0;

            if ( !networking.IsP2PPacketAvailable( out DataAvailable, channel ) )
                return false;

            if ( ReceiveBuffer.Length < DataAvailable )
                ReceiveBuffer = new byte[ DataAvailable + 1024 ];

            fixed ( byte* p = ReceiveBuffer )
            {
                SteamNative.CSteamID steamid = 1;
                if ( !networking.ReadP2PPacket( (IntPtr)p, DataAvailable, out DataAvailable, out steamid, channel ) || DataAvailable == 0 )
                    return false;

                OnP2PData?.Invoke( steamid, ReceiveBuffer, (int) DataAvailable, channel );
                return true;
            }
        }