Exemple #1
0
        public void ReCacheBans()
        {
            if (this._bans.Count > 0)
            {
                this._bans.Clear();
            }

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().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)
                    {
                        string value   = Convert.ToString(dRow["value"]);
                        string reason  = Convert.ToString(dRow["reason"]);
                        double expires = (double)dRow["expire"];
                        string type    = Convert.ToString(dRow["bantype"]);

                        ModerationBan Ban = new ModerationBan(BanTypeUtility.GetModerationBanType(type), value, reason, expires);
                        if (Ban != null)
                        {
                            if (expires > PlusEnvironment.GetUnixTimestamp())
                            {
                                if (!this._bans.ContainsKey(value))
                                {
                                    this._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();
                            }
                        }
                    }
                }
            }

            log.Info("Cached " + this._bans.Count + " username and machine bans.");
        }
Exemple #2
0
        public void Init()
        {
            if (this._userPresets.Count > 0)
            {
                this._userPresets.Clear();
            }
            if (this._moderationCFHTopics.Count > 0)
            {
                this._moderationCFHTopics.Clear();
            }
            if (this._moderationCFHTopicActions.Count > 0)
            {
                this._moderationCFHTopicActions.Clear();
            }
            if (this._bans.Count > 0)
            {
                this._bans.Clear();
            }

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                DataTable PresetsTable = null;
                dbClient.SetQuery("SELECT * FROM `moderation_presets`;");
                PresetsTable = dbClient.GetTable();

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

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

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                DataTable ModerationTopics = null;
                dbClient.SetQuery("SELECT * FROM `moderation_topics`;");
                ModerationTopics = dbClient.GetTable();

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

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                DataTable ModerationTopicsActions = null;
                dbClient.SetQuery("SELECT * FROM `moderation_topic_actions`;");
                ModerationTopicsActions = dbClient.GetTable();

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

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

                        this._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 (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                DataTable PresetsActionCats = null;
                dbClient.SetQuery("SELECT * FROM `moderation_preset_action_categories`;");
                PresetsActionCats = dbClient.GetTable();

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

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                DataTable PresetsActionMessages = null;
                dbClient.SetQuery("SELECT * FROM `moderation_preset_action_messages`;");
                PresetsActionMessages = dbClient.GetTable();

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

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

                        this._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 (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().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)
                    {
                        string value   = Convert.ToString(dRow["value"]);
                        string reason  = Convert.ToString(dRow["reason"]);
                        double expires = (double)dRow["expire"];
                        string type    = Convert.ToString(dRow["bantype"]);

                        ModerationBan Ban = new ModerationBan(BanTypeUtility.GetModerationBanType(type), value, reason, expires);
                        if (Ban != null)
                        {
                            if (expires > PlusEnvironment.GetUnixTimestamp())
                            {
                                if (!this._bans.ContainsKey(value))
                                {
                                    this._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();
                            }
                        }
                    }
                }
            }

            log.Info("Loaded " + (this._userPresets.Count + this._roomPresets.Count) + " moderation presets.");
            log.Info("Loaded " + this._userActionPresetCategories.Count + " moderation categories.");
            log.Info("Loaded " + this._userActionPresetMessages.Count + " moderation action preset messages.");
            log.Info("Cached " + this._bans.Count + " username and machine bans.");
        }
Exemple #3
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 = PlusEnvironment.GetDatabaseManager().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 = PlusEnvironment.GetDatabaseManager().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 = PlusEnvironment.GetDatabaseManager().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 = PlusEnvironment.GetDatabaseManager().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 = PlusEnvironment.GetDatabaseManager().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 = PlusEnvironment.GetDatabaseManager().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 > PlusEnvironment.GetUnixTimestamp())
                            {
                                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();
                            }
                        }
                    }
                }
            }

            Log.Info("Loaded " + (_userPresets.Count + _roomPresets.Count) + " moderation presets.");
            Log.Info("Loaded " + _userActionPresetCategories.Count + " moderation categories.");
            Log.Info("Loaded " + _userActionPresetMessages.Count + " moderation action preset messages.");
            Log.Info("Cached " + _bans.Count + " username and machine bans.");
        }