本文整理汇总了C#中ArgumentList.TryParseOne方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentList.TryParseOne方法的具体用法?C# ArgumentList.TryParseOne怎么用?C# ArgumentList.TryParseOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArgumentList
的用法示例。
在下文中一共展示了ArgumentList.TryParseOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExampleCommand
public static void ExampleCommand(ISender sender, ArgumentList args)
{
TDSM_Plugin MyPlugin = (TDSM_Plugin)args.Plugin; //Get the plugin object who's assigned to the "tdsmpluginexample"
int arg;
//if the user enters /tdsmpluginexample -test 1, it will retreive the next value '1' and put into 'arg' as an integer.
if (args.TryParseOne<int>("-test", out arg))
{
sender.sendMessage(sender.Name + " Argument: " + arg);
}
else
{
//For new people, I would not really expect you to understand the following.
//If needed I can simplify this down...
string Platform = Terraria_Server.Definitions.Platform.Type.ToString();
switch (Terraria_Server.Definitions.Platform.Type)
{
case Terraria_Server.Definitions.Platform.PlatformType.LINUX:
Platform = "Linux";
break;
case Terraria_Server.Definitions.Platform.PlatformType.MAC:
Platform = "Mac";
break;
case Terraria_Server.Definitions.Platform.PlatformType.WINDOWS:
Platform = "Windows";
break;
}
(sender as Player).sendMessage("TDSM Plugin Example, Running OS: " + Platform, ChatColor.DarkGreen);
}
}
示例2: ExampleCommand
public static void ExampleCommand(ISender sender, ArgumentList args)
{
TDSM_Plugin MyPlugin = (TDSM_Plugin)args.Plugin; //Get the plugin object who's assigned to the "tdsmpluginexample"
//if the user enters /tdsmpluginexample -test 1, it will retreive the next value '1' and put into 'arg' as an integer.
int arg;
if (args.TryParseOne<int>("-test", out arg))
sender.sendMessage(sender.Name + " Argument: " + arg);
else
{
//For new people to .NET, I would not really expect you to understand everything just yet.
string platform = Platform.Type.ToString();
switch (Platform.Type)
{
case Platform.PlatformType.LINUX:
platform = "Linux";
break;
case Platform.PlatformType.MAC:
platform = "Mac";
break;
case Platform.PlatformType.WINDOWS:
platform = "Windows";
break;
}
(sender as Player).sendMessage("TDSM Plugin Example, Running OS: " + platform, ChatColor.DarkGreen);
}
}
示例3: 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.");
}
示例4: Backups
/// <summary>
/// Allows a user to take backups and purge old data
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
public static void Backups(ISender sender, ArgumentList args)
{
var perform = args.TryPop("now");
var purge = args.TryPop("purge");
if (perform)
BackupManager.PerformBackup();
else if (purge)
{
int minutes;
if (args.TryParseOne<Int32>(out minutes))
{
var backups = BackupManager.GetBackupsBefore(Main.worldName, DateTime.Now.AddMinutes(-minutes));
var failCount = 0;
foreach (var backup in backups)
try
{
File.Delete(backup);
}
catch { failCount++; }
if (failCount > 0)
sender.sendMessage(
String.Format("Failed to deleted {0} backup(s).", failCount)
);
else
sender.sendMessage(
String.Format("Deleted {0} backup(s).", backups.Length - failCount)
);
}
else
throw new CommandError("Please specify a time frame.");
}
else
throw new CommandError("Argument expected.");
}
示例5: ClearRegion
public void ClearRegion(ISender sender, ArgumentList args)
{
string regionName = "";
int Slot;
if (args.TryParseOne<Int32>("-slot", out Slot) ||
args.TryParseOne<String>("-region", out regionName))
{
Region region = null;
for (int i = 0; i < regionManager.RegionList.Count; i++)
{
if (Slot == i)
{
region = regionManager.RegionList[i];
break;
}
}
//[TODO] TEST ME
if (region == null && regionName.Length > 0)
{
for (int i = 0; i < regionManager.RegionList.Count; i++)
{
if (regionManager.RegionList[i].Name.Trim().ToLower().Replace(" ", "").Equals(regionName.ToLower()))
{
region = regionManager.RegionList[i];
break;
}
}
}
if (region == null)
throw new CommandError("Specified Region Slot was incorrect.");
region.UserList.Clear();
if (regionManager.SaveRegion(region))
{
sender.sendMessage(String.Format("Successfully cleared Players from Region '{0}'", region.Name), 255, 0, 255);
}
else
sender.sendMessage(String.Format("Failed to save Region '{0}'", region.Name));
}
else
throw new CommandError("Invalid arguments, Please review your command.");
}
示例6: RequestsCommand
void RequestsCommand(ISender sender, ArgumentList args)
{
if (args.TryPop("-all") && args.TryPop("-g"))
{
int total = requests.Count;
for (int i = 0; i < total; i++)
{
RegistrationRequest req = requests.Values.ElementAt(i);
RegisterUser(i, req, false);
}
Server.notifyOps(
String.Format("<Restrict> Registration request granted for {0} user(s).", total)
, true);
return;
}
int num;
if (args.TryParseOne ("-g", out num) || args.TryParseOne ("grant", out num))
{
RegistrationRequest rq;
if (! requests.TryGetValue (num, out rq))
{
sender.sendMessage ("restrict.rr: No such registration request");
return;
}
RegisterUser(num, rq);
}
else if (args.TryParseOne ("-d", out num) || args.TryParseOne ("deny", out num))
{
RegistrationRequest rq;
if (! requests.TryGetValue (num, out rq))
{
sender.sendMessage ("restrict.rr: No such registration request");
return;
}
requests.Remove (num);
Server.notifyOps ("<Restrict> Registration request denied for: " + rq.name, true);
var player = FindPlayer (rq.name);
if (player != null)
player.sendMessage ("<Restrict> Your registration request has been denied.");
}
else
{
args.ParseNone ();
sender.sendMessage ("restrict.rr: Pending requests:");
foreach (var kv in requests)
{
var rq = kv.Value;
if (rq == null) continue;
sender.sendMessage (string.Format ("{0,3} : {1} : {2}", kv.Key, rq.address, rq.name));
}
}
}
示例7: WhiteList
/// <summary>
/// Adds or removes specified player to/from the white list.
/// </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 WhiteList(Server server, ISender sender, ArgumentList args)
{
// /whitelist <add:remove> <player>
String Exception, Type = "removed from";
if (args.TryParseOne<String>("-add", out Exception))
{
Program.server.WhiteList.addException(Exception);
Type = "added to";
}
else if (args.TryParseOne<String>("-remove", out Exception))
{
Program.server.WhiteList.removeException(Exception);
}
else
{
sender.sendMessage("Please review that command");
return;
}
Program.server.notifyOps(Exception + " was " + Type + " the Whitelist {" + sender.Name + "}", true);
if (!Program.server.WhiteList.Save())
{
Program.server.notifyOps("WhiteList Failed to Save due to " + sender.Name + "'s command", true);
}
}
示例8: 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 ("");
}
示例9: ItemRejection
public static void ItemRejection(ISender sender, ArgumentList args)
{
string exception;
if (args.TryParseOne<String>("-add", out exception))
{
if (!Server.RejectedItems.Contains(exception))
{
Server.RejectedItems.Add(exception);
sender.sendMessage(exception + " was added to the Item Rejection list!");
}
else
{
throw new CommandError("That item already exists in the list.");
}
}
else if (args.TryParseOne<String>("-remove", out exception))
{
if (Server.RejectedItems.Contains(exception))
{
Server.RejectedItems.Remove(exception);
sender.sendMessage(exception + " was removed from the Item Rejection list!");
}
else
{
throw new CommandError("That item already does not exist in the list.");
}
}
else if (args.TryPop("-clear"))
{
Server.RejectedItems.Clear();
sender.sendMessage("Item Rejection list has been cleared!");
}
else
{
throw new CommandError("No item/id provided with your command");
}
Program.properties.RejectedItems = String.Join(",", Server.RejectedItems);
Program.properties.Save(false);
}
示例10: RequestsCommand
void RequestsCommand(ISender sender, ArgumentList args)
{
int num;
if (args.TryParseOne ("-g", out num) || args.TryParseOne ("grant", out num))
{
RegistrationRequest rq;
if (! requests.TryGetValue (num, out rq))
{
sender.sendMessage ("restrict.rr: No such registration request");
return;
}
requests.Remove (num);
var pname = NameTransform (rq.name);
var hash = Hash (rq.name, rq.password);
users.setValue (pname, hash);
users.Save ();
var player = FindPlayer (rq.name);
if (player != null) // TODO: verify IP address
{
player.AuthenticatedAs = rq.name;
player.sendMessage ("<Restrict> You are now registered.");
}
Server.notifyOps ("<Restrict> Registration request granted for: " + rq.name, true);
var duplicates = requests.Where (kv => kv.Value.name == rq.name).ToArray();
foreach (var kv in duplicates)
{
// deny other requests for the same name
requests.Remove (kv.Key);
}
}
else if (args.TryParseOne ("-d", out num) || args.TryParseOne ("deny", out num))
{
RegistrationRequest rq;
if (! requests.TryGetValue (num, out rq))
{
sender.sendMessage ("restrict.rr: No such registration request");
return;
}
requests.Remove (num);
Server.notifyOps ("<Restrict> Registration request denied for: " + rq.name, true);
var player = FindPlayer (rq.name);
if (player != null)
player.sendMessage ("<Restrict> Your registration request has been denied.");
}
else
{
args.ParseNone ();
sender.sendMessage ("restrict.rr: Pending requests:");
foreach (var kv in requests)
{
var rq = kv.Value;
if (rq == null) continue;
sender.sendMessage (string.Format ("{0,3} : {1} : {2}", kv.Key, rq.address, rq.name));
}
}
}
示例11: RemoveUser
public void RemoveUser(ISender sender, ArgumentList args)
{
string User = "", IP = "";
int 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 = 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.Add(inflatee);
usersRemoved++;
}
}
}
if (usersRemoved > 0)
{
if (regionManager.SaveRegion(region))
{
sender.sendMessage(String.Format("{0} users were added to {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.");
}
示例12: Create
public void Create(ISender sender, ArgumentList args)
{
if (sender is Player)
{
string Name = "";
string Desc = "";
bool Restrict = args.TryPop("-res");
bool RestrictNPC = args.TryPop("-npcres");
string tempDesc = default(String);
if(args.TryParseOne<String>("-desc", out Desc))
{
Desc = tempDesc;
}
if (args.TryParseOne<String>("-name", out Name) && Name.Trim().Length > 0)
{
var player = sender as Player;
if (selection.isInSelectionlist(player))
{
Vector2[] regionAxis = selection.GetSelection(player);
Region rgn = new Region();
rgn.Name = Name;
rgn.Description = Desc;
rgn.Point1 = regionAxis[0];
rgn.Point2 = regionAxis[1];
rgn.Restricted = Restrict;
rgn.RestrictedNPCs = RestrictNPC;
if (rgn.IsValidRegion())
{
regionManager.Regions.Add(rgn);
if(regionManager.SaveRegion(rgn))
player.sendMessage("Region '" + Name + "' was successfully created.", ChatColor.Green);
else
player.sendMessage("There was an issue while saving the region", ChatColor.Red);
}
else
{
player.sendMessage("There was an issue while creating the region", ChatColor.Red);
}
}
else
{
player.sendMessage("You need to select a region first!", ChatColor.Red);
}
}
else
{
throw new CommandError("You have not specified certain arguments");
}
}
}
示例13: Connection
public void Connection(ISender sender, ArgumentList args)
{
var webKit = args.Plugin as WebKit;
var view = args.TryPop("view");
var kick = args.TryPop("kick");
if (kick && sender is WebSender)
{
sender.sendMessage("Unauthorized access.");
return;
}
int id = webKit.WebSessions.Count;
if (kick && (!args.TryParseOne<Int32>(out id) || id >= webKit.WebSessions.Count))
throw new CommandError("Please enter a valid slot number");
if (view)
{
var max = webKit.WebSessions.Count;
if ((from x in webKit.WebSessions where !Authentication.IsOutOfSession(x.Key, x.Value.LastUpdate, x.Value.IpAddress, webKit) select x).Count() == 0)
{
sender.sendMessage("No connections.");
return;
}
for (var i = 0; i < max; i++)
{
var pair = webKit.WebSessions.ElementAt(i);
var name = pair.Key;
var val = pair.Value;
if (!Authentication.IsOutOfSession(name, val.LastUpdate, val.IpAddress, webKit))
{
sender.sendMessage(
String.Format("[{0}] - {1}@{2}", i, name, val.IpAddress)
);
}
}
}
else if (kick)
{
var max = webKit.WebSessions.Count;
if (max == 0)
{
sender.sendMessage("No connection to kick.");
return;
}
for (var i = 0; i < max; i++)
{
if (i == id)
{
var pair = webKit.WebSessions.ElementAt(i);
var name = pair.Key;
var val = pair.Value;
if (!Authentication.IsOutOfSession(name, val.LastUpdate, val.IpAddress, webKit))
{
webKit.KickList.Add(pair);
sender.sendMessage(
String.Format("[{0}] - {1}@{2} added to kick queue.", i, name, val.IpAddress)
);
return;
}
}
}
sender.sendMessage("Failed to add the seleted identity at slot `" + id + "` to the kick queue.");
}
else
throw new CommandError(String.Empty);
}
示例14: 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);
}
示例15: WhiteList
/// <summary>
/// Adds or removes specified player to/from the white list.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void WhiteList(ISender sender, ArgumentList args)
{
// /whitelist <add:remove> <player>
string Exception, Type = "";
if (args.TryParseOne<String>(Languages.Add, out Exception))
{
Server.WhiteList.addException(Exception);
Type = Languages.Added;
}
else if (args.TryParseOne<String>(Languages.Remove, out Exception))
{
Server.WhiteList.removeException(Exception);
Type = Languages.RemovedFrom;
}
else
{
sender.sendMessage(Languages.PleaseReview);
return;
}
Server.notifyOps(Exception + " was " + Type + " the Whitelist [" + sender.Name + "]", true);
if (!Server.WhiteList.Save())
{
Server.notifyOps(Languages.WhilelistFailedSave + sender.Name + "'s " + Languages.Command, true);
}
}