Example #1
0
        public bool IsBanned(string Key, out ModerationBan Ban)
        {
            if (_bans.TryGetValue(Key, out Ban))
            {
                if (!Ban.Expired)
                {
                    return(true);
                }

                //This ban has expired, let us quickly remove it here.
                using (var dbClient = Program.DatabaseManager.GetQueryReactor())
                {
                    dbClient.SetQuery("DELETE FROM `bans` WHERE `bantype` = '" + BanTypeUtility.FromModerationBanType(Ban.Type) + "' AND `value` = @Key LIMIT 1");
                    dbClient.AddParameter("Key", Key);
                    dbClient.RunQuery();
                }

                //And finally, let us remove the ban record from the cache.
                if (_bans.ContainsKey(Key))
                {
                    _bans.Remove(Key);
                }

                return(false);
            }
            return(false);
        }
Example #2
0
        public void Init()
        {
            if (_userPresets.Count > 0)
            {
                _userPresets.Clear();
            }

            if (_moderationCFHTopics.Count > 0)
            {
                _moderationCFHTopics.Clear();
            }

            if (_moderationCFHTopicActions.Count > 0)
            {
                _moderationCFHTopicActions.Clear();
            }

            if (_bans.Count > 0)
            {
                _bans.Clear();
            }

            using (var dbClient = Program.DatabaseManager.GetQueryReactor())
            {
                DataTable PresetsTable = null;
                dbClient.SetQuery("SELECT * FROM `moderation_presets`;");
                PresetsTable = dbClient.GetTable();

                if (PresetsTable != null)
                {
                    foreach (DataRow Row in PresetsTable.Rows)
                    {
                        var Type = Convert.ToString(Row["type"]).ToLower();
                        switch (Type)
                        {
                        case "user":
                            _userPresets.Add(Convert.ToString(Row["message"]));
                            break;

                        case "room":
                            _roomPresets.Add(Convert.ToString(Row["message"]));
                            break;
                        }
                    }
                }
            }

            using (var dbClient = Program.DatabaseManager.GetQueryReactor())
            {
                DataTable ModerationTopics = null;
                dbClient.SetQuery("SELECT * FROM `moderation_topics`;");
                ModerationTopics = dbClient.GetTable();

                if (ModerationTopics != null)
                {
                    foreach (DataRow Row in ModerationTopics.Rows)
                    {
                        if (!_moderationCFHTopics.ContainsKey(Convert.ToInt32(Row["id"])))
                        {
                            _moderationCFHTopics.Add(Convert.ToInt32(Row["id"]), Convert.ToString(Row["caption"]));
                        }
                    }
                }
            }

            using (var dbClient = Program.DatabaseManager.GetQueryReactor())
            {
                DataTable ModerationTopicsActions = null;
                dbClient.SetQuery("SELECT * FROM `moderation_topic_actions`;");
                ModerationTopicsActions = dbClient.GetTable();

                if (ModerationTopicsActions != null)
                {
                    foreach (DataRow Row in ModerationTopicsActions.Rows)
                    {
                        var ParentId = Convert.ToInt32(Row["parent_id"]);

                        if (!_moderationCFHTopicActions.ContainsKey(ParentId))
                        {
                            _moderationCFHTopicActions.Add(ParentId, new List <ModerationPresetActions>());
                        }

                        _moderationCFHTopicActions[ParentId].Add(new ModerationPresetActions(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["parent_id"]), Convert.ToString(Row["type"]), Convert.ToString(Row["caption"]), Convert.ToString(Row["message_text"]),
                                                                                             Convert.ToInt32(Row["mute_time"]), Convert.ToInt32(Row["ban_time"]), Convert.ToInt32(Row["ip_time"]), Convert.ToInt32(Row["trade_lock_time"]), Convert.ToString(Row["default_sanction"])));
                    }
                }
            }

            using (var dbClient = Program.DatabaseManager.GetQueryReactor())
            {
                DataTable PresetsActionCats = null;
                dbClient.SetQuery("SELECT * FROM `moderation_preset_action_categories`;");
                PresetsActionCats = dbClient.GetTable();

                if (PresetsActionCats != null)
                {
                    foreach (DataRow Row in PresetsActionCats.Rows)
                    {
                        _userActionPresetCategories.Add(Convert.ToInt32(Row["id"]), Convert.ToString(Row["caption"]));
                    }
                }
            }

            using (var dbClient = Program.DatabaseManager.GetQueryReactor())
            {
                DataTable PresetsActionMessages = null;
                dbClient.SetQuery("SELECT * FROM `moderation_preset_action_messages`;");
                PresetsActionMessages = dbClient.GetTable();

                if (PresetsActionMessages != null)
                {
                    foreach (DataRow Row in PresetsActionMessages.Rows)
                    {
                        var ParentId = Convert.ToInt32(Row["parent_id"]);

                        if (!_userActionPresetMessages.ContainsKey(ParentId))
                        {
                            _userActionPresetMessages.Add(ParentId, new List <ModerationPresetActionMessages>());
                        }

                        _userActionPresetMessages[ParentId].Add(new ModerationPresetActionMessages(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["parent_id"]), Convert.ToString(Row["caption"]), Convert.ToString(Row["message_text"]),
                                                                                                   Convert.ToInt32(Row["mute_hours"]), Convert.ToInt32(Row["ban_hours"]), Convert.ToInt32(Row["ip_ban_hours"]), Convert.ToInt32(Row["trade_lock_days"]), Convert.ToString(Row["notice"])));
                    }
                }
            }

            using (var dbClient = Program.DatabaseManager.GetQueryReactor())
            {
                DataTable GetBans = null;
                dbClient.SetQuery("SELECT `bantype`,`value`,`reason`,`expire` FROM `bans` WHERE `bantype` = 'machine' OR `bantype` = 'user'");
                GetBans = dbClient.GetTable();

                if (GetBans != null)
                {
                    foreach (DataRow dRow in GetBans.Rows)
                    {
                        var value   = Convert.ToString(dRow["value"]);
                        var reason  = Convert.ToString(dRow["reason"]);
                        var expires = (double)dRow["expire"];
                        var type    = Convert.ToString(dRow["bantype"]);

                        var Ban = new ModerationBan(BanTypeUtility.GetModerationBanType(type), value, reason, expires);
                        if (Ban != null)
                        {
                            if (expires > UnixUtilities.GetNow())
                            {
                                if (!_bans.ContainsKey(value))
                                {
                                    _bans.Add(value, Ban);
                                }
                            }
                            else
                            {
                                dbClient.SetQuery("DELETE FROM `bans` WHERE `bantype` = '" + BanTypeUtility.FromModerationBanType(Ban.Type) + "' AND `value` = @Key LIMIT 1");
                                dbClient.AddParameter("Key", value);
                                dbClient.RunQuery();
                            }
                        }
                    }
                }
            }

            Logger.Trace("Loaded moderation manager");
        }
Example #3
0
        public void ReCacheBans()
        {
            if (_bans.Count > 0)
            {
                _bans.Clear();
            }

            using (var dbClient = Program.DatabaseManager.GetQueryReactor())
            {
                DataTable GetBans = null;
                dbClient.SetQuery("SELECT `bantype`,`value`,`reason`,`expire` FROM `bans` WHERE `bantype` = 'machine' OR `bantype` = 'user'");
                GetBans = dbClient.GetTable();

                if (GetBans != null)
                {
                    foreach (DataRow dRow in GetBans.Rows)
                    {
                        var value   = Convert.ToString(dRow["value"]);
                        var reason  = Convert.ToString(dRow["reason"]);
                        var expires = (double)dRow["expire"];
                        var type    = Convert.ToString(dRow["bantype"]);

                        var Ban = new ModerationBan(BanTypeUtility.GetModerationBanType(type), value, reason, expires);
                        if (Ban != null)
                        {
                            if (expires > UnixUtilities.GetNow())
                            {
                                if (!_bans.ContainsKey(value))
                                {
                                    _bans.Add(value, Ban);
                                }
                            }
                            else
                            {
                                dbClient.SetQuery("DELETE FROM `bans` WHERE `bantype` = '" + BanTypeUtility.FromModerationBanType(Ban.Type) + "' AND `value` = @Key LIMIT 1");
                                dbClient.AddParameter("Key", value);
                                dbClient.RunQuery();
                            }
                        }
                    }
                }
            }

            Logger.Trace("Cached " + _bans.Count + " username and machine bans.");
        }