Esempio n. 1
0
        public virtual void CopyTo(KickBanMessage dest)
        {
            base.CopyTo(dest);

            dest.KickedBy  = KickedBy;
            dest.Username  = Username;
            dest.Reason    = Reason;
            dest.EventType = EventType;
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public static bool TryParse(LogMessage msg, out KickBanMessage message)
 {
     message = null;
     try
     {
         message = Parse(msg);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 4
0
 public static bool TryParse(string line, out KickBanMessage message)
 {
     message = null;
     try
     {
         message = Parse(line);
         return(true);
     }
     catch
     {
         return(false);
     }
 }