Beispiel #1
0
        public bool Load(string directory)
        {
            Wrapped.Clear();
            String path = Path.Combine(directory, "DnsBans.xml");

            if (File.Exists(path))
            {
                FileStream stream = null;

                try {
                    stream = File.Open(path, FileMode.Open, FileAccess.Read);

                    XDocument document = XDocument.Load(stream);

                    var records = from x in document.Root.Elements("pattern")
                                  select new Regex(x.Value);

                    records.ForEach((record) => Wrapped.Add(record));
                    return(true);
                }
                catch { }
                finally {
                    if (stream != null)
                    {
                        stream.Close();
                        stream.Dispose();
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
        public IRecord Add(IClient client)
        {
            var record = (Record)this.Find((s) => s.Equals(client));

            if (record == null)
            {
                record = new Record();
                Wrapped.Add(record);
            }

            record.ClientId = client.ClientId;
            record.Name     = client.Name;
            record.DnsName  = (client.DnsEntry != null) ? client.DnsEntry.HostName : record.DnsName;
            record.Muzzled  = client.Muzzled;
            record.LastSeen = TimeBank.CurrentTime;

            if (record.Trusted && client.IsCaptcha)
            {
                record.Trusted = false;
            }

            if (TimeBank.CurrentTime.Subtract(lastSave).TotalMinutes > 30)
            {
                lastSave = TimeBank.CurrentTime;
                ThreadPool.QueueUserWorkItem((state) => Save());
            }

            return(record);
        }
Beispiel #3
0
        public bool Add(Regex regex)
        {
            if (Wrapped.Contains((s) => s.Equals(regex)))
            {
                return(false);
            }

            Wrapped.Add(regex);
            return(true);
        }
Beispiel #4
0
        public bool Add(IClientId banned)
        {
            if (this.Contains((s) => s.Equals(banned)))
            {
                return(false);
            }

            Wrapped.Add(banned);
            return(true);
        }
Beispiel #5
0
        public bool Load()
        {
            Wrapped.Clear();
            String path = Path.Combine(Directories.Cache, "Records.xml");

            if (File.Exists(path))
            {
                FileStream stream = null;

                try {
                    stream = File.Open(path, FileMode.Open, FileAccess.Read);

                    XDocument document = XDocument.Load(stream);

                    var records = from x in document.Root.Elements("Record")
                                  select new Record()
                    {
                        ClientId = new ClientId(
                            Guid.Parse(x.Element("guid").Value),
                            IPAddress.Parse(x.Element("address").Value)),
                        Name     = x.Element("name").Value,
                        DnsName  = x.Element("dnshost").Value,
                        Trusted  = bool.Parse(x.Element("trusted").Value),
                        LastSeen = DateTime.FromBinary(long.Parse(x.Element("lastseen").Value))
                    };

                    records.ForEach((record) => Wrapped.Add(record));

                    this.admins  = new Admin(server);
                    this.bans    = new Banned(server);
                    this.dnsBans = new DnsBanned();
                    this.rBans   = new RangeBanned();

                    return(true);
                }
                catch { }
                finally {
                    if (stream != null)
                    {
                        stream.Close();
                        stream.Dispose();
                    }
                }
            }

            this.admins  = new Admin(server);
            this.bans    = new Banned(server);
            this.dnsBans = new DnsBanned();
            this.rBans   = new RangeBanned();

            return(false);
        }
Beispiel #6
0
        public bool Add(IClient client, string password)
        {
            int index = this.FindIndex((s) => s.ClientId.Equals(client));

            if (index > -1)
            {
                this[index].Sha1Text = Password.CreateSha1Text(password);
                return(true);
            }

            Wrapped.Add(new Password(client, password));
            return(true);
        }
Beispiel #7
0
        public bool Add(IPassword password)
        {
            int index = this.FindIndex((s) => s.ClientId.Equals(password.ClientId));

            if (index > -1)
            {
                this[index].Sha1Text = password.Sha1Text;
                return(true);
            }

            Wrapped.Add(password);
            return(true);
        }
Beispiel #8
0
        public bool Load(string directory)
        {
            Wrapped.Clear();
            String path = Path.Combine(directory, "Passwords.xml");

            if (File.Exists(path))
            {
                FileStream stream = null;

                try {
                    stream = File.Open(path, FileMode.Open, FileAccess.Read);

                    XDocument document = XDocument.Load(stream);

                    var records = from x in document.Root.Elements("Password")
                                  select new Password(
                        Guid.Parse(x.Element("guid").Value),
                        IPAddress.Parse(x.Element("address").Value),
                        x.Element("string").Value,
                        (AdminLevel)Int32.Parse(x.Element("level").Value));

                    records.ForEach((record) => Wrapped.Add(record));
                    return(true);
                }
                catch { }
                finally {
                    if (stream != null)
                    {
                        stream.Close();
                        stream.Dispose();
                    }
                }
            }

            return(false);
        }
Beispiel #9
0
 public void Add(RawEntity entity)
 {
     wrapped.Add();
 }
 /// <summary>
 /// Adds an element with the provided key and value to the
 /// <see cref="IDictionary{TKey, TValue}"/>.
 /// </summary>
 ///
 /// <param name="value">
 /// The object to use as the value of the element to add.
 /// </param>
 /// <param name="key">
 /// The object to use as the key of the element to add.
 /// </param>
 /// <exception cref="NotSupportedException">
 /// The <see cref="AbstractDictionaryWrapper{TKey,TValue}.Wrapped"/> <see cref="IDictionary{TKey, TValue}"/>
 /// is read-only.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// An element with the same key already exists in the
 /// <see cref="IDictionary{TKey, TValue}"/>.
 /// </exception>
 /// <exception cref="ArgumentNullException">key is null.</exception>
 /// <exception cref="InstanceSealedException">
 /// When <see cref="IsSealed"/> is <see langword="true"/>.
 /// </exception>
 public override void Add(TKey key, TValue value)
 {
     FailIfSealed();
     Wrapped.Add(key, value);
 }
 void ICollection <KeyValuePair <TKey, TValue> > .Add(KeyValuePair <TKey, TValue> item)
 {
     Wrapped.Add(item);
 }
 /// <summary>
 /// Adds an item to the <see cref="ICollection{T}"/>.
 /// </summary>
 ///
 /// <param name="item">
 /// The object to add to the <see cref="ICollection{T}"/>.
 /// </param>
 /// <exception cref="NotSupportedException">
 /// The <see cref="Wrapped"/> <see cref="IDictionary{TKey, TValue}"/>
 /// is read-only.
 /// </exception>
 public override void Add(KeyValuePair <TKey, TValue> item)
 {
     Wrapped.Add(item);
 }