Provides data for Chat.Sending event. Cancelable. FormattedMessage and recipientList properties may be changed.
Inheritance: System.EventArgs, IPlayerEvent, ICancelableEvent
示例#1
0
文件: Chat.cs 项目: fragmer/fCraft
        /// <summary> Sends world/local chat message. </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was canceled by an event callback. </returns>
        /// <exception cref="ArgumentNullException"> If player or rawMessage is null. </exception>
        public static bool SendWorld( [NotNull] Player player, [NotNull] string rawMessage ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
            World playerWorld = player.World;
            if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );

            var recipientList = playerWorld.Players
                                           .NotIgnoring( player );

            string formattedMessage = String.Format( "({0}&F){1}: {2}",
                                                     playerWorld.ClassyName,
                                                     player.ClassyName,
                                                     rawMessage );

            var e = new ChatSendingEventArgs( player,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.World,
                                              recipientList );

            if( !SendInternal( e ) ) return false;

            Logger.Log( LogType.GlobalChat,
                        "(world {0}){1}: {2}",
                        playerWorld.Name, player.Name, rawMessage );
            return true;
        }
示例#2
0
 internal ChatSentEventArgs([NotNull] ChatSendingEventArgs args, int recipientCount)
 {
     Player           = args.Player;
     Message          = args.Message;
     MessageType      = args.MessageType;
     RecipientList    = args.RecipientList;
     FormattedMessage = args.FormattedMessage;
     RecipientCount   = recipientCount;
 }
示例#3
0
 internal ChatSentEventArgs(ChatSendingEventArgs e, int recipientCount)
 {
     Player           = e.Player;
     Message          = e.Message;
     MessageType      = e.MessageType;
     RecipientList    = e.RecipientList;
     FormattedMessage = e.FormattedMessage;
     RecipientCount   = recipientCount;
 }
示例#4
0
        public static void ChatSending( object sender, ChatSendingEventArgs e )
        {
            if ( e.MessageType == ChatMessageType.Global ) {
                if ( e.Message == null )
                    return;
                if ( e.Player == null )
                    return;

                //Parse greentext
                if ( e.Message.Length > 1 && e.MessageType == ChatMessageType.Global ) {
                    if ( e.Message.StartsWith( ">" ) && e.Message[1] != ' ' ) {
                        e.FormattedMessage = String.Format( "{0}&F: {1}{2}", e.Player.ClassyName, Color.Lime, e.Message );
                        return;
                    }
                }
                //Parse all others
                string Message = e.Message; //use only e.Message so you don't accidentally highlight user names ect
                Message = HighlightSections( Message );
                e.FormattedMessage = String.Format( "{0}&F: {1}", e.Player.ClassyName, Message ); //reformat the message
            }
        }
示例#5
0
文件: Chat.cs 项目: fragmer/fCraft
        /// <summary> Sends a private message (PM). Does NOT send a copy of the message to the sender. </summary>
        /// <param name="from"> Sender player. </param>
        /// <param name="to"> Recepient player. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendPM( [NotNull] Player from, [NotNull] Player to, [NotNull] string rawMessage ) {
            if( from == null ) throw new ArgumentNullException( "from" );
            if( to == null ) throw new ArgumentNullException( "to" );
            if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
            var recepientList = new[] { to };

            string formattedMessage = String.Format( "&Pfrom {0}: {1}",
                                                     from.Name, rawMessage );

            var e = new ChatSendingEventArgs( from,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.PM,
                                              recepientList );

            if( !SendInternal( e ) ) return false;

            Logger.Log( LogType.PrivateChat,
                        "{0} to {1}: {2}",
                        from.Name, to.Name, rawMessage );
            return true;
        }
示例#6
0
文件: Chat.cs 项目: fragmer/fCraft
        /// <summary> Sends an action message (/Me). </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendMe( [NotNull] Player player, [NotNull] string rawMessage ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );

            var recepientList = Server.Players.NotIgnoring( player );

            string formattedMessage = String.Format( "&M*{0} {1}",
                                                     player.Name,
                                                     rawMessage );

            var e = new ChatSendingEventArgs( player,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.Me,
                                              recepientList );

            if( !SendInternal( e ) ) return false;

            Logger.Log( LogType.GlobalChat,
                        "(me){0}: {1}", player.Name, rawMessage );
            return true;
        }
示例#7
0
文件: Chat.cs 项目: fragmer/fCraft
        /// <summary> Sends a global announcement (/Say). </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendSay( [NotNull] Player player, [NotNull] string rawMessage ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );

            var recepientList = Server.Players;

            string formattedMessage = Color.Say + rawMessage;

            var e = new ChatSendingEventArgs( player,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.Say,
                                              recepientList );

            if( !SendInternal( e ) ) return false;

            Logger.Log( LogType.GlobalChat,
                        "(say){0}: {1}", player.Name, rawMessage );
            return true;
        }
示例#8
0
 static void RaiseSentEvent( ChatSendingEventArgs args, int count )
 {
     var h = Sent;
     if( h != null ) h( null, new ChatSentEventArgs( args.Player, args.Message, args.FormattedMessage,
                                                     args.MessageType, args.RecepientList, count ) );
 }
示例#9
0
        /// <summary> Sends a rank-wide message (@@Rank message). </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rank"> Target rank. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendRank( [NotNull] Player player, [NotNull] Rank rank, [NotNull] string rawMessage )
        {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( rank == null ) throw new ArgumentNullException( "rank" );
            if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );

            var recepientList = rank.Players.NotIgnoring( player ).Union( player );

            string formattedMessage = String.Format( "&P({0}&P){1}: {2}",
                                                     rank.ClassyName,
                                                     player.Name,
                                                     rawMessage );

            var e = new ChatSendingEventArgs( player,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.Rank,
                                              recepientList );

            if( !SendInternal( e ) ) return false;

            Logger.Log( LogType.RankChat,
                        "(rank {0}){1}: {2}",
                        rank.Name, player.Name, rawMessage );
            return true;
        }
示例#10
0
文件: Chat.cs 项目: Magi1053/ProCraft
		/// <summary> Sends a global announcement to staff (/StaffSay). </summary>
		/// <param name="player"> Player writing the message. </param>
		/// <param name="rawMessage"> Message text. </param>
		/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
		public static bool SendStaffSay([NotNull] Player player, [NotNull] string rawMessage) {
			if (player == null)
				throw new ArgumentNullException("player");
			if (rawMessage == null)
				throw new ArgumentNullException("rawMessage");

			var recepientList = Server.Players.Where(p => p.Info.Rank != RankManager.HighestRank).Can(Permission.ReadStaffChat);
			string formattedMessage = Color.Say + rawMessage;
			var e = new ChatSendingEventArgs(player, rawMessage, formattedMessage, ChatMessageType.Staff, recepientList);
			if (!SendInternal(e))
				return false;

			var recepientListOwner = Server.Players.Where(p => p.Info.Rank == RankManager.HighestRank);
			string formattedMessageOwner = "&s[&yStaffSay&s][&f" + player.Name + "&s] &Y" + rawMessage;
			var eo = new ChatSendingEventArgs(player, rawMessage, formattedMessageOwner, ChatMessageType.StaffSayOwner, recepientListOwner);
			if (!SendInternal(eo))
				return false;

			Logger.Log(LogType.GlobalChat, "(staff_say){0}: {1}", player.Name, rawMessage);
			return true;
		}
示例#11
0
文件: Chat.cs 项目: Magi1053/ProCraft
        /// <summary> Sends a global announcement (/Say). </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
		public static bool SendSay([NotNull] Player player, [NotNull] string rawMessage) {
			if (player == null)
				throw new ArgumentNullException("player");
			if (rawMessage == null)
				throw new ArgumentNullException("rawMessage");

			var recepientList = Server.Players.Where(p => !p.IsStaff);
			string formattedMessage = Color.Say + rawMessage;
			var e = new ChatSendingEventArgs(player, rawMessage, formattedMessage, ChatMessageType.Say, recepientList);
			if (!SendInternal(e))
				return false;

			var recepientListStaff = Server.Players.Can(Permission.ReadStaffChat);
			string formattedMessageStaff = "&s[&YSay&s][&f" + player.Name + "&s] &Y" + rawMessage;
			var es = new ChatSendingEventArgs(player, rawMessage, formattedMessageStaff, ChatMessageType.SayStaff, recepientListStaff);
			if (!SendInternal(es))
				return false;


			Logger.Log(LogType.GlobalChat,
						"(say){0}: {1}", player.Name, rawMessage);
			return true;
		}
示例#12
0
        /// <summary> Sends a global (white) chat. </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendGlobal( [NotNull] Player player, [NotNull] string rawMessage )
        {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
            string OriginalMessage = rawMessage;
            if (Server.Moderation && !Server.VoicedPlayers.Contains(player) && player.World != null)
            {
                player.Message("&WError: Server Moderation is activated. Message failed to send");
                return false;
            }

            rawMessage = rawMessage.Replace("$name", player.ClassyName);
            rawMessage = rawMessage.Replace("$kicks", player.Info.TimesKickedOthers.ToString());
            rawMessage = rawMessage.Replace("$bans", player.Info.TimesBannedOthers.ToString());
            rawMessage = rawMessage.Replace("$awesome", "It is my professional opinion, that " + ConfigKey.ServerName.GetString() + " is the best server on Minecraft");
            rawMessage = rawMessage.Replace("$server", ConfigKey.ServerName.GetString());
            rawMessage = rawMessage.Replace("$motd", ConfigKey.MOTD.GetString());
            rawMessage = rawMessage.Replace("$date", DateTime.UtcNow.ToShortDateString());
            rawMessage = rawMessage.Replace("$time", DateTime.Now.ToString());
            rawMessage = rawMessage.Replace("$money", player.Info.Money.ToString());
            rawMessage = rawMessage.Replace("$ass", "You, my good sir, are an &cAss&f");
            rawMessage = rawMessage.Replace("$mad", "You mad, bro?");
            rawMessage = rawMessage.Replace("$welcome", "Welcome to " +ConfigKey.ServerName.GetString());
            rawMessage = rawMessage.Replace("$clap", "A round of applause might be appropriate, *claps*");

            if (player.Can(Permission.UseColorCodes))
            {
                rawMessage = rawMessage.Replace("$lime", "&a");     //alternate color codes for ease if you can't remember the codes
                rawMessage = rawMessage.Replace("$aqua", "&b");
                rawMessage = rawMessage.Replace("$red", "&c");
                rawMessage = rawMessage.Replace("$magenta", "&d");
                rawMessage = rawMessage.Replace("$yellow", "&e");
                rawMessage = rawMessage.Replace("$white", "&f");
                rawMessage = rawMessage.Replace("$navy", "&1");
                rawMessage = rawMessage.Replace("$green", "&2");
                rawMessage = rawMessage.Replace("$teal", "&3");
                rawMessage = rawMessage.Replace("$maroon", "&4");
                rawMessage = rawMessage.Replace("$purple", "&5");
                rawMessage = rawMessage.Replace("$olive", "&6");
                rawMessage = rawMessage.Replace("$silver", "&7");
                rawMessage = rawMessage.Replace("$grey", "&8");
                rawMessage = rawMessage.Replace("$gray", "&8");
                rawMessage = rawMessage.Replace("$blue", "&9");
                rawMessage = rawMessage.Replace("$black", "&0");
            }

            if (!player.Can(Permission.ChatWithCaps))
            {
                int caps = 0;
                for (int i = 0; i < rawMessage.Length; i++)
                {
                    if (Char.IsUpper(rawMessage[i]))
                    {
                        caps++;
                        if (caps > ConfigKey.MaxCaps.GetInt())
                        {
                            rawMessage = rawMessage.ToLower();
                            player.Message("Your message was changed to lowercase as it exceeded the maximum amount of capital letters.");
                        }
                    }
                }
            }

            if (!player.Can(Permission.Swear))
            {
                if (!File.Exists("SwearWords.txt"))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("#This txt file should be filled with bad words that you want to be filtered out");
                    sb.AppendLine("#I have included some examples, excuse my language :P");
                    sb.AppendLine("f**k");
                    sb.AppendLine("f*****g");
                    sb.AppendLine("f****d");
                    sb.AppendLine("dick");
                    sb.AppendLine("bitch");
                    sb.AppendLine("shit");
                    sb.AppendLine("s******g");
                    sb.AppendLine("s******d");
                    sb.AppendLine("c**t");
                    sb.AppendLine("nigger");
                    sb.AppendLine("wanker");
                    sb.AppendLine("wank");
                    sb.AppendLine("wanking");
                    sb.AppendLine("piss");
                    File.WriteAllText("SwearWords.txt", sb.ToString());
                }
                string CensoredText = Color.ReplacePercentCodes(ConfigKey.SwearName.GetString()) + Color.White;
                if (ConfigKey.SwearName.GetString() == null)
                {
                    CensoredText = "&CBlock&F";
                }

                const string PatternTemplate = @"\b({0})(s?)\b";
                const RegexOptions Options = RegexOptions.IgnoreCase;

                if (Swears.Count == 0)
                {
                    Swears.AddRange(File.ReadAllLines("SwearWords.txt").
                        Where(line => line.StartsWith("#") == false || line.Trim().Equals(String.Empty)));
                }

                if (badWordMatchers == null)
                {
                    badWordMatchers = Swears.
                        Select(x => new Regex(string.Format(PatternTemplate, x), Options));
                }

                string output = badWordMatchers.
                   Aggregate(rawMessage, (current, matcher) => matcher.Replace(current, CensoredText));
                rawMessage = output;
            }

            /*if (player.World != null)
            {
                if (player.World.GameOn)
                {
                    if (Games.MineChallenge.mode == Games.MineChallenge.GameMode.math1)
                    {
                        if (rawMessage == Games.MineChallenge.answer.ToString() && !Games.MineChallenge.completed.Contains(player))
                        {
                            Games.MineChallenge.completed.Add(player);
                            player.Message("&8Correct!");
                            if (player.World.blueTeam.Contains(player)) player.World.blueScore++;
                            else player.World.redScore++;
                        }
                        else
                        {
                            player.Message("&8Incorrect");
                        }
                        return false;
                    }

                    if (Games.MineChallenge.mode == Games.MineChallenge.GameMode.math2)
                    {
                        if (rawMessage == Games.MineChallenge.answer.ToString() && !Games.MineChallenge.completed.Contains(player))
                        {
                            Games.MineChallenge.completed.Add(player);
                            player.Message("&8Correct!");
                            if (player.World.blueTeam.Contains(player)) player.World.blueScore++;
                            else player.World.redScore++;
                        }
                        else
                        {
                            player.Message("&8Incorrect");
                        }
                        return false;
                    }
                }
            }*/

            var recepientList = Server.Players.NotIgnoring(player); if (player.World.WorldOnlyChat) recepientList = player.World.Players.NotIgnoring(player);

            string formattedMessage = String.Format( "{0}&F: {1}",
                                                     player.ClassyName,
                                                     rawMessage );

            var e = new ChatSendingEventArgs( player,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.Global,
                                              recepientList );

            if( !SendInternal( e ) ) return false;

            Logger.Log( LogType.GlobalChat,
                        "{0}: {1}", player.Name, OriginalMessage );
            return true;
        }
示例#13
0
文件: Chat.cs 项目: fragmer/fCraft
 internal ChatSentEventArgs( ChatSendingEventArgs e, int recipientCount ) {
     Player = e.Player;
     Message = e.Message;
     MessageType = e.MessageType;
     RecipientList = e.RecipientList;
     FormattedMessage = e.FormattedMessage;
     RecipientCount = recipientCount;
 }
示例#14
0
文件: Chat.cs 项目: 727021/800craft
        /// <summary> Sends a global (white) chat. </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendGlobal( [NotNull] Player player, [NotNull] string rawMessage ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( rawMessage == null ) throw new ArgumentNullException( "rawMessage" );
            string OriginalMessage = rawMessage;
            if (Server.Moderation && !Server.VoicedPlayers.Contains(player) && player.World != null)
            {
                player.Message("&WError: Server Moderation is activated. Message failed to send");
                return false;
            }
            rawMessage = rawMessage.Replace("$name", "Hello my name is " + player.ClassyName);
            rawMessage = rawMessage.Replace("$kicks", "I have kicked " + player.Info.TimesKickedOthers.ToString() + " players.");
            rawMessage = rawMessage.Replace("$bans", "I have banned " + player.Info.TimesBannedOthers.ToString() + " players.");
            rawMessage = rawMessage.Replace("$awesome", "It is my professional opinion, that " + ConfigKey.ServerName.GetString() + " is the best server on Minecraft");
            rawMessage = rawMessage.Replace("$server", ConfigKey.ServerName.GetString());
            rawMessage = rawMessage.Replace("$motd", ConfigKey.MOTD.GetString());
            rawMessage = rawMessage.Replace("$date", DateTime.UtcNow.ToShortDateString());
            rawMessage = rawMessage.Replace("$time", DateTime.Now.ToString());

            if (!player.Can(Permission.ChatWithCaps))
            {
                int caps = 0;
                for (int i = 0; i < rawMessage.Length; i++)
                {
                    if (Char.IsUpper(rawMessage[i]))
                    {
                        caps++;
                        if (caps > ConfigKey.MaxCaps.GetInt())
                        {
                            rawMessage = rawMessage.ToLower();
                            player.Message("Your message was changed to lowercase as it exceeded the maximum amount of capital letters.");
                        }
                    }
                }
            }

            if (!player.Can(Permission.Swear))
            {
                if (!File.Exists("SwearWords.txt"))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("#This txt file should be filled with bad words that you want to be filtered out");
                    sb.AppendLine("#I have included some examples, excuse my language :P");
                    sb.AppendLine("f**k");
                    sb.AppendLine("f*****g");
                    sb.AppendLine("f****d");
                    sb.AppendLine("dick");
                    sb.AppendLine("bitch");
                    sb.AppendLine("shit");
                    sb.AppendLine("s******g");
                    sb.AppendLine("s******d");
                    sb.AppendLine("c**t");
                    sb.AppendLine("nigger");
                    sb.AppendLine("wanker");
                    sb.AppendLine("wank");
                    sb.AppendLine("wanking");
                    sb.AppendLine("piss");
                    File.WriteAllText("SwearWords.txt", sb.ToString());
                }
                string CensoredText = Color.ReplacePercentCodes(ConfigKey.SwearName.GetString()) + Color.White;
                if (ConfigKey.SwearName.GetString() == null)
                {
                    CensoredText = "&CBlock&F";
                }

                const string PatternTemplate = @"\b({0})(s?)\b";
                const RegexOptions Options = RegexOptions.IgnoreCase;

                if (Swears.Count == 0)
                {
                    Swears.AddRange(File.ReadAllLines("SwearWords.txt").
                        Where(line => line.StartsWith("#") == false || line.Trim().Equals(String.Empty)));
                }

                if (badWordMatchers == null)
                {
                    badWordMatchers = Swears.
                        Select(x => new Regex(string.Format(PatternTemplate, x), Options));
                }

                string output = badWordMatchers.
                   Aggregate(rawMessage, (current, matcher) => matcher.Replace(current, CensoredText));
                rawMessage = output;
            }

            var recepientList = Server.Players.NotIgnoring(player);

            string formattedMessage = String.Format( "{0}&F: {1}",
                                                     player.ClassyName,
                                                     rawMessage );

            var e = new ChatSendingEventArgs( player,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.Global,
                                              recepientList );

            if( !SendInternal( e ) ) return false;

            Logger.Log( LogType.GlobalChat,
                        "{0}: {1}", player.Name, OriginalMessage );
            return true;
        }
示例#15
0
文件: Chat.cs 项目: Magi1053/ProCraft
        /// <summary> Sends a staff message (/IRCStaff). </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendIRCStaff([NotNull] Player player, [NotNull] string rawMessage)
        {
            if (player == null) throw new ArgumentNullException("player");
            if (rawMessage == null) throw new ArgumentNullException("rawMessage");

            var recipientList = Server.Players.Can(Permission.ReadStaffChat)
                                      .NotIgnoring(player)
                                      .Union(player);

            string formattedMessage = String.Format("&P(IRC+staff){0}&P: {1}",
                                                     player.Name,
                                                     rawMessage);

            var e = new ChatSendingEventArgs(player,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.Staff,
                                              recipientList);

            IRC.SendChannelMessage("\u212C(IRC+Staff)\u211C" + player.Name + ": " + rawMessage);

            if (!SendInternal(e)) return false;

            Logger.Log(LogType.GlobalChat,
                        "(IRC+staff){0}: {1}",
                        player.Name,
                        rawMessage);
            return true;
        }
示例#16
0
        /// <summary> Sends a global (white) chat. </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendGlobal([NotNull] Player player, [NotNull] string rawMessage)
        {
            if (player == null) throw new ArgumentNullException("player");
            if (rawMessage == null) throw new ArgumentNullException("rawMessage");

            rawMessage = rawMessage.Replace("$motd", ConfigKey.MOTD.GetString());
            rawMessage = rawMessage.Replace("$time", DateTime.Now.ToString()); //used to test env realistic

                var recepientList = Server.Players.NotIgnoring(player);

                // Check caps
                if (!player.Can(Permission.ChatWithCaps))
                {
                    int caps = 0;
                    for (int i = 0; i < rawMessage.Length; i++)
                    {
                        if (Char.IsUpper(rawMessage[i]))
                        {
                            caps++;
                            if (caps > ConfigKey.MaxCaps.GetInt())
                            {
                                rawMessage = rawMessage.ToLower();
                                player.Message("Your message was changed to lowercase as it exceeded the maximum amount of capital letters.");
                            }
                        }
                    }
                }

                if (player.IsStaticStaff)
                {
                    recepientList = Server.Players.Can(Permission.ReadStaffChat)
                                                  .NotIgnoring(player)
                                                  .Union(player);
                    rawMessage = rawMessage.Replace(rawMessage, "&P(staff)" + player.ClassyName + "&P: " + rawMessage);

                }

                // Swear filter
                if (!player.Can(Permission.Swear))
                {
                    if (!File.Exists("SwearWords.txt"))
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("#This txt file should be filled with bad words that you want to be filtered out");
                        sb.AppendLine("#I have included some examples, excuse my language :P");
                        sb.AppendLine("f**k");
                        sb.AppendLine("f*****g");
                        sb.AppendLine("f****d");
                        sb.AppendLine("dick");
                        sb.AppendLine("bitch");
                        sb.AppendLine("shit");
                        sb.AppendLine("s******g");
                        sb.AppendLine("s******d");
                        sb.AppendLine("c**t");
                        sb.AppendLine("nigger");
                        sb.AppendLine("wanker");
                        sb.AppendLine("wank");
                        sb.AppendLine("wanking");
                        sb.AppendLine("piss");
                        File.WriteAllText("SwearWords.txt", sb.ToString());
                    }
                    string CensoredText = Color.ReplacePercentCodes(ConfigKey.SwearReplace.GetString())+"&F";

                    if (ConfigKey.SwearReplace.GetString() == null)
                    {
                        CensoredText = "&CBlock&F";
                    }

                    const string PatternTemplate = @"\b({0})(s?)\b";
                    const RegexOptions Options = RegexOptions.IgnoreCase;

                    if (Swears.Count == 0)
                    {
                        Swears.AddRange(File.ReadAllLines("SwearWords.txt").Where(line => line.StartsWith("#") == false || line.Trim().Equals(String.Empty)));
                    }

                    if (badWordMatchers == null)
                    {
                        badWordMatchers = Swears.
                            Select(x => new Regex(string.Format(PatternTemplate, x), Options));
                    }

                    string output = badWordMatchers.
                       Aggregate(rawMessage, (current, matcher) => matcher.Replace(current, CensoredText));
                    rawMessage = output;
                }

                string formattedMessage = String.Format("{0}&F: {1}",
                                                         player.ClassyName,
                                                         rawMessage);

                var e = new ChatSendingEventArgs(player,
                                                  rawMessage,
                                                  formattedMessage,
                                                  ChatMessageType.Global,
                                                  recepientList);

                if (!SendInternal(e)) return false;

                Logger.Log(LogType.GlobalChat,
                            "{0}: {1}", player.Name, rawMessage);
                return true;
        }
示例#17
0
文件: Chat.cs 项目: Magi1053/ProCraft
        /// <summary> Sends a staff message from irc (!St). </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool IRCSendStaff([NotNull] string player, [NotNull] string rawMessage)
        {
            if (player == null) throw new ArgumentNullException("player");
            if (rawMessage == null) throw new ArgumentNullException("rawMessage");

            var recipientList = Server.Players.Can(Permission.ReadStaffChat).Where(p => p.Info.ReadIRC == true);

            string formattedMessage = String.Format("&P(IRC+staff)&5(IRC){0}&P: {1}",
                                                     player,
                                                     rawMessage);

            var e = new ChatSendingEventArgs( Player.Console,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.Staff,
                                              recipientList);

            if (!SendInternal(e)) return false;
			IRC.SendChannelMessage("\u211C\u212C(IRC+Staff)(IRC)\u211C" + player + ": " + rawMessage);

            Logger.Log(LogType.GlobalChat,
                        "(IRC+staff)(IRC){0}: {1}",
                        player,
                        rawMessage);
            return true;
        }
示例#18
0
 static bool RaiseSendingEvent( ChatSendingEventArgs args )
 {
     var h = Sending;
     if( h == null ) return false;
     h( null, args );
     return args.Cancel;
 }
示例#19
0
文件: Chat.cs 项目: Magi1053/ProCraft
        /// <summary> Sends a global (white) chat. </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendGlobal([NotNull] Player player, [NotNull] string rawMessage) {
            if (player == null) throw new ArgumentNullException("player");
            if (rawMessage == null) throw new ArgumentNullException("rawMessage");
            foreach (Filter Swear in Filters) {
                if (rawMessage.ToLower().Contains(Swear.Word.ToLower())) {
                    rawMessage = rawMessage.ReplaceString(Swear.Word, Swear.Replacement, StringComparison.InvariantCultureIgnoreCase);
                }
            }
            if (!player.IsStaff) {
                rawMessage = RegexIPMatcher.Replace(rawMessage, "<Redacted IP>");
            }
            if (rawMessage.Length >= 10 && player.Info.Rank.MaxCaps > 0) {
                int caps = 0;
                for (int i = 0; i < rawMessage.Length; i++) {
                    if (char.IsUpper(rawMessage[i])) {
                        caps++;
                    }
                }
                if (player.Info.Rank.MaxCaps == 1) {
                    if (caps > (rawMessage.Length / 2)) {
                        rawMessage = rawMessage.ToLower().UppercaseFirst();
                        player.Message("Max uppercase letters reached. Message set to lowercase");
                    }
                } else if (caps > player.Info.Rank.MaxCaps) {
                    rawMessage = rawMessage.ToLower().UppercaseFirst();
                    player.Message("Max uppercase letters reached. Message set to lowercase");
                }
            }
            if (player.Info.ChatRainbows) {
                rawMessage = Rainbow.Rainbowize(rawMessage);
            } else if (player.Info.ChatBWRainbows) {
                rawMessage = Rainbow.BWRainbowize(rawMessage);
            }

            var recipientList = Server.Players.NotIgnoring(player);

            string formattedMessage = string.Format("{0}&F: {1}",
                                                     player.ClassyName,
                                                     rawMessage);

            var e = new ChatSendingEventArgs(player,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.Global,
                                              recipientList);


            if (!SendInternal(e)) return false;
            rawMessage = Color.StripColors(rawMessage);

            checkBotResponses(player, rawMessage);

            Logger.Log(LogType.GlobalChat,
                        "(global){0}: {1}", player.Info.Rank.Color + player.Name + Color.White, rawMessage);
            return true;
        }
示例#20
0
        public static bool SendAdmin(Player player, string rawMessage)
        {
            if (player == null) throw new ArgumentNullException("player");
            if (rawMessage == null) throw new ArgumentNullException("rawMessage");

            var recepientList = Server.Players.Can(Permission.ReadAdminChat)
                                              .NotIgnoring(player);

            string formattedMessage = String.Format("&9(Admin){0}&b: {1}",
                                                     player.ClassyName,
                                                     rawMessage);

            var e = new ChatSendingEventArgs(player,
                                              rawMessage,
                                              formattedMessage,
                                              ChatMessageType.Staff,
                                              recepientList);

            if (!SendInternal(e)) return false;

            Logger.Log(LogType.GlobalChat, "(Admin){0}: {1}", player.Name, rawMessage);
            return true;
        }
示例#21
0
        /// <summary> Sends a world-specific message (!World message). </summary>
        /// <param name="player"> Player writing the message. </param>
        /// <param name="world"> Target world. </param>
        /// <param name="rawMessage"> Message text. </param>
        /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
        public static bool SendWorld([NotNull] Player player, [NotNull] World world, [NotNull] string rawMessage)
        {
            if (player == null) throw new ArgumentNullException("player");
            if (world == null)
            {
                if (player.World == null)
                {
                    player.Message("Please specify a world name when using WorldChat from console.");
                    return false;
                }
            }
            if (rawMessage == null) throw new ArgumentNullException("rawMessage");

            var recepientList = world.Players.NotIgnoring(player).Union(player);

            string formattedMessage = String.Format("&P({0}&P){1}: {2}", world.ClassyName, player.Name, rawMessage);

            var e = new ChatSendingEventArgs(player,
                                  rawMessage,
                                  formattedMessage,
                                  ChatMessageType.World, recepientList);

            if (!SendInternal(e)) return false;

            Logger.Log(LogType.GlobalChat, "({0}){1}: {2}", world.Name, player.Name, rawMessage);
            return true;
        }