Пример #1
0
        /// <summary>
        /// Broadcasts message to connected players.
        /// </summary>
        /// <typeparam name="T">The type of the message to broadcast.</typeparam>
        /// <param name="message">The message to broadcast.</param>
        /// <param name="sendType">The send type.</param>
        /// <param name="channel">The channel used to deliver message.</param>
        /// <returns></returns>
        public bool BroadcastMessage <T>(T message, Steamworks.EP2PSend sendType, int channel = 0) where T : INetMessage
        {
            if (players[1] == null)
            {
                return(false);
            }

            MemoryStream stream = new MemoryStream();

            if (!WriteMessage(message, stream))
            {
                return(false);
            }

            foreach (NetPlayer player in players)
            {
                if (player is NetLocalPlayer)
                {
                    continue;
                }

                player?.SendPacket(stream.GetBuffer(), sendType, channel);
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Broadcasts message to connected players.
        /// </summary>
        /// <typeparam name="T">The type of the message to broadcast.</typeparam>
        /// <param name="message">The message to broadcast.</param>
        /// <param name="sendType">The send type.</param>
        /// <param name="channel">The channel used to deliver message.</param>
        /// <returns></returns>
        public bool BroadcastMessage <T>(T message, Steamworks.EP2PSend sendType, int channel = 0) where T : INetMessage
        {
            if (players[1] == null)
            {
                return(false);
            }
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write((byte)message.MessageId);
            if (!message.Write(writer))
            {
                Client.FatalError("Failed to write network message " + message.MessageId);
                return(false);
            }

            foreach (NetPlayer player in players)
            {
                if (player is NetLocalPlayer)
                {
                    continue;
                }

                player?.SendPacket(stream.GetBuffer(), sendType, channel);
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Send message to given player.
        /// </summary>
        /// <typeparam name="T">The type of the message to broadcast.</typeparam>
        /// <param name="player">Player to who message should be send.</param>
        /// <param name="message">The message to broadcast.</param>
        /// <param name="sendType">The send type.</param>
        /// <param name="channel">The channel used to deliver message.</param>
        /// <returns>true if message was sent false otherwise</returns>
        public bool SendMessage <T>(NetPlayer player, T message, Steamworks.EP2PSend sendType, int channel = 0) where T : INetMessage
        {
            if (player == null)
            {
                return(false);
            }

            MemoryStream stream = new MemoryStream();

            if (!WriteMessage(message, stream))
            {
                return(false);
            }

            return(player.SendPacket(stream.GetBuffer(), sendType, channel));
        }
Пример #4
0
        /// <summary>
        /// Broadcasts message to connected players.
        /// </summary>
        /// <typeparam name="T">The type of the message to broadcast.</typeparam>
        /// <param name="message">The message to broadcast.</param>
        /// <param name="sendType">The send type.</param>
        /// <param name="channel">The channel used to deliver message.</param>
        /// <returns></returns>
        public bool BroadcastMessage <T>(T message, Steamworks.EP2PSend sendType, int channel = 0) where T : INetMessage
        {
            if (players[1] == null)
            {
                return(false);
            }
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write((byte)message.MessageId);
            if (!message.Write(writer))
            {
                Logger.Log("Failed to write network message " + message.MessageId);
                return(false);
            }

            players[1].SendPacket(stream.GetBuffer(), sendType, channel);
            return(true);
        }
Пример #5
0
 /// <summary>
 /// Send a packet to this player.
 /// </summary>
 /// <param name="data">The data to send.</param>
 /// <param name="sendType">Type of the send.</param>
 /// <param name="channel">The channel to send message.</param>
 /// <returns>true if packet was sent, false otherwise</returns>
 public bool SendPacket(byte[] data, Steamworks.EP2PSend sendType, int channel = 0)
 {
     return(Steamworks.SteamNetworking.SendP2PPacket(this.steamId, data, (uint)data.Length, sendType, channel));
 }