Example #1
0
        static void ReadVersion1(string[] lines, List <string> cmdNames)
        {
            foreach (string line in lines)
            {
                if (line == "" || line[0] == '#')
                {
                    continue;
                }
                rankAllowance perms = new rankAllowance();
                string        key   = line.Split('=')[0].Trim().ToLower();
                string        value = line.Split('=')[1].Trim().ToLower();

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

                    for (int i = 0; i < allowedCommands.Count; i++)
                    {
                        if (allowedCommands[i].commandName == key)
                        {
                            allowedCommands[i] = perms; break;
                        }
                    }
                }
            }
        }
Example #2
0
        static void LoadVersion1(string[] lines)
        {
            foreach (string line in lines)
            {
                if (line == "" || line[0] == '#')
                {
                    continue;
                }

                try {
                    byte            block      = Block.Byte(line.Split(' ')[0]);
                    LevelPermission lowestRank = Level.PermissionFromName(line.Split(' ')[2]);
                    if (lowestRank != LevelPermission.Null)
                    {
                        BlockList[block].lowestRank = lowestRank;
                    }
                    else
                    {
                        throw new InvalidDataException("Line " + line + " is invalid.");
                    }
                }
                catch { Server.s.Log("Could not find the rank given on " + line + ". Using default"); }
            }
        }
Example #3
0
        static void LoadVersion1(string[] lines)
        {
            foreach (string s in lines)
            {
                if (s[0] == '#')
                {
                    continue;
                }

                try {
                    byte            type       = Block.Byte(s.Split(' ')[0]);
                    LevelPermission lowestRank = Level.PermissionFromName(s.Split(' ')[2]);
                    if (lowestRank != LevelPermission.Null)
                    {
                        BlockList[type].lowestRank = lowestRank;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                catch { Server.s.Log("Could not find the rank given on " + s + ". Using default"); }
            }
        }
Example #4
0
        public static void fillRanks()
        {
            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"))
            {
                string[] lines = File.ReadAllLines("properties/command.properties");

                //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.s.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.s.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.s.Log("Incorrect command name: " + key);
                        }
                        else if (Level.PermissionFromName(value) == LevelPermission.Null)
                        {
                            Server.s.Log("Incorrect value given for " + key + ", using default value.");
                        }
                        else
                        {
                            allowVar.commandName = key;
                            allowVar.lowestRank  = Level.PermissionFromName(value);

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

            foreach (Group grp in Group.GroupList)
            {
                grp.fillCommands();
            }
        }