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)); }
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); }