[Bobbot-cvs] Bob/Core IStore.cs,1.3,1.4 Kernel.cs,1.3,1.4 KernelHelper.cs,1.1,1.2 User.cs,1.1,1.2
Status: Alpha
Brought to you by:
iainmckay
From: Iain M. <iai...@us...> - 2004-12-30 03:34:09
|
Update of /cvsroot/bobbot/Bob/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8381/Core Modified Files: IStore.cs Kernel.cs KernelHelper.cs User.cs Log Message: Many new changes. Most notably host-based recognition. Index: User.cs =================================================================== RCS file: /cvsroot/bobbot/Bob/Core/User.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** User.cs 23 Dec 2004 22:56:11 -0000 1.1 --- User.cs 30 Dec 2004 03:33:28 -0000 1.2 *************** *** 22,25 **** --- 22,29 ---- using System; using System.Collections; + using System.Collections.Specialized; + using System.Text.RegularExpressions; + + using Bot.Core.Collections; namespace Bot.Core *************** *** 31,44 **** { #region Public properties ! public virtual object this[string key] { ! get { return GetProperty(key); } ! set ! { ! if(HasProperty(key)) ! SetProperty(key, value, ((PropertyEntry) m_Properties[key]).Type); ! else ! AddProperty(key, value, value.GetType()); ! } } --- 35,48 ---- { #region Public properties ! public virtual PropertyCollection Properties { ! get { return m_Properties; } ! set { m_Properties = value; } ! } ! ! public virtual StringCollection Hosts ! { ! get { return m_Hosts; } ! set { m_Hosts = value; } } *************** *** 69,73 **** { get { return (bool) GetProperty("IsAdmin"); } ! set { SetProperty("IsAdmin", true, typeof(bool)); } } #endregion --- 73,77 ---- { get { return (bool) GetProperty("IsAdmin"); } ! set { SetProperty("IsAdmin", true); } } #endregion *************** *** 79,83 **** protected DateTime m_Created; ! protected Hashtable m_Properties; #endregion --- 83,88 ---- protected DateTime m_Created; ! protected StringCollection m_Hosts; ! protected PropertyCollection m_Properties; #endregion *************** *** 86,94 **** { m_Created = DateTime.Now; ! m_Properties = new Hashtable(); } #endregion ! #region Public methods public int ComparePassword(string password) { --- 91,100 ---- { m_Created = DateTime.Now; ! m_Hosts = new StringCollection(); ! m_Properties = new PropertyCollection(); } #endregion ! #region Public methods public int ComparePassword(string password) { *************** *** 96,127 **** } ! public virtual void AddProperty(string key, object value, Type type) { ! m_Properties[key] = new PropertyEntry(key, value, type); } ! public virtual void RemoveProperty(string key) { ! if(m_Properties.ContainsKey(key)) ! m_Properties.Remove(key); } ! public virtual void SetProperty(string key, object value, Type type) { ! ((PropertyEntry) m_Properties[key]).Type = type; ! ((PropertyEntry) m_Properties[key]).Value = value; } ! public virtual object GetProperty(string key) { ! if(!m_Properties.ContainsKey(key)) ! return ""; ! return ((PropertyEntry) m_Properties[key]).Value; } ! public virtual bool HasProperty(string key) { ! return m_Properties.ContainsKey(key); } #endregion --- 102,167 ---- } ! public virtual void AddProperty(string name, object value, Type type) { ! m_Properties.AddProperty(name, value, type); } ! public virtual void RemoveProperty(string name) { ! m_Properties.RemoveProperty(name); } ! public virtual void SetProperty(string name, object value) { ! m_Properties.SetProperty(name, value); } ! public virtual object GetProperty(string name) { ! if(m_Properties.ContainsProperty(name) == false) ! return null; ! return m_Properties[name].Value; } ! public virtual bool HasProperty(string name) { ! return m_Properties.ContainsProperty(name); ! } ! ! public virtual void AddHost(string host) ! { ! if(m_Hosts.Contains(host)) ! return; ! ! m_Hosts.Add(host); ! } ! ! public virtual void RemoveHost(string host) ! { ! m_Hosts.Remove(host); ! } ! ! public virtual bool HasHost(string host) ! { ! return m_Hosts.Contains(host); ! } ! ! public virtual bool HasMatchingHost(string matchHost) ! { ! Regex r = new Regex(matchHost.Replace("*", ".*"), RegexOptions.Singleline); ! ! lock(m_Hosts) ! { ! foreach(string host in m_Hosts) ! { ! Console.WriteLine("Matching {0} against {1}, is match {2}", matchHost.Replace("*", ".*"), host.Replace("*", ".*"), r.IsMatch(host.Replace("*", ".*"))); ! ! if(r.IsMatch(host.Replace("*", ".*"))) ! return true; ! } ! } ! ! return false; } #endregion Index: KernelHelper.cs =================================================================== RCS file: /cvsroot/bobbot/Bob/Core/KernelHelper.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** KernelHelper.cs 23 Dec 2004 23:03:38 -0000 1.1 --- KernelHelper.cs 30 Dec 2004 03:33:28 -0000 1.2 *************** *** 21,25 **** --- 21,27 ---- using System; + using System.Net; using System.Text; + using System.Globalization; using System.Security.Cryptography; *************** *** 39,42 **** --- 41,70 ---- return hashedString; } + + #region Borrowed from thresher + public static string IPAddressToLong( IPAddress ipAddress ) + { + if( ipAddress == null ) + { + throw new ArgumentException("Address cannot be null"); + } + return NetworkUnsignedLong( ipAddress.Address ).ToString( CultureInfo.InvariantCulture ); + } + + private static long NetworkUnsignedLong( long hostOrderLong ) + { + long networkLong = IPAddress.HostToNetworkOrder( hostOrderLong ); + //Network order has the octets in reverse order starting with byte 7 + //To get the correct string simply shift them down 4 bytes + //and zero out the first 4 bytes. + return (networkLong >> 32 ) & 0x00000000ffffffff; + } + + public static IPAddress GetLocalHost() + { + IPHostEntry localhost = Dns.Resolve( Dns.GetHostName() ); + return localhost.AddressList[0]; + } + #endregion } } \ No newline at end of file Index: Kernel.cs =================================================================== RCS file: /cvsroot/bobbot/Bob/Core/Kernel.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Kernel.cs 23 Dec 2004 22:56:11 -0000 1.3 --- Kernel.cs 30 Dec 2004 03:33:28 -0000 1.4 *************** *** 151,155 **** #endregion ! #region Private methods private void LoadStorageSolution() { --- 151,155 ---- #endregion ! #region Private methods private void LoadStorageSolution() { *************** *** 162,166 **** if(type == null) ! throw new TypeLoadException("xyz"); m_DataStore = (IStore) asm.CreateInstance(type.ToString(), true); --- 162,166 ---- if(type == null) ! throw new TypeLoadException(); m_DataStore = (IStore) asm.CreateInstance(type.ToString(), true); *************** *** 409,413 **** { int index = 0; ! string comStr = ""; ArrayList chanParts = new ArrayList(); --- 409,414 ---- { int index = 0; ! string comStr = ""; ! bool validCommand = false; ArrayList chanParts = new ArrayList(); *************** *** 436,442 **** --- 437,448 ---- } ); + + validCommand = true; } } } + + if(!validCommand) + RemoteAdmin.Broadcast("[{0}] {1}", ((RemoteConnection) sender).Data.Name, args.Message); } #endregion Index: IStore.cs =================================================================== RCS file: /cvsroot/bobbot/Bob/Core/IStore.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IStore.cs 23 Dec 2004 22:56:11 -0000 1.3 --- IStore.cs 30 Dec 2004 03:33:28 -0000 1.4 *************** *** 39,43 **** User GetUser(string name); User CreateUser(string name); ! void DeleteUser(string name); bool UserExists(string name); --- 39,43 ---- User GetUser(string name); User CreateUser(string name); ! bool DeleteUser(string name); bool UserExists(string name); *************** *** 49,52 **** --- 49,55 ---- IChannelCollection FindChannelsWithProperty(string prop); IChannelCollection FindChannelsWithProperty(string prop, object value); + + User FindClosestUser(string toHost); + IUserCollection FindUsersWithHost(string host); } } |