示例#1
0
文件: AdKats.cs 项目: BP4U/AdKats
        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);
        }
示例#2
0
文件: AdKats.cs 项目: BP4U/AdKats
 public void cancelSourcePendingAction(AdKat_Record record)
 {
     this.DebugWrite("attempting to cancel command", 6);
     lock (actionConfirmMutex)
     {
         if (!this.actionConfirmDic.Remove(record.source_name))
         {
             this.DebugWrite("No command to cancel.", 6);
             //this.sendMessageToSource(record, "No command to cancel.");
         }
         else
         {
             this.DebugWrite("Commmand Canceled", 6);
             //this.sendMessageToSource(record, "Previous Command Canceled.");
         }
     }
 }
示例#3
0
文件: AdKats.cs 项目: BP4U/AdKats
        //Before calling this, the record is initialized, and command_source/source_name are filled
        public void completeRecord(AdKat_Record record, String message)
        {
            try
            {
                //Initial split of command by whitespace
                String[] splitMessage = message.Split(' ');
                if (splitMessage.Length < 1)
                {
                    this.DebugWrite("Completely blank command entered", 5);
                    this.sendMessageToSource(record, "You entered a completely blank command.");
                    return;
                }
                String commandString = splitMessage[0].ToLower();
                DebugWrite("Raw Command: " + commandString, 6);
                String remainingMessage = message.TrimStart(splitMessage[0].ToCharArray()).Trim();

                //GATE 1: Add general data
                record.server_id = this.server_id;
                record.record_time = DateTime.Now;

                //GATE 2: Add Command
                AdKat_CommandType commandType = this.getCommand(commandString);
                if (commandType == AdKat_CommandType.Default)
                {
                    //If command not parsable, return without creating
                    DebugWrite("Command not parsable", 6);
                    return;
                }
                record.command_type = commandType;
                record.command_action = commandType;
                DebugWrite("Command type: " + record.command_type, 6);

                //GATE 3: Check Access Rights
                //Check for server command case
                if (record.source_name == "server")
                {
                    record.source_name = "PRoConAdmin";
                    record.command_source = AdKat_CommandSource.Console;
                }
                //Check if player has the right to perform what he's asking, only perform for InGame actions
                else if (record.command_source == AdKat_CommandSource.InGame && !this.hasAccess(record.source_name, record.command_type))
                {
                    DebugWrite("No rights to call command", 6);
                    this.sendMessageToSource(record, "Cannot use class " + this.AdKat_CommandAccessRank[record.command_type] + " command, " + record.command_type + ". You are access class " + this.getAccessLevel(record.source_name) + ".");
                    //Return without creating if player doesn't have rights to do it
                    return;
                }

                //GATE 4: Add specific data based on command type.
                //Items that need filling before record processing:
                //target_name
                //target_guid
                //target_playerInfo
                //record_message
                switch (record.command_type)
                {
                    #region MovePlayer
                    case AdKat_CommandType.MovePlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 1);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 1:
                                    record.record_message = "MovePlayer";
                                    record.target_name = parameters[0];
                                    //Handle based on report ID if possible
                                    if (!this.handleRoundReport(record))
                                    {
                                        this.completeTargetInformation(record, false);
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region ForceMovePlayer
                    case AdKat_CommandType.ForceMovePlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 1);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 1:
                                    record.record_message = "ForceMovePlayer";
                                    record.target_name = parameters[0];
                                    //Handle based on report ID if possible
                                    if (!this.handleRoundReport(record))
                                    {
                                        this.completeTargetInformation(record, false);
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region Teamswap
                    case AdKat_CommandType.Teamswap:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //May only call this command from in-game
                            if (record.command_source != AdKat_CommandSource.InGame)
                            {
                                this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                break;
                            }
                            record.record_message = "TeamSwap";
                            record.target_name = record.source_name;
                            this.completeTargetInformation(record, false);
                        }
                        break;
                    #endregion
                    #region KillPlayer
                    case AdKat_CommandType.KillPlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 1:
                                    record.target_name = parameters[0];
                                    //Handle based on report ID as only option
                                    if (!this.handleRoundReport(record))
                                    {
                                        this.sendMessageToSource(record, "No reason given, unable to submit.");
                                    }
                                    break;
                                case 2:
                                    record.target_name = parameters[0];

                                    //attempt to handle via pre-message ID
                                    record.record_message = this.getPreMessage(parameters[1], this.requirePreMessageUse);
                                    if (record.record_message == null)
                                    {
                                        this.sendMessageToSource(record, "Invalid PreMessage ID, valid PreMessage IDs are 1-" + this.preMessageList.Count);
                                        break;
                                    }

                                    //Handle based on report ID if possible
                                    if (!this.handleRoundReport(record))
                                    {
                                        if (record.record_message.Length >= this.requiredReasonLength)
                                        {
                                            this.completeTargetInformation(record, false);
                                        }
                                        else
                                        {
                                            this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                        }
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region KickPlayer
                    case AdKat_CommandType.KickPlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 1:
                                    record.target_name = parameters[0];
                                    //Handle based on report ID as only option
                                    if (!this.handleRoundReport(record))
                                    {
                                        this.sendMessageToSource(record, "No reason given, unable to submit.");
                                    }
                                    break;
                                case 2:
                                    record.target_name = parameters[0];

                                    //attempt to handle via pre-message ID
                                    record.record_message = this.getPreMessage(parameters[1], this.requirePreMessageUse);
                                    if (record.record_message == null)
                                    {
                                        this.sendMessageToSource(record, "Invalid PreMessage ID, valid PreMessage IDs are 1-" + this.preMessageList.Count);
                                        break;
                                    }

                                    //Handle based on report ID if possible
                                    if (!this.handleRoundReport(record))
                                    {
                                        if (record.record_message.Length >= this.requiredReasonLength)
                                        {
                                            this.completeTargetInformation(record, false);
                                        }
                                        else
                                        {
                                            this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                        }
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region TempBanPlayer
                    case AdKat_CommandType.TempBanPlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 3);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    this.sendMessageToSource(record, "No parameters given, unable to submit.");
                                    break;
                                case 1:
                                    int record_duration = 0;
                                    DebugWrite("Raw Duration: " + parameters[0], 6);
                                    if (!Int32.TryParse(parameters[0], out record_duration))
                                    {
                                        this.sendMessageToSource(record, "Invalid time given, unable to submit.");
                                        return;
                                    }
                                    record.command_numeric = record_duration;
                                    //Target is source
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 2:
                                    DebugWrite("Raw Duration: " + parameters[0], 6);
                                    if (Int32.TryParse(parameters[0], out record_duration))
                                    {
                                        record.command_numeric = record_duration;

                                        record.target_name = parameters[1];
                                        DebugWrite("target: " + record.target_name, 6);

                                        //Handle based on report ID as only option
                                        if (!this.handleRoundReport(record))
                                        {
                                            this.sendMessageToSource(record, "No reason given, unable to submit.");
                                        }
                                    }
                                    else
                                    {
                                        this.sendMessageToSource(record, "Invalid time given, unable to submit.");
                                    }
                                    break;
                                case 3:
                                    DebugWrite("Raw Duration: " + parameters[0], 6);
                                    if (Int32.TryParse(parameters[0], out record_duration))
                                    {
                                        record.command_numeric = record_duration;

                                        record.target_name = parameters[1];
                                        DebugWrite("target: " + record.target_name, 6);

                                        //attempt to handle via pre-message ID
                                        record.record_message = this.getPreMessage(parameters[2], this.requirePreMessageUse);
                                        if (record.record_message == null)
                                        {
                                            this.sendMessageToSource(record, "Invalid PreMessage ID, valid PreMessage IDs are 1-" + this.preMessageList.Count);
                                            break;
                                        }

                                        DebugWrite("reason: " + record.record_message, 6);

                                        //Handle based on report ID if possible
                                        if (!this.handleRoundReport(record))
                                        {
                                            if (record.record_message.Length >= this.requiredReasonLength)
                                            {
                                                this.completeTargetInformation(record, false);
                                            }
                                            else
                                            {
                                                this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        this.sendMessageToSource(record, "Invalid time given, unable to submit.");
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region PermabanPlayer
                    case AdKat_CommandType.PermabanPlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 1:
                                    record.target_name = parameters[0];
                                    //Handle based on report ID as only option
                                    if (!this.handleRoundReport(record))
                                    {
                                        this.sendMessageToSource(record, "No reason given, unable to submit.");
                                    }
                                    break;
                                case 2:
                                    record.target_name = parameters[0];

                                    //attempt to handle via pre-message ID
                                    record.record_message = this.getPreMessage(parameters[1], this.requirePreMessageUse);
                                    if (record.record_message == null)
                                    {
                                        this.sendMessageToSource(record, "Invalid PreMessage ID, valid PreMessage IDs are 1-" + this.preMessageList.Count);
                                        break;
                                    }

                                    //Handle based on report ID if possible
                                    if (!this.handleRoundReport(record))
                                    {
                                        if (record.record_message.Length >= this.requiredReasonLength)
                                        {
                                            this.completeTargetInformation(record, false);
                                        }
                                        else
                                        {
                                            this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                        }
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region PunishPlayer
                    case AdKat_CommandType.PunishPlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 1:
                                    record.target_name = parameters[0];
                                    //Handle based on report ID as only option
                                    if (!this.handleRoundReport(record))
                                    {
                                        this.sendMessageToSource(record, "No reason given, unable to submit.");
                                    }
                                    break;
                                case 2:
                                    record.target_name = parameters[0];

                                    //attempt to handle via pre-message ID
                                    record.record_message = this.getPreMessage(parameters[1], this.requirePreMessageUse);
                                    if (record.record_message == null)
                                    {
                                        this.sendMessageToSource(record, "Invalid PreMessage ID, valid PreMessage IDs are 1-" + this.preMessageList.Count);
                                        break;
                                    }

                                    //Handle based on report ID if possible
                                    if (!this.handleRoundReport(record))
                                    {
                                        if (record.record_message.Length >= this.requiredReasonLength)
                                        {
                                            this.completeTargetInformation(record, false);
                                        }
                                        else
                                        {
                                            this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                        }
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region ForgivePlayer
                    case AdKat_CommandType.ForgivePlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 1:
                                    record.target_name = parameters[0];
                                    //Handle based on report ID as only option
                                    if (!this.handleRoundReport(record))
                                    {
                                        this.sendMessageToSource(record, "No reason given, unable to submit.");
                                    }
                                    break;
                                case 2:
                                    record.target_name = parameters[0];

                                    //attempt to handle via pre-message ID
                                    record.record_message = this.getPreMessage(parameters[1], this.requirePreMessageUse);
                                    if (record.record_message == null)
                                    {
                                        this.sendMessageToSource(record, "Invalid PreMessage ID, valid PreMessage IDs are 1-" + this.preMessageList.Count);
                                        break;
                                    }

                                    //Handle based on report ID if possible
                                    if (!this.handleRoundReport(record))
                                    {
                                        if (record.record_message.Length >= this.requiredReasonLength)
                                        {
                                            this.completeTargetInformation(record, false);
                                        }
                                        else
                                        {
                                            this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                        }
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region MutePlayer
                    case AdKat_CommandType.MutePlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 1:
                                    record.target_name = parameters[0];
                                    //Handle based on report ID as only option
                                    if (!this.handleRoundReport(record))
                                    {
                                        this.sendMessageToSource(record, "No reason given, unable to submit.");
                                    }
                                    break;
                                case 2:
                                    record.target_name = parameters[0];

                                    //attempt to handle via pre-message ID
                                    record.record_message = this.getPreMessage(parameters[1], this.requirePreMessageUse);
                                    if (record.record_message == null)
                                    {
                                        this.sendMessageToSource(record, "Invalid PreMessage ID, valid PreMessage IDs are 1-" + this.preMessageList.Count);
                                        break;
                                    }

                                    //Handle based on report ID if possible
                                    if (!this.handleRoundReport(record))
                                    {
                                        if (record.record_message.Length >= this.requiredReasonLength)
                                        {
                                            this.completeTargetInformation(record, false);
                                        }
                                        else
                                        {
                                            this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                        }
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region RoundWhitelistPlayer
                    case AdKat_CommandType.RoundWhitelistPlayer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    if (record.command_source != AdKat_CommandSource.InGame)
                                    {
                                        this.sendMessageToSource(record, "You can't use a self-inflicting command from outside the game.");
                                        break;
                                    }
                                    record.record_message = "Self-Inflicted";
                                    record.target_name = record.source_name;
                                    this.completeTargetInformation(record, true);
                                    break;
                                case 1:
                                    record.target_name = parameters[0];
                                    //Handle based on report ID as only option
                                    if (!this.handleRoundReport(record))
                                    {
                                        this.sendMessageToSource(record, "No reason given, unable to submit.");
                                    }
                                    break;
                                case 2:
                                    record.target_name = parameters[0];

                                    //attempt to handle via pre-message ID
                                    record.record_message = this.getPreMessage(parameters[1], false);

                                    //Handle based on report ID if possible
                                    if (!this.handleRoundReport(record))
                                    {
                                        if (record.record_message.Length >= this.requiredReasonLength)
                                        {
                                            this.completeTargetInformation(record, false);
                                        }
                                        else
                                        {
                                            this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                        }
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region ReportPlayer
                    case AdKat_CommandType.ReportPlayer:
                        {
                            string command = this.m_strReportCommand;

                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    this.sendMessageToSource(record, "Format must be: @" + command + " playername reason");
                                    break;
                                case 1:
                                    this.sendMessageToSource(record, "Format must be: @" + command + " playername reason");
                                    break;
                                case 2:
                                    record.target_name = parameters[0];
                                    DebugWrite("target: " + record.target_name, 6);

                                    //attempt to handle via pre-message ID
                                    record.record_message = this.getPreMessage(parameters[1], false);

                                    DebugWrite("reason: " + record.record_message, 6);

                                    //Only 1 character reasons are required for reports and admin calls
                                    if (record.record_message.Length >= 1)
                                    {
                                        this.completeTargetInformation(record, false);
                                    }
                                    else
                                    {
                                        DebugWrite("reason too short", 6);
                                        this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                        return;
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region CallAdmin
                    case AdKat_CommandType.CallAdmin:
                        {
                            string command = this.m_strCallAdminCommand;

                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    this.sendMessageToSource(record, "Format must be: @" + command + " playername reason");
                                    break;
                                case 1:
                                    this.sendMessageToSource(record, "Format must be: @" + command + " playername reason");
                                    break;
                                case 2:
                                    record.target_name = parameters[0];
                                    DebugWrite("target: " + record.target_name, 6);

                                    //attempt to handle via pre-message ID
                                    record.record_message = this.getPreMessage(parameters[1], false);

                                    DebugWrite("reason: " + record.record_message, 6);
                                    //Only 1 character reasons are required for reports and admin calls
                                    if (record.record_message.Length >= 1)
                                    {
                                        this.completeTargetInformation(record, false);
                                    }
                                    else
                                    {
                                        DebugWrite("reason too short", 6);
                                        this.sendMessageToSource(record, "Reason too short, unable to submit.");
                                        return;
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region NukeServer
                    case AdKat_CommandType.NukeServer:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    this.sendMessageToSource(record, "No parameters given, unable to submit.");
                                    break;
                                case 1:
                                    string targetTeam = parameters[0];
                                    record.record_message = "Nuke Server";
                                    DebugWrite("target: " + targetTeam, 6);
                                    if (targetTeam.ToLower().Contains("us"))
                                    {
                                        record.target_name = "US Team";
                                        record.record_message += " (US Team)";
                                    }
                                    else if (targetTeam.ToLower().Contains("ru"))
                                    {
                                        record.target_name = "RU Team";
                                        record.record_message += " (RU Team)";
                                    }
                                    else if (targetTeam.ToLower().Contains("all"))
                                    {
                                        record.target_name = "Everyone";
                                        record.record_message += " (Everyone)";
                                    }
                                    else
                                    {
                                        this.sendMessageToSource(record, "Use 'US', 'RU', or 'ALL' as targets.");
                                    }
                                    //Have the admin confirm the action
                                    this.confirmActionWithSource(record);
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region KickAll
                    case AdKat_CommandType.KickAll:
                        this.cancelSourcePendingAction(record);
                        record.target_name = "Non-Admins";
                        record.record_message = "Kick All Players";
                        this.confirmActionWithSource(record);
                        break;
                    #endregion
                    #region EndLevel
                    case AdKat_CommandType.EndLevel:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    this.sendMessageToSource(record, "No parameters given, unable to submit.");
                                    return;
                                case 1:
                                    string targetTeam = parameters[0];
                                    DebugWrite("target team: " + targetTeam, 6);
                                    record.record_message = "End Round";
                                    if (targetTeam.ToLower().Contains("us"))
                                    {
                                        record.target_name = "US Team";
                                        record.command_numeric = AdKats.USTeamID;
                                        record.record_message += " (US Win)";
                                    }
                                    else if (targetTeam.ToLower().Contains("ru"))
                                    {
                                        record.target_name = "RU Team";
                                        record.command_numeric = AdKats.RUTeamID;
                                        record.record_message += " (RU Win)";
                                    }
                                    else
                                    {
                                        this.sendMessageToSource(record, "Use 'US' or 'RU' as team names to end round");
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                            //Have the admin confirm the action
                            this.confirmActionWithSource(record);
                        }
                        break;
                    #endregion
                    #region RestartLevel
                    case AdKat_CommandType.RestartLevel:
                        this.cancelSourcePendingAction(record);
                        record.target_name = "Server";
                        record.record_message = "Restart Round";
                        this.confirmActionWithSource(record);
                        break;
                    #endregion
                    #region NextLevel
                    case AdKat_CommandType.NextLevel:
                        this.cancelSourcePendingAction(record);
                        record.target_name = "Server";
                        record.record_message = "Run Next Map";
                        this.confirmActionWithSource(record);
                        break;
                    #endregion
                    #region WhatIs
                    case AdKat_CommandType.WhatIs:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 1);
                            switch (parameters.Length)
                            {
                                case 0:
                                    this.sendMessageToSource(record, "No parameters given, unable to submit.");
                                    return;
                                case 1:
                                    record.record_message = this.getPreMessage(parameters[0], true);
                                    if (record.record_message == null)
                                    {
                                        this.sendMessageToSource(record, "Invalid PreMessage ID, valid PreMessage IDs are 1-" + this.preMessageList.Count);
                                    }
                                    else
                                    {
                                        this.sendMessageToSource(record, record.record_message);
                                    }
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                            //This type is not processed
                        }
                        break;
                    #endregion
                    #region AdminSay
                    case AdKat_CommandType.AdminSay:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 1);
                            switch (parameters.Length)
                            {
                                case 0:
                                    this.sendMessageToSource(record, "No parameters given, unable to submit.");
                                    return;
                                case 1:
                                    record.record_message = this.getPreMessage(parameters[0], false);
                                    DebugWrite("message: " + record.record_message, 6);
                                    record.target_name = "Server";
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                            this.queueRecordForProcessing(record);
                        }
                        break;
                    #endregion
                    #region AdminYell
                    case AdKat_CommandType.AdminYell:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 1);
                            switch (parameters.Length)
                            {
                                case 0:
                                    this.sendMessageToSource(record, "No parameters given, unable to submit.");
                                    return;
                                case 1:
                                    record.record_message = this.getPreMessage(parameters[0], false).ToUpper();
                                    DebugWrite("message: " + record.record_message, 6);
                                    record.target_name = "Server";
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                            this.queueRecordForProcessing(record);
                        }
                        break;
                    #endregion
                    #region PlayerSay
                    case AdKat_CommandType.PlayerSay:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    this.sendMessageToSource(record, "No parameters given, unable to submit.");
                                    return;
                                case 1:
                                    this.sendMessageToSource(record, "No message given, unable to submit.");
                                    return;
                                case 2:
                                    record.target_name = parameters[0];
                                    DebugWrite("target: " + record.target_name, 6);

                                    record.record_message = this.getPreMessage(parameters[1], false);
                                    DebugWrite("message: " + record.record_message, 6);

                                    this.completeTargetInformation(record, false);
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region PlayerYell
                    case AdKat_CommandType.PlayerYell:
                        {
                            //Remove previous commands awaiting confirmation
                            this.cancelSourcePendingAction(record);

                            //Parse parameters using max param count
                            String[] parameters = this.parseParameters(remainingMessage, 2);
                            switch (parameters.Length)
                            {
                                case 0:
                                    this.sendMessageToSource(record, "No parameters given, unable to submit.");
                                    return;
                                case 1:
                                    this.sendMessageToSource(record, "No message given, unable to submit.");
                                    return;
                                case 2:
                                    record.target_name = parameters[0];
                                    DebugWrite("target: " + record.target_name, 6);

                                    record.record_message = this.getPreMessage(parameters[1], false).ToUpper();
                                    DebugWrite("message: " + record.record_message, 6);

                                    this.completeTargetInformation(record, false);
                                    break;
                                default:
                                    this.sendMessageToSource(record, "Invalid parameters, unable to submit.");
                                    return;
                            }
                        }
                        break;
                    #endregion
                    #region ConfirmCommand
                    case AdKat_CommandType.ConfirmCommand:
                        this.DebugWrite("attempting to confirm command", 6);
                        AdKat_Record recordAttempt = null;
                        this.actionConfirmDic.TryGetValue(record.source_name, out recordAttempt);
                        if (recordAttempt != null)
                        {
                            this.DebugWrite("command found, calling processing", 6);
                            this.actionConfirmDic.Remove(record.source_name);
                            this.queueRecordForProcessing(recordAttempt);
                        }
                        else
                        {
                            this.DebugWrite("no command to confirm", 6);
                            this.sendMessageToSource(record, "No command to confirm.");
                        }
                        //This type is not processed
                        break;
                    #endregion
                    #region CancelCommand
                    case AdKat_CommandType.CancelCommand:
                        this.DebugWrite("attempting to cancel command", 6);
                        if (!this.actionConfirmDic.Remove(record.source_name))
                        {
                            this.DebugWrite("no command to cancel", 6);
                            this.sendMessageToSource(record, "No command to cancel.");
                        }
                        //This type is not processed
                        break;
                    #endregion
                    default:
                        break;
                }
                return;
            }
            catch (Exception e)
            {
                this.ConsoleException(e.ToString());
            }
        }
示例#4
0
文件: AdKats.cs 项目: BP4U/AdKats
 private void queueRecordForProcessing(AdKat_Record record)
 {
     this.DebugWrite("Preparing to queue record for processing", 6);
     lock (unprocessedRecordMutex)
     {
         this.unprocessedRecordQueue.Enqueue(record);
         this.DebugWrite("Record queued for processing", 6);
         this.dbCommHandle.Set();
     }
 }
示例#5
0
文件: AdKats.cs 项目: BP4U/AdKats
 public string callAdminOnTarget(AdKat_Record record)
 {
     Random random = new Random();
     int reportID;
     do
     {
         reportID = random.Next(100, 999);
     } while (round_reports.ContainsKey(reportID + ""));
     this.round_reports.Add(reportID + "", record);
     string adminAssistantIdentifier = (this.adminAssistantCache.ContainsKey(record.source_name)) ? ("[AA]") : ("");
     foreach (String admin_name in this.playerAccessCache.Keys)
     {
         if (this.playerAccessCache[admin_name].access_level <= 4 && this.playerDictionary.ContainsKey(admin_name))
         {
             this.playerSayMessage(admin_name, "ADMIN CALL " + adminAssistantIdentifier + "[" + reportID + "]: " + record.source_name + " called admin on " + record.target_name + " for " + record.record_message);
         }
     }
     return this.sendMessageToSource(record, "ADMIN CALL [" + reportID + "] sent. " + record.target_name + " for " + record.record_message);
 }
示例#6
0
文件: AdKats.cs 项目: BP4U/AdKats
        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!");
            }
        }
示例#7
0
文件: AdKats.cs 项目: BP4U/AdKats
        private void messagingThreadLoop()
        {
            try
            {
                this.DebugWrite("MESSAGE: Starting Messaging Thread", 2);
                Thread.CurrentThread.Name = "messaging";
                while (true)
                {
                    this.DebugWrite("MESSAGE: Entering Messaging Thread Loop", 7);
                    if (!this.isEnabled)
                    {
                        this.DebugWrite("MESSAGE: Detected AdKats not enabled. Exiting thread " + Thread.CurrentThread.Name, 6);
                        break;
                    }

                    //Get all unparsed inbound messages
                    Queue<KeyValuePair<String, String>> inboundMessages;
                    if (this.unparsedMessageQueue.Count > 0)
                    {
                        this.DebugWrite("MESSAGE: Preparing to lock messaging to retrive new messages", 7);
                        lock (unparsedMessageMutex)
                        {
                            this.DebugWrite("MESSAGE: Inbound messages found. Grabbing.", 6);
                            //Grab all messages in the queue
                            inboundMessages = new Queue<KeyValuePair<string, string>>(this.unparsedMessageQueue.ToArray());
                            //Clear the queue for next run
                            this.unparsedMessageQueue.Clear();
                        }
                    }
                    else
                    {
                        this.DebugWrite("MESSAGE: No inbound messages. Waiting for Input.", 4);
                        //Wait for input
                        this.messageParsingHandle.Reset();
                        this.messageParsingHandle.WaitOne(Timeout.Infinite);
                        continue;
                    }

                    //Loop through all messages in order that they came in
                    while (inboundMessages != null && inboundMessages.Count > 0)
                    {
                        this.DebugWrite("MESSAGE: begin reading message", 6);
                        //Dequeue the first/next message
                        KeyValuePair<String, String> messagePair = inboundMessages.Dequeue();
                        string speaker = messagePair.Key;
                        string message = messagePair.Value;

                        //check for player mute case
                        //ignore if it's a server call
                        if (speaker != "Server")
                        {
                            lock (playersMutex)
                            {
                                //Check if the player is muted
                                this.DebugWrite("MESSAGE: Checking for mute case.", 7);
                                if (this.round_mutedPlayers.ContainsKey(speaker))
                                {
                                    this.DebugWrite("MESSAGE: Player is muted. Acting.", 7);
                                    //Increment the muted chat count
                                    this.round_mutedPlayers[speaker] = this.round_mutedPlayers[speaker] + 1;
                                    //Create record
                                    AdKat_Record record = new AdKat_Record();
                                    record.command_source = AdKat_CommandSource.InGame;
                                    record.server_id = this.server_id;
                                    record.source_name = "PlayerMuteSystem";
                                    record.target_player = this.playerDictionary[speaker];
                                    record.target_name = record.target_player.player_name;
                                    if (this.round_mutedPlayers[speaker] > this.mutedPlayerChances)
                                    {
                                        record.record_message = this.mutedPlayerKickMessage;
                                        record.command_type = AdKat_CommandType.KickPlayer;
                                        record.command_action = AdKat_CommandType.KickPlayer;
                                    }
                                    else
                                    {
                                        record.record_message = mutedPlayerKillMessage;
                                        record.command_type = AdKat_CommandType.KillPlayer;
                                        record.command_action = AdKat_CommandType.KillPlayer;
                                    }

                                    this.queueRecordForProcessing(record);
                                    continue;
                                }
                            }
                        }

                        //Check if the message is a command
                        if (message.StartsWith("@") || message.StartsWith("!"))
                        {
                            message = message.Substring(1);
                        }
                        else if (message.StartsWith("/@") || message.StartsWith("/!"))
                        {
                            message = message.Substring(2);
                        }
                        else if (message.StartsWith("/"))
                        {
                            message = message.Substring(1);
                        }
                        else
                        {
                            //If the message does not cause either of the above clauses, then ignore it.
                            this.DebugWrite("MESSAGE: Message is regular chat. Ignoring.", 7);
                            continue;
                        }
                        this.queueCommandForParsing(speaker, message);
                    }
                }
                this.DebugWrite("MESSAGE: Ending Messaging Thread", 2);
            }
            catch (Exception e)
            {
                this.ConsoleException(e.ToString());
                if (typeof(ThreadAbortException).Equals(e.GetType()))
                {
                    this.DebugWrite("Thread Exception", 4);
                    Thread.ResetAbort();
                    return;
                }
            }
        }
示例#8
0
文件: AdKats.cs 项目: BP4U/AdKats
 public string sendMessageToSource(AdKat_Record record, string message)
 {
     string response = null;
     switch (record.command_source)
     {
         case AdKat_CommandSource.InGame:
             this.playerSayMessage(record.source_name, message);
             break;
         case AdKat_CommandSource.Console:
             this.ConsoleWrite(message);
             break;
         case AdKat_CommandSource.Settings:
             this.ConsoleWrite(message);
             break;
         case AdKat_CommandSource.Database:
             //Do nothing, no way to communicate to source when database
             break;
         case AdKat_CommandSource.HTTP:
             response = message;
             break;
         default:
             //this.ConsoleWarn("Command source not set, or not recognized.");
             break;
     }
     return response;
 }
示例#9
0
文件: AdKats.cs 项目: BP4U/AdKats
        public void SetPluginVariable(string strVariable, string strValue)
        {
            try
            {
                string[] variableParse = CPluginVariable.DecodeStringArray(strVariable);

                if (strVariable.Equals("UpdateSettings"))
                {
                    //Do nothing. Settings page will be updated after return.
                }
                else if (Regex.Match(strVariable, @"Setting Import").Success)
                {
                    int tmp = -1;
                    if (int.TryParse(strValue, out tmp))
                    {
                        if (tmp != -1)
                            this.queueSettingImport(tmp);
                    }
                    else
                    {
                        this.ConsoleError("Invalid Input for Setting Import");
                    }
                }
                else if (Regex.Match(strVariable, @"Using AdKats WebAdmin").Success)
                {
                    Boolean tmp = false;
                    if (Boolean.TryParse(strValue, out tmp))
                    {
                        this.usingAWA = tmp;

                        //Update necessary settings for AWA use
                        if (this.usingAWA)
                        {
                            this.useBanEnforcer = true;
                            this.fetchActionsFromDB = true;
                            this.dbCommHandle.Set();
                        }
                    }
                    else
                    {
                        this.ConsoleError("Invalid Input for Using AdKats WebAdmin");
                    }
                }
                #region debugging
                else if (Regex.Match(strVariable, @"Command Entry").Success)
                {
                    //Check if the message is a command
                    if (strValue.StartsWith("@") || strValue.StartsWith("!"))
                    {
                        strValue = strValue.Substring(1);
                    }
                    else if (strValue.StartsWith("/@") || strValue.StartsWith("/!"))
                    {
                        strValue = strValue.Substring(2);
                    }
                    else if (strValue.StartsWith("/"))
                    {
                        strValue = strValue.Substring(1);
                    }
                    AdKat_Record recordItem = new AdKat_Record();
                    recordItem.command_source = AdKat_CommandSource.Settings;
                    recordItem.source_name = "SettingsAdmin";
                    this.completeRecord(recordItem, strValue);
                }
                else if (Regex.Match(strVariable, @"Debug level").Success)
                {
                    int tmp = 2;
                    if (int.TryParse(strValue, out tmp))
                    {
                        if (tmp != this.debugLevel)
                        {
                            this.debugLevel = tmp;
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Debug level", typeof(Int32), this.debugLevel));
                        }
                    }
                }
                else if (Regex.Match(strVariable, @"Debug Soldier Name").Success)
                {
                    if (this.soldierNameValid(strValue))
                    {
                        if (strValue != this.debugSoldierName)
                        {
                            this.debugSoldierName = strValue;
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Debug Soldier Name", typeof(string), this.debugSoldierName));
                        }
                    }
                }
                #endregion
                #region HTTP settings
                else if (Regex.Match(strVariable, @"External Access Key").Success)
                {
                    if (strValue != this.externalCommandAccessKey)
                    {
                        this.externalCommandAccessKey = strValue;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"External Access Key", typeof(string), this.externalCommandAccessKey));
                    }
                }
                else if (Regex.Match(strVariable, @"Fetch Actions from Database").Success)
                {
                    Boolean fetch;
                    if (fetch = Boolean.Parse(strValue))
                    {
                        if (fetch != this.fetchActionsFromDB)
                        {
                            this.fetchActionsFromDB = fetch;
                            this.dbCommHandle.Set();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Fetch Actions from Database", typeof(Boolean), this.fetchActionsFromDB));
                        }
                    }
                }
                #endregion
                #region ban settings
                else if (Regex.Match(strVariable, @"Use Additional Ban Message").Success)
                {
                    Boolean use = Boolean.Parse(strValue);
                    if (this.useBanAppend != use)
                    {
                        this.useBanAppend = use;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Use Additional Ban Message", typeof(Boolean), this.useBanAppend));
                    }
                }
                else if (Regex.Match(strVariable, @"Additional Ban Message").Success)
                {
                    if (strValue.Length > 30)
                    {
                        strValue = strValue.Substring(0, 30);
                        this.ConsoleError("Ban append cannot be more than 30 characters.");
                    }
                    else
                    {
                        if (this.banAppend != strValue)
                        {
                            this.banAppend = strValue;
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Additional Ban Message", typeof(string), this.banAppend));
                        }
                    }
                }
                else if (Regex.Match(strVariable, @"Use Ban Enforcer").Success)
                {
                    Boolean use = Boolean.Parse(strValue);
                    if (this.useBanEnforcer != use)
                    {
                        this.useBanEnforcer = use;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Use Ban Enforcer", typeof(Boolean), this.useBanEnforcer));
                        if (this.useBanEnforcer)
                        {
                            this.fetchActionsFromDB = true;
                            this.dbCommHandle.Set();
                        }
                    }
                }
                else if (Regex.Match(strVariable, @"Enforce New Bans by NAME").Success)
                {
                    Boolean enforceName = Boolean.Parse(strValue);
                    if (this.defaultEnforceName != enforceName)
                    {
                        this.defaultEnforceName = enforceName;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Enforce New Bans by NAME", typeof(Boolean), this.defaultEnforceName));
                    }
                }
                else if (Regex.Match(strVariable, @"Enforce New Bans by GUID").Success)
                {
                    Boolean enforceGUID = Boolean.Parse(strValue);
                    if (this.defaultEnforceGUID != enforceGUID)
                    {
                        this.defaultEnforceGUID = enforceGUID;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Enforce New Bans by GUID", typeof(Boolean), this.defaultEnforceGUID));
                    }
                }
                else if (Regex.Match(strVariable, @"Enforce New Bans by IP").Success)
                {
                    Boolean enforceIP = Boolean.Parse(strValue);
                    if (this.defaultEnforceIP != enforceIP)
                    {
                        this.defaultEnforceIP = enforceIP;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Enforce New Bans by IP", typeof(Boolean), this.defaultEnforceIP));
                    }
                }
                #endregion
                #region In-Game Command Settings
                else if (Regex.Match(strVariable, @"Minimum Required Reason Length").Success)
                {
                    Int32 required = Int32.Parse(strValue);
                    if (this.requiredReasonLength != required)
                    {
                        this.requiredReasonLength = required;
                        if (this.requiredReasonLength < 1)
                        {
                            this.requiredReasonLength = 1;
                        }
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Minimum Required Reason Length", typeof(Int32), this.requiredReasonLength));
                    }
                }
                else if (Regex.Match(strVariable, @"Confirm Command").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strConfirmCommand != strValue)
                        {
                            this.m_strConfirmCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Confirm Command", typeof(string), this.m_strConfirmCommand));
                        }
                    }
                    else
                    {
                        this.m_strConfirmCommand = AdKat_CommandType.ConfirmCommand + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Cancel Command").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strCancelCommand != strValue)
                        {
                            this.m_strCancelCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Cancel Command", typeof(string), this.m_strCancelCommand));
                        }
                    }
                    else
                    {
                        this.m_strCancelCommand = AdKat_CommandType.CancelCommand + " COMMAND BLANK";
                    }
                }
                else if (strVariable.EndsWith(@"Kill Player"))
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strKillCommand != strValue)
                        {
                            this.m_strKillCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Kill Player", typeof(string), this.m_strKillCommand));
                        }
                    }
                    else
                    {
                        this.m_strKillCommand = AdKat_CommandType.KillPlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Kick Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strKickCommand != strValue)
                        {
                            this.m_strKickCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Kick Player", typeof(string), this.m_strKickCommand));
                        }
                    }
                    else
                    {
                        this.m_strKickCommand = AdKat_CommandType.KickPlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Temp-Ban Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strTemporaryBanCommand != strValue)
                        {
                            this.m_strTemporaryBanCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Temp-Ban Player", typeof(string), this.m_strTemporaryBanCommand));
                        }
                    }
                    else
                    {
                        this.m_strTemporaryBanCommand = AdKat_CommandType.TempBanPlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Permaban Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strPermanentBanCommand != strValue)
                        {
                            this.m_strPermanentBanCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Permaban Player", typeof(string), this.m_strPermanentBanCommand));
                        }
                    }
                    else
                    {
                        this.m_strPermanentBanCommand = AdKat_CommandType.PermabanPlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Punish Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strPunishCommand != strValue)
                        {
                            this.m_strPunishCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Punish Player", typeof(string), this.m_strPunishCommand));
                        }
                    }
                    else
                    {
                        this.m_strPunishCommand = AdKat_CommandType.PunishPlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Forgive Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strForgiveCommand != strValue)
                        {
                            this.m_strForgiveCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Forgive Player", typeof(string), this.m_strForgiveCommand));
                        }
                    }
                    else
                    {
                        this.m_strForgiveCommand = AdKat_CommandType.ForgivePlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Mute Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strMuteCommand != strValue)
                        {
                            this.m_strMuteCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Mute Player", typeof(string), this.m_strMuteCommand));
                        }
                    }
                    else
                    {
                        this.m_strMuteCommand = AdKat_CommandType.MutePlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Round Whitelist Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strRoundWhitelistCommand != strValue)
                        {
                            this.m_strRoundWhitelistCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Round Whitelist Player", typeof(string), this.m_strRoundWhitelistCommand));
                        }
                    }
                    else
                    {
                        this.m_strRoundWhitelistCommand = AdKat_CommandType.RoundWhitelistPlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"OnDeath Move Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strMoveCommand != strValue)
                        {
                            this.m_strMoveCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"OnDeath Move Player", typeof(string), this.m_strMoveCommand));
                        }
                    }
                    else
                    {
                        this.m_strMoveCommand = AdKat_CommandType.MovePlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Force Move Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strForceMoveCommand != strValue)
                        {
                            this.m_strForceMoveCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Force Move Player", typeof(string), this.m_strForceMoveCommand));
                        }
                    }
                    else
                    {
                        this.m_strForceMoveCommand = AdKat_CommandType.ForceMovePlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Teamswap Self").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strTeamswapCommand != strValue)
                        {
                            this.m_strTeamswapCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Teamswap Self", typeof(string), this.m_strTeamswapCommand));
                        }
                    }
                    else
                    {
                        this.m_strTeamswapCommand = AdKat_CommandType.Teamswap + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Report Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strReportCommand != strValue)
                        {
                            this.m_strReportCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Report Player", typeof(string), this.m_strReportCommand));
                        }
                    }
                    else
                    {
                        this.m_strReportCommand = AdKat_CommandType.ReportPlayer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Call Admin on Player").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strCallAdminCommand != strValue)
                        {
                            this.m_strCallAdminCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Call Admin on Player", typeof(string), this.m_strCallAdminCommand));
                        }
                    }
                    else
                    {
                        this.m_strCallAdminCommand = AdKat_CommandType.CallAdmin + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Admin Say").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strSayCommand != strValue)
                        {
                            this.m_strSayCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Admin Say", typeof(string), this.m_strSayCommand));
                        }
                    }
                    else
                    {
                        this.m_strSayCommand = AdKat_CommandType.AdminSay + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Player Say").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strPlayerSayCommand != strValue)
                        {
                            this.m_strPlayerSayCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Player Say", typeof(string), this.m_strPlayerSayCommand));
                        }
                    }
                    else
                    {
                        this.m_strPlayerSayCommand = AdKat_CommandType.PlayerSay + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Admin Yell").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strYellCommand != strValue)
                        {
                            this.m_strYellCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Admin Yell", typeof(string), this.m_strYellCommand));
                        }
                    }
                    else
                    {
                        this.m_strYellCommand = AdKat_CommandType.AdminYell + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Player Yell").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strPlayerYellCommand != strValue)
                        {
                            this.m_strPlayerYellCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Player Yell", typeof(string), this.m_strPlayerYellCommand));
                        }
                    }
                    else
                    {
                        this.m_strPlayerYellCommand = AdKat_CommandType.PlayerYell + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"What Is").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strWhatIsCommand != strValue)
                        {
                            this.m_strWhatIsCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"What Is", typeof(string), this.m_strWhatIsCommand));
                        }
                    }
                    else
                    {
                        this.m_strWhatIsCommand = AdKat_CommandType.WhatIs + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Restart Level").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strRestartLevelCommand != strValue)
                        {
                            this.m_strRestartLevelCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Restart Level", typeof(string), this.m_strRestartLevelCommand));
                        }
                    }
                    else
                    {
                        this.m_strRestartLevelCommand = AdKat_CommandType.RestartLevel + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Next Level").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strNextLevelCommand != strValue)
                        {
                            this.m_strNextLevelCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Next Level", typeof(string), this.m_strNextLevelCommand));
                        }
                    }
                    else
                    {
                        this.m_strNextLevelCommand = AdKat_CommandType.NextLevel + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"End Level").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strEndLevelCommand != strValue)
                        {
                            this.m_strEndLevelCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"End Level", typeof(string), this.m_strEndLevelCommand));
                        }
                    }
                    else
                    {
                        this.m_strEndLevelCommand = AdKat_CommandType.EndLevel + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Nuke Server").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strNukeCommand != strValue)
                        {
                            this.m_strNukeCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Nuke Server", typeof(string), this.m_strNukeCommand));
                        }
                    }
                    else
                    {
                        this.m_strNukeCommand = AdKat_CommandType.NukeServer + " COMMAND BLANK";
                    }
                }
                else if (Regex.Match(strVariable, @"Kick All NonAdmins").Success)
                {
                    if (strValue.Length > 0)
                    {
                        //trim variable
                        if (strValue.ToLower().EndsWith("|log"))
                        {
                            strValue = strValue.Remove(strValue.IndexOf("|log"));
                        }
                        if (this.m_strKickAllCommand != strValue)
                        {
                            this.m_strKickAllCommand = strValue;
                            rebindAllCommands();
                            //Once setting has been changed, upload the change to database
                            this.queueSettingForUpload(new CPluginVariable(@"Kick All NonAdmins", typeof(string), this.m_strKickAllCommand));
                        }
                    }
                    else
                    {
                        this.m_strKickAllCommand = AdKat_CommandType.KickAll + " COMMAND BLANK";
                    }
                }
                #endregion
                #region punishment settings
                else if (Regex.Match(strVariable, @"Punishment Hierarchy").Success)
                {
                    this.punishmentHierarchy = CPluginVariable.DecodeStringArray(strValue);
                    //Once setting has been changed, upload the change to database
                    this.queueSettingForUpload(new CPluginVariable(@"Punishment Hierarchy", typeof(string), CPluginVariable.EncodeStringArray(this.punishmentHierarchy)));
                }
                else if (Regex.Match(strVariable, @"Combine Server Punishments").Success)
                {
                    Boolean combine = Boolean.Parse(strValue);
                    if (this.combineServerPunishments != combine)
                    {
                        this.combineServerPunishments = combine;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Combine Server Punishments", typeof(Boolean), this.combineServerPunishments));
                    }
                }
                else if (Regex.Match(strVariable, @"Only Kill Players when Server in low population").Success)
                {
                    Boolean onlyKill = Boolean.Parse(strValue);
                    if (onlyKill != this.onlyKillOnLowPop)
                    {
                        this.onlyKillOnLowPop = onlyKill;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Only Kill Players when Server in low population", typeof(Boolean), this.onlyKillOnLowPop));
                    }
                }
                else if (Regex.Match(strVariable, @"Low Population Value").Success)
                {
                    Int32 lowPop = Int32.Parse(strValue);
                    if (lowPop != this.lowPopPlayerCount)
                    {
                        this.lowPopPlayerCount = lowPop;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Low Population Value", typeof(Int32), this.lowPopPlayerCount));
                    }
                }
                else if (Regex.Match(strVariable, @"IRO Punishment Overrides Low Pop").Success)
                {
                    Boolean overrideIRO = Boolean.Parse(strValue);
                    if (overrideIRO != this.IROOverridesLowPop)
                    {
                        this.IROOverridesLowPop = overrideIRO;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"IRO Punishment Overrides Low Pop", typeof(Boolean), this.IROOverridesLowPop));
                    }
                }
                #endregion
                #region sql settings
                else if (Regex.Match(strVariable, @"MySQL Hostname").Success)
                {
                    mySqlHostname = strValue;
                    this.dbSettingsChanged = true;
                    this.dbCommHandle.Set();
                }
                else if (Regex.Match(strVariable, @"MySQL Port").Success)
                {
                    int tmp = 3306;
                    int.TryParse(strValue, out tmp);
                    if (tmp > 0 && tmp < 65536)
                    {
                        mySqlPort = strValue;
                        this.dbSettingsChanged = true;
                        this.dbCommHandle.Set();
                    }
                    else
                    {
                        ConsoleException("Invalid value for MySQL Port: '" + strValue + "'. Must be number between 1 and 65535!");
                    }
                }
                else if (Regex.Match(strVariable, @"MySQL Database").Success)
                {
                    this.mySqlDatabaseName = strValue;
                    this.dbSettingsChanged = true;
                    this.dbCommHandle.Set();
                }
                else if (Regex.Match(strVariable, @"MySQL Username").Success)
                {
                    mySqlUsername = strValue;
                    this.dbSettingsChanged = true;
                    this.dbCommHandle.Set();
                }
                else if (Regex.Match(strVariable, @"MySQL Password").Success)
                {
                    mySqlPassword = strValue;
                    this.dbSettingsChanged = true;
                    this.dbCommHandle.Set();
                }
                #endregion
                #region email settings
                else if (strVariable.CompareTo("Send Emails") == 0)
                {
                    //Disabled
                    this.useEmail = false;// Boolean.Parse(strValue);
                    //Once setting has been changed, upload the change to database
                    this.queueSettingForUpload(new CPluginVariable("Send Emails", typeof(Boolean), this.useEmail));
                }
                else if (strVariable.CompareTo("Admin Request Email?") == 0)
                {
                    //this.blNotifyEmail = Boolean.Parse(strValue);
                    //Once setting has been changed, upload the change to database
                    //this.queueSettingForUpload(new CPluginVariable("Admin Request Email?", typeof(string), strValue));
                }
                else if (strVariable.CompareTo("Use SSL?") == 0)
                {
                    this.emailHandler.blUseSSL = Boolean.Parse(strValue);
                    //Once setting has been changed, upload the change to database
                    //this.queueSettingForUpload(new CPluginVariable("Use SSL?", typeof(Boolean), this.emailHandler.blUseSSL));
                }
                else if (strVariable.CompareTo("SMTP-Server address") == 0)
                {
                    this.emailHandler.strSMTPServer = strValue;
                    //Once setting has been changed, upload the change to database
                    //this.queueSettingForUpload(new CPluginVariable("SMTP-Server address", typeof(string), strValue));
                }
                else if (strVariable.CompareTo("SMTP-Server port") == 0)
                {
                    int iPort = Int32.Parse(strValue);
                    if (iPort > 0)
                    {
                        this.emailHandler.iSMTPPort = iPort;
                        //Once setting has been changed, upload the change to database
                        //this.queueSettingForUpload(new CPluginVariable("SMTP-Server port", typeof(Int32), iPort));
                    }
                }
                else if (strVariable.CompareTo("Sender address") == 0)
                {
                    if (strValue == null || strValue == String.Empty)
                    {
                        this.emailHandler.strSenderMail = "SENDER_CANNOT_BE_EMPTY";
                        this.ConsoleError("No sender for email was given! Canceling Operation.");
                    }
                    else
                    {
                        this.emailHandler.strSenderMail = strValue;
                        //Once setting has been changed, upload the change to database
                        //this.queueSettingForUpload(new CPluginVariable("Sender address", typeof(string), strValue));
                    }
                }
                else if (strVariable.CompareTo("SMTP-Server username") == 0)
                {
                    if (strValue == null || strValue == String.Empty)
                    {
                        this.emailHandler.strSMTPUser = "******";
                        this.ConsoleError("No username for SMTP was given! Canceling Operation.");
                    }
                    else
                    {
                        this.emailHandler.strSMTPUser = strValue;
                        //Once setting has been changed, upload the change to database
                        //this.queueSettingForUpload(new CPluginVariable("SMTP-Server username", typeof(string), strValue));
                    }
                }
                else if (strVariable.CompareTo("SMTP-Server password") == 0)
                {
                    if (strValue == null || strValue == String.Empty)
                    {
                        this.emailHandler.strSMTPPassword = "******";
                        this.ConsoleError("No password for SMTP was given! Canceling Operation.");
                    }
                    else
                    {
                        this.emailHandler.strSMTPPassword = strValue;
                        //Once setting has been changed, upload the change to database
                        //this.queueSettingForUpload(new CPluginVariable("SMTP-Server password", typeof(string), strValue));
                    }
                }
                #endregion
                #region mute settings
                else if (Regex.Match(strVariable, @"On-Player-Muted Message").Success)
                {
                    if (this.mutedPlayerMuteMessage != strValue)
                    {
                        this.mutedPlayerMuteMessage = strValue;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"On-Player-Muted Message", typeof(string), this.mutedPlayerMuteMessage));
                    }
                }
                else if (Regex.Match(strVariable, @"On-Player-Killed Message").Success)
                {
                    if (this.mutedPlayerKillMessage != strValue)
                    {
                        this.mutedPlayerKillMessage = strValue;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"On-Player-Killed Message", typeof(string), this.mutedPlayerKillMessage));
                    }
                }
                else if (Regex.Match(strVariable, @"On-Player-Kicked Message").Success)
                {
                    if (this.mutedPlayerKickMessage != strValue)
                    {
                        this.mutedPlayerKickMessage = strValue;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"On-Player-Kicked Message", typeof(string), this.mutedPlayerKickMessage));
                    }
                }
                if (Regex.Match(strVariable, @"# Chances to give player before kicking").Success)
                {
                    int tmp = 5;
                    int.TryParse(strValue, out tmp);
                    if (this.mutedPlayerChances != tmp)
                    {
                        this.mutedPlayerChances = tmp;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"# Chances to give player before kicking", typeof(Int32), this.mutedPlayerChances));
                    }
                }
                #endregion
                #region teamswap settings
                else if (Regex.Match(strVariable, @"Require Whitelist for Access").Success)
                {
                    Boolean require = Boolean.Parse(strValue);
                    if (this.requireTeamswapWhitelist != require)
                    {
                        this.requireTeamswapWhitelist = require;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Require Whitelist for Access", typeof(Boolean), this.requireTeamswapWhitelist));
                    }
                }
                else if (Regex.Match(strVariable, @"Auto-Whitelist Count").Success)
                {
                    int tmp = 1;
                    int.TryParse(strValue, out tmp);
                    if (tmp != this.playersToAutoWhitelist)
                    {
                        if (tmp < 0)
                            tmp = 0;
                        this.playersToAutoWhitelist = tmp;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Auto-Whitelist Count", typeof(Int32), this.playersToAutoWhitelist));
                    }
                }
                else if (Regex.Match(strVariable, @"Ticket Window High").Success)
                {
                    int tmp = 2;
                    int.TryParse(strValue, out tmp);
                    if (tmp != this.teamSwapTicketWindowHigh)
                    {
                        this.teamSwapTicketWindowHigh = tmp;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Ticket Window High", typeof(Int32), this.teamSwapTicketWindowHigh));
                    }
                }
                else if (Regex.Match(strVariable, @"Ticket Window Low").Success)
                {
                    int tmp = 2;
                    int.TryParse(strValue, out tmp);
                    if (tmp != this.teamSwapTicketWindowLow)
                    {
                        this.teamSwapTicketWindowLow = tmp;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Ticket Window Low", typeof(Int32), this.teamSwapTicketWindowLow));
                    }
                }
                #endregion
                #region Admin Assistants
                else if (Regex.Match(strVariable, @"Enable Admin Assistant Perk").Success)
                {
                    Boolean enableAA = Boolean.Parse(strValue);
                    if (this.enableAdminAssistants != enableAA)
                    {
                        this.enableAdminAssistants = enableAA;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Enable Admin Assistant Perk", typeof(Boolean), this.enableAdminAssistants));
                    }
                }
                else if (Regex.Match(strVariable, @"Minimum Confirmed Reports Per Week").Success)
                {
                    Int32 weeklyReports = Int32.Parse(strValue);
                    if (this.minimumRequiredWeeklyReports != weeklyReports)
                    {
                        this.minimumRequiredWeeklyReports = weeklyReports;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Minimum Confirmed Reports Per Week", typeof(Int32), this.minimumRequiredWeeklyReports));
                    }
                }
                #endregion
                #region Messaging Settings
                else if (Regex.Match(strVariable, @"Yell display time seconds").Success)
                {
                    Int32 yellTime = Int32.Parse(strValue);
                    if (this.m_iShowMessageLength != yellTime)
                    {
                        this.m_iShowMessageLength = yellTime;
                        this.m_strShowMessageLength = m_iShowMessageLength + "";
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Yell display time seconds", typeof(Int32), this.m_iShowMessageLength));
                    }
                }
                else if (Regex.Match(strVariable, @"Pre-Message List").Success)
                {
                    this.preMessageList = new List<string>(CPluginVariable.DecodeStringArray(strValue));
                    //Once setting has been changed, upload the change to database
                    this.queueSettingForUpload(new CPluginVariable(@"Pre-Message List", typeof(string), CPluginVariable.EncodeStringArray(this.preMessageList.ToArray())));
                }
                else if (Regex.Match(strVariable, @"Require Use of Pre-Messages").Success)
                {
                    Boolean require = Boolean.Parse(strValue);
                    if (require != this.requirePreMessageUse)
                    {
                        this.requirePreMessageUse = require;
                        //Once setting has been changed, upload the change to database
                        this.queueSettingForUpload(new CPluginVariable(@"Require Use of Pre-Messages", typeof(Boolean), this.requirePreMessageUse));
                    }
                }
                #endregion
                #region access settings
                else if (Regex.Match(strVariable, @"Add Access").Success)
                {
                    if (this.soldierNameValid(strValue))
                    {
                        //Create the access object
                        AdKat_Access access = new AdKat_Access();
                        access.player_name = strValue;
                        access.access_level = 6;
                        //Queue it for processing
                        this.queueAccessUpdate(access);
                    }
                }
                else if (Regex.Match(strVariable, @"Remove Access").Success)
                {
                    this.queueAccessRemoval(strValue);
                }
                else if (this.playerAccessCache.ContainsKey(variableParse[0]))
                {
                    this.DebugWrite("Preparing for access change", 5);
                    AdKat_Access access = this.playerAccessCache[variableParse[0]];
                    if (variableParse[1] == "Access Level")
                    {
                        this.DebugWrite("Changing access level", 5);
                        access.access_level = Int32.Parse(strValue);
                    }
                    else if (variableParse[1] == "Email Address")
                    {
                        this.DebugWrite("Changing email", 5);
                        access.player_email = strValue;
                    }
                    this.queueAccessUpdate(access);
                }
                #endregion
            }
            catch (Exception e)
            {
                this.ConsoleException(e.ToString());
            }
        }
示例#10
0
文件: AdKats.cs 项目: BP4U/AdKats
 public string restartLevel(AdKat_Record record)
 {
     string message = "No Message";
     this.ExecuteCommand("procon.protected.send", "mapList.restartRound");
     message = "Round Restarted.";
     return message;
 }
示例#11
0
文件: AdKats.cs 项目: BP4U/AdKats
 public string roundWhitelistTarget(AdKat_Record record)
 {
     string message = null;
     try
     {
         if (!this.teamswapRoundWhitelist.ContainsKey(record.target_name))
         {
             if (this.teamswapRoundWhitelist.Count < this.playersToAutoWhitelist + 2)
             {
                 this.teamswapRoundWhitelist.Add(record.target_name, false);
                 string command = this.m_strTeamswapCommand;
                 message = record.target_name + " can now use @" + command + " for this round.";
             }
             else
             {
                 message = "Cannot whitelist more than two extra people per round.";
             }
         }
         else
         {
             message = record.target_name + " is already in this round's teamswap whitelist.";
         }
     }
     catch (Exception e)
     {
         message = e.ToString();
         this.ConsoleException(e.ToString());
     }
     return this.sendMessageToSource(record, message);
 }
示例#12
0
文件: AdKats.cs 项目: BP4U/AdKats
        public string punishTarget(AdKat_Record record)
        {
            this.DebugWrite("punishing target", 6);
            string message = "ERROR";
            //Get number of points the player from server
            int points = this.fetchPoints(record.target_player);
            this.DebugWrite(record.target_player.player_name + " has " + points + " points.", 5);
            //Get the proper action to take for player punishment
            string action = "noaction";
            if (points > (this.punishmentHierarchy.Length - 1))
            {
                action = this.punishmentHierarchy[this.punishmentHierarchy.Length - 1];
            }
            else if (points > 0)
            {
                action = this.punishmentHierarchy[points - 1];
            }
            //Set additional message
            string additionalMessage = "[" + ((record.isIRO) ? ("IRO ") : ("")) + points + "pts]";

            Boolean isLowPop = this.onlyKillOnLowPop && (this.playerDictionary.Count < this.lowPopPlayerCount);
            Boolean IROOverride = record.isIRO && this.IROOverridesLowPop;

            //Call correct action
            if (action.Equals("kill") || (isLowPop && !IROOverride))
            {
                record.command_action = AdKat_CommandType.KillPlayer;
                message = this.killTarget(record, additionalMessage);
            }
            else if (action.Equals("kick"))
            {
                record.command_action = AdKat_CommandType.KickPlayer;
                message = this.kickTarget(record, additionalMessage);
            }
            else if (action.Equals("tban60"))
            {
                record.command_numeric = 60;
                record.command_action = AdKat_CommandType.TempBanPlayer;
                message = this.tempBanTarget(record, additionalMessage);
            }
            else if (action.Equals("tbanday"))
            {
                record.command_numeric = 1440;
                record.command_action = AdKat_CommandType.TempBanPlayer;
                message = this.tempBanTarget(record, additionalMessage);
            }
            else if (action.Equals("tbanweek"))
            {
                record.command_numeric = 10080;
                record.command_action = AdKat_CommandType.TempBanPlayer;
                message = this.tempBanTarget(record, additionalMessage);
            }
            else if (action.Equals("tban2weeks"))
            {
                record.command_numeric = 20160;
                record.command_action = AdKat_CommandType.TempBanPlayer;
                message = this.tempBanTarget(record, additionalMessage);
            }
            else if (action.Equals("tbanmonth"))
            {
                record.command_numeric = 43200;
                record.command_action = AdKat_CommandType.TempBanPlayer;
                message = this.tempBanTarget(record, additionalMessage);
            }
            else if (action.Equals("ban"))
            {
                record.command_action = AdKat_CommandType.PermabanPlayer;
                message = this.permaBanTarget(record, additionalMessage);
            }
            else
            {
                record.command_action = AdKat_CommandType.KillPlayer;
                this.killTarget(record, additionalMessage);
                message = "Punish options are set incorrectly. Inform plugin setting manager.";
                this.ConsoleError(message);
            }
            return message;
        }
示例#13
0
文件: AdKats.cs 项目: BP4U/AdKats
 public string playerYell(AdKat_Record record)
 {
     string message = "No Message";
     this.ExecuteCommand("procon.protected.send", "admin.yell", record.record_message, this.m_strShowMessageLength, "player", record.target_name);
     message = record.target_name + " has been told '" + record.record_message + "'";
     return message;
 }
示例#14
0
文件: AdKats.cs 项目: BP4U/AdKats
 public string playerSay(AdKat_Record record)
 {
     string message = "No Message";
     this.playerSayMessage(record.target_name, record.record_message);
     message = record.target_name + " has been told '" + record.record_message + "'";
     return message;
 }
示例#15
0
文件: AdKats.cs 项目: BP4U/AdKats
 /*
  * This method handles uploading of records and calling their action methods
  * Will only upload a record if upload setting for that command is true, or if uploading is required
  */
 private Boolean handleRecordUpload(AdKat_Record record)
 {
     try
     {
         this.DebugWrite("DBCOMM: Entering handle record upload", 5);
         Boolean recordNeedsAction = true;
         //Check whether to call update, or full upload
         if (record.record_id != -1)
         {
             recordNeedsAction = false;
             //Record already has a record ID, it can only be updated
             if (this.AdKat_LoggingSettings[record.command_type])
             {
                 this.DebugWrite("DBCOMM: UPDATING record for " + record.command_type, 5);
                 //Update Record
                 this.updateRecord(record);
             }
             else
             {
                 this.DebugWrite("DBCOMM: Skipping record UPDATE for " + record.command_type, 5);
             }
         }
         else
         {
             this.DebugWrite("DBCOMM: Record needs full upload, checking.", 5);
             //No record ID. Perform full upload
             switch (record.command_type)
             {
                 case AdKat_CommandType.PunishPlayer:
                     //Upload for punish is required
                     //Check if the punish will be double counted
                     if (this.isDoubleCounted(record))
                     {
                         this.DebugWrite("DBCOMM: Punish is double counted.", 5);
                         //Check if player is on timeout
                         if (this.canPunish(record))
                         {
                             //IRO - Immediate Repeat Offence
                             record.isIRO = true;
                             //Upload record twice
                             this.DebugWrite("DBCOMM: UPLOADING IRO Punish", 5);
                             this.uploadRecord(record);
                             this.uploadRecord(record);
                         }
                         else
                         {
                             this.sendMessageToSource(record, record.target_name + " already punished in the last 20 seconds.");
                             recordNeedsAction = false;
                         }
                     }
                     else
                     {
                         //Upload record once
                         this.DebugWrite("DBCOMM: UPLOADING Punish", 5);
                         this.uploadRecord(record);
                     }
                     break;
                 case AdKat_CommandType.ForgivePlayer:
                     //Upload for forgive is required
                     //No restriction on forgives/minute
                     this.DebugWrite("DBCOMM: UPLOADING Forgive", 5);
                     this.uploadRecord(record);
                     break;
                 default:
                     if (this.AdKat_LoggingSettings[record.command_type])
                     {
                         this.DebugWrite("UPLOADING record for " + record.command_type, 5);
                         //Upload Record
                         this.uploadRecord(record);
                     }
                     else
                     {
                         this.DebugWrite("Skipping record UPLOAD for " + record.command_type, 6);
                     }
                     break;
             }
         }
         return recordNeedsAction;
     }
     catch (Exception e)
     {
         ConsoleException(e.ToString());
         return false;
     }
 }
示例#16
0
文件: AdKats.cs 项目: BP4U/AdKats
        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);
        }
示例#17
0
文件: AdKats.cs 项目: BP4U/AdKats
 public string adminYell(AdKat_Record record)
 {
     string message = "No Message";
     this.ExecuteCommand("procon.protected.send", "admin.yell", record.record_message, this.m_strShowMessageLength, "all");
     message = "Server has been told '" + record.record_message + "'";
     return message;
 }
示例#18
0
文件: AdKats.cs 项目: BP4U/AdKats
        private void banEnforcerThreadLoop()
        {
            try
            {
                this.DebugWrite("BANENF: Starting Ban Enforcer Thread", 2);
                Thread.CurrentThread.Name = "BanEnforcer";

                Queue<AdKat_Player> playerCheckingQueue;
                while (true)
                {
                    this.DebugWrite("BANENF: Entering Ban Enforcer Thread Loop", 7);
                    if (!this.isEnabled)
                    {
                        this.DebugWrite("BANENF: Detected AdKats not enabled. Exiting thread " + Thread.CurrentThread.Name, 6);
                        break;
                    }

                    //Get all unchecked players
                    playerCheckingQueue = new Queue<AdKat_Player>();
                    if (this.banEnforcerCheckingQueue.Count > 0 && this.useBanEnforcer)
                    {
                        this.DebugWrite("BANENF: Preparing to lock banEnforcerMutex to retrive new players", 6);
                        lock (banEnforcerMutex)
                        {
                            this.DebugWrite("BANENF: Inbound players found. Grabbing.", 5);
                            //Grab all players in the queue
                            playerCheckingQueue = new Queue<AdKat_Player>(this.banEnforcerCheckingQueue.ToArray());
                            //Clear the queue for next run
                            this.banEnforcerCheckingQueue.Clear();
                        }
                    }
                    else
                    {
                        this.DebugWrite("BANENF: No inbound ban checks. Waiting for Input.", 4);
                        //Wait for input
                        this.banEnforcerHandle.Reset();
                        this.banEnforcerHandle.WaitOne(Timeout.Infinite);
                        continue;
                    }

                    //Get all checks in order that they came in
                    AdKat_Player aPlayer = null;
                    while (playerCheckingQueue != null && playerCheckingQueue.Count > 0)
                    {
                        //Grab first/next player
                        aPlayer = playerCheckingQueue.Dequeue();
                        this.DebugWrite("BANENF: begin reading player", 5);

                        //this.DebugWrite("Checking " + aPlayer.player_name + " Against " + this.AdKat_BanList_Name.Count + " Name Bans. " + this.AdKat_BanList_GUID.Count + " GUID Bans. And " + this.AdKat_BanList_IP.Count + " IP Bans.", 5);

                        if (this.playerDictionary.ContainsKey(aPlayer.player_name))
                        {
                            AdKat_Ban aBan = this.fetchPlayerBan(aPlayer);

                            if (aBan != null)
                            {
                                this.DebugWrite("BANENF: BAN ENFORCED", 3);
                                //Create the new record
                                AdKat_Record record = new AdKat_Record();
                                record.source_name = "BanEnforcer";
                                record.isIRO = false;
                                record.server_id = this.server_id;
                                record.target_name = aBan.ban_record.target_player.player_name;
                                record.target_player = aBan.ban_record.target_player;
                                record.command_source = AdKat_CommandSource.InGame;
                                record.command_type = AdKat_CommandType.EnforceBan;
                                record.command_numeric = (int)aBan.ban_id;
                                record.record_message = aBan.ban_record.record_message;
                                //Queue record for upload
                                this.queueRecordForProcessing(record);
                                //Enforce the ban
                                this.enforceBan(aBan);
                            }
                            else
                            {
                                this.DebugWrite("BANENF: No ban found for player", 5);
                            }
                        }
                    }
                }
                this.DebugWrite("BANENF: Ending Ban Enforcer Thread", 2);
            }
            catch (Exception e)
            {
                this.ConsoleException(e.ToString());
                if (typeof(ThreadAbortException).Equals(e.GetType()))
                {
                    this.DebugWrite("Thread Exception", 4);
                    Thread.ResetAbort();
                    return;
                }
            }
        }
示例#19
0
文件: AdKats.cs 项目: BP4U/AdKats
        //DONE
        private Boolean isDoubleCounted(AdKat_Record record)
        {
            DebugWrite("isDoubleCounted starting!", 6);

            try
            {
                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = @"
                        SELECT
                            `record_time` AS `latest_time`
                        FROM
                            `" + this.mySqlDatabaseName + @"`.`adkats_records`
                        WHERE
                            `adkats_records`.`command_type` = 'Punish'
                        AND
                            `adkats_records`.`target_id` = " + record.target_player.player_id + @"
                        AND
                            DATE_ADD(`record_time`, INTERVAL 5 MINUTE) > NOW()
                        ORDER BY
                            `record_time`
                        DESC LIMIT 1";

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                this.DebugWrite("Punish is double counted", 6);
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DebugWrite(e.ToString(), 3);
            }
            DebugWrite("ERROR in isDoubleCounted!", 6);
            return false;
        }
示例#20
0
文件: AdKats.cs 项目: BP4U/AdKats
        private void commandParsingThreadLoop()
        {
            try
            {
                this.DebugWrite("COMMAND: Starting Command Parsing Thread", 2);
                Thread.CurrentThread.Name = "Command";
                while (true)
                {
                    this.DebugWrite("COMMAND: Entering Command Parsing Thread Loop", 7);
                    if (!this.isEnabled)
                    {
                        this.DebugWrite("COMMAND: Detected AdKats not enabled. Exiting thread " + Thread.CurrentThread.Name, 6);
                        break;
                    }

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

                    //Get all unparsed inbound messages
                    Queue<KeyValuePair<String, String>> unparsedCommands;
                    if (this.unparsedCommandQueue.Count > 0)
                    {
                        this.DebugWrite("COMMAND: Preparing to lock command queue to retrive new commands", 7);
                        lock (unparsedCommandMutex)
                        {
                            this.DebugWrite("COMMAND: Inbound commands found. Grabbing.", 6);
                            //Grab all messages in the queue
                            unparsedCommands = new Queue<KeyValuePair<string, string>>(this.unparsedCommandQueue.ToArray());
                            //Clear the queue for next run
                            this.unparsedCommandQueue.Clear();
                        }

                        //Loop through all commands in order that they came in
                        while (unparsedCommands != null && unparsedCommands.Count > 0)
                        {
                            this.DebugWrite("COMMAND: begin reading command", 6);
                            //Dequeue the first/next command
                            KeyValuePair<String, String> commandPair = unparsedCommands.Dequeue();
                            string speaker = commandPair.Key;
                            string command = commandPair.Value;

                            AdKat_Record record = new AdKat_Record();
                            record.command_source = AdKat_CommandSource.InGame;
                            record.source_name = speaker;
                            //Complete the record creation
                            this.completeRecord(record, command);
                        }
                    }
                    else
                    {
                        this.DebugWrite("COMMAND: No inbound commands, ready.", 7);
                        //No commands to parse, ready.
                        this.commandParsingHandle.Reset();
                        this.commandParsingHandle.WaitOne(Timeout.Infinite);
                        continue;
                    }
                }
                this.DebugWrite("COMMAND: Ending Command Thread", 2);
            }
            catch (Exception e)
            {
                this.ConsoleException(e.ToString());
                if (typeof(ThreadAbortException).Equals(e.GetType()))
                {
                    this.DebugWrite("COMMAND: Thread Exception", 4);
                    Thread.ResetAbort();
                    return;
                }
            }
        }
示例#21
0
文件: AdKats.cs 项目: BP4U/AdKats
 private void queueRecordForActionHandling(AdKat_Record record)
 {
     this.DebugWrite("Preparing to queue record for action handling", 6);
     lock (unprocessedActionMutex)
     {
         this.unprocessedActionQueue.Enqueue(record);
         this.DebugWrite("Record queued for action handling", 6);
         this.actionHandlingHandle.Set();
     }
 }
示例#22
0
文件: AdKats.cs 项目: BP4U/AdKats
        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;
                }
            }
        }
示例#23
0
文件: AdKats.cs 项目: BP4U/AdKats
 private string runAction(AdKat_Record record)
 {
     string response = "No Message";
     //Perform Actions
     switch (record.command_type)
     {
         case AdKat_CommandType.MovePlayer:
             response = this.moveTarget(record);
             break;
         case AdKat_CommandType.ForceMovePlayer:
             response = this.forceMoveTarget(record);
             break;
         case AdKat_CommandType.Teamswap:
             response = this.forceMoveTarget(record);
             break;
         case AdKat_CommandType.KillPlayer:
             response = this.killTarget(record, "");
             break;
         case AdKat_CommandType.KickPlayer:
             response = this.kickTarget(record, "");
             break;
         case AdKat_CommandType.TempBanPlayer:
             response = this.tempBanTarget(record, "");
             break;
         case AdKat_CommandType.PermabanPlayer:
             response = this.permaBanTarget(record, "");
             break;
         case AdKat_CommandType.PunishPlayer:
             response = this.punishTarget(record);
             break;
         case AdKat_CommandType.ForgivePlayer:
             response = this.forgiveTarget(record);
             break;
         case AdKat_CommandType.MutePlayer:
             response = this.muteTarget(record);
             break;
         case AdKat_CommandType.RoundWhitelistPlayer:
             response = this.roundWhitelistTarget(record);
             break;
         case AdKat_CommandType.ReportPlayer:
             response = this.reportTarget(record);
             break;
         case AdKat_CommandType.CallAdmin:
             response = this.callAdminOnTarget(record);
             break;
         case AdKat_CommandType.RestartLevel:
             response = this.restartLevel(record);
             break;
         case AdKat_CommandType.NextLevel:
             response = this.nextLevel(record);
             break;
         case AdKat_CommandType.EndLevel:
             response = this.endLevel(record);
             break;
         case AdKat_CommandType.NukeServer:
             response = this.nukeTarget(record);
             break;
         case AdKat_CommandType.KickAll:
             response = this.kickAllPlayers(record);
             break;
         case AdKat_CommandType.AdminSay:
             response = this.adminSay(record);
             break;
         case AdKat_CommandType.PlayerSay:
             response = this.playerSay(record);
             break;
         case AdKat_CommandType.AdminYell:
             response = this.adminYell(record);
             break;
         case AdKat_CommandType.PlayerYell:
             response = this.playerYell(record);
             break;
         case AdKat_CommandType.EnforceBan:
             //Don't do anything here, ban enforcer handles this
             break;
         default:
             response = "Command not recognized when running action.";
             this.DebugWrite("Command not found in runAction", 5);
             break;
     }
     return response;
 }
示例#24
0
文件: AdKats.cs 项目: BP4U/AdKats
        //DONE
        private AdKat_Record fetchRecordByID(Int64 record_id)
        {
            DebugWrite("fetchRecordByID starting!", 6);
            AdKat_Record record = null;
            try
            {
                //Success fetching record
                Boolean success = false;
                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        String sql = @"
                        SELECT
                            `record_id`,
                            `server_id`,
                            `command_type`,
                            `command_action`,
                            `command_numeric`,
                            `target_name`,
                            `target_id`,
                            `source_name`,
                            `record_message`,
                            `record_time`
                        FROM
                            `" + this.mySqlDatabaseName + @"`.`adkats_records`
                        WHERE
                            `record_id` = " + record_id;
                        command.CommandText = sql;
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            //Grab the record
                            if (reader.Read())
                            {
                                success = true;

                                record = new AdKat_Record();

                                record.record_id = reader.GetInt64("record_id");
                                record.server_id = reader.GetInt64("server_id");
                                record.command_type = this.getDBCommand(reader.GetString("command_type"));
                                record.command_action = this.getDBCommand(reader.GetString("command_action"));
                                record.command_numeric = reader.GetInt32("command_numeric");
                                record.target_name = reader.GetString("target_name");
                                if (!reader.IsDBNull(6))
                                {
                                    record.target_player = new AdKat_Player();
                                    record.target_player.player_id = reader.GetInt64(6);
                                }
                                record.source_name = reader.GetString("source_name");
                                record.record_message = reader.GetString("record_message");
                                record.record_time = reader.GetDateTime("record_time");
                            }
                            if (success)
                            {
                                this.DebugWrite("Record found for ID " + record_id, 5);
                            }
                            else
                            {
                                this.DebugWrite("No record found for ID " + record_id, 5);
                            }
                        }
                        if (success && record.target_player != null)
                        {
                            record.target_player = this.fetchPlayer(record.target_player.player_id, null, null, null);
                            record.target_name = record.target_player.player_name;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleException(e.ToString());
            }

            DebugWrite("fetchRecordByID finished!", 6);
            return record;
        }
示例#25
0
文件: AdKats.cs 项目: BP4U/AdKats
        //DONE
        private void updateDB_0251_0300()
        {
            if (!this.confirmTable("adkat_records"))
            {
                this.DebugWrite("No tables from previous versions. No need for database update.", 3);
                return;
            }

            try
            {
                //Get record count from current version table
                int currentRecordCount = 0;
                //initial record ID. Fetching 250 records at a time.
                Int64 initial_record_id = 0;
                Int64 importCount = 0;
                Int64 uploadCount = 0;

                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = @"
                            SELECT
                                COUNT(*) AS `record_count`
                            FROM
                                `adkats_records`";

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                currentRecordCount = reader.GetInt32("record_count");
                            }
                            else
                            {
                                this.ConsoleException("Unable to fetch current record count.");
                            }
                        }
                    }
                }

                if (currentRecordCount == 0)
                {
                    this.ConsoleWarn("Updating records from previous versions to 0.3.0.0! Do not turn off AdKats until it's finished!");
                    List<AdKat_Record> newRecords = new List<AdKat_Record>();
                    do
                    {
                        newRecords = new List<AdKat_Record>();

                        using (MySqlConnection connection = this.getDatabaseConnection())
                        {
                            this.ConsoleWrite("creating connection to update records");

                            using (MySqlCommand command = connection.CreateCommand())
                            {
                                this.ConsoleWrite("creating fetch command");
                                command.CommandText = @"
                                SELECT
                                    `record_id`,
                                    `tbl_server`.`ServerID` AS `server_id`,
                                    `command_type`,
                                    `command_action`,
                                    `record_durationMinutes`,
                                    `target_guid`,
                                    `target_name`,
                                    `source_name`,
                                    `record_message`,
                                    `record_time`
                                FROM
                                    `adkat_records`
                                INNER JOIN
                                    `tbl_server`
                                ON
                                    `adkat_records`.`server_ip` = `tbl_server`.`IP_Address`
                                WHERE
                                    `record_id` > @initial_record_id
                                ORDER BY
                                    `record_id` ASC
                                LIMIT
                                    50";

                                command.Parameters.AddWithValue("@initial_record_id", initial_record_id);

                                this.ConsoleWrite("reading input");
                                using (MySqlDataReader reader = command.ExecuteReader())
                                {
                                    //Loop through all incoming bans
                                    while (reader.Read())
                                    {
                                        //Pull record ID to post as new greatest ID
                                        initial_record_id = reader.GetInt64("record_id");

                                        AdKat_Record record = new AdKat_Record();
                                        //Get server information
                                        record.server_id = reader.GetInt64("server_id");
                                        //Get command information
                                        record.command_type = this.getDBCommand(reader.GetString("command_type"));
                                        record.command_action = this.getDBCommand(reader.GetString("command_action"));
                                        record.command_numeric = reader.GetInt32("record_durationMinutes");
                                        //Get source information
                                        record.source_name = reader.GetString("source_name");
                                        //Get target information
                                        record.target_player = this.fetchPlayer(-1, reader.GetString("target_name"), reader.GetString("target_guid"), null);
                                        //Get general record information
                                        record.record_message = reader.GetString("record_message");
                                        record.record_time = reader.GetDateTime("record_time");

                                        //Push to lists
                                        newRecords.Add(record);

                                        //Increase the import count
                                        importCount++;
                                    }
                                    this.ConsoleWrite(importCount + " records downloaded...");
                                }
                            }
                        }

                        foreach (AdKat_Record record in newRecords)
                        {
                            this.uploadRecord(record);

                            uploadCount++;
                        }
                        this.ConsoleWrite(uploadCount + " records uploaded...");
                    } while (newRecords.Count > 0);
                }

                this.ConsoleSuccess(uploadCount + " records imported from previous versions of AdKats!");

                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    //Get player access count from current version table
                    int currentAccessCount = 0;
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = @"
                        SELECT
                            COUNT(*) AS `access_count`
                        FROM
                            `adkats_accesslist`";

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                currentAccessCount = reader.GetInt32("access_count");
                            }
                            else
                            {
                                this.ConsoleException("Unable to fetch current access count.");
                            }
                        }
                    }
                    if (currentAccessCount == 0)
                    {
                        this.ConsoleWarn("Updating player access from previous versions to 0.3.0.0! Do not turn off AdKats until it's finished!");

                        List<AdKat_Access> newAccess = new List<AdKat_Access>();

                        using (MySqlCommand command = connection.CreateCommand())
                        {
                            command.CommandText = @"
                            SELECT
                                `player_name`,
                                `access_level`
                            FROM
                                `adkat_accesslist`";

                            using (MySqlDataReader reader = command.ExecuteReader())
                            {
                                importCount = 0;

                                //Loop through all incoming bans
                                while (reader.Read())
                                {
                                    AdKat_Access access = new AdKat_Access();
                                    access.player_name = reader.GetString("player_name");
                                    access.access_level = reader.GetInt32("access_level");
                                    access.member_id = 0;
                                    access.player_email = "*****@*****.**";

                                    //Push to lists
                                    newAccess.Add(access);

                                    if ((++importCount % 500) == 0)
                                    {
                                        this.ConsoleWrite(importCount + " access entries downloaded...");
                                    }
                                }
                                this.ConsoleWrite(importCount + " access entries downloaded...");
                            }
                        }

                        uploadCount = 0;
                        foreach (AdKat_Access access in newAccess)
                        {
                            this.uploadPlayerAccess(access);

                            if ((++uploadCount % 500) == 0)
                            {
                                this.ConsoleWrite(uploadCount + " access entries uploaded...");
                            }
                        }
                        this.ConsoleSuccess(uploadCount + " access entries imported from previous versions of AdKats!");

                        //Fetch the updated access list
                        this.fetchAccessList();
                    }
                }
                this.updateSettingPage();
            }
            catch (Exception e)
            {
                ConsoleException(e.ToString());
            }
        }
示例#26
0
文件: AdKats.cs 项目: BP4U/AdKats
        //DONE
        private List<AdKat_Record> fetchUnreadRecords()
        {
            DebugWrite("fetchUnreadRecords starting!", 6);
            //Create return list

            List<AdKat_Record> records = new List<AdKat_Record>();
            try
            {
                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        String sql = @"
                        SELECT
                            `record_id`,
                            `server_id`,
                            `command_type`,
                            `command_action`,
                            `command_numeric`,
                            `target_name`,
                            `target_id`,
                            `source_name`,
                            `record_message`,
                            `record_time`
                        FROM
                            `" + this.mySqlDatabaseName + @"`.`adkats_records`
                        WHERE
                            `adkats_read` = 'N'
                        AND
                            `server_id` = " + this.server_id;
                        command.CommandText = sql;
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            //Grab the record
                            while (reader.Read())
                            {
                                AdKat_Record record = new AdKat_Record();

                                record.record_id = reader.GetInt64("record_id");
                                record.server_id = reader.GetInt64("server_id");
                                record.command_type = this.getDBCommand(reader.GetString("command_type"));
                                record.command_action = this.getDBCommand(reader.GetString("command_action"));
                                record.command_numeric = reader.GetInt32("command_numeric");
                                record.target_name = reader.GetString("target_name");
                                object value = reader.GetValue(6);
                                Int64 target_id_parse = -1;
                                DebugWrite("id fetched!", 6);
                                if (Int64.TryParse(value.ToString(), out target_id_parse))
                                {
                                    DebugWrite("id parsed! " + target_id_parse, 6);
                                    record.target_player = this.fetchPlayer(target_id_parse, null, null, null);
                                    record.target_name = record.target_player.player_name;
                                }
                                else
                                {
                                    DebugWrite("id parse failed!", 6);
                                }
                                record.source_name = reader.GetString("source_name");
                                record.record_message = reader.GetString("record_message");
                                record.record_time = reader.GetDateTime("record_time");

                                records.Add(record);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleException(e.ToString());
            }

            DebugWrite("fetchUnreadRecords finished!", 6);
            return records;
        }
示例#27
0
文件: AdKats.cs 项目: BP4U/AdKats
        private void updateRecord(AdKat_Record record)
        {
            DebugWrite("updateRecord starting!", 6);

            Boolean success = false;
            try
            {
                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        Boolean hasRecordID = (record.record_id > 0);
                        //Set the insert command structure
                        command.CommandText = "UPDATE `" + this.mySqlDatabaseName + @"`.`adkats_records`
                        SET
                            `command_action` = @command_action,
                            `adkats_read` = 'Y'
                        WHERE
                            `record_id` = @record_id";
                        //Fill the command
                        //Convert enum to DB string
                        command.Parameters.AddWithValue("@record_id", record.record_id);
                        command.Parameters.AddWithValue("@command_action", this.AdKat_RecordTypes[record.command_action]);

                        //Attempt to execute the query
                        if (command.ExecuteNonQuery() > 0)
                        {
                            success = true;
                        }
                    }
                }

                string temp = this.AdKat_RecordTypes[record.command_action];

                if (success)
                {
                    DebugWrite(temp + " update for player " + record.target_name + " by " + record.source_name + " SUCCESSFUL!", 3);
                }
                else
                {
                    ConsoleError(temp + " update for player '" + record.target_name + " by " + record.source_name + " FAILED!");
                }

                DebugWrite("updateRecord finished!", 6);
            }
            catch (Exception e)
            {
                ConsoleException(e.ToString());
            }
        }
示例#28
0
文件: AdKats.cs 项目: BP4U/AdKats
 public string adminSay(AdKat_Record record)
 {
     string message = "No Message";
     this.ExecuteCommand("procon.protected.send", "admin.say", record.record_message, "all");
     message = "Server has been told '" + record.record_message + "'";
     return message;
 }
示例#29
0
文件: AdKats.cs 项目: BP4U/AdKats
        private void uploadRecord(AdKat_Record record)
        {
            DebugWrite("uploadRecord starting!", 6);

            Boolean success = false;
            try
            {
                using (MySqlConnection connection = this.getDatabaseConnection())
                {
                    using (MySqlCommand command = connection.CreateCommand())
                    {
                        //Set the insert command structure
                        command.CommandText = "INSERT INTO `" + this.mySqlDatabaseName + @"`.`adkats_records`
                        (
                            `server_id`,
                            `command_type`,
                            `command_action`,
                            `command_numeric`,
                            `target_name`,
                            `target_id`,
                            `source_name`,
                            `record_message`,
                            `adkats_read`
                        )
                        VALUES
                        (
                            @server_id,
                            @command_type,
                            @command_action,
                            @command_numeric,
                            @target_name,
                            @target_id,
                            @source_name,
                            @record_message,
                            'Y'
                        )";

                        //Fill the command
                        command.Parameters.AddWithValue("@server_id", record.server_id);

                        //Convert enum to DB string
                        string type = String.Empty;
                        string action = String.Empty;
                        if (this.AdKat_RecordTypes.TryGetValue(record.command_type, out type))
                        {
                            if (record.command_action != AdKat_CommandType.Default)
                            {
                                if (!this.AdKat_RecordTypes.TryGetValue(record.command_action, out action))
                                {
                                    this.ConsoleError("Could not find '" + record.command_type + "' in the record type list. Canceling upload.");
                                    return;
                                }
                            }
                            else
                            {
                                action = type;
                                record.command_action = record.command_type;
                            }
                        }
                        else
                        {
                            this.ConsoleError("Could not find '" + record.command_type + "' in the record type list. Canceling upload.");
                            return;
                        }
                        command.Parameters.AddWithValue("@command_type", type);
                        command.Parameters.AddWithValue("@command_action", action);
                        command.Parameters.AddWithValue("@command_numeric", record.command_numeric);
                        string tName = "NoNameTarget";
                        if (!String.IsNullOrEmpty(record.target_name))
                        {
                            tName = record.target_name;
                        }
                        if (record.target_player != null)
                        {
                            if (!String.IsNullOrEmpty(record.target_player.player_name))
                            {
                                tName = record.target_player.player_name;
                            }
                            command.Parameters.AddWithValue("@target_id", record.target_player.player_id);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@target_id", null);
                        }
                        command.Parameters.AddWithValue("@target_name", tName);
                        command.Parameters.AddWithValue("@source_name", record.source_name);
                        string messageIRO = record.record_message + ((record.isIRO) ? (" [IRO]") : (""));
                        messageIRO = messageIRO.Length <= 150 ? messageIRO : messageIRO.Substring(0, 150);
                        command.Parameters.AddWithValue("@record_message", messageIRO);
                        //Attempt to execute the query
                        if (command.ExecuteNonQuery() > 0)
                        {
                            success = true;
                            record.record_id = command.LastInsertedId;
                        }
                    }
                }

                string temp = this.AdKat_RecordTypes[record.command_action];

                if (success)
                {
                    DebugWrite(temp + " upload for player " + record.target_name + " by " + record.source_name + " SUCCESSFUL!", 3);
                }
                else
                {
                    ConsoleError(temp + " upload for player '" + record.target_name + " by " + record.source_name + " FAILED!");
                }

                DebugWrite("uploadRecord finished!", 6);
            }
            catch (Exception e)
            {
                ConsoleException(e.ToString());
            }
        }
示例#30
0
文件: AdKats.cs 项目: BP4U/AdKats
        public override HttpWebServerResponseData OnHttpRequest(HttpWebServerRequestData data)
        {
            string responseString = "AdKats Remote: ";
            try
            {
                /*foreach (String key in data.POSTData.AllKeys)
                {
                    this.DebugWrite("POST Key: " + key + " val: " + data.Headers[key], 6);
                }*/
                foreach (String key in data.Query.AllKeys)
                {
                    this.DebugWrite("Query Key: " + key + " val: " + data.Query[key], 6);
                }
                this.DebugWrite("method: " + data.Method, 6);
                //this.DebugWrite("doc: " + data.Document, 6);
                AdKat_Record record = new AdKat_Record();
                record.command_source = AdKat_CommandSource.HTTP;

                NameValueCollection dataCollection = null;
                if (String.Compare(data.Method, "GET", true) == 0)
                {
                    dataCollection = data.Query;
                }
                else if (String.Compare(data.Method, "POST", true) == 0)
                {
                    return null;//dataCollection = data.POSTData;
                }
                string commandString = dataCollection["command_type"];
                record.command_type = this.getDBCommand(commandString);

                if (dataCollection["access_key"] != null && dataCollection["access_key"].Equals(this.externalCommandAccessKey))
                {
                    //If command not parsable, return without creating
                    if (record.command_type != AdKat_CommandType.Default)
                    {
                        //Set the command action
                        record.command_action = record.command_type;

                        //Set the source
                        string sourceName = dataCollection["source_name"];
                        if (!String.IsNullOrEmpty(sourceName))
                            record.source_name = sourceName;
                        else
                            record.source_name = "HTTPAdmin";

                        string duration = dataCollection["record_durationMinutes"];
                        if (duration != null && duration.Length > 0)
                        {
                            record.command_numeric = Int32.Parse(duration);
                        }
                        else
                        {
                            record.command_numeric = 0;
                        }

                        string message = dataCollection["record_message"];
                        if (!String.IsNullOrEmpty(message))
                        {
                            if (message.Length >= this.requiredReasonLength)
                            {
                                record.record_message = message;

                                //Check the target
                                string targetName = dataCollection["target_name"];
                                //Check for an exact match
                                if (!String.IsNullOrEmpty(targetName))
                                {
                                    record.target_name = targetName;
                                    responseString += this.completeTargetInformation(record, false);
                                }
                                else
                                {
                                    responseString += "target_name cannot be null";
                                }
                            }
                            else
                            {
                                responseString += "Reason too short. Needs to be at least " + this.requiredReasonLength + " chars.";
                            }
                        }
                        else
                        {
                            responseString += "record_message cannot be null.";
                        }
                    }
                    else
                    {
                        responseString += "Command '" + commandString + "' Not Parsable. Check AdKats doc for valid DB commands.";
                    }
                }
                else
                {
                    responseString += "access_key either not given or incorrect.";
                }
            }
            catch (Exception e)
            {
                responseString += e.ToString();
            }
            return new HttpWebServerResponseData(responseString);
        }