コード例 #1
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");
            }
            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);
        }
コード例 #2
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);
        }
コード例 #3
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");
            }
            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);
        }
コード例 #4
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,
                                  [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);
        }
コード例 #5
0
ファイル: Player.Chat.cs プロジェクト: TheDireMaster/fCraft
 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);
         }
     }
 }
コード例 #6
0
ファイル: Player.Chat.cs プロジェクト: TheDireMaster/fCraft
 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);
         }
     }
 }
コード例 #7
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);
        }
コード例 #8
0
        /// <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);
        }