Beispiel #1
0
        public int AddBan(string bzID, string address, string host, string author, string reason, int lenght)
        {
            YAMLDB.BanRecord record = new YAMLDB.BanRecord();

            record.Active     = true;
            record.BZID       = bzID;
            record.Address    = address;
            record.Host       = host;
            record.Author     = author;
            record.Reason     = reason;
            record.CreateTime = DateTime.Now;
            if (lenght > 0)
            {
                record.EndTime = DateTime.Now + new TimeSpan(0, lenght, 0);
            }
            else
            {
                record.EndTime = DateTime.MaxValue;
            }

            lock (DB)
            {
                DB.LastID++;
                record.ID = DB.LastID;
                DB.Records.Add(record);
                CacheRecord(record);
            }
            StartUpdate();

            return((int)record.ID);
        }
Beispiel #2
0
        private void FlushRecordFromCache(YAMLDB.BanRecord record)
        {
            if (record.Active)
            {
                return;
            }

            if (record.BZID != string.Empty && BZIDCache.ContainsKey(record.BZID) && BZIDCache[record.BZID] == record)
            {
                BZIDCache.Remove(record.BZID);
            }

            if (record.Address != string.Empty)
            {
                if (AddressCache.ContainsKey(record.Address))
                {
                    AddressCache[record.Address].Remove(record);
                }
            }

            if (record.Host != string.Empty)
            {
                if (HostCache.ContainsKey(record.Host))
                {
                    HostCache[record.Host].Remove(record);
                }
            }
        }
Beispiel #3
0
        private Databases.BanRecord ConvertBanRecord(YAMLDB.BanRecord inRec)
        {
            Databases.BanRecord outRec = new BanRecord();

            outRec.ID         = (int)inRec.ID;
            outRec.CreateTime = inRec.CreateTime;
            outRec.Author     = inRec.Author;
            outRec.Reason     = inRec.Reason;
            return(outRec);
        }
Beispiel #4
0
        private void CacheRecord(YAMLDB.BanRecord record)
        {
            if (!record.Active)
            {
                return;
            }

            if (record.BZID != string.Empty && !BZIDCache.ContainsKey(record.BZID))
            {
                BZIDCache.Add(record.BZID, record);
            }

            if (record.Address != string.Empty)
            {
                if (!AddressCache.ContainsKey(record.Address))
                {
                    AddressCache.Add(record.Address, new List <YAMLDB.BanRecord>());
                }
                AddressCache[record.Address].Add(record);
            }

            if (record.Host != string.Empty)
            {
                if (!HostCache.ContainsKey(record.Host))
                {
                    HostCache.Add(record.Host, new List <YAMLDB.BanRecord>());
                }
                HostCache[record.Host].Add(record);
            }

            if (record.EndTime != DateTime.MaxValue)
            {
                if (!ExpirtingBans.ContainsKey(record.EndTime))
                {
                    ExpirtingBans.Add(record.EndTime, new List <YAMLDB.BanRecord>());
                }

                ExpirtingBans[record.EndTime].Add(record);
            }
        }