Exemplo n.º 1
0
        public void AddBan(string moderatorUsername, ModerationBanType banType, string banValue, string banReason, double expireTimestamp)
        {
            var type = (banType == ModerationBanType.ByIp ? "ip" : banType == ModerationBanType.ByMachine ? "machine" : "user");

            using (var mysqlConnection = Sahara.GetServer().GetMySql().GetConnection())
            {
                mysqlConnection.OpenConnection();
                mysqlConnection.AddParameter("banType", type);
                mysqlConnection.AddParameter("banValue", banValue);
                mysqlConnection.AddParameter("reason", banReason);
                mysqlConnection.AddParameter("expireTimestamp", expireTimestamp);
                mysqlConnection.AddParameter("moderatorUsername", moderatorUsername);
                mysqlConnection.AddParameter("addedTimestamp", UnixTimestampGenerator.GetNow());
                mysqlConnection.SetQuery("REPLACE INTO `bans` (`bantype`, `value`, `reason`, `expire`, `added_by`, `added_date`) VALUES (@banType, @banValue, @reason, @expireTimestamp, @moderatorUsername, @addedTimestamp)");
                mysqlConnection.RunQuery();
                mysqlConnection.CloseConnection();
            }

            if (banType != ModerationBanType.ByMachine && banType != ModerationBanType.ByUsername)
            {
                return;
            }

            if (!_moderationBans.ContainsKey(banValue))
            {
                _moderationBans.Add(banValue, new ModerationBan(banType, banValue, banReason, expireTimestamp));
            }
        }
Exemplo n.º 2
0
        private void LoadModerationBans(DatabaseConnection mysqlConnection)
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();

                mysqlConnection.SetQuery("SELECT `bantype`, `value`, `reason`, `expire` FROM `bans` WHERE `bantype` = 'machine' OR `bantype` = 'user'");
                var moderationBanTable = mysqlConnection.GetTable();

                if (moderationBanTable != null)
                {
                    foreach (DataRow banRow in moderationBanTable.Rows)
                    {
                        var banValue          = Convert.ToString(banRow["value"]);
                        var banReason         = Convert.ToString(banRow["reason"]);
                        var banExpirationDate = (double)banRow["expire"];
                        var banType           = Convert.ToString(banRow["bantype"]);
                        var banTypeValue      = (banType == "ip" ? ModerationBanType.ByIp : banType == "machine" ? ModerationBanType.ByMachine : ModerationBanType.ByUsername);
                        var ban = new ModerationBan(banTypeValue, banValue, banReason, banExpirationDate);

                        if (banExpirationDate <= UnixTimestampGenerator.GetNow())
                        {
                            mysqlConnection.AddParameter("Key", banValue);
                            mysqlConnection.SetQuery("DELETE FROM `bans` WHERE `bantype` = '" + banType + "' AND `value` = @Key LIMIT 1");
                            mysqlConnection.RunQuery();
                        }
                        else if (!_moderationBans.ContainsKey(banValue))
                        {
                            _moderationBans.Add(banValue, ban);
                        }
                    }
                }

                stopwatch.Stop();
                _logManager.Log($"Loaded {_moderationBans.Count} moderation bans [{stopwatch.ElapsedMilliseconds}ms]", LogType.Information);
            }
            catch (Exception exception)
            {
                var method = System.Reflection.MethodBase.GetCurrentMethod().Name;
                _logManager.Log($"Error in {method}: {exception.Message}", LogType.Error);
                _logManager.Log(exception.StackTrace, LogType.Error);
            }
        }
Exemplo n.º 3
0
        public void PickTicket(int moderatorId, bool updateDatabase)
        {
            _ticketStatus = SupportTicketStatus.Picked;
            _moderatorId  = moderatorId;

            PlayerData moderatorPlayerData;

            if (PlayerLoader.TryGetDataById(moderatorId, out moderatorPlayerData))
            {
                _moderatorUsername = moderatorPlayerData.Username;
            }

            if (updateDatabase)
            {
                using (var mysqlConnection = Sahara.GetServer().GetMySql().GetConnection())
                {
                    mysqlConnection.OpenConnection();
                    mysqlConnection.RunQuery("UPDATE `moderation_tickets` SET `status` = 'picked', moderator_id = " + _moderatorId + ", timestamp = '" + UnixTimestampGenerator.GetNow() + "' WHERE id = " + _ticketId + "");
                    mysqlConnection.CloseConnection();
                }
            }

            moderatorPlayerData = null;
        }