Example #1
0
 private void FetchCommands()
 {
     this.DebugWrite("fetchCommands starting!", 6);
     //Make sure database connection active
     if (this.HandlePossibleDisconnect()) {
         return;
     }
     try {
         //Lock all command dictionaries for this operation
         lock (this._CommandIDDictionary) {
             lock (this._CommandKeyDictionary) {
                 lock (this._CommandNameDictionary) {
                     lock (this._CommandTextDictionary) {
                         //Create the connection
                         using (MySqlConnection connection = this.GetDatabaseConnection()) {
                             //Create the command
                             using (MySqlCommand sqlcommand = connection.CreateCommand()) {
                                 //Query to fetch all commands
                                 const string sql = @"
                                 SELECT
                                     `command_id`,
                                     `command_active`,
                                     `command_key`,
                                     `command_logging`,
                                     `command_name`,
                                     `command_text`,
                                     `command_playerInteraction`
                                 FROM
                                     `adkats_commands`";
                                 sqlcommand.CommandText = sql;
                                 List<AdKatsCommand> commandList = new List<AdKatsCommand>();
                                 using (MySqlDataReader reader = sqlcommand.ExecuteReader()) {
                                     //Grab the commands
                                     while (reader.Read()) {
                                         //Create as new AdKats_Command
                                         AdKatsCommand command = new AdKatsCommand {
                                                                                       command_id = reader.GetInt32("command_id"),
                                                                                       command_active = (AdKatsCommand.CommandActive) Enum.Parse(typeof (AdKatsCommand.CommandActive), reader.GetString("command_active")),
                                                                                       command_key = reader.GetString("command_key"),
                                                                                       command_logging = (AdKatsCommand.CommandLogging) Enum.Parse(typeof (AdKatsCommand.CommandLogging), reader.GetString("command_logging")),
                                                                                       command_name = reader.GetString("command_name"),
                                                                                       command_text = reader.GetString("command_text"),
                                                                                       command_playerInteraction = reader.GetBoolean("command_playerInteraction")
                                                                                   };
                                         //Add the command to temp list
                                         commandList.Add(command);
                                     }
                                 }
                                 if (commandList.Count > 0) {
                                     //Empty all the command dictionaries
                                     this._CommandIDDictionary.Clear();
                                     this._CommandKeyDictionary.Clear();
                                     this._CommandNameDictionary.Clear();
                                     this._CommandTextDictionary.Clear();
                                     //Loop over each command found and add it into the dictionaries
                                     foreach (AdKatsCommand command in commandList) {
                                         this._CommandIDDictionary.Add(command.command_id, command);
                                         this._CommandKeyDictionary.Add(command.command_key, command);
                                         this._CommandNameDictionary.Add(command.command_name, command);
                                         this._CommandTextDictionary.Add(command.command_text, command);
                                     }
                                     //Successful
                                     return;
                                 }
                                 this.ConsoleError("Commands could not be fetched.");
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e) {
         this.HandleException(new AdKatsException("Error while fetching commands from database.", e));
     }
     this.DebugWrite("fetchCommands finished!", 6);
 }
Example #2
0
 private Boolean HasAccess(AdKatsPlayer aPlayer, AdKatsCommand command)
 {
     try {
         if (aPlayer == null) {
             this.ConsoleError("player was null in hasAccess.");
             return false;
         }
         if (aPlayer.player_role == null) {
             this.ConsoleError("player role was null in hasAccess.");
             return false;
         }
         if (command == null) {
             this.ConsoleError("Command was null in hasAccess.");
             return false;
         }
         lock (aPlayer.player_role) {
             lock (aPlayer.player_role.allowedCommands) {
                 foreach (AdKatsCommand innerCommand in aPlayer.player_role.allowedCommands.Values) {
                     if (innerCommand.command_active != AdKatsCommand.CommandActive.Disabled && command.command_id == innerCommand.command_id)
                         return true;
                 }
             }
         }
         return false;
     }
     catch (Exception e) {
         this.HandleException(new AdKatsException("Error while checking command access on player.", e));
         return false;
     }
 }
Example #3
0
        private void UploadCommand(AdKatsCommand command)
        {
            DebugWrite("uploadCommand starting!", 6);

            //Make sure database connection active
            if (this.HandlePossibleDisconnect()) {
                return;
            }
            try {
                using (MySqlConnection connection = this.GetDatabaseConnection()) {
                    using (MySqlCommand sqlcommand = connection.CreateCommand()) {
                        //Set the insert command structure
                        sqlcommand.CommandText = @"
                        INSERT INTO
                        `" + this._MySqlDatabaseName + @"`.`adkats_commands`
                        (
                            `command_id`,
                            `command_active`,
                            `command_key`,
                            `command_logging`,
                            `command_name`,
                            `command_text`,
                            `command_playerInteraction`
                        )
                        VALUES
                        (
                            @command_id,
                            @command_active,
                            @command_key,
                            @command_logging,
                            @command_name,
                            @command_text,
                            @command_playerInteraction
                        )
                        ON DUPLICATE KEY
                        UPDATE
                            `command_active` = @command_active,
                            `command_logging` = @command_logging,
                            `command_name` = @command_name,
                            `command_text` = @command_text,
                            `command_playerInteraction` = @command_playerInteraction";

                        //Fill the command
                        sqlcommand.Parameters.AddWithValue("@command_id", command.command_id);
                        sqlcommand.Parameters.AddWithValue("@command_active", command.command_active.ToString());
                        sqlcommand.Parameters.AddWithValue("@command_key", command.command_key);
                        sqlcommand.Parameters.AddWithValue("@command_logging", command.command_logging.ToString());
                        sqlcommand.Parameters.AddWithValue("@command_name", command.command_name);
                        sqlcommand.Parameters.AddWithValue("@command_text", command.command_text);
                        sqlcommand.Parameters.AddWithValue("@command_playerInteraction", command.command_playerInteraction);

                        //Get reference to the command in case of error
                        //Attempt to execute the query
                        if (sqlcommand.ExecuteNonQuery() > 0) {
                        }
                    }
                }

                DebugWrite("uploadCommand finished!", 6);
            }
            catch (Exception e) {
                this.HandleException(new AdKatsException("Unexpected error uploading command.", e));
            }
        }
Example #4
0
 private void QueueCommandForUpload(AdKatsCommand command)
 {
     this.DebugWrite("Entering queueCommandForUpload", 7);
     try {
         if (this._IsEnabled) {
             this.DebugWrite("Preparing to queue command " + command.command_key + " for upload", 6);
             lock (this._CommandUploadQueue) {
                 this._CommandUploadQueue.Enqueue(command);
                 this._DbCommunicationWaitHandle.Set();
             }
         }
     }
     catch (Exception e) {
         this.HandleException(new AdKatsException("Error while queueing command for upload.", e));
     }
     this.DebugWrite("Exiting queueCommandForUpload", 7);
 }
Example #5
0
 private void QueueCommandForUpload(AdKatsCommand command) {
     DebugWrite("Entering queueCommandForUpload", 7);
     try {
         if (_pluginEnabled) {
             DebugWrite("Preparing to queue command " + command.command_key + " for upload", 6);
             if (_isTestingAuthorized)
                 PushThreadDebug(DateTime.Now.Ticks, (String.IsNullOrEmpty(Thread.CurrentThread.Name) ? ("mainthread") : (Thread.CurrentThread.Name)), Thread.CurrentThread.ManagedThreadId, new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber(), "");
             lock (_CommandUploadQueue) {
                 _CommandUploadQueue.Enqueue(command);
                 _DbCommunicationWaitHandle.Set();
             }
         }
     }
     catch (Exception e) {
         HandleException(new AdKatsException("Error while queueing command for upload.", e));
     }
     DebugWrite("Exiting queueCommandForUpload", 7);
 }
Example #6
0
        private void FetchCommands() {
            DebugWrite("fetchCommands starting!", 6);
            if (HandlePossibleDisconnect()) {
                return;
            }
            try {
                if (_isTestingAuthorized)
                    PushThreadDebug(DateTime.Now.Ticks, (String.IsNullOrEmpty(Thread.CurrentThread.Name) ? ("mainthread") : (Thread.CurrentThread.Name)), Thread.CurrentThread.ManagedThreadId, new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber(), "");
                lock (_CommandIDDictionary) {
                    using (MySqlConnection connection = GetDatabaseConnection()) {
                        using (MySqlCommand sqlcommand = connection.CreateCommand()) {
                            const string sql = @"
                            SELECT 
	                            `command_id`,
	                            `command_active`,
	                            `command_key`,
	                            `command_logging`,
	                            `command_name`,
	                            `command_text`,
                                `command_playerInteraction`
                            FROM 
	                            `adkats_commands`";
                            sqlcommand.CommandText = sql;
                            var validIDs = new HashSet<Int64>();
                            using (MySqlDataReader reader = sqlcommand.ExecuteReader()) {
                                _CommandKeyDictionary.Clear();
                                _CommandNameDictionary.Clear();
                                _CommandTextDictionary.Clear();
                                while (reader.Read()) {
                                    //ID is the immutable element
                                    int commandID = reader.GetInt32("command_id");
                                    var commandActive = (AdKatsCommand.CommandActive) Enum.Parse(typeof (AdKatsCommand.CommandActive), reader.GetString("command_active"));
                                    string commandKey = reader.GetString("command_key");
                                    var commandLogging = (AdKatsCommand.CommandLogging) Enum.Parse(typeof (AdKatsCommand.CommandLogging), reader.GetString("command_logging"));
                                    string commandName = reader.GetString("command_name");
                                    string commandText = reader.GetString("command_text");
                                    bool commandPlayerInteraction = reader.GetBoolean("command_playerInteraction");

                                    validIDs.Add(commandID);
                                    AdKatsCommand currentCommand;
                                    if (_CommandIDDictionary.TryGetValue(commandID, out currentCommand)) {
                                        if (!currentCommand.command_active.Equals(commandActive)) {
                                            ConsoleWarn(currentCommand.command_key + " active state being changed from " + currentCommand.command_active + " to " + commandActive);
                                            currentCommand.command_active = commandActive;
                                        }
                                        if (currentCommand.command_key != commandKey) {
                                            ConsoleWarn(currentCommand.command_key + " command key being changed from " + currentCommand.command_key + " to " + commandKey);
                                            currentCommand.command_key = commandKey;
                                        }
                                        if (!currentCommand.command_logging.Equals((commandLogging))) {
                                            ConsoleWarn(currentCommand.command_key + " logging state being changed from " + currentCommand.command_logging + " to " + commandLogging);
                                            currentCommand.command_logging = commandLogging;
                                        }
                                        if (currentCommand.command_name != commandName) {
                                            ConsoleWarn(currentCommand.command_key + " command name being changed from " + currentCommand.command_name + " to " + commandName);
                                            currentCommand.command_name = commandName;
                                        }
                                        if (currentCommand.command_text != commandText) {
                                            ConsoleWarn(currentCommand.command_key + " command text being changed from " + currentCommand.command_text + " to " + commandText);
                                            currentCommand.command_text = commandText;
                                        }
                                        if (currentCommand.command_playerInteraction != commandPlayerInteraction) {
                                            ConsoleWarn(currentCommand.command_key + " player interaction state being changed from " + currentCommand.command_playerInteraction + " to " + commandPlayerInteraction);
                                            currentCommand.command_playerInteraction = commandPlayerInteraction;
                                        }
                                    }
                                    else {
                                        currentCommand = new AdKatsCommand {
                                            command_id = commandID,
                                            command_active = commandActive,
                                            command_key = commandKey,
                                            command_logging = commandLogging,
                                            command_name = commandName,
                                            command_text = commandText,
                                            command_playerInteraction = commandPlayerInteraction
                                        };

                                        _CommandIDDictionary.Add(currentCommand.command_id, currentCommand);
                                    }
                                    _CommandKeyDictionary.Add(currentCommand.command_key, currentCommand);
                                    _CommandNameDictionary.Add(currentCommand.command_name, currentCommand);
                                    _CommandTextDictionary.Add(currentCommand.command_text, currentCommand);
                                    _commandUsageTimes[currentCommand.command_key] = DateTime.UtcNow;
                                }
                            }
                            if (_CommandIDDictionary.Count > 0) {
                                foreach (AdKatsCommand remCommand in _CommandIDDictionary.Values.Where(aRole => !validIDs.Contains(aRole.command_id)).ToList()) {
                                    ConsoleWarn("Removing command " + remCommand.command_key);
                                    _CommandIDDictionary.Remove(remCommand.command_id);
                                }
                                Boolean changed = false;
                                if (!_CommandIDDictionary.ContainsKey(1)) {
                                    SendNonQuery("Adding command 1", "REPLACE INTO `adkats_commands` VALUES(1, 'Active', 'command_confirm', 'Unable', 'Confirm Command', 'yes', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(2)) {
                                    SendNonQuery("Adding command 2", "REPLACE INTO `adkats_commands` VALUES(2, 'Active', 'command_cancel', 'Unable', 'Cancel Command', 'no', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(3)) {
                                    SendNonQuery("Adding command 3", "REPLACE INTO `adkats_commands` VALUES(3, 'Active', 'player_kill', 'Log', 'Kill Player', 'kill', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(4)) {
                                    SendNonQuery("Adding command 4", "REPLACE INTO `adkats_commands` VALUES(4, 'Invisible', 'player_kill_lowpop', 'Log', 'Kill Player (Low Population)', 'lowpopkill', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(5)) {
                                    SendNonQuery("Adding command 5", "REPLACE INTO `adkats_commands` VALUES(5, 'Invisible', 'player_kill_repeat', 'Log', 'Kill Player (Repeat Kill)', 'repeatkill', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(6)) {
                                    SendNonQuery("Adding command 6", "REPLACE INTO `adkats_commands` VALUES(6, 'Active', 'player_kick', 'Log', 'Kick Player', 'kick', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(7)) {
                                    SendNonQuery("Adding command 7", "REPLACE INTO `adkats_commands` VALUES(7, 'Active', 'player_ban_temp', 'Log', 'Temp-Ban Player', 'tban', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(8)) {
                                    SendNonQuery("Adding command 8", "REPLACE INTO `adkats_commands` VALUES(8, 'Active', 'player_ban_perm', 'Log', 'Permaban Player', 'ban', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(9)) {
                                    SendNonQuery("Adding command 9", "REPLACE INTO `adkats_commands` VALUES(9, 'Active', 'player_punish', 'Mandatory', 'Punish Player', 'punish', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(10)) {
                                    SendNonQuery("Adding command 10", "REPLACE INTO `adkats_commands` VALUES(10, 'Active', 'player_forgive', 'Mandatory', 'Forgive Player', 'forgive', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(11)) {
                                    SendNonQuery("Adding command 11", "REPLACE INTO `adkats_commands` VALUES(11, 'Active', 'player_mute', 'Log', 'Mute Player', 'mute', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(12)) {
                                    SendNonQuery("Adding command 12", "REPLACE INTO `adkats_commands` VALUES(12, 'Active', 'player_join', 'Log', 'Join Player', 'join', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(14)) {
                                    SendNonQuery("Adding command 14", "REPLACE INTO `adkats_commands` VALUES(14, 'Active', 'player_move', 'Log', 'On-Death Move Player', 'move', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(15)) {
                                    SendNonQuery("Adding command 15", "REPLACE INTO `adkats_commands` VALUES(15, 'Active', 'player_fmove', 'Log', 'Force Move Player', 'fmove', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(16)) {
                                    SendNonQuery("Adding command 16", "REPLACE INTO `adkats_commands` VALUES(16, 'Active', 'self_teamswap', 'Log', 'Teamswap Self', 'moveme', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(17)) {
                                    SendNonQuery("Adding command 17", "REPLACE INTO `adkats_commands` VALUES(17, 'Active', 'self_kill', 'Log', 'Kill Self', 'killme', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(18)) {
                                    SendNonQuery("Adding command 18", "REPLACE INTO `adkats_commands` VALUES(18, 'Active', 'player_report', 'Log', 'Report Player', 'report', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(19)) {
                                    SendNonQuery("Adding command 19", "REPLACE INTO `adkats_commands` VALUES(19, 'Invisible', 'player_report_confirm', 'Log', 'Report Player (Confirmed)', 'confirmreport', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(20)) {
                                    SendNonQuery("Adding command 20", "REPLACE INTO `adkats_commands` VALUES(20, 'Active', 'player_calladmin', 'Log', 'Call Admin on Player', 'admin', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(21)) {
                                    SendNonQuery("Adding command 21", "REPLACE INTO `adkats_commands` VALUES(21, 'Active', 'admin_say', 'Log', 'Admin Say', 'say', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(22)) {
                                    SendNonQuery("Adding command 22", "REPLACE INTO `adkats_commands` VALUES(22, 'Active', 'player_say', 'Log', 'Player Say', 'psay', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(23)) {
                                    SendNonQuery("Adding command 23", "REPLACE INTO `adkats_commands` VALUES(23, 'Active', 'admin_yell', 'Log', 'Admin Yell', 'yell', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(24)) {
                                    SendNonQuery("Adding command 24", "REPLACE INTO `adkats_commands` VALUES(24, 'Active', 'player_yell', 'Log', 'Player Yell', 'pyell', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(25)) {
                                    SendNonQuery("Adding command 25", "REPLACE INTO `adkats_commands` VALUES(25, 'Active', 'admin_tell', 'Log', 'Admin Tell', 'tell', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(26)) {
                                    SendNonQuery("Adding command 26", "REPLACE INTO `adkats_commands` VALUES(26, 'Active', 'player_tell', 'Log', 'Player Tell', 'ptell', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(27)) {
                                    SendNonQuery("Adding command 27", "REPLACE INTO `adkats_commands` VALUES(27, 'Active', 'self_whatis', 'Unable', 'What Is', 'whatis', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(28)) {
                                    SendNonQuery("Adding command 28", "REPLACE INTO `adkats_commands` VALUES(28, 'Active', 'self_voip', 'Unable', 'VOIP', 'voip', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(29)) {
                                    SendNonQuery("Adding command 29", "REPLACE INTO `adkats_commands` VALUES(29, 'Active', 'self_rules', 'Log', 'Request Rules', 'rules', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(30)) {
                                    SendNonQuery("Adding command 30", "REPLACE INTO `adkats_commands` VALUES(30, 'Active', 'round_restart', 'Log', 'Restart Current Round', 'restart', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(31)) {
                                    SendNonQuery("Adding command 31", "REPLACE INTO `adkats_commands` VALUES(31, 'Active', 'round_next', 'Log', 'Run Next Round', 'nextlevel', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(32)) {
                                    SendNonQuery("Adding command 32", "REPLACE INTO `adkats_commands` VALUES(32, 'Active', 'round_end', 'Log', 'End Current Round', 'endround', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(33)) {
                                    SendNonQuery("Adding command 33", "REPLACE INTO `adkats_commands` VALUES(33, 'Active', 'server_nuke', 'Log', 'Server Nuke', 'nuke', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(34)) {
                                    SendNonQuery("Adding command 34", "REPLACE INTO `adkats_commands` VALUES(34, 'Active', 'server_kickall', 'Log', 'Kick All Guests', 'kickall', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(35)) {
                                    SendNonQuery("Adding command 35", "REPLACE INTO `adkats_commands` VALUES(35, 'Invisible', 'adkats_exception', 'Mandatory', 'Logged Exception', 'logexception', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(36)) {
                                    SendNonQuery("Adding command 36", "REPLACE INTO `adkats_commands` VALUES(36, 'Invisible', 'banenforcer_enforce', 'Mandatory', 'Enforce Active Ban', 'enforceban', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(37)) {
                                    SendNonQuery("Adding command 37", "REPLACE INTO `adkats_commands` VALUES(37, 'Active', 'player_unban', 'Log', 'Unban Player', 'unban', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(38)) {
                                    SendNonQuery("Adding command 38", "REPLACE INTO `adkats_commands` VALUES(38, 'Active', 'self_admins', 'Log', 'Request Online Admins', 'admins', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(39)) {
                                    SendNonQuery("Adding command 39", "REPLACE INTO `adkats_commands` VALUES(39, 'Active', 'self_lead', 'Log', 'Lead Current Squad', 'lead', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(40)) {
                                    SendNonQuery("Adding command 40", "REPLACE INTO `adkats_commands` VALUES(40, 'Active', 'admin_accept', 'Log', 'Accept Round Report', 'accept', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(41)) {
                                    SendNonQuery("Adding command 41", "REPLACE INTO `adkats_commands` VALUES(41, 'Active', 'admin_deny', 'Log', 'Deny Round Report', 'deny', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(42)) {
                                    SendNonQuery("Adding command 42", "REPLACE INTO `adkats_commands` VALUES(42, 'Invisible', 'player_report_deny', 'Log', 'Report Player (Denied)', 'denyreport', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(43)) {
                                    SendNonQuery("Adding command 43", "REPLACE INTO `adkats_commands` VALUES(43, 'Active', 'server_swapnuke', 'Log', 'SwapNuke Server', 'swapnuke', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(44)) {
                                    SendNonQuery("Adding command 44", "REPLACE INTO `adkats_commands` VALUES(44, 'Active', 'player_blacklistdisperse', 'Log', 'Blacklist Disperse Player', 'disperse', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(45)) {
                                    SendNonQuery("Adding command 45", "REPLACE INTO `adkats_commands` VALUES(45, 'Active', 'player_whitelistbalance', 'Log', 'Autobalance Whitelist Player', 'mbwhitelist', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(46)) {
                                    SendNonQuery("Adding command 46", "REPLACE INTO `adkats_commands` VALUES(46, 'Active', 'player_slotreserved', 'Log', 'Reserved Slot Player', 'reserved', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(47)) {
                                    SendNonQuery("Adding command 47", "REPLACE INTO `adkats_commands` VALUES(47, 'Active', 'player_slotspectator', 'Log', 'Spectator Slot Player', 'spectator', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(48)) {
                                    SendNonQuery("Adding command 48", "REPLACE INTO `adkats_commands` VALUES(48, 'Invisible', 'player_changename', 'Log', 'Player Changed Name', 'changename', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(49)) {
                                    SendNonQuery("Adding command 49", "REPLACE INTO `adkats_commands` VALUES(49, 'Invisible', 'player_changeip', 'Log', 'Player Changed IP', 'changeip', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(50)) {
                                    SendNonQuery("Adding command 50", "REPLACE INTO `adkats_commands` VALUES(50, 'Active', 'player_ban_perm_future', 'Log', 'Future Permaban Player', 'fban', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(51)) {
                                    SendNonQuery("Adding command 51", "REPLACE INTO `adkats_commands` VALUES(51, 'Active', 'self_assist', 'Log', 'Assist Losing Team', 'assist', FALSE)", true);
                                    changed = true;
                                }
                                SendNonQuery("Updating command 51 player interaction", "UPDATE `adkats_commands` SET `command_playerInteraction`=0 WHERE `command_id`=51", false);
                                if (!_CommandIDDictionary.ContainsKey(52)) {
                                    SendNonQuery("Adding command 52", "REPLACE INTO `adkats_commands` VALUES(52, 'Active', 'self_uptime', 'Log', 'Request Uptimes', 'uptime', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(53)) {
                                    SendNonQuery("Adding command 53", "REPLACE INTO `adkats_commands` VALUES(53, 'Active', 'self_contest', 'Log', 'Contest Report', 'contest', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(54)) {
                                    SendNonQuery("Adding command 54", "REPLACE INTO `adkats_commands` VALUES(54, 'Active', 'player_kill_force', 'Log', 'Kill Player (Force)', 'fkill', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(55))
                                {
                                    SendNonQuery("Adding command 55", "REPLACE INTO `adkats_commands` VALUES(55, 'Active', 'player_info', 'Log', 'Fetch Player Info', 'pinfo', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(56))
                                {
                                    SendNonQuery("Adding command 56", "REPLACE INTO `adkats_commands` VALUES(56, 'Active', 'player_dequeue', 'Log', 'Dequeue Player Action', 'deq', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(57))
                                {
                                    SendNonQuery("Adding command 57", "REPLACE INTO `adkats_commands` VALUES(57, 'Active', 'self_help', 'Log', 'Request Server Commands', 'help', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(58))
                                {
                                    SendNonQuery("Adding command 58", "REPLACE INTO `adkats_commands` VALUES(58, 'Active', 'player_find', 'Log', 'Find Player', 'find', FALSE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(59))
                                {
                                    SendNonQuery("Adding command 59", "REPLACE INTO `adkats_commands` VALUES(59, 'Active', 'server_afk', 'Log', 'Manage AFK Players', 'afk', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(60))
                                {
                                    SendNonQuery("Adding command 60", "REPLACE INTO `adkats_commands` VALUES(60, 'Active', 'player_pull', 'Log', 'Pull Player', 'pull', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(61))
                                {
                                    SendNonQuery("Adding command 61", "REPLACE INTO `adkats_commands` VALUES(61, 'Active', 'admin_ignore', 'Log', 'Ignore Round Report', 'ignore', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(62))
                                {
                                    SendNonQuery("Adding command 62", "REPLACE INTO `adkats_commands` VALUES(62, 'Invisible', 'player_report_ignore', 'Log', 'Report Player (Ignored)', 'ignorereport', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(63))
                                {
                                    SendNonQuery("Adding command 63", "REPLACE INTO `adkats_commands` VALUES(63, 'Active', 'player_mark', 'Unable', 'Mark Player', 'mark', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(64))
                                {
                                    SendNonQuery("Adding command 64", "REPLACE INTO `adkats_commands` VALUES(64, 'Active', 'player_chat', 'Log', 'Fetch Player Chat', 'pchat', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(65))
                                {
                                    SendNonQuery("Adding command 65", "REPLACE INTO `adkats_commands` VALUES(65, 'Active', 'player_whitelisthackerchecker', 'Log', 'Hacker-Checker Whitelist Player', 'hcwhitelist', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(66))
                                {
                                    SendNonQuery("Adding command 66", "REPLACE INTO `adkats_commands` VALUES(66, 'Active', 'player_lock', 'Log', 'Lock Player Commands', 'lock', TRUE)", true);
                                    changed = true;
                                }
                                if (!_CommandIDDictionary.ContainsKey(67))
                                {
                                    SendNonQuery("Adding command 67", "REPLACE INTO `adkats_commands` VALUES(67, 'Active', 'player_unlock', 'Log', 'Unlock Player Commands', 'unlock', TRUE)", true);
                                    changed = true;
                                }
                                if (changed) {
                                    FetchCommands();
                                    return;
                                }
                            }
                            else {
                                ConsoleError("Commands could not be fetched.");
                            }
                            //Update functions for command timeouts
                            UpdateCommandTimeouts();
                        }
                    }
                }
            }
            catch (Exception e) {
                HandleException(new AdKatsException("Error while fetching commands from database.", e));
            }
            UpdateSettingPage();
            DebugWrite("fetchCommands finished!", 6);
        }
Example #7
0
 private Boolean HasAccess(AdKatsPlayer aPlayer, AdKatsCommand command) {
     try {
         if (aPlayer == null) {
             ConsoleError("player was null in hasAccess.");
             return false;
         }
         if (aPlayer.player_role == null) {
             ConsoleError("player role was null in hasAccess.");
             return false;
         }
         if (command == null) {
             ConsoleError("Command was null in hasAccess.");
             return false;
         }
         if (_isTestingAuthorized)
             PushThreadDebug(DateTime.Now.Ticks, (String.IsNullOrEmpty(Thread.CurrentThread.Name) ? ("mainthread") : (Thread.CurrentThread.Name)), Thread.CurrentThread.ManagedThreadId, new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber(), "");
         lock (aPlayer.player_role) {
             if (_isTestingAuthorized)
                 PushThreadDebug(DateTime.Now.Ticks, (String.IsNullOrEmpty(Thread.CurrentThread.Name) ? ("mainthread") : (Thread.CurrentThread.Name)), Thread.CurrentThread.ManagedThreadId, new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber(), "");
             lock (aPlayer.player_role.RoleAllowedCommands) {
                 if (aPlayer.player_role.RoleAllowedCommands.ContainsKey(command.command_key)) {
                     return true;
                 }
                 if (aPlayer.player_role.ConditionalAllowedCommands.Values.Any(innerCommand => (innerCommand.Value.command_key == command.command_key) && innerCommand.Key(this, aPlayer))) {
                     return true;
                 }
             }
         }
     }
     catch (Exception e) {
         HandleException(new AdKatsException("Error while checking command access on player.", e));
     }
     return false;
 }