Example #1
0
        public static bool QuickCheck(LogMessage message)
        {
            string content = message.Content.Trim();

            if (content.Length == 0)
            {
                return(false);
            }

            if (UserTalkMessage.QuickCheck(message))
            {
                return(false);
            }

            int space = content.IndexOf(WordSeparator);

            if (space == -1)
            {
                return(false);
            }
            content = content.Substring(space);

            // This will return true if a user says one of the key phrases as the first part of their message.
            //   Checking the UserTalkMessage check above should eliminate that.
            return(content.StartsWith(KickIndicator, sComp) || content.StartsWith(BanIndicator, sComp));
        }
Example #2
0
        public virtual void CopyTo(UserTalkMessage dest)
        {
            base.CopyTo(dest);

            dest.Username  = Username;
            dest.EventType = EventType;
            dest.Content   = Content;
        }
Example #3
0
        public static KickBanMessage Parse(LogMessage message)
        {
            // These messages are very similar. If it's a valid chat message, it's not a kick or ban.
            if (UserTalkMessage.QuickCheck(message))
            {
                throw InvalidFormatException;
            }

            KickBanMessage msg = new KickBanMessage(message);

            msg.Username = msg.Content.Substring(0, msg.Content.IndexOf(WordSeparator));

            // What type of action, kick or ban?
            string rest = msg.Content.Substring(msg.Username.Length);

            if (rest.StartsWith(KickIndicator, sComp))
            {
                rest          = rest.Substring(KickIndicator.Length);
                msg.EventType = EventType.Kick;
            }
            else if (rest.StartsWith(BanIndicator, sComp))
            {
                rest          = rest.Substring(BanIndicator.Length);
                msg.EventType = EventType.Ban;
            }

            // who is responsible?
            msg.KickedBy = rest.Split(WordSeparator)[0];
            if (rest.Length == msg.KickedBy.Length)
            {
                msg.KickedBy = msg.KickedBy.Substring(0, msg.KickedBy.Length - 1);
            }
            else
            {
                // why did they do it?
                rest = rest.Substring(msg.KickedBy.Length);
                if (rest.StartsWith(ReasonStart, sComp))
                {
                    msg.Reason = rest.Substring(ReasonStart.Length);

                    // Remove the trailing bits if they are there.
                    foreach (char c in ReasonEnd.Reverse())
                    {
                        if (msg.Reason.EndsWith(c.ToString(), sComp))
                        {
                            msg.Reason = msg.Reason.Substring(0, msg.Reason.Length - 1);
                        }
                    }
                }
            }

            return(msg);
        }
Example #4
0
 public static bool TryParse(LogMessage msg, out UserTalkMessage message)
 {
     message = null;
     try
     {
         message = Parse(msg);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #5
0
 public static bool TryParse(string line, out UserTalkMessage message)
 {
     message = null;
     try
     {
         message = Parse(line);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #6
0
        public static UserTalkMessage Parse(LogMessage message)
        {
            UserTalkMessage msg = new UserTalkMessage(message);

            string[] parts = msg.Content.Split(WordSeparator);

            if (parts[0].StartsWith(UserStart, sComp) && parts[0].EndsWith(UserEnd, sComp))
            {
                // normal chat
                msg.Username = parts[0].Substring(UserStart.Length, parts[0].Length - (UserStart.Length + UserEnd.Length));

                msg.Content   = msg.Content.Substring(parts[0].Length + 1);
                msg.EventType = EventType.UserTalk;
            }
            else if ((parts[0].StartsWith(WhisperInStart, sComp) || parts[0].StartsWith(WhisperOutStart, sComp)) && parts[1].EndsWith(UserEnd, sComp))
            {
                // whispers
                msg.Username  = parts[1].Substring(0, parts[1].Length - UserEnd.Length);
                msg.Content   = msg.Content.Substring(parts[0].Length + 1 + parts[1].Length + 1);
                msg.EventType = parts[0].StartsWith(WhisperInStart, sComp) ? EventType.WhisperIn : EventType.WhisperOut;
            }
            else if (parts[0].StartsWith(UserStart, sComp) && msg.Content.EndsWith(UserEnd, sComp))
            {
                // emotes
                msg.Username = msg.Content.Substring(UserStart.Length);

                msg.Content = msg.Content.Substring(parts[0].Length + 1);
                msg.Content = msg.Content.Substring(0, msg.Content.Length - UserEnd.Length);

                msg.EventType = EventType.UserEmote;
            }
            else
            {
                throw InvalidFormatException;
            }

            return(msg);
        }