Пример #1
0
 /// <summary>
 /// Fill the commands that this group can use
 /// </summary>
 public void fillCommands()
 {
     CommandList _commands = new CommandList();
     GrpCommands.AddCommands(out _commands, Permission);
     commands = _commands;
 }
Пример #2
0
        public static void AddCommands(out CommandList commands, LevelPermission perm)
        {
            commands = new CommandList();

                            foreach (rankAllowance aV in allowedCommands.Where(aV => (aV.lowestRank <= perm && !aV.disallow.Contains(perm)) || aV.allow.Contains(perm)))
                                commands.Add(Command.all.Find(aV.commandName));
        }
Пример #3
0
        public static void LoadPermissions()
        {
            foundCommands = Command.all.commandNames();
            allowedCommands = new List<rankAllowance>();

            rankAllowance allowVar;

            foreach (Command cmd in Command.all.All())
            {
                allowVar = new rankAllowance();
                allowVar.commandName = cmd.name;
                allowVar.lowestRank = cmd.defaultRank;
                allowedCommands.Add(allowVar);
            }
            if (File.Exists("properties/command.properties"))
                File.Move("properties/command.properties", "properties/bc_command.config");
            if (File.Exists("properties/bc_command.config"))
            {
                string[] lines = File.ReadAllLines("properties/bc_command.config");

                //if (lines.Length == 0) ; // this is useless?
                /*else */if (lines[0] == "#Version 2")
                {
                    string[] colon = new[] { " : " };
                    foreach (string line in lines)
                    {
                        allowVar = new rankAllowance();
                        if (line == "" || line[0] == '#') continue;
                        //Name : Lowest : Disallow : Allow
                        string[] command = line.Split(colon, StringSplitOptions.None);

                        if (!foundCommands.Contains(command[0]))
                        {
                            Server.Log("Incorrect command name: " + command[0]);
                            continue;
                        }
                        allowVar.commandName = command[0];

                        string[] disallow = new string[0];
                        if (command[2] != "")
                            disallow = command[2].Split(',');
                        string[] allow = new string[0];
                        if (command[3] != "")
                            allow = command[3].Split(',');

                        try
                        {
                            allowVar.lowestRank = (LevelPermission)int.Parse(command[1]);
                            foreach (string s in disallow) { allowVar.disallow.Add((LevelPermission)int.Parse(s)); }
                            foreach (string s in allow) { allowVar.allow.Add((LevelPermission)int.Parse(s)); }
                        }
                        catch
                        {
                            Server.Log("Hit an error on the command " + line);
                            continue;
                        }

                        int current = 0;
                        foreach (rankAllowance aV in allowedCommands)
                        {
                            if (command[0] == aV.commandName)
                            {
                                allowedCommands[current] = allowVar;
                                break;
                            }
                            current++;
                        }
                    }
                }
                else
                {
                    foreach (string line in lines.Where(line => line != "" && line[0] != '#'))
                    {
                        allowVar = new rankAllowance();
                        string key = line.Split('=')[0].Trim().ToLower();
                        string value = line.Split('=')[1].Trim().ToLower();

                        if (!foundCommands.Contains(key))
                        {
                            Server.Log("Incorrect command name: " + key);
                        }
                        else if (PermissionFromName(value) == LevelPermission.Null)
                        {
                            Server.Log("Incorrect value given for " + key + ", using default value.");
                        }
                        else
                        {
                            allowVar.commandName = key;
                            allowVar.lowestRank = PermissionFromName(value);

                            int current = 0;
                            foreach (rankAllowance aV in allowedCommands)
                            {
                                if (key == aV.commandName)
                                {
                                    allowedCommands[current] = allowVar;
                                    break;
                                }
                                current++;
                            }
                        }
                    }
                }
                Save(allowedCommands);
            }
            else Save(allowedCommands);

            for (int i = 0; i < Group.getGroupList().size(); i++)
            {
                Group g = (Group)Group.getGroupList().get(i);
                CommandList commands = new CommandList();

                foreach (rankAllowance aV in allowedCommands.Where(aV => (aV.lowestRank <= (LevelPermission)g.permissionlevel && !aV.disallow.Contains((LevelPermission)g.permissionlevel)) || aV.allow.Contains((LevelPermission)g.permissionlevel)))
                    commands.Add(Command.all.Find(aV.commandName));

                Command.permission.Add(g, commands);
            }
        }