Ejemplo n.º 1
0
        //DONE
        private Boolean updateBanStatus(AdKat_Ban aBan)
        {
            DebugWrite("updateBanStatus starting!", 6);

            Boolean success = false;
            if (aBan == null)
            {
                this.ConsoleError("Ban invalid in updateBanStatus.");
            }
            else
            {
                try
                {
                    //Conditionally modify the ban_sync for this server
                    if (!aBan.ban_sync.Contains("*" + this.server_id + "*"))
                    {
                        aBan.ban_sync += ("*" + this.server_id + "*");
                    }

                    using (MySqlConnection connection = this.getDatabaseConnection())
                    {
                        using (MySqlCommand command = connection.CreateCommand())
                        {
                            string query = @"
                            UPDATE
                            `" + this.mySqlDatabaseName + @"`.`adkats_banlist`
                            SET
                            `ban_sync` = '" + aBan.ban_sync + @"',
                            `ban_status` = '" + aBan.ban_status + @"'
                            WHERE
                            `ban_id` = " + aBan.ban_id;
                            command.CommandText = query;
                            //Attempt to execute the query
                            if (command.ExecuteNonQuery() > 0)
                            {
                                success = true;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    ConsoleException(e.ToString());
                }
            }

            DebugWrite("updateBanStatus finished!", 6);
            return success;
        }
Ejemplo n.º 2
0
        //DONE
        private Boolean uploadBan(AdKat_Ban aBan)
        {
            DebugWrite("uploadBan starting!", 6);

            Boolean success = false;
            if (aBan == null)
            {
                this.ConsoleError("Ban invalid in uploadBan.");
            }
            else
            {
                try
                {
                    //Upload the inner record if needed
                    if (aBan.ban_record.record_id < 0)
                    {
                        this.uploadRecord(aBan.ban_record);
                    }

                    using (MySqlConnection connection = this.getDatabaseConnection())
                    {
                        using (MySqlCommand command = connection.CreateCommand())
                        {
                            command.CommandText = @"
                            INSERT INTO
                            `" + this.mySqlDatabaseName + @"`.`adkats_banlist`
                            (
                                `player_id`,
                                `latest_record_id`,
                                `ban_status`,
                                `ban_notes`,
                                `ban_startTime`,
                                `ban_endTime`,
                                `ban_enforceName`,
                                `ban_enforceGUID`,
                                `ban_enforceIP`,
                                `ban_sync`
                            )
                            VALUES
                            (
                                @player_id,
                                @latest_record_id,
                                @ban_status,
                                @ban_notes,
                                NOW(),
                                DATE_ADD(NOW(), INTERVAL @ban_durationMinutes MINUTE),
                                @ban_enforceName,
                                @ban_enforceGUID,
                                @ban_enforceIP,
                                @ban_sync
                            )
                            ON DUPLICATE KEY
                            UPDATE
                                `latest_record_id` = @latest_record_id,
                                `ban_status` = @ban_status,
                                `ban_notes` = @ban_notes,
                                `ban_startTime` = NOW(),
                                `ban_endTime` = DATE_ADD(NOW(), INTERVAL @ban_durationMinutes MINUTE),
                                `ban_enforceName` = @ban_enforceName,
                                `ban_enforceGUID` = @ban_enforceGUID,
                                `ban_enforceIP` = @ban_enforceIP,
                                `ban_sync` = @ban_sync";

                            command.Parameters.AddWithValue("@player_id", aBan.ban_record.target_player.player_id);
                            command.Parameters.AddWithValue("@latest_record_id", aBan.ban_record.record_id);
                            command.Parameters.AddWithValue("@ban_status", "Active");
                            if (String.IsNullOrEmpty(aBan.ban_notes))
                                aBan.ban_notes = "NoNotes";
                            command.Parameters.AddWithValue("@ban_notes", aBan.ban_notes);
                            command.Parameters.AddWithValue("@ban_enforceName", aBan.ban_enforceName ? ('Y') : ('N'));
                            command.Parameters.AddWithValue("@ban_enforceGUID", aBan.ban_enforceGUID ? ('Y') : ('N'));
                            command.Parameters.AddWithValue("@ban_enforceIP", aBan.ban_enforceIP ? ('Y') : ('N'));
                            command.Parameters.AddWithValue("@ban_sync", "*" + this.server_id + "*");
                            //Handle permaban case
                            if (aBan.ban_record.command_type == AdKat_CommandType.PermabanPlayer)
                            {
                                aBan.ban_record.command_numeric = (int)this.permaBanEndTime.Subtract(DateTime.Now).TotalMinutes;
                            }
                            command.Parameters.AddWithValue("@ban_durationMinutes", aBan.ban_record.command_numeric);
                            //Attempt to execute the query
                            if (command.ExecuteNonQuery() >= 0)
                            {
                                this.DebugWrite("Success Uploading Ban on player " + aBan.ban_record.target_player.player_id, 5);
                                success = true;
                            }
                        }
                        if (success)
                        {
                            using (MySqlCommand command = connection.CreateCommand())
                            {
                                command.CommandText = @"
                                SELECT
                                    `ban_id`,
                                    `ban_startTime`,
                                    `ban_endTime`
                                FROM
                                    `adkats_banlist`
                                WHERE
                                    `player_id` = @player_id";

                                command.Parameters.AddWithValue("@player_id", aBan.ban_record.target_player.player_id);
                                //Attempt to execute the query
                                using (MySqlDataReader reader = command.ExecuteReader())
                                {
                                    //Grab the ban ID
                                    if (reader.Read())
                                    {
                                        aBan.ban_id = reader.GetInt64("ban_id");
                                        aBan.ban_startTime = reader.GetDateTime("ban_startTime");
                                        aBan.ban_endTime = reader.GetDateTime("ban_endTime");
                                        this.DebugWrite("Ban ID: " + aBan.ban_id, 5);
                                    }
                                    else
                                    {
                                        this.ConsoleError("Could not fetch ban information after upload");
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    ConsoleException(e.ToString());
                }
            }
            DebugWrite("uploadBan finished!", 6);
            return success;
        }
Ejemplo n.º 3
0
 private void queueBanForProcessing(AdKat_Ban aBan)
 {
     if (this.isEnabled)
     {
         this.DebugWrite("Preparing to queue ban for processing", 6);
         lock (banEnforcerMutex)
         {
             this.banEnforcerProcessingQueue.Enqueue(aBan);
             this.DebugWrite("Ban queued for processing", 6);
             this.dbCommHandle.Set();
         }
     }
 }
Ejemplo n.º 4
0
        //DONE
        private void repopulateProconBanList()
        {
            DebugWrite("repopulateProconBanList starting!", 6);
            this.ConsoleWarn("Downloading bans from database, please wait. This might take several minutes depending on your ban count!");

            double totalBans = 0;
            double bansRepopulated = 0;
            Boolean earlyExit = false;
            DateTime startTime = DateTime.Now;

            List<AdKat_Ban> updatedBans = new List<AdKat_Ban>();
            try
            {
                //Success fetching bans
                Boolean success = false;
                List<AdKat_Ban> tempBanList = new List<AdKat_Ban>();

                using (MySqlConnection connection = this.getDatabaseConnection())
                {

                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = @"
                        SELECT
                            COUNT(*) AS `ban_count`
                        FROM
                            `adkats_banlist`";

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                totalBans = reader.GetInt64("ban_count");
                            }
                        }
                    }
                    if (totalBans < 1)
                    {
                        return;
                    }
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = @"
                        SELECT
                            `ban_id`,
                            `player_id`,
                            `latest_record_id`,
                            `ban_status`,
                            `ban_notes`,
                            `ban_sync`,
                            `ban_startTime`,
                            `ban_endTime`,
                            `ban_enforceName`,
                            `ban_enforceGUID`,
                            `ban_enforceIP`
                        FROM
                            `adkats_banlist`";

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            //Loop through all incoming bans
                            long totalBanSeconds;
                            while (reader.Read())
                            {
                                //Break from the loop if the plugin is disabled or the setting is reverted.
                                if (!this.isEnabled || this.useBanEnforcer)
                                {
                                    this.ConsoleWarn("You exited the ban download process early, the process was not completed.");
                                    earlyExit = true;
                                    break;
                                }

                                //Bans have been found
                                success = true;

                                //Create the ban element
                                AdKat_Ban aBan = new AdKat_Ban();
                                aBan.ban_id = reader.GetInt64("ban_id");
                                aBan.ban_status = reader.GetString("ban_status");
                                aBan.ban_notes = reader.GetString("ban_notes");
                                aBan.ban_sync = reader.GetString("ban_sync");
                                aBan.ban_startTime = reader.GetDateTime("ban_startTime");
                                aBan.ban_endTime = reader.GetDateTime("ban_endTime");

                                //Get the record information
                                aBan.ban_record = this.fetchRecordByID(reader.GetInt64("latest_record_id"));

                                totalBanSeconds = (long)this.convertToProconTime(aBan.ban_endTime).Subtract(DateTime.Now).TotalSeconds;
                                if (totalBanSeconds > 0)
                                {
                                    this.DebugWrite("Re-ProconBanning: " + aBan.ban_record.target_player.player_name + " for " + totalBanSeconds + "sec for " + aBan.ban_record.record_message, 4);

                                    //Push the name ban
                                    if (reader.GetString("ban_enforceName").Equals("Y"))
                                    {
                                        Thread.Sleep(75);
                                        //Permabans and Temp bans longer than 1 year will be defaulted to permaban
                                        if (totalBanSeconds > 0 && totalBanSeconds < 31536000)
                                        {
                                            this.ExecuteCommand("procon.protected.send", "banList.add", "name", aBan.ban_record.target_player.player_name, "seconds", totalBanSeconds + "", aBan.ban_record.record_message);
                                        }
                                        else
                                        {
                                            this.ExecuteCommand("procon.protected.send", "banList.add", "name", aBan.ban_record.target_player.player_name, "perm", aBan.ban_record.record_message);
                                        }
                                    }

                                    //Push the guid ban
                                    if (reader.GetString("ban_enforceGUID").Equals("Y"))
                                    {
                                        Thread.Sleep(75);
                                        //Permabans and Temp bans longer than 1 year will be defaulted to permaban
                                        if (totalBanSeconds > 0 && totalBanSeconds < 31536000)
                                        {
                                            this.ExecuteCommand("procon.protected.send", "banList.add", "guid", aBan.ban_record.target_player.player_guid, "seconds", totalBanSeconds + "", aBan.ban_record.record_message);
                                        }
                                        else
                                        {
                                            this.ExecuteCommand("procon.protected.send", "banList.add", "guid", aBan.ban_record.target_player.player_guid, "perm", aBan.ban_record.record_message);
                                        }
                                    }

                                    //Push the IP ban
                                    if (reader.GetString("ban_enforceIP").Equals("Y"))
                                    {
                                        Thread.Sleep(75);
                                        //Permabans and Temp bans longer than 1 year will be defaulted to permaban
                                        if (totalBanSeconds > 0 && totalBanSeconds < 31536000)
                                        {
                                            this.ExecuteCommand("procon.protected.send", "banList.add", "ip", aBan.ban_record.target_player.player_ip, "seconds", totalBanSeconds + "", aBan.ban_record.record_message);
                                        }
                                        else
                                        {
                                            this.ExecuteCommand("procon.protected.send", "banList.add", "ip", aBan.ban_record.target_player.player_ip, "perm", aBan.ban_record.record_message);
                                        }
                                    }
                                }

                                if (++bansRepopulated % 15 == 0)
                                {
                                    this.ConsoleWrite(Math.Round(100 * bansRepopulated / totalBans, 2) + "% of bans repopulated. AVG " + Math.Round(bansRepopulated / ((DateTime.Now - startTime).TotalSeconds), 2) + " downloads/sec.");
                                }
                            }
                            this.ExecuteCommand("procon.protected.send", "banList.save");
                            this.ExecuteCommand("procon.protected.send", "banList.list");
                            if (!earlyExit)
                            {
                                this.ConsoleSuccess("All AdKats Enforced bans repopulated to procon's ban list.");
                            }

                            //Update the last db ban fetch time
                            this.lastDBBanFetch = DateTime.Now;

                            return;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleException(e.ToString());
            }
            return;
        }
Ejemplo n.º 5
0
 private TimeSpan getRemainingBanTime(AdKat_Ban aBan)
 {
     return aBan.ban_endTime.Subtract(this.convertToDBTime(DateTime.Now));
 }
Ejemplo n.º 6
0
        private void importBansFromBBM5108()
        {
            //Check if tables exist from BF3 Ban Manager
            if (!this.confirmTable("bm_banlist"))
            {
                return;
            }
            this.ConsoleWarn("BF3 Ban Manager tables detected. Checking validity....");

            //Check if any BBM5108 bans exist in the AdKats Banlist
            try
            {
                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = @"
                        SELECT
                            *
                        FROM
                            `" + this.mySqlDatabaseName + @"`.`adkats_banlist`
                        WHERE
                            `adkats_banlist`.`ban_notes` = 'BBM5108'
                        LIMIT 1";

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                this.ConsoleWarn("BF3 Ban Manager bans already imported, canceling import.");
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                this.ConsoleException(e.ToString());
                return;
            }

            this.ConsoleWarn("Validity confirmed. Preparing to fetch all BF3 Ban Manager Bans...");
            double totalBans = 0;
            double bansImported = 0;
            Queue<BBM5108_Ban> inboundBBMBans = new Queue<BBM5108_Ban>();
            DateTime startTime = DateTime.Now;
            try
            {
                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        this.DebugWrite("Creating query to import BBM5108", 3);
                        command.CommandText = @"
                        SELECT
                            soldiername, eaguid, ban_length, ban_duration, ban_reason
                        FROM
                            bm_banlist
                        INNER JOIN
                            bm_soldiers
                        ON
                            bm_banlist.soldierID = bm_soldiers.soldierID";

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            BBM5108_Ban BBMBan;
                            Boolean told = false;
                            while (reader.Read())
                            {
                                if (!told)
                                {
                                    this.DebugWrite("BBM5108 bans found, grabbing.", 3);
                                }
                                BBMBan = new BBM5108_Ban();
                                BBMBan.soldiername = reader.IsDBNull(reader.GetOrdinal("soldiername")) ? null : reader.GetString("soldiername");
                                BBMBan.eaguid = reader.IsDBNull(reader.GetOrdinal("eaguid")) ? null : reader.GetString("eaguid");
                                BBMBan.ban_length = reader.GetString("ban_length");
                                BBMBan.ban_duration = reader.GetDateTime("ban_duration");
                                BBMBan.ban_reason = reader.IsDBNull(reader.GetOrdinal("ban_reason")) ? null : reader.GetString("ban_reason");
                                inboundBBMBans.Enqueue(BBMBan);
                                totalBans++;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                this.ConsoleException(e.ToString());
                return;
            }
            this.ConsoleWarn(totalBans + " Ban Manager bans fetched, starting import to AdKats Ban Enforcer...");

            try
            {
                //Loop through all BBMBans in order that they came in
                AdKat_Ban aBan;
                AdKat_Record record;
                while (inboundBBMBans.Count > 0)
                {
                    //Break from the loop if the plugin is disabled or the setting is reverted.
                    if (!this.isEnabled || !this.useBanEnforcer)
                    {
                        this.ConsoleError("You exited the ban import process process early, the process was not completed and cannot recover without manual override. Talk to ColColonCleaner.");
                        break;
                    }

                    BBM5108_Ban BBMBan = inboundBBMBans.Dequeue();

                    //Create the record
                    record = new AdKat_Record();
                    //Fetch the player
                    record.target_player = this.fetchPlayer(-1, BBMBan.soldiername, BBMBan.eaguid, null);

                    record.command_source = AdKat_CommandSource.InGame;
                    if (BBMBan.ban_length == "permanent")
                    {
                        this.DebugWrite("Ban is permanent", 4);
                        record.command_type = AdKat_CommandType.PermabanPlayer;
                        record.command_action = AdKat_CommandType.PermabanPlayer;
                        record.command_numeric = 0;
                    }
                    else if (BBMBan.ban_length == "seconds")
                    {
                        this.DebugWrite("Ban is temporary", 4);
                        record.command_type = AdKat_CommandType.TempBanPlayer;
                        record.command_action = AdKat_CommandType.TempBanPlayer;
                        record.command_numeric = (int)(BBMBan.ban_duration - DateTime.UtcNow).TotalMinutes;
                    }
                    else
                    {
                        //Ignore all other cases e.g. round bans
                        this.DebugWrite("Ban type '" + BBMBan.ban_length + "' not usable", 3);
                        continue;
                    }

                    record.source_name = "BanEnforcer";
                    record.server_id = this.server_id;
                    if (!String.IsNullOrEmpty(record.target_player.player_name))
                    {
                        record.target_name = record.target_player.player_name;
                    }
                    record.isIRO = false;
                    record.record_message = BBMBan.ban_reason;
                    //Create the ban
                    aBan = new AdKat_Ban();
                    aBan.ban_record = record;
                    aBan.ban_notes = "BBM5108";

                    //Update the ban enforcement depending on available information
                    Boolean nameAvailable = !String.IsNullOrEmpty(record.target_player.player_name);
                    Boolean GUIDAvailable = !String.IsNullOrEmpty(record.target_player.player_guid);
                    Boolean IPAvailable = !String.IsNullOrEmpty(record.target_player.player_ip);
                    aBan.ban_enforceName = nameAvailable && (this.defaultEnforceName || (!GUIDAvailable && !IPAvailable) || !String.IsNullOrEmpty(BBMBan.soldiername));
                    aBan.ban_enforceGUID = GUIDAvailable && (this.defaultEnforceGUID || (!nameAvailable && !IPAvailable) || !String.IsNullOrEmpty(BBMBan.eaguid));
                    aBan.ban_enforceIP = IPAvailable && this.defaultEnforceIP;
                    if (!aBan.ban_enforceName && !aBan.ban_enforceGUID && !aBan.ban_enforceIP)
                    {
                        this.ConsoleError("Unable to create ban, no proper player information");
                        continue;
                    }

                    //Upload the ban
                    this.DebugWrite("Uploading Ban Manager ban.", 5);
                    this.uploadBan(aBan);

                    if (++bansImported % 25 == 0)
                    {
                        this.ConsoleWrite(Math.Round(100 * bansImported / totalBans, 2) + "% of Ban Manager bans uploaded. AVG " + Math.Round(bansImported / ((DateTime.Now - startTime).TotalSeconds), 2) + " uploads/sec.");
                    }
                }
            }
            catch (Exception e)
            {
                this.ConsoleException(e.ToString());
                return;
            }
            if (inboundBBMBans.Count == 0)
            {
                this.ConsoleSuccess("All Ban Manager bans imported into AdKats Ban Enforcer!");
            }
        }
Ejemplo n.º 7
0
        //DONE
        private AdKat_Ban fetchPlayerBan(AdKat_Player player)
        {
            DebugWrite("fetchPlayerBan starting!", 6);

            AdKat_Ban aBan = null;
            try
            {
                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        //Build the query
                        string query = @"
                        SELECT
                            `adkats_banlist`.`ban_id`,
                            `adkats_banlist`.`player_id`,
                            `adkats_banlist`.`latest_record_id`,
                            `adkats_banlist`.`ban_status`,
                            `adkats_banlist`.`ban_notes`,
                            `adkats_banlist`.`ban_startTime`,
                            `adkats_banlist`.`ban_endTime`,
                            `adkats_banlist`.`ban_enforceName`,
                            `adkats_banlist`.`ban_enforceGUID`,
                            `adkats_banlist`.`ban_enforceIP`,
                            `adkats_banlist`.`ban_sync`
                        FROM
                            `adkats_banlist`
                        INNER JOIN
                            `tbl_playerdata`
                        ON
                            `tbl_playerdata`.`PlayerID` = `adkats_banlist`.`player_id`
                        WHERE
                            `adkats_banlist`.`ban_status` = 'Active'
                        AND
                        (";
                        Boolean started = false;
                        if (!String.IsNullOrEmpty(player.player_name))
                        {
                            started = true;
                            query += "(`tbl_playerdata`.`SoldierName` = '" + player.player_name + @"' AND `adkats_banlist`.`ban_enforceName` = 'Y')";
                        }
                        if (!String.IsNullOrEmpty(player.player_guid))
                        {
                            if (started)
                            {
                                query += " OR ";
                            }
                            started = true;
                            query += "(`tbl_playerdata`.`EAGUID` = '" + player.player_guid + "' AND `adkats_banlist`.`ban_enforceGUID` = 'Y')";
                        }
                        if (!String.IsNullOrEmpty(player.player_ip))
                        {
                            if (started)
                            {
                                query += " OR ";
                            }
                            started = true;
                            query += "(`tbl_playerdata`.`IP_Address` = '" + player.player_ip + "' AND `adkats_banlist`.`ban_enforceIP` = 'Y')";
                        }
                        if (!started)
                        {
                            this.ConsoleException("No data to fetch ban with, this should never happen.");
                            return null;
                        }
                        query += ")";

                        //Assign the query
                        command.CommandText = query;

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            Boolean fetchedFirstBan = false;
                            if (reader.Read())
                            {
                                fetchedFirstBan = true;
                                //Create the ban element
                                aBan = new AdKat_Ban();
                                aBan.ban_id = reader.GetInt64("ban_id");
                                aBan.ban_status = reader.GetString("ban_status");
                                aBan.ban_notes = reader.GetString("ban_notes");
                                aBan.ban_sync = reader.GetString("ban_sync");
                                aBan.ban_startTime = reader.GetDateTime("ban_startTime");
                                aBan.ban_endTime = reader.GetDateTime("ban_endTime");

                                if (reader.GetString("ban_enforceName").Equals("Y"))
                                    aBan.ban_enforceName = true;
                                else
                                    aBan.ban_enforceName = false;

                                if (reader.GetString("ban_enforceGUID").Equals("Y"))
                                    aBan.ban_enforceGUID = true;
                                else
                                    aBan.ban_enforceGUID = false;

                                if (reader.GetString("ban_enforceIP").Equals("Y"))
                                    aBan.ban_enforceIP = true;
                                else
                                    aBan.ban_enforceIP = false;

                                //Get the record information
                                aBan.ban_record = this.fetchRecordByID(reader.GetInt64("latest_record_id"));
                            }
                            if (reader.Read() && fetchedFirstBan)
                            {
                                this.ConsoleWarn("Multiple banned players matched ban information, possible duplicate account");
                            }
                        }
                    }
                    //If bans were fetched successfully, update the ban lists and sync back
                    if (aBan != null)
                    {
                        long totalSeconds = (long)this.convertToProconTime(aBan.ban_endTime).Subtract(DateTime.Now).TotalSeconds;
                        if (totalSeconds < 0)
                        {
                            aBan.ban_status = "Expired";
                            //Update the sync for this ban
                            this.updateBanStatus(aBan);
                            return null;
                        }
                        else
                        {
                            //Update the sync for this ban
                            this.updateBanStatus(aBan);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleException(e.ToString());
            }
            return aBan;
        }
Ejemplo n.º 8
0
        private void databaseCommThreadLoop()
        {
            try
            {
                this.DebugWrite("DBCOMM: Starting Database Comm Thread", 2);
                Thread.CurrentThread.Name = "databasecomm";
                Boolean firstRun = true;
                Queue<AdKat_Record> inboundRecords;
                Queue<AdKat_Ban> inboundBans;
                Queue<AdKat_Access> inboundAccessUpdates;
                Queue<String> inboundAccessRemoval;
                Queue<CPluginVariable> inboundSettingUpload;
                Queue<CBanInfo> inboundCBans;
                while (true)
                {
                    this.DebugWrite("DBCOMM: Entering Database Comm Thread Loop", 7);
                    if (!this.isEnabled)
                    {
                        this.DebugWrite("DBCOMM: Detected AdKats not enabled. Exiting thread " + Thread.CurrentThread.Name, 6);
                        break;
                    }

                    //Sleep for 10ms
                    Thread.Sleep(10);

                    //Check if database connection settings have changed
                    if (this.dbSettingsChanged)
                    {
                        this.DebugWrite("DBCOMM: DB Settings have changed, calling test.", 6);
                        if (this.testDatabaseConnection())
                        {
                            this.DebugWrite("DBCOMM: Database Connection Good. Continuing Thread.", 6);
                        }
                        else
                        {
                            this.dbSettingsChanged = true;
                            continue;
                        }
                    }

                    //Update server ID
                    if (this.server_id < 0)
                    {
                        //Checking for database server info
                        if (this.fetchServerID() >= 0)
                        {
                            this.ConsoleSuccess("Database Server Info Fetched. Server ID is " + this.server_id + "!");

                            //Now that we have the current server ID from stat logger, import all records from previous versions of AdKats
                            this.updateDB_0251_0300();

                            //Push all settings for this instance to the database
                            this.uploadAllSettings();
                        }
                        else
                        {
                            //Inform the user
                            this.ConsoleError("Database Server info could not be fetched! Make sure XpKiller's Stat Logger is running on this server!");
                            //Disable the plugin
                            this.disable();
                            break;
                        }
                    }
                    else
                    {
                        this.DebugWrite("Skipping server ID fetch. Server ID: " + this.server_id, 7);
                    }

                    //Check if settings need sync
                    if (this.settingImportID != this.server_id || this.lastDBSettingFetch.AddSeconds(this.dbSettingFetchFrequency) < DateTime.Now)
                    {
                        this.DebugWrite("Preparing to fetch settings from server " + server_id, 6);
                        //Fetch new settings from the database
                        this.fetchSettings(this.settingImportID);
                        //Update the database with setting logic employed here
                        this.uploadAllSettings();
                    }

                    //Handle Inbound Setting Uploads
                    if (this.settingUploadQueue.Count > 0)
                    {
                        this.DebugWrite("DBCOMM: Preparing to lock inbound setting queue to retrive new settings", 7);
                        lock (this.settingUploadQueue)
                        {
                            this.DebugWrite("DBCOMM: Inbound settings found. Grabbing.", 6);
                            //Grab all settings in the queue
                            inboundSettingUpload = new Queue<CPluginVariable>(this.settingUploadQueue.ToArray());
                            //Clear the queue for next run
                            this.settingUploadQueue.Clear();
                        }
                        //Loop through all settings in order that they came in
                        while (inboundSettingUpload != null && inboundSettingUpload.Count > 0)
                        {
                            CPluginVariable setting = inboundSettingUpload.Dequeue();

                            this.uploadSetting(setting);
                        }
                    }

                    //Check for new actions from the database at given interval
                    if (this.fetchActionsFromDB && (DateTime.Now > this.lastDBActionFetch.AddSeconds(this.dbActionFrequency)))
                    {
                        this.runActionsFromDB();
                    }
                    else
                    {
                        this.DebugWrite("DBCOMM: Skipping DB action fetch", 7);
                    }

                    //Handle access updates
                    if (this.playerAccessUpdateQueue.Count > 0 || this.playerAccessRemovalQueue.Count > 0)
                    {
                        this.DebugWrite("DBCOMM: Preparing to lock inbound access queues to retrive access changes", 7);
                        lock (playerAccessMutex)
                        {
                            this.DebugWrite("DBCOMM: Inbound access changes found. Grabbing.", 6);
                            //Grab all in the queue
                            inboundAccessUpdates = new Queue<AdKat_Access>(this.playerAccessUpdateQueue.ToArray());
                            inboundAccessRemoval = new Queue<String>(this.playerAccessRemovalQueue.ToArray());
                            //Clear the queue for next run
                            this.playerAccessUpdateQueue.Clear();
                            this.playerAccessRemovalQueue.Clear();
                        }
                        //Loop through all records in order that they came in
                        while (inboundAccessUpdates != null && inboundAccessUpdates.Count > 0)
                        {
                            AdKat_Access playerAccess = inboundAccessUpdates.Dequeue();
                            this.uploadPlayerAccess(playerAccess);
                        }
                        //Loop through all records in order that they came in
                        while (inboundAccessRemoval != null && inboundAccessRemoval.Count > 0)
                        {
                            String playerName = inboundAccessRemoval.Dequeue();
                            this.removePlayerAccess(playerName);
                        }
                        this.fetchAccessList();
                        //Update the setting page with new information
                        this.updateSettingPage();
                    }
                    else if (DateTime.Now > this.lastDBAccessFetch.AddSeconds(this.dbAccessFetchFrequency))
                    {
                        //Handle access updates directly from the database
                        this.fetchAccessList();
                        //Update the setting page with new information
                        this.updateSettingPage();
                    }
                    else
                    {
                        this.DebugWrite("DBCOMM: No inbound access changes.", 7);
                    }

                    //Start the other threads
                    if (firstRun)
                    {
                        //Start other threads
                        this.MessagingThread.Start();
                        this.CommandParsingThread.Start();
                        this.ActionHandlingThread.Start();
                        this.TeamSwapThread.Start();
                        this.BanEnforcerThread.Start();
                        firstRun = false;

                        this.threadsReady = true;
                        this.updateSettingPage();

                        //Register a command to indicate availibility to other plugins
                        this.RegisterCommand(AdKatsAvailableIndicator);

                        this.ConsoleWrite("^b^2Enabled!^n^0 Version: " + this.GetPluginVersion());
                    }

                    //Ban Enforcer
                    if (this.useBanEnforcer)
                    {
                        if (!this.useBanEnforcerPreviousState || (DateTime.Now > this.lastDBBanFetch.AddSeconds(this.dbBanFetchFrequency)))
                        {
                            //Load all bans on startup
                            if (!this.useBanEnforcerPreviousState)
                            {
                                //Get all bans from procon
                                this.ConsoleWarn("Preparing to queue procon bans for import. Please wait.");
                                this.dbCommHandle.Reset();
                                this.ExecuteCommand("procon.protected.send", "banList.list");
                                this.dbCommHandle.WaitOne(Timeout.Infinite);
                                this.ConsoleWrite(this.cBanProcessingQueue.Count + " procon bans queued for import. Import might take several minutes if you have many bans!");
                            }
                        }
                        else
                        {
                            this.DebugWrite("DBCOMM: Skipping DB ban fetch", 7);
                        }

                        //Handle Inbound Ban Comms
                        if (this.banEnforcerProcessingQueue.Count > 0)
                        {
                            this.DebugWrite("DBCOMM: Preparing to lock inbound ban enforcer queue to retrive new bans", 7);
                            lock (this.banEnforcerMutex)
                            {
                                this.DebugWrite("DBCOMM: Inbound bans found. Grabbing.", 6);
                                //Grab all messages in the queue
                                inboundBans = new Queue<AdKat_Ban>(this.banEnforcerProcessingQueue.ToArray());
                                //Clear the queue for next run
                                this.banEnforcerProcessingQueue.Clear();
                            }
                            Int32 index = 1;
                            //Loop through all bans in order that they came in
                            while (inboundBans != null && inboundBans.Count > 0)
                            {
                                if (!this.isEnabled || !this.useBanEnforcer)
                                {
                                    this.ConsoleWarn("Canceling ban import mid-operation.");
                                    break;
                                }
                                //Grab the ban
                                AdKat_Ban aBan = inboundBans.Dequeue();

                                this.DebugWrite("DBCOMM: Processing Frostbite Ban: " + index++, 6);

                                //Upload the ban
                                this.uploadBan(aBan);

                                //Only perform special action when ban is direct
                                //Indirect bans are through the procon banlist, so the player has already been kicked
                                if (!aBan.ban_record.source_name.Equals("BanEnforcer"))
                                {
                                    //Enforce the ban
                                    this.enforceBan(aBan);
                                }
                                else
                                {
                                    this.removePlayerFromDictionary(aBan.ban_record.target_player.player_name);
                                }
                            }
                        }

                        //Handle BF3 Ban Manager imports
                        if (!this.useBanEnforcerPreviousState)
                        {
                            //Import all bans from BF3 Ban Manager
                            this.importBansFromBBM5108();
                        }

                        //Handle Inbound CBan Uploads
                        if (this.cBanProcessingQueue.Count > 0)
                        {
                            if (!this.useBanEnforcerPreviousState)
                            {
                                this.ConsoleWarn("Do not disable AdKats or change any settings until upload is complete!");
                            }
                            this.DebugWrite("DBCOMM: Preparing to lock inbound cBan queue to retrive new cBans", 7);
                            double totalCBans = 0;
                            double bansImported = 0;
                            Boolean earlyExit = false;
                            DateTime startTime = DateTime.Now;
                            lock (this.cBanProcessingQueue)
                            {
                                this.DebugWrite("DBCOMM: Inbound cBans found. Grabbing.", 6);
                                //Grab all cBans in the queue
                                inboundCBans = new Queue<CBanInfo>(this.cBanProcessingQueue.ToArray());
                                totalCBans = inboundCBans.Count;
                                //Clear the queue for next run
                                this.cBanProcessingQueue.Clear();
                            }
                            //Loop through all cBans in order that they came in
                            AdKat_Ban aBan;
                            AdKat_Record record;
                            Boolean bansFound = false;
                            while (inboundCBans != null && inboundCBans.Count > 0)
                            {
                                //Break from the loop if the plugin is disabled or the setting is reverted.
                                if (!this.isEnabled || !this.useBanEnforcer)
                                {
                                    this.ConsoleWarn("You exited the ban upload process early, the process was not completed.");
                                    earlyExit = true;
                                    break;
                                }

                                bansFound = true;

                                CBanInfo cBan = inboundCBans.Dequeue();

                                //Create the record
                                record = new AdKat_Record();
                                record.command_source = AdKat_CommandSource.InGame;
                                //Permabans and Temp bans longer than 1 year will be defaulted to permaban
                                if (cBan.BanLength.Seconds > 0 && cBan.BanLength.Seconds < 31536000)
                                {
                                    record.command_type = AdKat_CommandType.TempBanPlayer;
                                    record.command_action = AdKat_CommandType.TempBanPlayer;
                                    record.command_numeric = cBan.BanLength.Seconds / 60;
                                }
                                else
                                {
                                    record.command_type = AdKat_CommandType.PermabanPlayer;
                                    record.command_action = AdKat_CommandType.PermabanPlayer;
                                    record.command_numeric = 0;
                                }
                                record.source_name = "BanEnforcer";
                                record.server_id = this.server_id;
                                record.target_player = this.fetchPlayer(-1, cBan.SoldierName, cBan.Guid, cBan.IpAddress);
                                if (!String.IsNullOrEmpty(record.target_player.player_name))
                                {
                                    record.target_name = record.target_player.player_name;
                                }
                                record.isIRO = false;
                                record.record_message = cBan.Reason;

                                //Create the ban
                                aBan = new AdKat_Ban();
                                aBan.ban_record = record;

                                //Update the ban enforcement depending on available information
                                Boolean nameAvailable = !String.IsNullOrEmpty(record.target_player.player_name);
                                Boolean GUIDAvailable = !String.IsNullOrEmpty(record.target_player.player_guid);
                                Boolean IPAvailable = !String.IsNullOrEmpty(record.target_player.player_ip);
                                aBan.ban_enforceName = nameAvailable && (this.defaultEnforceName || (!GUIDAvailable && !IPAvailable) || !String.IsNullOrEmpty(cBan.SoldierName));
                                aBan.ban_enforceGUID = GUIDAvailable && (this.defaultEnforceGUID || (!nameAvailable && !IPAvailable) || !String.IsNullOrEmpty(cBan.Guid));
                                aBan.ban_enforceIP = IPAvailable && (this.defaultEnforceIP || (!nameAvailable && !GUIDAvailable) || !String.IsNullOrEmpty(cBan.IpAddress));
                                if (!aBan.ban_enforceName && !aBan.ban_enforceGUID && !aBan.ban_enforceIP)
                                {
                                    this.ConsoleError("Unable to create ban, no proper player information");
                                    continue;
                                }

                                //Upload the ban
                                this.DebugWrite("Uploading ban from procon.", 5);
                                this.uploadBan(aBan);

                                if (!this.useBanEnforcerPreviousState && (++bansImported % 25 == 0))
                                {
                                    this.ConsoleWrite(Math.Round(100 * bansImported / totalCBans, 2) + "% of bans uploaded. AVG " + Math.Round(bansImported / ((DateTime.Now - startTime).TotalSeconds), 2) + " uploads/sec.");
                                }
                            }
                            if (bansFound && !earlyExit)
                            {
                                //If all bans have been queued for processing, clear the ban list
                                this.ExecuteCommand("procon.protected.send", "banList.clear");
                                this.ExecuteCommand("procon.protected.send", "banList.save");
                                this.ExecuteCommand("procon.protected.send", "banList.list");
                                if (!this.useBanEnforcerPreviousState)
                                {
                                    this.ConsoleSuccess("All bans uploaded into AdKats database.");
                                }
                            }
                        }

                        this.useBanEnforcerPreviousState = true;
                    }
                    else
                    {
                        //If the ban enforcer was previously enabled, and the user disabled it, repopulate procon's ban list
                        if (this.useBanEnforcerPreviousState)
                        {
                            this.repopulateProconBanList();
                            this.useBanEnforcerPreviousState = false;
                            this.bansFirstListed = false;
                        }
                        //If not, completely ignore all ban enforcer code
                    }

                    //Handle Inbound Records
                    if (this.unprocessedRecordQueue.Count > 0)
                    {
                        this.DebugWrite("DBCOMM: Preparing to lock inbound record queue to retrive new records", 7);
                        lock (this.unprocessedRecordMutex)
                        {
                            this.DebugWrite("DBCOMM: Inbound records found. Grabbing.", 6);
                            //Grab all messages in the queue
                            inboundRecords = new Queue<AdKat_Record>(this.unprocessedRecordQueue.ToArray());
                            //Clear the queue for next run
                            this.unprocessedRecordQueue.Clear();
                        }
                        //Loop through all records in order that they came in
                        while (inboundRecords != null && inboundRecords.Count > 0)
                        {
                            AdKat_Record record = inboundRecords.Dequeue();

                            //Only run action if the record needs action
                            if (this.handleRecordUpload(record))
                            {
                                //Action is only called after initial upload, not after update
                                this.DebugWrite("DBCOMM: Upload success. Attempting to add to action queue.", 6);

                                //Only queue the record for action handling if it's not an enforced ban
                                if (record.command_type != AdKat_CommandType.EnforceBan)
                                {
                                    this.queueRecordForActionHandling(record);
                                }
                            }
                            else
                            {
                                //Performance testing area
                                if (record.source_name == this.debugSoldierName)
                                {
                                    this.sendMessageToSource(record, "Duration: " + ((int)DateTime.Now.Subtract(this.commandStartTime).TotalMilliseconds) + "ms");
                                }
                                this.DebugWrite("DBCOMM: Update success. Record does not need action handling.", 6);
                            }
                        }
                    }
                    else
                    {
                        this.DebugWrite("DBCOMM: No unprocessed records. Waiting for input", 7);
                        this.dbCommHandle.Reset();

                        if (this.fetchActionsFromDB || this.useBanEnforcer || this.usingAWA)
                        {
                            //If waiting on DB input, the maximum time we can wait is "db action frequency"
                            this.dbCommHandle.WaitOne(this.dbActionFrequency * 1000);
                        }
                        else
                        {
                            //Maximum wait time is DB access fetch time
                            this.dbCommHandle.WaitOne(this.dbAccessFetchFrequency * 1000);
                        }
                    }
                }
                this.DebugWrite("DBCOMM: Ending Database Comm Thread", 2);
            }
            catch (Exception e)
            {
                this.ConsoleException(e.ToString());
                if (typeof(ThreadAbortException).Equals(e.GetType()))
                {
                    this.DebugWrite("Thread Exception", 4);
                    Thread.ResetAbort();
                    return;
                }
            }
        }
Ejemplo n.º 9
0
        public string tempBanTarget(AdKat_Record record, string additionalMessage)
        {
            //Subtract 1 second for visual effect
            Int32 seconds = (record.command_numeric * 60) - 1;

            //Calculate the remaining ban time
            TimeSpan remainingTime = TimeSpan.FromSeconds(seconds);

            //Create the prefix and suffix for the ban
            string banMessagePrefix = "" + record.source_name + " [" + this.formatTimeString(remainingTime) + "] ";
            string banMessageSuffix = ((this.useBanAppend) ? (" - " + this.banAppend) : (""));
            //Create the total kick message
            string banMessage = banMessagePrefix + record.record_message + banMessageSuffix;

            //Trim the kick message if necessary
            int cutLength = banMessage.Length - 80;
            if (cutLength > 0)
            {
                string cutReason = record.record_message.Substring(0, record.record_message.Length - cutLength);
                banMessage = banMessagePrefix + cutReason + banMessageSuffix;
            }
            this.DebugWrite("Ban Message: '" + banMessage + "'", 3);

            //Perform Actions
            if (this.useBanEnforcer)
            {
                //Create the ban
                AdKat_Ban aBan = new AdKat_Ban();
                aBan.ban_record = record;

                //Update the ban enforcement depending on available information
                aBan.ban_enforceName = false;
                aBan.ban_enforceGUID = !String.IsNullOrEmpty(record.target_player.player_guid);
                aBan.ban_enforceIP = false;

                this.queueBanForProcessing(aBan);
            }
            else
            {
                if (!String.IsNullOrEmpty(record.target_player.player_guid))
                {
                    this.ExecuteCommand("procon.protected.send", "banList.add", "guid", record.target_player.player_guid, "seconds", seconds + "", banMessage);
                    this.ExecuteCommand("procon.protected.send", "banList.save");
                    this.ExecuteCommand("procon.protected.send", "banList.list");
                }
                else if (!String.IsNullOrEmpty(record.target_player.player_ip))
                {
                    this.ExecuteCommand("procon.protected.send", "banList.add", "ip", record.target_player.player_ip, "seconds", seconds + "", banMessage);
                    this.ExecuteCommand("procon.protected.send", "banList.save");
                    this.ExecuteCommand("procon.protected.send", "banList.list");
                }
                else if (!String.IsNullOrEmpty(record.target_player.player_name))
                {
                    this.ExecuteCommand("procon.protected.send", "banList.add", "name", record.target_player.player_name, "seconds", seconds + "", banMessage);
                    this.ExecuteCommand("procon.protected.send", "banList.save");
                    this.ExecuteCommand("procon.protected.send", "banList.list");
                }
                else
                {
                    this.ConsoleError("Player has no information to ban with.");
                    return "ERROR";
                }

                this.removePlayerFromDictionary(record.target_player.player_name);
            }
            this.ExecuteCommand("procon.protected.send", "admin.say", "Player " + record.target_name + " was BANNED by admin for " + record.record_message + " " + additionalMessage, "all");

            return this.sendMessageToSource(record, "You TEMP BANNED " + record.target_name + " for " + record.command_numeric + " minutes. " + additionalMessage);
        }
Ejemplo n.º 10
0
        public string permaBanTarget(AdKat_Record record, string additionalMessage)
        {
            //Create the prefix and suffix for the ban
            string banMessagePrefix = "" + record.source_name + " [perm] ";
            string banMessageSuffix = ((this.useBanAppend) ? (" - " + this.banAppend) : (""));
            //Create the total kick message
            string banMessage = banMessagePrefix + record.record_message + banMessageSuffix;

            //Trim the kick message if necessary
            int cutLength = banMessage.Length - 80;
            if (cutLength > 0)
            {
                string cutReason = record.record_message.Substring(0, record.record_message.Length - cutLength);
                banMessage = banMessagePrefix + cutReason + banMessageSuffix;
            }
            this.DebugWrite("Ban Message: '" + banMessage + "'", 3);

            //Perform Actions
            if (this.useBanEnforcer)
            {
                //Create the ban
                AdKat_Ban aBan = new AdKat_Ban();
                aBan.ban_record = record;

                //Update the ban enforcement depending on available information
                aBan.ban_enforceName = false;
                aBan.ban_enforceGUID = !String.IsNullOrEmpty(record.target_player.player_guid);
                aBan.ban_enforceIP = false;

                this.queueBanForProcessing(aBan);
            }
            else
            {
                this.DebugWrite("BANNING: " + banMessage, 4);
                if (!String.IsNullOrEmpty(record.target_player.player_guid))
                {
                    this.ExecuteCommand("procon.protected.send", "banList.add", "guid", record.target_player.player_guid, "perm", banMessage);
                    this.ExecuteCommand("procon.protected.send", "banList.save");
                    this.ExecuteCommand("procon.protected.send", "banList.list");
                }
                else if (!String.IsNullOrEmpty(record.target_player.player_ip))
                {
                    this.ExecuteCommand("procon.protected.send", "banList.add", "ip", record.target_player.player_ip, "perm", banMessage);
                    this.ExecuteCommand("procon.protected.send", "banList.save");
                    this.ExecuteCommand("procon.protected.send", "banList.list");
                }
                else if (!String.IsNullOrEmpty(record.target_player.player_name))
                {
                    this.ExecuteCommand("procon.protected.send", "banList.add", "name", record.target_player.player_name, "perm", banMessage);
                    this.ExecuteCommand("procon.protected.send", "banList.save");
                    this.ExecuteCommand("procon.protected.send", "banList.list");
                }
                else
                {
                    this.ConsoleError("Player has no information to ban with.");
                    return "ERROR";
                }

                this.removePlayerFromDictionary(record.target_player.player_name);
            }
            this.ExecuteCommand("procon.protected.send", "admin.say", "Player " + record.target_name + " was BANNED by admin for " + record.record_message + additionalMessage, "all");

            return this.sendMessageToSource(record, "You PERMA BANNED " + record.target_name + "! Get a vet admin NOW!" + additionalMessage);
        }
Ejemplo n.º 11
0
        public string enforceBan(AdKat_Ban aBan)
        {
            //Create the prefix and suffix for the ban
            string kickMessagePrefix = "" + aBan.ban_record.source_name;
            //If ban time > 1000 days just say perm ban
            TimeSpan remainingTime = this.getRemainingBanTime(aBan);

            if (remainingTime.TotalDays > 1000)
            {
                kickMessagePrefix += " [perm] ";
            }
            else
            {
                kickMessagePrefix += " [" + this.formatTimeString(remainingTime) + "] ";
            }
            string kickMessageSuffix = ((this.useBanAppend) ? (" - " + this.banAppend) : (""));
            //Create the total kick message
            string kickMessage = kickMessagePrefix + aBan.ban_record.record_message + kickMessageSuffix;

            //Trim the kick message if necessary
            int cutLength = kickMessage.Length - 80;
            if (cutLength > 0)
            {
                string cutReason = aBan.ban_record.record_message.Substring(0, aBan.ban_record.record_message.Length - cutLength);
                kickMessage = kickMessagePrefix + cutReason + kickMessageSuffix;
            }
            this.DebugWrite("Ban Enforce Message: '" + kickMessage + "'", 3);

            //Perform Actions
            ExecuteCommand("procon.protected.send", "admin.kickPlayer", aBan.ban_record.target_player.player_name, kickMessage);

            this.removePlayerFromDictionary(aBan.ban_record.target_player.player_name);
            //Inform the server of the enforced ban
            this.adminSay("Enforcing ban on " + aBan.ban_record.target_player.player_name + " for " + aBan.ban_record.record_message);
            return "Ban Enforced";
        }