コード例 #1
0
ファイル: ChatFilter.cs プロジェクト: jonypan/TestGit2
        public static bool BanUser(string username)
        {
            if (string.IsNullOrEmpty(username))
            {
                return(false);
            }

            if (Monitor.TryEnter(lockLoadBanUsers, 60000))
            {
                try
                {
                    if (CheckBanUsers(username))
                    {
                        return(true);
                    }

                    File.AppendAllText(BANUSERS_FILE, Environment.NewLine + username);

                    BanUsers.Add(username);
                    NLogManager.LogMessage(string.Format("Admins has been banned user: username={0}", username));

                    return(true);
                }
                finally
                {
                    Monitor.Exit(lockLoadBanUsers);
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: ChatFilter.cs プロジェクト: jonypan/TestGit2
 private static void LoadAccountBlock()
 {
     try
     {
         string key = "ACCOUNTBLOCK_FILE";
         if (BicCache.ReadCache(key) == null)
         {
             XDocument xmldoc         = XDocument.Load(ACCOUNTBLOCK_FILE);
             IEnumerable <XElement> q = from xe in xmldoc.Descendants("key") select xe;
             var dt = new DataTable();
             dt.Columns.Add("key");
             dt.Columns.Add("name");
             dt.Columns.Add("accountid");
             dt.Columns.Add("reasonblock");
             dt.Columns.Add("namereasonblock");
             dt.Columns.Add("typeblock");
             dt.Columns.Add("endtimeblock");
             dt.Columns.Add("createDate");
             foreach (XElement xe in q)
             {
                 DataRow row = dt.NewRow();
                 row[0] = xe.Attribute("key").Value;
                 row[1] = xe.Attribute("name").Value;
                 row[2] = xe.Attribute("accountid").Value;
                 row[3] = xe.Attribute("reasonblock").Value;
                 row[4] = xe.Attribute("namereasonblock").Value;
                 row[5] = xe.Attribute("typeblock").Value;
                 row[6] = xe.Attribute("endtimeblock").Value;
                 row[7] = xe.Attribute("createDate").Value;
                 dt.Rows.Add(row); // Thêm dòng mới vào dtb
             }
             List <ListAccountBlock> Data = ListAccountBlock = dt.AsEnumerable().Select(m => new ListAccountBlock()
             {
                 key             = m.Field <string>("key"),
                 name            = m.Field <string>("name"),
                 accountid       = m.Field <string>("accountid"),
                 reasonblock     = m.Field <string>("reasonblock"),
                 namereasonblock = m.Field <string>("namereasonblock"),
                 typeblock       = m.Field <string>("typeblock"),
                 endtimeblock    = m.Field <string>("endtimeblock"),
                 createDate      = m.Field <string>("createDate")
             }).ToList();
             BicCache.CacheData(key, Data);
         }
         else
         {
             ListAccountBlock = (List <ListAccountBlock>)BicCache.ReadCache(key);
         }
     }
     catch (Exception ex)
     {
         NLogManager.LogMessage(">> Ex LoadAccountBlock:" + ex.Message);
     }
 }
コード例 #3
0
ファイル: ChatFilter.cs プロジェクト: jonypan/TestGit2
        public static bool AddBadWord(string word)
        {
            if (Monitor.TryEnter(lockLoadBadWords, 60000))
            {
                try
                {
                    File.AppendAllText(BADWORDS_FILE, Environment.NewLine + word);

                    BadWords.Add(word);
                    NLogManager.LogMessage(string.Format("Admins has been added bad word: word={0}", word));

                    return(true);
                }
                finally
                {
                    Monitor.Exit(lockLoadBadWords);
                }
            }

            return(false);
        }
コード例 #4
0
ファイル: ChatFilter.cs プロジェクト: jonypan/TestGit2
        public static bool AddBadLink(string link)
        {
            if (Monitor.TryEnter(lockLoadBadLinks, 60000))
            {
                try
                {
                    File.AppendAllText(BADLINKS_FILE, Environment.NewLine + link);

                    BadLinks.Add(link);
                    NLogManager.LogMessage(string.Format("Admins has been added bad link: link={0}", link));

                    return(true);
                }
                finally
                {
                    Monitor.Exit(lockLoadBadLinks);
                }
            }

            return(false);
        }
コード例 #5
0
ファイル: ChatFilter.cs プロジェクト: jonypan/TestGit2
        static ChatFilter()
        {
            if (KeywordReplace == null || KeywordReplace.Count < 1)
            {
                try
                {
                    NLogManager.LogMessage(string.Format("Load file keyword replace: {0}", KEYWORDREPLACE_FILE));
                    if (File.Exists(KEYWORDREPLACE_FILE))
                    {
                        LoadKeywordReplace();
                    }
                }
                catch (Exception e)
                {
                    NLogManager.PublishException(e);
                }
            }

            if (BadWords == null || BadWords.Count < 1)
            {
                if (Monitor.TryEnter(lockLoadBadWords, 60000))
                {
                    try
                    {
                        NLogManager.LogMessage(string.Format("Load file bad word: {0}", BLACKLIST_FILE));
                        if (File.Exists(BLACKLIST_FILE))
                        {
                            //string[] allText = File.ReadAllLines(BADWORDS_FILE);
                            //BadWords = new List<string>(allText);
                            LoadBlackList();
                        }
                    }
                    catch (Exception e)
                    {
                        NLogManager.PublishException(e);
                    }
                    finally
                    {
                        Monitor.Exit(lockLoadBadWords);
                    }
                }
            }

            if (BadLinks == null || BadLinks.Count < 1)
            {
                if (Monitor.TryEnter(lockLoadBadLinks, 60000))
                {
                    try
                    {
                        NLogManager.LogMessage(string.Format("Load file bad links: {0}", BADLINKS_FILE));
                        if (File.Exists(BADLINKS_FILE))
                        {
                            string[] allText = File.ReadAllLines(BADLINKS_FILE);

                            BadLinks = new List <string>(allText);
                        }
                    }
                    catch (Exception e)
                    {
                        NLogManager.PublishException(e);
                    }
                    finally
                    {
                        Monitor.Exit(lockLoadBadLinks);
                    }
                }
            }

            if (ListAccountBlock == null || ListAccountBlock.Count < 1)
            {
                try
                {
                    NLogManager.LogMessage(string.Format("Load file Account Block: {0}", ACCOUNTBLOCK_FILE));
                    if (File.Exists(ACCOUNTBLOCK_FILE))
                    {
                        LoadAccountBlock();
                    }
                }
                catch (Exception e)
                {
                    NLogManager.PublishException(e);
                }
            }
            //if (BanUsers == null || BanUsers.Count < 1)
            //{
            //    if (Monitor.TryEnter(lockLoadBanUsers, 60000))
            //    {
            //        try
            //        {
            //            NLogManager.LogMessage(string.Format("Load file banned user: {0}", BANUSERS_FILE));
            //            if (File.Exists(BANUSERS_FILE))
            //            {
            //                string[] allText = File.ReadAllLines(BANUSERS_FILE);

            //                BanUsers.AddRange(allText);
            //            }
            //        }
            //        catch (Exception e)
            //        {
            //            NLogManager.PublishException(e);
            //        }
            //        finally
            //        {
            //            Monitor.Exit(lockLoadBanUsers);
            //        }
            //    }
            //}
        }