Ejemplo n.º 1
0
        public void ExecuteConnectionConfig(string strConfigFile, int iRecursion, List<string> lstArguments, bool blIncPlugin) {

            //FileStream stmConfigFile = null;
            try {

                if (File.Exists(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Configs"),strConfigFile)) == true) {

                    //stmConfigFile = new FileStream(String.Format(@"{0}Configs\{1}", AppDomain.CurrentDomain.BaseDirectory, strConfigFile), FileMode.Open);

                    string[] a_strConfigData = File.ReadAllLines(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs"), strConfigFile));

                    if (a_strConfigData != null) {

                        foreach (string strLine in a_strConfigData) {
                            if (strLine.Length > 0 && Regex.Match(strLine, "^[ ]+//.*").Success == false) { // AND not a comment..

                                if (lstArguments != null) {

                                    string strReplacedLine = strLine;

                                    for (int i = 0; i < lstArguments.Count; i++) {
                                        strReplacedLine = strReplacedLine.Replace(String.Format("%arg:{0}%", i), lstArguments[i]);
                                    }

                                    List<string> lstWordifiedCommand = Packet.Wordify(strReplacedLine);
                                    // procon.protected.config.demand 48543 CanKickPlayers procon.protected.send admin.say "You're not allowed to kick" player phogue
                                    if (lstWordifiedCommand.Count >= 3 && String.Compare(lstWordifiedCommand[0], "procon.protected.config.demand", true) == 0) {

                                        UInt32 ui32PrivilegesFlags = 0;

                                        if (UInt32.TryParse(lstWordifiedCommand[1], out ui32PrivilegesFlags) == true) {
                                            CPrivileges cpConfigPrivs = new CPrivileges(ui32PrivilegesFlags);
                                            bool blHasPrivileges = false;

                                            try {
                                                System.Reflection.PropertyInfo[] a_piAllProperties = cpConfigPrivs.GetType().GetProperties();

                                                foreach (System.Reflection.PropertyInfo pInfo in a_piAllProperties) {
                                                    if (String.Compare(pInfo.GetGetMethod().Name, "get_" + lstWordifiedCommand[2]) == 0) {
                                                        blHasPrivileges = (bool)pInfo.GetValue(cpConfigPrivs, null);
                                                        break;
                                                    }
                                                }

                                                if (blHasPrivileges == false) {

                                                    // If they have asked for a command on failure..
                                                    if (lstWordifiedCommand.Count > 3) {
                                                        if (blIncPlugin == true) {
                                                            this.Parent.ExecutePRoConCommandCon(this, lstWordifiedCommand.GetRange(3, lstWordifiedCommand.Count - 3), iRecursion++);
                                                        } else {
                                                            this.Parent.ExecutePRoConCommand(this, lstWordifiedCommand.GetRange(3, lstWordifiedCommand.Count - 3), iRecursion++);
                                                        }
                                                    }

                                                    // Cancel execution of the config file, they don't have the demanded privileges.
                                                    break;
                                                }
                                            }
                                            catch (Exception e) {
                                                FrostbiteConnection.LogError("Parsing a config.", String.Empty, e);
                                                break;
                                            }
                                        }
                                        else {
                                            // Cancel execution of the config file, wrong format for demand.
                                            break;
                                        }
                                    }
                                    else {
                                        if (blIncPlugin == true) {
                                            this.Parent.ExecutePRoConCommandCon(this, lstWordifiedCommand, iRecursion++);
                                        } else {
                                            this.Parent.ExecutePRoConCommand(this, lstWordifiedCommand, iRecursion++);
                                        }
                                    }
                                }
                                else {
                                    if (blIncPlugin == true) {
                                        this.Parent.ExecutePRoConCommandCon(this, Packet.Wordify(strLine), iRecursion++);
                                    } else {
                                        this.Parent.ExecutePRoConCommand(this, Packet.Wordify(strLine), iRecursion++);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) {
                FrostbiteConnection.LogError("ExecuteConnectionConfig", String.Empty, e);
            }
        }