public void UserPermissions(ISender sender, ArgumentList args) { var addPerms = args.TryPop("addperms"); var addGroup = args.TryPop("addgroup"); var denyPerms = args.TryPop("denyperms"); var removeGroup = args.TryPop("removegroup"); var removePerms = args.TryPop("removeperms"); var removeDeniedPerms = args.TryPop("removedenied"); var save = args.TryPop("-save"); if (addPerms || denyPerms || removePerms || removeDeniedPerms) { string username, permission; if (args.TryParseTwo <String, String>(out username, out permission)) { Player trueUser = null; var matches = Server.FindPlayerByPart(username); if (matches.Count == 1) { trueUser = matches.ToArray()[0]; } var user = trueUser == null ? username : (trueUser.Name ?? username); if (!XmlParser.HasUser(user)) { throw new CommandError("{1} `{0}`", user, Languages.NoUser); } var permissions = permission.Split(','); var add = addPerms || denyPerms; int added = 0, failed = 0; foreach (var node in permissions) { var res = false; if (add) { if (addPerms) { res = XmlParser.AddNodeToUser(user, node); } else { res = XmlParser.AddDeniedNodeToUser(user, node); } } else { if (removePerms) { res = XmlParser.RemovePermissionFromUser(user, node); } else { res = XmlParser.RemoveDeniedPermissionFromUser(user, node); } } if (res) { added++; } else { failed++; } } if (save) { XmlParser.Save(); } sender.sendMessage( String.Format("{2} {0} {3} {1} {4}", added, failed, add ? Languages.Added : Languages.Removed, Languages.NodesWhere, Languages.Failed ) ); } else { throw new CommandError(Languages.UserAndNodeExpected); } } else if (addGroup || removeGroup) { string username, group; if (args.TryParseTwo <String, String>(out username, out group)) { var groups = group.Split(','); Player trueUser = null; var matches = Server.FindPlayerByPart(username); if (matches.Count == 1) { trueUser = matches.ToArray()[0]; } var user = trueUser == null ? username : (trueUser.Name ?? username); if (!XmlParser.HasUser(user)) { throw new CommandError("{1} `{0}`", user, Languages.NoUser); } int added = 0, failed = 0; foreach (var node in groups) { if (!XmlParser.HasGroup(node)) { sender.sendMessage(String.Format("{1} `{0}`", node, Languages.NoGroup)); continue; } var res = false; if (addGroup) { res = XmlParser.AddGroupToUser(user, node); } else { res = XmlParser.RemoveGroupFromUser(user, node); } if (res) { added++; } else { failed++; } } if (save) { XmlParser.Save(); } sender.sendMessage( String.Format("{2} {0} {3} {1} {4}", added, failed, addGroup ? Languages.Added : Languages.Removed, Languages.NodesWhere, Languages.Failed ) ); } else { throw new CommandError(Languages.UserAndGrpExpected); } } else { throw new CommandError(Languages.ArgumentsExpected); } }