示例#1
0
        /// <summary> Broadcasts a message. </summary>
        /// <param name="source"> List of players who will receive the message. </param>
        /// <param name="except"> Player to exclude from the recepient list. </param>
        /// <param name="message"> String/message to send. </param>
        /// <returns> Number of players who received the message. </returns>
        public static int Message([NotNull] this IEnumerable <Player> source,
                                  [CanBeNull] Player except,
                                  MessageType type,
                                  [NotNull] string message)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (!MessageTypeUtil.Enabled() || message.Length >= 64)
            {
                type = MessageType.Chat;
            }
            int i = 0;

            foreach (Player player in source)
            {
                foreach (Packet packet in LineWrapper.Wrap(message, player.SupportsFullCP437, type))
                {
                    if (player == except)
                    {
                        continue;
                    }
                    player.Send(packet);
                    i++;
                }
            }
            return(i);
        }
示例#2
0
        public static int Message([NotNull] this IEnumerable <Player> source,
                                  [NotNull] string message,
                                  [Optional] MessageType?type,
                                  [NotNull] params object[] formatArgs)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (formatArgs == null)
            {
                throw new ArgumentNullException("formatArgs");
            }
            if (type == null)
            {
                type = 0;
            }
            if (!MessageTypeUtil.Enabled() || message.Length >= 64)
            {
                type = MessageType.Chat;
            }
            if (!Enum.IsDefined(typeof(MessageType), type))
            {
                throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(MessageType));
            }

            int i = 0;

            foreach (Player player in source)
            {
                foreach (Packet packet in LineWrapper.Wrap(string.Format(message, formatArgs), player.SupportsFullCP437, type.Value))
                {
                    player.Send(packet);
                    i++;
                }
            }
            return(i);
        }