本文整理汇总了C#中ArgumentList.TryParseTwo方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentList.TryParseTwo方法的具体用法?C# ArgumentList.TryParseTwo怎么用?C# ArgumentList.TryParseTwo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArgumentList
的用法示例。
在下文中一共展示了ArgumentList.TryParseTwo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Perms_Add
void Perms_Add(ISender sender, ArgumentList args)
{
//permsadd -group <group> -node <node>
//permsadd -user <user> -group <group>
//permsadd -user <user> -node <node>
var Name = "";
var Secondary = "";
if (args.TryParseTwo("-group", out Name, "-node", out Secondary))
{
Group grp = Permissions.GetGroup(Name);
if (grp == null)
throw new CommandError("Group not found.");
var token = Secondary.Substring(0, 1) == "-"; //Allowed or not?.
grp.permissions.Add(Secondary, token);
}
else if (args.TryParseTwo("-user", out Name, "-group", out Secondary))
{
Group grp = Permissions.GetGroup(Secondary);
if (grp == null)
throw new CommandError("Group not found.");
User usr = Permissions.GetUser(Name);
if (usr == null)
throw new CommandError("User not found.");
usr.group.Add(Secondary);
}
else if (args.TryParseTwo("-user", out Name, "-node", out Secondary))
{
User usr = Permissions.GetUser(Name);
if (usr == null)
throw new CommandError("User not found.");
usr.hasPerm.Add(Secondary);
}
else
throw new CommandError("Unknown command.");
sender.sendMessage(
String.Format("`{0}` successfully added to `{1}`", Secondary, Name)
);
}
示例2: AddUser
public static void AddUser(Server server, ISender sender, ArgumentList args)
{
String User = "", IP = "";
Int32 Slot;
args.TryParseOne<String>("-ip", out IP); //Optional
//IP or name?
if (args.TryParseTwo<String, Int32>("-name", out User, "-slot", out Slot))
{
String[] exceptions = new String[2];
if (User.Length > 0)
{
exceptions[0] = User;
}
if (IP.Length > 0)
{
exceptions[1] = IP;
}
Region.Region region = null;
for (int i = 0; i < Regions.regionManager.Regions.Count; i++)
{
if (Slot == i)
region = Regions.regionManager.Regions[i];
break;
}
if (region == null)
throw new CommandError("Specified Region Slot was incorrect.");
//List<String> users = new List<String>();
int usersAdded = 0;
foreach (String toInflate in exceptions)
{
if (toInflate != null)
foreach (String inflatee in toInflate.Split(','))
{
region.UserList.Add(inflatee);
usersAdded++;
}
}
if (usersAdded > 0)
{
sender.sendMessage(string.Format("{0} users were added to {1}", usersAdded, region.Name),
255, 0, 255, 0);
Regions.Log(sender.Name + " created region {0} with {1} user/s", region.Name, usersAdded);
}
else
throw new CommandError("A user was not able to be added to a Region.");
}
else
throw new CommandError("Invalid arguments, Please review your command.");
}
示例3: GroupPermissions
public void GroupPermissions(ISender sender, ArgumentList args)
{
var addPerms = args.TryPop("addperms");
var denyPerms = args.TryPop("denyperms");
var removePerms = args.TryPop("removeperms");
var removeDeniedPerms = args.TryPop("removedenied");
var save = args.TryPop("-save");
if (addPerms || denyPerms || removePerms || removeDeniedPerms)
{
string group, permission;
if (args.TryParseTwo<String, String>(out group, out permission))
{
if (!XmlParser.HasGroup(group)) throw new CommandError("{1} `{0}`", group,Languages.NoGroup);
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.AddNodeToGroup(group, node);
else res = XmlParser.AddDeniedNodeToGroup(group, node);
}
else
{
if (removePerms) res = XmlParser.RemovePermissionFromGroup(group, node);
else res = XmlParser.RemoveDeniedPermissionFromGroup(group, 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.GrpAndNodeExpected);
}
else throw new CommandError(Languages.ArgumentsExpected);
}
示例4: Create
public static void Create(Server server, ISender sender, ArgumentList args)
{
if (sender is Player)
{
String Name = "";
String Desc = "";
Boolean Restrict = args.TryPop("-res");
Boolean RestrictNPC = args.TryPop("-npcres");
if (args.TryParseTwo<String, String>("-name", out Name, "-desc", out Desc)
&& Name.Trim().Length > 0)
{
var player = sender as Player;
if (Selection.isInSelectionlist(player))
{
Vector2[] regionAxis = Selection.GetSelection(player);
Region.Region rgn = new Region.Region();
rgn.Name = Name;
rgn.Description = Desc;
rgn.Point1 = regionAxis[0];
rgn.Point2 = regionAxis[1];
rgn.Restricted = Restrict;
rgn.RestrictedNPCs = RestrictNPC;
if (rgn.IsValidRegion())
{
Regions.regionManager.Regions.Add(rgn);
if(Regions.regionManager.SaveRegion(rgn))
player.sendMessage("Region '" + Name + "' was successfully created.", ChatColour.Green);
else
player.sendMessage("There was an issue while saving the region", ChatColour.Red);
}
else
{
player.sendMessage("There was an issue while creating the region", ChatColour.Red);
}
}
else
{
player.sendMessage("You need to select a region first!", ChatColour.Red);
}
}
else
{
throw new CommandError("You have not specified certain arguments");
}
}
}
示例5: RConCommand
internal static void RConCommand(ISender sender, ArgumentList args)
{
string name, pass;
if (args.TryPop("add") && args.TryParseTwo(out name, out pass))
{
if (sender is Player || sender is RConSender)
{
sender.SendMessage("Permissions error", 255, 238, 130, 238);
return;
}
var password = Hash(name, pass);
LoginDatabase.SetValue(name, password);
LoginDatabase.Save();
ProgramLog.Log("User `{0}` was added to the RCON Database.", name);
}
else if (args.TryParseOne("cut", out name))
{
if (sender is Player || sender is RConSender)
{
sender.SendMessage("Permissions error", 255, 238, 130, 238);
return;
}
var lower = name.ToLower();
foreach (var rcon in clients)
{
if (rcon.Name.ToLower() == lower)
rcon.Close();
}
ProgramLog.Admin.Log("Cut all remote console connections from {0}.", name);
}
else if (args.TryParseOne("ban", out name))
{
if (sender is Player || sender is RConSender)
{
sender.SendMessage("Permissions error", 255, 238, 130, 238);
return;
}
LoginDatabase.SetValue(name, null);
var lower = name.ToLower();
foreach (var rcon in clients)
{
if (rcon.Name.ToLower() == lower)
rcon.Close();
}
ProgramLog.Admin.Log("Cut all remote console connections from {0} and revoked credentials.", name);
}
else if (args.Count == 1 && args.GetString(0) == "list")
{
foreach (var rcon in clients)
{
sender.SendMessage(String.Format("{0} {1}", rcon.Id, rcon.state));
}
}
else if (args.Count == 1 && args.GetString(0) == "load")
{
if (sender is Player || sender is RConSender)
{
sender.SendMessage("Permissions error", 255, 238, 130, 238);
return;
}
LoginDatabase.Load();
ProgramLog.Admin.Log("Reloaded remote console login database.");
}
else
{
throw new CommandError("");
}
}
示例6: AddProjectile
public void AddProjectile(ISender sender, ArgumentList args)
{
string projectiles, regionName = "";
int Slot;
if (args.TryParseTwo<String, Int32>("-proj", out projectiles, "-slot", out Slot) ||
args.TryParseTwo<String, String>("-proj", out projectiles, "-region", out regionName))
{
Region region = null;
for (int i = 0; i < regionManager.Regions.Count; i++)
{
if (Slot == i)
{
region = regionManager.Regions[i];
break;
}
}
//[TODO] TEST ME
if (region == null && regionName.Length > 0)
{
for (int i = 0; i < regionManager.Regions.Count; i++)
{
if (regionManager.Regions[i].Name.Trim().ToLower().Replace(" ", "").Equals(regionName.ToLower()))
{
region = regionManager.Regions[i];
break;
}
}
}
if (region == null)
throw new CommandError("Specified Region Slot was incorrect.");
int Count = 0;
foreach (string proj in projectiles.Split(','))
{
if (proj.Trim().Length > 0)
{
region.ProjectileList.Add(proj.Trim().ToLower().Replace(" ", ""));
Count++;
}
}
if (Count > 0)
{
if (regionManager.SaveRegion(region))
{
string Proj = (projectiles == "*") ? "All" : Count.ToString();
sender.sendMessage(String.Format("{0} projectiles were blocked in Region '{1}'", Proj, region.Name),
255, 0, 255);
}
else
sender.sendMessage(String.Format("Failed to save Region '{0}'", region.Name));
}
else
sender.sendMessage(String.Format("No projectiles specified to add to Region '{0}'", region.Name));
}
else
throw new CommandError("Please review your command");
}
示例7: RemoveUser
public void RemoveUser(ISender sender, ArgumentList args)
{
string User = "", IP = "";
int Slot;
TryFindArg(args, "-ip", out IP); //Optional
//IP or name?
if (args.TryParseTwo<String, Int32>("-name", out User, "-slot", out Slot))
{
string[] exceptions = new string[2];
if (User.Length > 0)
{
exceptions[0] = User;
}
if (IP.Length > 0)
{
exceptions[1] = IP;
}
Region region = null;
for (int i = 0; i < regionManager.Regions.Count; i++)
{
if (Slot == i)
{
region = regionManager.Regions[i];
break;
}
}
if (region == null)
throw new CommandError("Specified Region Slot was incorrect.");
int usersRemoved = 0;
foreach (string toInflate in exceptions)
{
if (toInflate != null)
foreach (string inflatee in toInflate.Split(','))
{
if (region.UserList.Contains(inflatee))
{
region.UserList.Remove(inflatee);
usersRemoved++;
}
}
}
if (usersRemoved > 0)
{
if (regionManager.SaveRegion(region))
{
sender.sendMessage(String.Format("{0} users were removed from {1}", usersRemoved, region.Name),
255, 0, 255);
}
else
sender.sendMessage(String.Format("Failed to save Region '{0}'", region.Name));
}
else
throw new CommandError("A user was not able to be removed from a Region.");
}
else
throw new CommandError("Invalid arguments, Please review your command.");
}
示例8: RemoveProjectile
public void RemoveProjectile(ISender sender, ArgumentList args)
{
string projectiles;
int Slot;
if (args.TryParseTwo<String, Int32>("-proj", out projectiles, "-slot", out Slot))
{
Region region = null;
for (int i = 0; i < regionManager.Regions.Count; i++)
{
if (Slot == i)
{
region = regionManager.Regions[i];
break;
}
}
if (region == null)
throw new CommandError("Specified Region Slot was incorrect.");
int Count = 0;
foreach (string proj in projectiles.Split(','))
{
if (proj.Trim().Length > 0)
{
string projectile = proj.Trim().ToLower().Replace(" ", "");
while (region.ProjectileList.Contains(projectile))
{
if (region.ProjectileList.Remove(projectile))
Count++;
}
}
}
if (Count > 0)
{
if (regionManager.SaveRegion(region))
{
string Proj = (projectiles == "*") ? "All" : Count.ToString();
sender.sendMessage(String.Format("{0} projectiles were unblocked in Region '{1}'", Proj, region.Name),
255, 0, 255);
}
else
sender.sendMessage(String.Format("Failed to save Region '{0}'", region.Name));
}
else
sender.sendMessage(String.Format("No projectiles specified to remove from Region '{0}'", region.Name));
}
else
throw new CommandError("Please review your command");
}
示例9: AddUser
public void AddUser(ISender sender, ArgumentList args)
{
string User = "", IP = "", regionName = "";
int Slot = -1;
//args.TryParseOne<String>("-ip", out IP); //Optional
//IP or name?
if (args.TryParseTwo<String, Int32>("-name", out User, "-slot", out Slot) ||
args.TryParseTwo<String, Int32>("-ip", out User, "-slot", out Slot) ||
args.TryParseTwo<String, String>("-name", out User, "-region", out regionName) ||
args.TryParseTwo<String, String>("-ip", out User, "-region", out regionName))
{
string[] exceptions = new string[2];
if (User.Length > 0)
{
exceptions[0] = User;
}
if (IP.Length > 0)
{
exceptions[1] = IP;
}
Region region = null;
for (int i = 0; i < regionManager.Regions.Count; i++)
{
if (Slot == i)
{
region = regionManager.Regions[i];
break;
}
}
//[TODO] TEST ME
if (region == null && regionName.Length > 0)
{
for (int i = 0; i < regionManager.Regions.Count; i++)
{
if (regionManager.Regions[i].Name.Trim().ToLower().Replace(" ", "").Equals(regionName.ToLower()))
{
region = regionManager.Regions[i];
break;
}
}
}
if (region == null)
throw new CommandError("Specified Region Slot was incorrect.");
int usersAdded = 0;
foreach (string toInflate in exceptions)
{
if (toInflate != null)
foreach (string inflatee in toInflate.Split(','))
{
region.UserList.Add(inflatee);
usersAdded++;
}
}
if (usersAdded > 0)
{
if (regionManager.SaveRegion(region))
{
sender.sendMessage(String.Format("{0} users were added to {1}", usersAdded, region.Name),
255, 0, 255);
RegionsPlugin.Log(sender.Name + " created region {0} with {1} user/s", region.Name, usersAdded);
}
else
sender.sendMessage(String.Format("Failed to save Region '{0}'", region.Name));
}
else
throw new CommandError("A user was not able to be added to a Region.");
}
else
throw new CommandError("Invalid arguments, Please review your command.");
}
示例10: Teleport
/// <summary>
/// Teleports player1 to a second specified player's location.
/// </summary>
/// <param name="server">Current Server instance</param>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void Teleport(Server server, ISender sender, ArgumentList args)
{
Player subject;
Player target;
if (! args.TryPopOne (out subject))
{
subject = sender as Player;
if (subject == null)
{
sender.sendMessage ("Need specify who to teleport.");
return;
}
if (args.Count == 0)
{
if (subject.Teleport (Main.spawnTileX, Main.spawnTileY))
{
Program.server.notifyOps (string.Concat ("Teleported ", subject.Name, " to spawn."), true);
}
else
sender.sendMessage ("Teleportation failed.");
return;
}
}
else if (args.Count == 0)
{
target = subject;
subject = sender as Player;
if (subject == null)
{
sender.sendMessage ("Need specify who to teleport.");
return;
}
if (subject.Teleport (target))
{
Program.server.notifyOps (string.Concat ("Teleported ", subject.Name, " to ",
target.Name, ". {", sender.Name, "}"), true);
}
else
sender.sendMessage ("Teleportation failed.");
return;
}
int x;
int y;
if (args.Count == 1)
{
if (args.TryParseOne (out target))
{
if (subject.Teleport (target))
{
Program.server.notifyOps (string.Concat ("Teleported ", subject.Name, " to ",
target.Name, ". {", sender.Name, "}"), true);
}
else
sender.sendMessage ("Teleportation failed.");
}
else
sender.sendMessage ("Target player not found.");
return;
}
else if (args.Count == 2)
{
if (args.TryParseTwo (out x, out y))
{
if (x < 0 || x >= Main.maxTilesX || y < 0 || y >= Main.maxTilesY)
{
sender.sendMessage (string.Format ("Coordinates out of range of (0, {0}); (0, {1}).", Main.maxTilesX, Main.maxTilesY));
return;
}
if (subject.Teleport (x, y))
{
Program.server.notifyOps (string.Concat ("Teleported ", subject.Name, " to ",
x, ":", y, ". {", sender.Name, "}"), true);
}
else
sender.sendMessage ("Teleportation failed.");
}
else
throw new CommandError ("Invalid coordinates.");
return;
}
throw new CommandError ("");
}
示例11: Teleport
/// <summary>
/// Teleports player1 to a second specified player's location.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void Teleport(ISender sender, ArgumentList args)
{
Player subject;
Player target;
if (!args.TryPopOne(out subject))
{
subject = sender as Player;
if (subject == null)
{
sender.sendMessage(Languages.NeedTeleportTarget);
return;
}
if (args.Count == 0)
{
if (subject.Teleport(Main.spawnTileX, Main.spawnTileY))
{
Server.notifyOps(String.Format(Languages.TeleportedToSpawn, subject.Name), true);
}
else
sender.sendMessage(Languages.TeleportFailed);
return;
}
}
else if (args.Count == 0)
{
target = subject;
subject = sender as Player;
if (subject == null)
{
sender.sendMessage(Languages.NeedTeleportTarget);
return;
}
if (subject.Teleport(target))
{
Server.notifyOps(string.Concat("Teleported ", subject.Name, " to ",
target.Name, ". [", sender.Name, "]"), true);
}
else
sender.sendMessage(Languages.TeleportFailed);
return;
}
int x;
int y;
if (args.Count == 1)
{
if (args.TryParseOne(out target))
{
if (subject.Teleport(target))
{
Server.notifyOps(string.Concat("Teleported ", subject.Name, " to ",
target.Name, ". [", sender.Name, "]"), true);
}
else
sender.sendMessage(Languages.TeleportFailed);
}
else
sender.sendMessage(Languages.PlayerNotFound);
return;
}
else if (args.Count == 2)
{
if (args.TryParseTwo(out x, out y))
{
if (x < 0 || x >= Main.maxTilesX || y < 0 || y >= Main.maxTilesY)
{
sender.sendMessage(String.Format("Coordinates out of range of (0, {0}); (0, {1}).", Main.maxTilesX - 1, Main.maxTilesY - 1));
return;
}
if (subject.Teleport(x, y))
{
Server.notifyOps(string.Concat("Teleported ", subject.Name, " to ",
x, ":", y, ". [", sender.Name, "]"), true);
}
else
sender.sendMessage(Languages.TeleportFailed);
}
else
throw new CommandError(Languages.InvalidCoords);
return;
}
throw new CommandError("");
}
示例12: Teleport
/// <summary>
/// Teleports player1 to a second specified player's location.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public void Teleport(ISender sender, ArgumentList args)
{
Player subject;
Player target;
if (!args.TryPopOne(out subject))
{
subject = sender as Player;
if (subject == null)
{
sender.Message("Need a teleport target");
return;
}
if (args.Count == 0)
{
/*if (*/
subject.Teleport(Main.spawnTileX * 16f, Main.spawnTileY * 16f - subject.height);//)
{
Tools.NotifyAllOps(String.Format("{0} has teleported to spawn", subject.Name), true);
}
//else
// sender.Message(Languages.TeleportFailed);
return;
}
}
else if (args.Count == 0)
{
target = subject;
subject = sender as Player;
if (subject == null)
{
sender.Message("Need a teleport target");
return;
}
/*if (*/
subject.Teleport(target); //)
{
Tools.NotifyAllOps(string.Concat("Teleported ", subject.Name, " to ",
target.Name, ". [", sender.SenderName, "]"), true);
}
//else
// sender.Message(Languages.TeleportFailed);
return;
}
int x;
int y;
if (args.Count == 1)
{
if (args.TryParseOne(out target))
{
/*if (*/
subject.Teleport(target); //)
{
Tools.NotifyAllOps(string.Concat("Teleported ", subject.Name, " to ",
target.Name, ". [", sender.SenderName, "]"), true);
}
//else
// sender.Message(Languages.TeleportFailed);
}
else
sender.Message("Cannot find player");
return;
}
else if (args.Count == 2)
{
if (args.TryParseTwo(out x, out y))
{
if (x < 0 || x >= Main.maxTilesX || y < 0 || y >= Main.maxTilesY)
{
sender.Message(String.Format("Coordinates out of range of (0, {0}); (0, {1}).", Main.maxTilesX - 1, Main.maxTilesY - 1));
return;
}
const Int32 OutOfBoundsPadding = 0; // 41;
/*if (*/
subject.Teleport((x - OutOfBoundsPadding) * 16f, (y - OutOfBoundsPadding) * 16f); //)
{
Tools.NotifyAllOps(string.Concat("Teleported ", subject.Name, " to ",
x, ":", y, ". [", sender.SenderName, "]"), true);
}
//else
// sender.Message(Languages.TeleportFailed);
}
else
throw new CommandError("Invalid coordinates");
return;
}
throw new CommandError(String.Empty);
//.........这里部分代码省略.........
示例13: Users
public void Users(ISender sender, ArgumentList args)
{
if (sender is WebSender)
{
sender.sendMessage("Unauthorized access.");
return;
}
var reloadConfig = args.TryPop("reloadconfig");
var add = args.TryPop("add");
var remove = args.TryPop("remove");
var webKit = args.Plugin as WebKit;
if (reloadConfig)
{
sender.sendMessage("Reloading WebKit credential list...");
webKit.CredentialList = Authentication.GetCredentials();
sender.sendMessage("Complete.");
}
else if (add)
{
string user, pass;
if (args.TryParseTwo<String, String>(out user, out pass))
{
var hashed = Authentication.ComputeHash(user, pass, webKit.Properties.ServerId);
if (Authentication.AddUserCredential(user, hashed, webKit.Properties.ServerId))
sender.sendMessage("User `" + user + "` successfully added.");
else
sender.sendMessage("Failed to add `" + user + "` to the list.", 255, 355, 0, 0);
}
else
throw new CommandError("Please specify a username and password.");
}
else if (remove)
{
string user;
if (args.TryParseOne<String>(out user))
{
if (Authentication.CleanOutUser(user))
sender.sendMessage("User `" + user + "` has been removed.");
else
sender.sendMessage("Failed to remove `" + user + "`.", 255, 355, 0, 0);
}
else
throw new CommandError("Please specify a username.");
}
else
throw new CommandError(String.Empty);
}
示例14: SetWarp
public static void SetWarp(ISender sender, ArgumentList args)
{
Vector2 Location = default(Vector2);
if (!(sender is Player))
{
int x, y;
if (!args.TryParseTwo<Int32, Int32>("", out x, "", out y))
throw new CommandError("Non Player Senders need to provide -x & -y tile indices.");
}
else
Location = (sender as Player).Position / 16;
string name = args.GetString(0);
Warp warp = new Warp()
{
Name = name,
Location = Location,
Type = WarpType.PUBLIC,
Users = new List<String>()
};
WarpManager.WarpList.Add(warp);
WarpManager.Save((args.Plugin as Essentials).WarpFile, "warp");
sender.Message("Warp {0} has been created.", warp.Name);
}
示例15: UserPermissions
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);
}
//.........这里部分代码省略.........