/// <summary>
        ///     Sends a message over the steam lobby message system. Max size is 1024 bytes.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="qos"></param>
        public void Send(short opcode, ISerializablePacket packet)/* OutgoingMessage msg)*/
        {
            if (!network.LocalConnection.InLobby)
            {
                return;
            }

            using (PooledNetWriter w = NetWriterPool.GetWriter())
            {
                MessageHelper.CreateAndFinalize(w, opcode, packet);
                var array = w.ToArray();
                SteamMatchmaking.SendLobbyChatMsg(network.LocalConnection.LobbyID, array, array.Length);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Sends a message to the target.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="qos"></param>
        public void Send(short opcode, ISerializablePacket packet, SteamNetworkingIdentity target)/* OutgoingMessage msg)*/
        {
            if (!IsConnected)
            {
                return;
            }
            if (!IsLocal)
            {
                return;
            }

            using (PooledNetWriter w = NetWriterPool.GetWriter())
            {
                MessageHelper.CreateAndFinalize(w, opcode, packet);
                var segment = w.ToArray();
                //if (NetLogFilter.messageDiagnostics) { NetDiagnostics.OnSend(opcode, segment.Count, 1); }

                // Initialize unmanaged memory to hold the array.
                int    size = Marshal.SizeOf(segment[0]) * segment.Length;
                IntPtr pnt  = Marshal.AllocHGlobal(size);

                try
                {
                    // Copy the array to unmanaged memory.
                    Marshal.Copy(segment, 0, pnt, segment.Length);
                    EResult result = SteamNetworkingMessages.SendMessageToUser(ref target, pnt, (uint)size, Constants.k_nSteamNetworkingSend_ReliableNoNagle, 0);
                    if (NetLogFilter.logInfo)
                    {
                        Debug.Log($"Packet to {SteamFriends.GetFriendPersonaName(target.GetSteamID())} was sent with resilt: {result}. ({Time.time})");
                    }
                }
                finally
                {
                    // Free the unmanaged memory.
                    Marshal.FreeHGlobal(pnt);
                }


                //if (SteamNetworking.SendP2PPacket(target, segment, (uint)segment.Length, EP2PSend.k_EP2PSendReliable))
                //{
                //    if (NetLogFilter.logInfo) { Debug.Log($"Packet to {SteamFriends.GetFriendPersonaName(target)} was successfully sent. ({Time.time})"); }
                //}
                //else
                //{
                //    if (NetLogFilter.logInfo) { Debug.Log($"Packet to {SteamFriends.GetFriendPersonaName(target)} failed to send. ({Time.time})"); }
                //}
            }
        }
Ejemplo n.º 3
0
        public void Send(short opcode, ISerializablePacket packet)
        {
            if (!IsConnected)
            {
                return;
            }
            if (!IsLocal)
            {
                return;
            }

            using (PooledNetWriter w = NetWriterPool.GetWriter())
            {
                MessageHelper.CreateAndFinalize(w, opcode, packet);
                var segment = w.ToArray();
                //if (NetLogFilter.messageDiagnostics) { NetDiagnostics.OnSend(opcode, segment.Count, 1); }

                // Initialize unmanaged memory to hold the array.
                int    size = Marshal.SizeOf(segment[0]) * segment.Length;
                IntPtr pnt  = Marshal.AllocHGlobal(size);

                try
                {
                    foreach (var conn in connectedPeers.Values)
                    {
                        Marshal.Copy(segment, 0, pnt, segment.Length);
                        EResult result = SteamNetworkingMessages.SendMessageToUser(ref conn.identity, pnt, (uint)size, Constants.k_nSteamNetworkingSend_ReliableNoNagle, 0);
                        if (NetLogFilter.logInfo)
                        {
                            Debug.Log($"Packet to {SteamFriends.GetFriendPersonaName(conn.identity.GetSteamID())} was sent with resilt: {result}. ({Time.time})");
                        }
                    }
                    // Copy the array to unmanaged memory.
                }
                finally
                {
                    // Free the unmanaged memory.
                    Marshal.FreeHGlobal(pnt);
                }
            }
        }