public static int Message([NotNull] this IEnumerable <Player> source,
                                  [NotNull] string message,
                                  [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 (formatArgs.Length > 0)
            {
                message = String.Format(message, formatArgs);
            }
            int i = 0;

            Player[] sourceEnumerated = source.ToArray();
            foreach (Packet packet in LineWrapper.Wrap(String.Format(message, formatArgs)))
            {
                foreach (Player player in sourceEnumerated)
                {
                    player.Send(packet);
                    i++;
                }
            }
            return(i);
        }
        public static int Message([NotNull] this IEnumerable <Player> source,
                                  [CanBeNull] Player except,
                                  [NotNull] string message,
                                  [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");
            }
            int i = 0;

            foreach (Packet packet in LineWrapper.Wrap(String.Format(message, formatArgs)))
            {
                foreach (Player player in source)
                {
                    if (player == except)
                    {
                        continue;
                    }
                    player.Send(packet);
                    i++;
                }
            }
            return(i);
        }
        public static int MessagePrefixed([NotNull] this IEnumerable <Player> source, [NotNull] string prefix, [NotNull] string message, params object[] formatArgs)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }
            if (formatArgs == null)
            {
                throw new ArgumentNullException("formatArgs");
            }
            int i = 0;

            foreach (Packet packet in LineWrapper.WrapPrefixed(prefix, String.Format(message, formatArgs)))
            {
                foreach (Player player in source)
                {
                    player.Send(packet);
                    i++;
                }
            }
            return(i);
        }
Exemple #4
0
 public static int MessagePrefixed([NotNull] this IEnumerable <Player> source, [NotNull] string prefix,
                                   [NotNull] string message, [NotNull] params object[] formatArgs)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (prefix == null)
     {
         throw new ArgumentNullException("prefix");
     }
     if (formatArgs == null)
     {
         throw new ArgumentNullException("formatArgs");
     }
     if (formatArgs.Length > 0)
     {
         message = String.Format(message, formatArgs);
     }
     Player[] sourceArray = source.ToArray();
     foreach (Packet packet in LineWrapper.WrapPrefixed(prefix, message))
     {
         foreach (Player player in sourceArray)
         {
             player.Send(packet);
         }
     }
     return(sourceArray.Length);
 }
Exemple #5
0
        public static int Message([NotNull] this IEnumerable <Player> source,
                                  [NotNull] string message,
                                  [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");
            }
            int i = 0;

            if (formatArgs.Length > 0)
            {
                message = String.Format(message, formatArgs);
            }
            Player[] sourceArray = source.ToArray();
            foreach (Player player in sourceArray)
            {
                foreach (Packet packet in LineWrapper.Wrap(Color.Sys + message, player.Supports(CpeExt.EmoteFix),
                                                           player.HasCP437, player.FallbackColors))
                {
                    player.Send(packet);
                    i++;
                }
            }
            return(i);
        }
        /// <summary> Broadcasts a message, prefixing wrapped lines. </summary>
        /// <param name="source"> List of players who will receive the message. </param>
        /// <param name="prefix"> Prefix to prepend to prepend to each line after the 1st,
        /// if any line-wrapping occurs. Does NOT get prepended to first line. </param>
        /// <param name="message"> String/message to send. </param>
        /// <returns> Number of players who received the message. </returns>
        public static int MessagePrefixed([NotNull] this IEnumerable <Player> source, [NotNull] string prefix, [NotNull] string message)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            int i = 0;

            Player[] sourceArray = source.ToArray();
            foreach (Packet packet in LineWrapper.WrapPrefixed(prefix, message))
            {
                foreach (Player player in sourceArray)
                {
                    player.Send(packet);
                    i++;
                }
            }
            return(i);
        }
        /// <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,
                                  [NotNull] string message)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            int i = 0;

            Player[] sourceArray = source.ToArray();
            foreach (Packet packet in LineWrapper.Wrap(message))
            {
                foreach (Player player in sourceArray)
                {
                    if (player == except)
                    {
                        continue;
                    }
                    player.Send(packet);
                    i++;
                }
            }
            return(i);
        }
Exemple #8
0
 internal void MessageNow([NotNull] string message, [NotNull] params object[] args)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (args == null)
     {
         throw new ArgumentNullException("args");
     }
     if (IsDeaf)
     {
         return;
     }
     if (args.Length > 0)
     {
         message = String.Format(message, args);
     }
     if (this == Console)
     {
         Logger.LogToConsole(message);
     }
     else
     {
         if (Thread.CurrentThread != ioThread)
         {
             throw new InvalidOperationException("SendNow may only be called from player's own thread.");
         }
         foreach (Packet p in LineWrapper.Wrap(ChatColor.Sys + message))
         {
             SendNow(p);
         }
     }
 }
Exemple #9
0
 public void MessagePrefixed([NotNull] string prefix, [NotNull] string message,
                             [NotNull] params object[] formatArgs)
 {
     if (prefix == null)
     {
         throw new ArgumentNullException("prefix");
     }
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (formatArgs == null)
     {
         throw new ArgumentNullException("formatArgs");
     }
     if (formatArgs.Length > 0)
     {
         message = String.Format(message, formatArgs);
     }
     if (this == Console)
     {
         Logger.LogToConsole(message);
     }
     else
     {
         foreach (Packet p in LineWrapper.WrapPrefixed(prefix, message))
         {
             Send(p);
         }
     }
 }
Exemple #10
0
 public void Message([NotNull] string message, [NotNull] params object[] formatArgs)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (formatArgs == null)
     {
         throw new ArgumentNullException("formatArgs");
     }
     if (formatArgs.Length > 0)
     {
         message = String.Format(message, formatArgs);
     }
     if (IsSuper)
     {
         Logger.LogToConsole(message);
     }
     else
     {
         foreach (Packet p in LineWrapper.Wrap(ChatColor.Sys + message))
         {
             Send(p);
         }
     }
 }
Exemple #11
0
        public static int Message([NotNull] this IEnumerable <Player> source,
                                  [CanBeNull] Player except,
                                  [NotNull] string message,
                                  [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 (formatArgs.Length > 0)
            {
                message = String.Format(message, formatArgs);
            }
            int skipped = 0;

            Player[] sourceArray = source.ToArray();
            foreach (Packet packet in LineWrapper.Wrap(message))
            {
                skipped = 0;
                foreach (Player player in sourceArray)
                {
                    if (player == except)
                    {
                        skipped++;
                        continue;
                    }
                    player.Send(packet);
                }
            }
            return(sourceArray.Length - skipped);
        }
        /// <summary> Broadcasts a message. </summary>
        /// <param name="source"> List of players who will receive the message. </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,
                                  [NotNull] string message)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            int i = 0;

            foreach (Packet packet in LineWrapper.Wrap(message))
            {
                foreach (Player player in source)
                {
                    player.Send(packet);
                    i++;
                }
            }
            return(i);
        }