public void AddGroup(string name)
 {
     var group = new Group()
     {
         Name = name
     };
     group.Initialize();
     Groups.Add(group);
 }
 public void UpdateGroup(Group group)
 {
     for (var i = 0; i < Groups.Count; i++)
     {
         if (Groups[i].Name == group.Name) Groups[i] = group;
     }
 }
        public void ParseGroup(XmlNode node)
        {
            if (node.Attributes.Count > 0)
            {
                var group = new Group();
                group.Initialize();

                foreach (XmlAttribute attribute in node.Attributes)
                {
                    switch (attribute.Name)
                    {
                        case "Name":
                            group.Name = attribute.Value;
                            break;
                        case "Color":
                            Color colour;
                            if (Color.TryParseRGB(attribute.Value, out colour)) group.Color = colour;
                            break;
                        case "CanBuild":
                            bool canBuild;
                            if (Boolean.TryParse(attribute.Value, out canBuild)) group.CanBuild = canBuild;
                            break;
                        case "Default":
                            if (HasDefaultGroup())
                            {
                                ProgramLog.Admin.Log("[Warning] Multiple default groups");
                                continue;
                            }

                            bool _default;
                            if (Boolean.TryParse(attribute.Value, out _default)) group.Default = _default;
                            break;
                        case "Prefix":
                            group.Prefix = attribute.Value;
                            break;
                        case "Suffix":
                            group.Suffix = attribute.Value;
                            break;
                        case "ChatSeperator":
                            group.ChatSeperator = attribute.Value;
                            break;
                        case "Rank":
                            int rank;
                            if (Int32.TryParse(attribute.Value, out rank)) group.Rank = rank;
                            break;
                    }
                }

                if (node.HasChildNodes)
                {
                    foreach (XmlNode cNode in node.ChildNodes)
                    {
                        switch (cNode.Name)
                        {
                            case "Permissions":
                                if (cNode.HasChildNodes)
                                    foreach (XmlNode gNode in cNode.ChildNodes)
                                    {
                                        var permission = gNode.InnerText.Trim();
                                        if (permission != null && permission.Length > 0) group.Permissions.Add(permission);
                                    }
                                break;
                            case "DenyPermissions":
                                if (cNode.HasChildNodes)
                                    foreach (XmlNode gNode in cNode.ChildNodes)
                                    {
                                        var permission = gNode.InnerText.Trim();
                                        if (permission != null && permission.Length > 0) group.DenyPermissions.Add(permission);
                                    }
                                break;
                            default:
                                PermissionsX.XLog("Uknown element `{0}`", cNode.Name);
                                break;
                        }
                    }
                }

                Groups.Add(group);
            }
        }
        public bool GetParentGroup(User user, out Group group)
        {
            group = default(Group);

            int rank = -1;
            foreach (var userGroup in user.Groups)
            {
                if (userGroup.Rank > rank)
                {
                    group = userGroup;
                    rank = userGroup.Rank;
                }
            }
            if (rank != -1) return true;

            if (XmlParser.HasDefaultGroup())
            {
                group = XmlParser.GetDefaultGroup();
                return true;
            }

            return false;
        }