public bool CanBuild(User user) { if (!user.CanBuild) return false; if ((from x in user.Groups where !x.CanBuild select x).Count() > 0) return false; return true; }
public void ParseUser(XmlNode node) { if (node.Attributes.Count > 0) { var user = new User(); user.Initialize(); foreach (XmlAttribute attribute in node.Attributes) { switch (attribute.Name) { case "Name": user.Name = attribute.Value; break; case "Color": Color colour; if (Color.TryParseRGB(attribute.Value, out colour)) user.Color = colour; break; case "CanBuild": bool canBuild; if (Boolean.TryParse(attribute.Value, out canBuild)) user.CanBuild = canBuild; break; case "Prefix": user.Prefix = attribute.Value; break; case "Suffix": user.Suffix = attribute.Value; break; case "ChatSeperator": user.ChatSeperator = attribute.Value; break; } } if (node.HasChildNodes) { foreach (XmlNode cNode in node.ChildNodes) { switch (cNode.Name) { case "UserGroups": if (cNode.HasChildNodes) foreach (XmlNode gNode in cNode.ChildNodes) { var groupName = gNode.InnerText.Trim(); if (HasGroup(groupName)) { var group = GetGroup(groupName); user.Groups.Add(group); } } break; case "Permissions": if (cNode.HasChildNodes) foreach (XmlNode gNode in cNode.ChildNodes) { var permission = gNode.InnerText.Trim(); if (permission != null && permission.Length > 0) user.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) user.DenyPermissions.Add(permission); } break; default: PermissionsX.XLog("Uknown element `{0}`", cNode.Name); break; } } } Users.Add(user); } }
public void AddUser(string name) { var user = new User() { Name = name }; user.Initialize(); Users.Add(user); }
public bool GetChatSeperator(User user, out string chatSeperator) { chatSeperator = ": "; if (user.ChatSeperator != chatSeperator && user.ChatSeperator != String.Empty) { chatSeperator = user.ChatSeperator; return true; } int rank = -1; foreach (var userGroup in user.Groups) { if (userGroup.Rank > rank) { chatSeperator = userGroup.ChatSeperator; rank = userGroup.Rank; } } if (rank != -1) return true; if (XmlParser.HasDefaultGroup()) { chatSeperator = XmlParser.GetDefaultGroup().ChatSeperator; return true; } return false; }
public bool HasPermission(User user, string node) { var cleanNode = node.Trim().ToLower(); foreach (var _group in user.Groups) { var groupHasDeny = (from x in _group.DenyPermissions where x.Trim().ToLower() == cleanNode || x.Trim().ToLower() == "*" select x).Count() > 0; var groupHas = (from x in _group.Permissions where x.Trim().ToLower() == cleanNode || x.Trim().ToLower() == "*" select x).Count() > 0; if (groupHasDeny) return false; if (groupHas) return true; } if ((from x in user.DenyPermissions where x.Trim().ToLower() == cleanNode || x.Trim().ToLower() == "*" select x).Count() > 0) return false; return (from x in user.Permissions where x.Trim().ToLower() == cleanNode || x.Trim().ToLower() == "*" select x).Count() > 0; }
public bool GetSuffix(User user, out string suffix) { suffix = String.Empty; if (user.Suffix.Length > 0) { suffix = user.Suffix; return true; } int rank = -1; foreach (var userGroup in user.Groups) { if (userGroup.Rank > rank) { suffix = userGroup.Suffix; rank = userGroup.Rank; } } if (rank != -1) return true; if (XmlParser.HasDefaultGroup()) { suffix = XmlParser.GetDefaultGroup().Suffix; return true; } return false; }
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; }
public bool GetColor(User user, out Color color) { color = ChatColor.White; if (user.Color != ChatColor.White) { color = user.Color; return true; } int rank = -1; foreach (var userGroup in user.Groups) { if (userGroup.Rank > rank) { color = userGroup.Color; rank = userGroup.Rank; } } if (rank != -1) return true; if (XmlParser.HasDefaultGroup()) { color = XmlParser.GetDefaultGroup().Color; return true; } return false; }