コード例 #1
0
        protected bool Receive(out uint readPacketSize, out SteamId clientSteamID, out byte[] receiveBuffer, int channel)
        {
            readPacketSize = 0;
            clientSteamID  = new SteamId();
            receiveBuffer  = null;

            if (!Steamworks.SteamClient.IsValid)
            {
                throw new ObjectDisposedException("Steamworks");
            }

            if (SteamNetworking.IsP2PPacketAvailable(channel))
            {
                packet = SteamNetworking.ReadP2PPacket(channel);

                if (packet != null)
                {
                    readPacketSize = (uint)packet.Value.Data.Length;
                    clientSteamID  = packet.Value.SteamId;
                    receiveBuffer  = packet.Value.Data;
                }

                return(packet != null);
            }

            return(false);
        }
コード例 #2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            uint size;

            long oldPos = incoming.Position;

            incoming.Position = incoming.Seek(0, SeekOrigin.End);
            while (incoming.Length - oldPos < count)//(SteamNetworking.IsP2PPacketAvailable(out size, conn.channel))
            {
                //Log.trace("" + incoming.Length + " " + incoming.Position + " " + oldPos + " " + count);
                if (!SteamNetworking.IsP2PPacketAvailable(out size, conn.channel))
                {
                    Thread.Sleep(1);
                    continue;
                }
                byte[]   tmp = new byte[size];
                CSteamID id  = new CSteamID();
                SteamNetworking.ReadP2PPacket(tmp, size, out size, out id, conn.channel);
                if (id.m_SteamID != conn.friend.id)
                {
                    continue;
                }
                incoming.Write(tmp, 0, (int)size);
            }
            incoming.Position = oldPos;

            return(incoming.Read(buffer, offset, count));
        }
コード例 #3
0
        void Update()
        {
            uint size;

            try
            {
                while (SteamNetworking.IsP2PPacketAvailable(out size))
                {
                    var      buffer = new byte[size];
                    uint     bytesRead;
                    CSteamID remoteId;
                    if (SteamNetworking.ReadP2PPacket(buffer, size, out bytesRead, out remoteId))
                    {
                        var          message = Encoding.UTF8.GetString(buffer).Replace(" ", "");
                        PlayerPacket info    = new PlayerPacket(message);
                        if (info.playerId != SteamAPI.GetUserID() && SteamAPI.getLobbyID().m_SteamID != 0)
                        {
                            UpsertPlayer(info);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
コード例 #4
0
ファイル: Sender.cs プロジェクト: xz000/testingLL
    void BattlesFinish()
    {
        MSM.CloseMainSkillMenu();
        Learning           = false;
        WaitingSkillLevels = false;
        TimeCount          = 0;
        ResetSelf();
        Debug.Log("All Battle Finished" + RoundNow);
        GameObject safeground = GameObject.FindGameObjectWithTag("Ground");

        Destroy(safeground);
        GameObject[] pcs = GameObject.FindGameObjectsWithTag("Player");
        foreach (GameObject pc in pcs)
        {
            Destroy(pc);
        }
        RoundNow = -10;
        TOmb     = null;
        ShowMC();
        testMenu02.LeaveLobby();
        uint msgSize;

        while (SteamNetworking.IsP2PPacketAvailable(out msgSize))
        {
            byte[]   packet = new byte[msgSize];
            CSteamID steamIDRemote;
            uint     bytesRead = 0;
            if (SteamNetworking.ReadP2PPacket(packet, msgSize, out bytesRead, out steamIDRemote))
            {
                Debug.Log("PACKET after Exit");
            }
        }
    }
コード例 #5
0
        void PlayingFunc()
        {
            uint networkSize;
            var  networkBuffer    = new byte[8000];
            var  inputBuffer      = new byte[8000];
            var  decompressBuffer = new byte[20000];

            while (true)
            {
                if (Program.CloseOnNext)
                {
                    return;
                }
                if (SteamAPI.IsSteamRunning() && SteamNetworking.IsP2PPacketAvailable(out networkSize))
                {
                    CSteamID remotUSer;
                    if (SteamNetworking.ReadP2PPacket(networkBuffer, (uint)networkBuffer.Length, out networkSize, out remotUSer))
                    {
                        PlaySoundFromNetworkData(remotUSer.m_SteamID, networkBuffer, networkSize, inputBuffer, decompressBuffer);
                    }
                }
                else
                {
                    Thread.Sleep(networkCheckIntervalMs);
                }
                NotifyNotTalking();
            }
        }
コード例 #6
0
    public void Receive()
    {
        System.Diagnostics.Stopwatch timeSpentProcessingPackets = new System.Diagnostics.Stopwatch();
        timeSpentProcessingPackets.Start();

        /*
         * if (failedPackets.Count > 0) {
         *  MeshPacket p = failedPackets[0];
         *  failedPackets.RemoveAt(0);
         *  ParseData(p);
         * }
         */

        uint bufferLength = 0;

        while (timeSpentProcessingPackets.Elapsed.TotalMilliseconds < msAllowedForPackets)
        {
            bufferLength = 0;
            if (SteamNetworking.IsP2PPacketAvailable(out bufferLength))
            {
                //Debug.Log("Receiving Packet, " + bufferLength + " bytes long");
                byte[]   destBuffer = new byte[bufferLength];
                UInt32   bytesRead  = 0;
                CSteamID remoteID;
                SteamNetworking.ReadP2PPacket(destBuffer, bufferLength, out bytesRead, out remoteID);
                //Debug.Log("CSteamID remoteID = " + remoteID.m_SteamID);
                ParseData(new MeshPacket(destBuffer));
            }
            else
            {
                break;
            }
        }
    }
コード例 #7
0
// ReSharper disable once UnusedMember.Local
        private void Update()
        {
            if (!IsInitialized)
            {
                return;
            }

            Profiler.BeginSample("SteamClient.RunCallbacks");
            SteamAPI.RunCallbacks();
            Profiler.EndSample();

            Profiler.BeginSample("SteamAvatarCache.Cycle");
            SteamAvatarCache.Cycle();
            Profiler.EndSample();

            Profiler.BeginSample("SteamNetworking.P2P");
            uint DataAvailable = 0;

            while (SteamNetworking.IsP2PPacketAvailable(out DataAvailable))
            {
                var      dest = new byte[DataAvailable];
                CSteamID steamid;
                if (SteamNetworking.ReadP2PPacket(dest, DataAvailable, out DataAvailable, out steamid))
                {
                    ProcessSteamNetworkingPacket(dest, steamid);
                }
            }
            Profiler.EndSample();
        }
コード例 #8
0
        /// <summary>
        /// Check for and return any packets sent to us
        /// </summary>
        /// <param name="from">SteamId of the player who sent us this packet</param>
        /// <returns>Packet in BMSByte format</returns>
        public BMSByte Receive(out SteamId from)
        {
            CheckDisposed();

            if (!SteamNetworking.IsP2PPacketAvailable())
            {
                from = default;
                return(null);
            }

            recBuffer.Clear();

            var packet = SteamNetworking.ReadP2PPacket();

            if (packet.HasValue)
            {
                from = packet.Value.SteamId;
                recBuffer.SetSize(packet.Value.Data.Length);
                recBuffer.byteArr = packet.Value.Data;
                return(recBuffer);
            }

            from = default;
            return(null);
        }
コード例 #9
0
    void getNetworkData()
    {
        //Recieve packets from other members in the lobby with us
        uint msgSize;

        while (SteamNetworking.IsP2PPacketAvailable(out msgSize))
        {
            byte[]   packet = new byte[msgSize];
            CSteamID steamIDRemote;
            uint     bytesRead = 0;
            if (SteamNetworking.ReadP2PPacket(packet, msgSize, out bytesRead, out steamIDRemote))
            {
                int    TYPE = packet[0];
                string msg  = System.Text.Encoding.UTF8.GetString(SubArray(packet, 1, packet.Length - 1));

                switch (TYPE)
                {
                case 1:     //Packet type 1 == GOT IN-GAME CHAT MESSAGE
                    Debug.log(lobby_names_[getPlayerIndex(steamIDRemote)] + " says: " + msg);
                    break;

                default: Debug.Log("BAD PACKET"); break;
                }
            }
        }
    }
コード例 #10
0
        private void Update()
        {
            uint size;

            while (SteamNetworking.IsP2PPacketAvailable(out size))
            {
                byte[]   buffer = new byte[size];
                uint     bytesRead;
                CSteamID remoteId;

                if (SteamNetworking.ReadP2PPacket(buffer, size, out bytesRead, out remoteId))
                {
                    switch ((eventCode)buffer[0])
                    {
                    case eventCode.Internal:
                        UnpackInternal(buffer, remoteId);
                        break;

                    case eventCode.Rpc:
                        UnpackRpc(buffer);
                        break;

                    case eventCode.Sync:
                        UnpackSync(buffer);
                        break;

                    default:
                        UnpackEvent(buffer, remoteId);
                        break;
                    }
                }
            }
        }
コード例 #11
0
        public static bool MessageAvailable()
        {
            uint msgSize = 0;
            bool result  = SteamNetworking.IsP2PPacketAvailable(out msgSize);

            return(result);
        }
コード例 #12
0
        public static Tuple <UInt64, byte[]> ReadBytes()
        {
            UInt32 msgSize = 0;
            bool   result  = SteamNetworking.IsP2PPacketAvailable(out msgSize, 0);

            if (!result)
            {
                return(null);
            }

            var      packet = new byte[msgSize];
            CSteamID steamIDRemote;
            UInt32   bytesRead = 0;

            byte[] Bytes = new byte[msgSize];
            if (SteamNetworking.ReadP2PPacket(packet, msgSize, out bytesRead, out steamIDRemote, 0))
            {
                for (int i = 0; i < msgSize; i++)
                {
                    Bytes[i] = packet[i];
                }
            }

            return(new Tuple <UInt64, byte[]>((UInt64)steamIDRemote, Bytes));
        }
コード例 #13
0
ファイル: SteamP2PReader.cs プロジェクト: egshels/Sources
 private bool IsPacketAvailable(out uint size)
 {
     lock (SteamLock)
     {
         return(SteamNetworking.IsP2PPacketAvailable(ref size, _channel));
     }
 }
コード例 #14
0
ファイル: MPDataHelper.cs プロジェクト: thswogur00/ETGMod
        public static void PacketCollectionThread()
        {
            uint     packetSize;
            uint     readBytes;
            CSteamID remoteID;

            byte[] data;

            while (SteamNetworking.IsP2PPacketAvailable(out packetSize))
            {
                data = new byte[packetSize];
                if (SteamNetworking.ReadP2PPacket(data, packetSize, out readBytes, out remoteID))
                {
                    CustomPacket newPacket = ParseCustomPacket(data);

                    if (newPacket != null)
                    {
                        if (newPacket.PACKETID >= GlobalPacketID && !newPacket.ignorePacketID)
                        {
                            PacketsReady.Add(newPacket);
                            GlobalPacketID = newPacket.PACKETID + 1;
                        }
                        else
                        {
                            //Junk packet
                        }
                    }
                }
            }
        }
コード例 #15
0
    public unsafe static SteamPacket ReadPacket()
    {
        if (!_initialized)
        {
            return(null);
        }
        uint size;

        if (SteamNetworking.IsP2PPacketAvailable(out size))
        {
            byte[] data;
            if (size > kPacketBufferSize)
            {
                data = new byte[size];
            }
            else
            {
                data = _packetData;
            }
            CSteamID user;
            if (SteamNetworking.ReadP2PPacket(data, size, out size, out user))
            {
                if (data == _packetData)
                {
                    data = new byte[size];
                    Array.Copy(_packetData, data, size);
                }
                return(new SteamPacket {
                    data = data,
                    connection = User.GetUser(user)
                });
            }
        }
        return(null);
    }
コード例 #16
0
    public VoicePacketInfo Receive(GamePacket packet)
    {
        CSteamID id;
        uint     packSize;

        if (SteamNetworking.IsP2PPacketAvailable(out packSize))
        {
            if (packSize > packet.MaxCapacity)
            {
                return(VoicePacketInfo.InvalidPacket);
            }

            uint b;

            SteamNetworking.ReadP2PPacket(temp1024.Data, packSize, out b, out id);

            VoicePacketInfo info = new VoicePacketInfo();
            info.NetId           = temp1024.ReadUInt(0);
            info.Frequency       = temp1024.ReadUShort();
            info.Channels        = temp1024.ReadByte();
            info.Format          = (AudioDataTypeFlag)temp1024.ReadByte();
            info.ValidPacketInfo = true;

            packet.WriteByteData(temp1024.Data, FirstPacketByteAvailable, (int)b);

            return(info);
        }

        return(VoicePacketInfo.InvalidPacket);
    }
コード例 #17
0
ファイル: SteamSocket.cs プロジェクト: DevZhav/The-Forest
 private bool IsP2PPacketAvailable(bool isServer, out uint size)
 {
     if (isServer)
     {
         return(SteamGameServerNetworking.IsP2PPacketAvailable(out size, 0));
     }
     return(SteamNetworking.IsP2PPacketAvailable(out size, 0));
 }
コード例 #18
0
        private void Update()
        {
            if (PlayerCount != PlayerList.Count)
            {
                PlayerCount = PlayerList.Count;
                UpdatePlayerList();
            }

            #region Recieve Data Packet

            uint size;
            while (SteamNetworking.IsP2PPacketAvailable(out size))
            {
                var      data = new byte[size];
                uint     bytesRead;
                CSteamID remoteId;
                if (!SteamNetworking.ReadP2PPacket(data, size, out bytesRead, out remoteId))
                {
                    continue;
                }
                var package = (P2PPackage) new BinaryFormatter().Deserialize(new MemoryStream(data));
                //Debug.Log("从 " + SteamFriends.GetFriendPersonaName(remoteId) + " 收到包" + package.type + " ID " +
                //          package.Object_identity);
                if (NetworkLobbyManager.instance.lobby.m_SteamID != 0)
                {
                    Analyze(package, remoteId);
                }
            }

            #endregion

            JunkPackagetime -= Time.deltaTime;
            if (JunkPackagetime <= 0)
            {
                JunkPackagetime = 1 / 8f;
                if (NetworkLobbyManager.instance.lobby.m_SteamID != 0)
                {
                    SendPackets(new P2PPackage(null, P2PPackageType.Broadcast), EP2PSend.k_EP2PSendUnreliable, false);
                }
            }

            if (checking_joined)
            {
                var ready = true;
                foreach (var t in player_need_to_connect)
                {
                    if (!t)
                    {
                        ready = false;
                    }
                }
                if (ready)
                {
                    events.JoinedLobby.Invoke();
                    checking_joined = false;
                }
            }
        }
コード例 #19
0
 private void ReadPackets(bool multithreaded)
 {
     for (int i = 0; i < 2; i++)
     {
         uint pcubMsgSize = 0u;
         while (SteamNetworking.IsP2PPacketAvailable(out pcubMsgSize, i) && (NetGame.isNetStarting || NetGame.isNetStarted))
         {
             int    num          = NetStream.CalculateTierForSize((int)pcubMsgSize);
             byte[] array        = NetStream.AllocateBuffer(num);
             uint   pcubMsgSize2 = 0u;
             if (SteamNetworking.ReadP2PPacket(array, pcubMsgSize, out pcubMsgSize2, out CSteamID psteamIDRemote, i))
             {
                 if (array[0] == 0)
                 {
                     int num2 = array[1] * 256 * 256 + array[2] * 256 + array[3];
                     if (multipartBuffer == null)
                     {
                         int num3 = NetStream.CalculateSizeForTier(0) - 4;
                         multipartBufferTier   = NetStream.CalculateTierForSize((num2 + 1) * num3);
                         multipartBuffer       = NetStream.AllocateBuffer(multipartBufferTier);
                         multipartBufferOffset = 0u;
                     }
                     Array.Copy(array, 4L, multipartBuffer, multipartBufferOffset, pcubMsgSize2 - 4);
                     multipartBufferOffset += pcubMsgSize2 - 4;
                     NetStream.ReleaseBuffer(num, array);
                     if (num2 == 0)
                     {
                         num             = multipartBufferTier;
                         array           = multipartBuffer;
                         pcubMsgSize2    = multipartBufferOffset;
                         multipartBuffer = null;
                     }
                     else
                     {
                         array = null;
                     }
                 }
                 if (array != null)
                 {
                     if (multithreaded && i == 0)
                     {
                         lock (reliableQueueLock)
                         {
                             reliableQueue.Enqueue(new QueuedData
                             {
                                 steamIDRemote = psteamIDRemote,
                                 buffer        = array,
                                 bufferTier    = num,
                                 bytesRead     = (int)pcubMsgSize2
                             });
                         }
                         continue;
                     }
                     NetGame.instance.OnData(psteamIDRemote, array, num, (int)pcubMsgSize2);
                     NetStream.ReleaseBuffer(num, array);
                 }
             }
コード例 #20
0
        private bool IsPacketAvailable(out uint size)
        {
            bool flag;

            lock (this.SteamLock)
            {
                flag = SteamNetworking.IsP2PPacketAvailable(out size, this._channel);
            }
            return(flag);
        }
コード例 #21
0
ファイル: Sender.cs プロジェクト: xz000/testingLL
    public void SWControl()
    {
        //Recieve packets from other members in the lobby with us
        uint msgSize;

        while (SteamNetworking.IsP2PPacketAvailable(out msgSize))
        {
            byte[]   packet = new byte[msgSize];
            CSteamID steamIDRemote;
            uint     bytesRead = 0;
            if (SteamNetworking.ReadP2PPacket(packet, msgSize, out bytesRead, out steamIDRemote))
            {
                if (Array.IndexOf(TOmb, steamIDRemote) == -1)
                {
                    return;
                }
                int TYPE = packet[0];
                Array.Copy(packet, 1, rcbuffer, 0, packet.Length - 1);
                switch (TYPE)
                {
                case 0:
                    DeSerializeReceived();
                    break;

                case 1:
                    SetSD();
                    break;

                case 2:
                    EndBattle(Array.IndexOf(TOmb, steamIDRemote));
                    break;

                case 3:
                    testMenu02.ConnectedWho(steamIDRemote);
                    SetCntbAndCheck(Array.IndexOf(TOmb, steamIDRemote));
                    break;

                case 4:
                    Send666();
                    break;

                case 5:
                    SetSLTempAndCheck(Array.IndexOf(TOmb, steamIDRemote));
                    break;

                case 9:
                    heQuit();
                    break;

                default: Debug.Log("BAD PACKET"); break;
                }
            }
        }
    }
コード例 #22
0
        // Token: 0x06000B55 RID: 2901 RVA: 0x003CD990 File Offset: 0x003CBB90
        private bool IsPacketAvailable(out uint size)
        {
            object steamLock = this.SteamLock;
            bool   result;

            lock (steamLock)
            {
                result = SteamNetworking.IsP2PPacketAvailable(out size, this._channel);
            }
            return(result);
        }
コード例 #23
0
 void ReceiveDataPacket()
 {
     while (SteamNetworking.IsP2PPacketAvailable())
     {
         var packet = SteamNetworking.ReadP2PPacket();
         if (packet.HasValue)
         {
             HandleOpponentDataPacket(packet.Value.Data);
         }
     }
 }
コード例 #24
0
    void Update()
    {
        uint dataLenght;

        while (SteamNetworking.IsP2PPacketAvailable(out dataLenght))
        {
            Receive(dataLenght);
        }

        SetOwner();
    }
コード例 #25
0
        public void Update()
        {
            while (SteamNetworking.IsP2PPacketAvailable(0))
            {
                P2Packet?packet = SteamNetworking.ReadP2PPacket(0);

                if (packet.HasValue)
                {
                    OnMessageReceived?.Invoke(connections[packet.Value.SteamId], new P2PMessage(packet.Value.Data));
                }
            }
        }
コード例 #26
0
        /**
         * Check for new network messages
         */
        private bool ReceiveInternal(out int connectionId, out byte[] data)
        {
            data = null;


            //finally look for new packets

            uint     packetSize;
            CSteamID clientSteamID;

            if (SteamNetworking.IsP2PPacketAvailable(out packetSize, (int)SteamChannels.SEND_INTERNAL))
            {
                //check we have enough room for this packet
                if (packetSize > Transport.MaxPacketSize)
                {
                    //cant read .. too big! should error here
                    Debug.LogError("Available message is too large");
                    connectionId = -1;
                    return(false);
                }

                if (SteamNetworking.ReadP2PPacket(serverReceiveBuffer, packetSize, out packetSize /*actual size read*/, out clientSteamID, (int)SteamChannels.SEND_INTERNAL))
                {
                    SteamClient steamClient;
                    try
                    {
                        //check we have a record for this connection
                        steamClient = steamConnectionMap.fromSteamID[clientSteamID];
                    }
                    catch (KeyNotFoundException)
                    {
                        connectionId = -1;
                        return(false);
                    }

                    if (packetSize != 0)
                    {
                        connectionId = steamClient.connectionID;
                        //for now allocate a new buffer TODO: do we need to do this?
                        data = new byte[packetSize];
                        Array.Copy(serverReceiveBuffer, data, packetSize);

                        return(true);
                    }
                }
            }

            //nothing available
            connectionId = -1;
            return(false);
        }
コード例 #27
0
        public static void RemoveOldPackets()
        {
            byte[]   pubDest        = new byte[2048];
            CSteamID psteamIDRemote = default(CSteamID);

            for (int i = 0; i < 2; i++)
            {
                uint pcubMsgSize = 0u;
                if (SteamNetworking.IsP2PPacketAvailable(out pcubMsgSize, i))
                {
                    SteamNetworking.ReadP2PPacket(pubDest, pcubMsgSize, out uint _, out psteamIDRemote, i);
                }
            }
        }
コード例 #28
0
    private void ReadP2P()
    {
        uint num;

        while (SteamNetworking.IsP2PPacketAvailable(out num))
        {
            byte[]   array = new byte[num];
            uint     num2;
            CSteamID csteamID;
            if (SteamNetworking.ReadP2PPacket(array, num, out num2, out csteamID, 0))
            {
                ReadP2PPacket(array, num, num2, csteamID);
            }
        }
    }
コード例 #29
0
        private bool Receive(out uint readPacketSize, out CSteamID clientSteamID, out byte[] receiveBuffer, int channel)
        {
            uint packetSize;

            if (SteamNetworking.IsP2PPacketAvailable(out packetSize, channel) && packetSize > 0)
            {
                receiveBuffer = new byte[packetSize];
                return(SteamNetworking.ReadP2PPacket(receiveBuffer, packetSize, out readPacketSize, out clientSteamID, channel));
            }

            receiveBuffer  = null;
            readPacketSize = 0;
            clientSteamID  = CSteamID.Nil;
            return(false);
        }
コード例 #30
0
    // Token: 0x060009AF RID: 2479 RVA: 0x00046A78 File Offset: 0x00044C78
    private static void ReceivePackages()
    {
        uint num;

        while (SteamNetworking.IsP2PPacketAvailable(out num, 0))
        {
            byte[]   array = new byte[num];
            uint     num2;
            CSteamID sender;
            if (!SteamNetworking.ReadP2PPacket(array, num, out num2, out sender, 0))
            {
                break;
            }
            ZSteamSocketOLD.QueueNewPkg(sender, array);
        }
    }