[Bobbot-cvs] Plugins/Sphere/Messages JSInformationRequestMessage.cs,NONE,1.1
Status: Alpha
Brought to you by:
iainmckay
From: Mr S. C. <mrs...@us...> - 2005-10-18 20:26:17
|
Update of /cvsroot/bobbot/Plugins/Sphere/Messages In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21047/Sphere/Messages Added Files: JSInformationRequestMessage.cs Log Message: -Added this! --- NEW FILE: JSInformationRequestMessage.cs --- #region LGPL License /* Bastard of a Bot Library Copyright (C) 2004 Bastard of a Bot Team This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #endregion using System; using System.Net; using System.Globalization; using System.Text.RegularExpressions; using Bot.Plugins.Sphere; using UltimaOnline.Sphere.Connection; using UltimaOnline.Sphere.Connection.Messages; namespace Bot.Plugins.Sphere.Messages { public delegate void JSInformationRequestEventHandler(object sender, JSInformationRequestEventArgs args); /// <summary> /// Summary description for JSInformationRequestMessage. /// </summary> public class JSInformationRequestMessage : BaseMessage { #region Members protected Regex m_Regex = new Regex( @"^([0-9]{2}:[0-9]{2}):\(.+\)JS:Information Request::Account:(.+)::RequestBy:(.+)", RegexOptions.Compiled ); protected DateTime m_Time; protected string m_Account; protected string m_RequestBy; #endregion #region Public properties /// <summary> /// The time this message was sent. /// </summary> public DateTime Time { get { return m_Time; } } public string Account { get { return m_Account; } } public string RequestBy { get { return m_RequestBy; } } #endregion public JSInformationRequestMessage() { } public override bool CanParse(string message) { if(m_Regex.IsMatch(message)) return true; return false; } public override void Parse(string message) { if(!CanParse(message)) throw new MessageParserException("Cannot parse this message.", message); Match match = m_Regex.Match(message); if(!match.Success) return; m_Time = DateTime.Parse(match.Groups[1].Value); m_Account = match.Groups[2].Value; m_RequestBy = match.Groups[3].Value; } public override void Notify(SphereConnection server) { server.OnCustomEvent(new JSInformationRequestEventArgs(this)); } } public class JSInformationRequestEventArgs : System.EventArgs { protected JSInformationRequestMessage m_Message; /// <summary> /// Gets the <see cref="Plugin.Messages.JSInformationRequestMessage"/> object of this event. /// </summary> public JSInformationRequestMessage Message { get { return m_Message; } } /// <summary> /// Instanciates the <see cref="JSInformationRequestEventArgs"/> class with a <see cref="JSInformationRequestMessage"/> object. /// </summary> /// <param name="msg"></param> public JSInformationRequestEventArgs(JSInformationRequestMessage msg) { m_Message = msg; } } } |