本文整理汇总了C#中ArgumentList.TryGetString方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentList.TryGetString方法的具体用法?C# ArgumentList.TryGetString怎么用?C# ArgumentList.TryGetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArgumentList
的用法示例。
在下文中一共展示了ArgumentList.TryGetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvalidatePlayer
public static void InvalidatePlayer(Server server, ISender sender, ArgumentList args)
{
string playerName, param;
Player player = server.GetPlayerByName(sender.Name);
if (args.TryGetString(0, out playerName))
{
if (server.GetPlayerByName(playerName) != null)
{
Login.plugin.SetPlayerInvalid(playerName);
SendMessage(player, "You have invalidated " + playerName);
}
else
{
if (args.TryGetString(1, out param))
{
if (param.ToUpper() == "FORCE")
{
Login.plugin.SetPlayerInvalid(playerName);
SendMessage(player, "You have invalidated " + playerName);
}
else
SendMessage(player, "Usage: /invalidate <player> (force)");
}
else
{
SendMessage(player, "There is no current player names " + playerName);
SendMessage(player, "Use /invalidate <player> force to remove offline players");
}
}
}
else
SendMessage(player, "You must supply a player name");
}
示例2: AddAccount
void AddAccount(ISender sender, ArgumentList args)
{
if (!Storage.IsAvailable)
throw new CommandError("No permissions plugin or data plugin is attached");
var a = 0;
string name, pass;
APIAccount acc = null;
//api addaccount "username" "password"
if (!args.TryGetString(a++, out name))
throw new CommandError("Expected username after addaccount");
if (!args.TryGetString(a++, out pass))
throw new CommandError("Expected password after username");
acc = APIAccountManager.FindByName(name);
if (acc == null)
{
acc = APIAccountManager.Create(name, pass);
if (acc.Id > 0)
{
sender.SendMessage("Successfully created account.", R: 0, B: 0);
}
else
{
sender.SendMessage("Failed to create account.", G: 0, B: 0);
}
}
else
{
throw new CommandError("Existing API account found by " + name);
}
}
示例3: SetPoint
public static void SetPoint(Server server, ISender sender, ArgumentList args)
{
string param;
Player player = server.GetPlayerByName(sender.Name);
if (args.TryGetString(0, out param))
{
switch (param.ToUpper())
{
case "LOBBY":
player.PluginData["lobby"] = true;
player.sendMessage("Hit a block where you want the lobby to be", Login.plugin.chatColor);
break;
case "VALIDATED":
player.PluginData["validated"] = true;
player.sendMessage("Hit a block where you want the validated point to be", Login.plugin.chatColor);
break;
default:
player.sendMessage("You must specify either lobby or validated", Login.plugin.chatColor);
break;
}
}
else
player.sendMessage("You must specify either lobby or validated", Login.plugin.chatColor);
}
示例4: Ban
/// <summary>
/// Adds a player or ip (Exception) to the ban list.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void Ban(ISender sender, ArgumentList args)
{
Player banee;
string playerName = null;
if (args.TryGetOnlinePlayer(0, out banee))
{
playerName = banee.Name;
banee.Kick("You have been banned from this Server.");
Server.BanList.addException(NetPlay.slots[banee.whoAmi].
remoteAddress.Split(':')[0]);
}
else if(!args.TryGetString(0, out playerName))
{
throw new CommandError("A player or IP was expected.");
}
Server.BanList.addException(playerName);
Server.notifyOps(playerName + " has been banned {" + sender.Name + "}", true);
if (!Server.BanList.Save())
{
Server.notifyOps("BanList Failed to Save due to " + sender.Name + "'s command", true);
}
}
示例5: Exit
/// <summary>
/// Closes the Server all connections.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public void Exit(ISender sender, ArgumentList args)
{
var accessLevel = Core.Config.ExitAccessLevel;
if (accessLevel == -1 && sender is Player)
{
sender.Message("You cannot perform that action.", 255, 238, 130, 238);
return;
}
else if (!sender.HasAccessLevel((AccessLevel)accessLevel))
{
sender.Message("You cannot perform that action.", 255, 238, 130, 238);
return;
}
string message;
args.TryGetString(0, out message);
if (String.IsNullOrEmpty(message))
message = "Server is going down";
// args.ParseNone();
Utils.NotifyAllOps("Exiting on request.");
if (Netplay.anyClients)
{
for (var x = 0; x < Main.player.Length; x++)
{
if (Main.player[x].active)
{
NetMessage.SendData((int)Packet.DISCONNECT, x, -1, message);
#if CUSTOM_SOCKETS
var rc = Netplay.Clients[x];
if (rc != null && rc.Socket != null && rc.Socket is ClientConnection)
{
(rc.Socket as ClientConnection).Flush();
}
#endif
}
}
//Prevent further connections
Terraria.Netplay.Connection.Socket.StopListening();
// //Wait for total disconnection
// while (Netplay.anyClients)
// {
// System.Threading.Thread.Sleep(100);
// }
}
Terraria.IO.WorldFile.saveWorld(false);
Terraria.Netplay.disconnect = true;
throw new OTA.Misc.ExitException(sender.SenderName + " requested that TDSM is to shutdown.");
}
示例6: Give
/// <summary>
/// Gives specified item to the specified player.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public void Give(ISender sender, ArgumentList args)
{
// /give <stack> <item> [prefix] [player]
var index = 0;
int stack = args.GetInt(index++);
string name = args.GetString(index++);
// var max = Tools.AvailableItemSlots; //Perhaps remove a few incase of new drops
// if (stack > max)
// {
// stack = max; // Set to Tools.AvailableItemSlots because number given was larger than this.
// }
int id;
var results = Int32.TryParse(name, out id) ? DefinitionManager.FindItem(id) : DefinitionManager.FindItem(name);
if (results != null && results.Length > 0)
{
if (results.Length > 1)
throw new CommandError(String.Format("More than 1 item found, total is: {0}", results.Length));
var item = results[0];
string prefix;
if (args.TryGetString(index, out prefix))
{
try
{
Affix afx;
if (Enum.TryParse(prefix, out afx))
{
item.Prefix = (int)afx;
index++;
}
}
catch (ArgumentException)
{
throw new CommandError(String.Format("Error, the Prefix you entered was not found: {0}", args.GetString(3)));
}
}
Player receiver;
if (!args.TryGetOnlinePlayer(index, out receiver))
{
if (sender is Player)
receiver = sender as Player;
else throw new CommandError("Expected an online player");
}
receiver.GiveItem(item.Id, stack, item.MaxStack, sender, item.NetId, true, item.Prefix);
}
else
throw new CommandError(String.Format("No item known by: {0}", name));
}
示例7: Restart
/// <summary>
/// Restart and reload the world without reloading the application
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public void Restart(ISender sender, ArgumentList args)
{
#if TDSMServer
string cmd = null;
args.TryGetString(0, out cmd);
if (String.IsNullOrEmpty(cmd))
PerformRestart();
else if (cmd == "-wait")
{
RestartWhenNoPlayers = !RestartWhenNoPlayers;
if (_waitFPState == null) _waitFPState = Server.AcceptNewConnections;
if (RestartWhenNoPlayers)
{
Server.AcceptNewConnections = false;
if (ClientConnection.All.Count == 0)
{
PerformRestart();
return;
}
if (_tskWaitForPlayers == null)
{
_tskWaitForPlayers = new Task()
{
Enabled = true,
Method = (tsk) =>
{
Tools.NotifyAllPlayers("The server is waiting to restart.", Color.Orange, false);
Tools.NotifyAllPlayers("Please finish what you are doing and disconnect.", Color.Orange, false);
var players = from p in Terraria.Main.player where p.active orderby p.name select p.Name;
var pn = players.Count();
if (pn == 0) return;
ProgramLog.Admin.Log("Notified player(s) of restart: " + String.Join(", ", players));
},
Trigger = 60
};
Tasks.Schedule(_tskWaitForPlayers);
}
else
{
_tskWaitForPlayers.Enabled = true;
}
}
else
{
Server.AcceptNewConnections = _waitFPState.Value; //Restore
if (_tskWaitForPlayers != null && _tskWaitForPlayers.Enabled)
{
if (_tskWaitForPlayers.HasTriggered)
{
Tools.NotifyAllPlayers("Restart was terminated.", Color.Orange);
}
_tskWaitForPlayers.Enabled = false;
}
}
sender.Message("The server is " + (_tskWaitForPlayers != null && _tskWaitForPlayers.Enabled ? "waiting to restart" : "not restarting"));
}
else throw new CommandError("No restart command: " + cmd);
#endif
}
示例8: UnBan
/// <summary>
/// Removes an exception from the ban list.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void UnBan(ISender sender, ArgumentList args)
{
string playerName;
if (!args.TryGetString(0, out playerName))
{
throw new CommandError("A player or IP was expected.");
}
Server.BanList.removeException(playerName);
Server.notifyOps(playerName + " has been unbanned {" + sender.Name + "}", true);
if (!Server.BanList.Save())
{
Server.notifyOps("BanList Failed to Save due to " + sender.Name + "'s command", true);
}
}
示例9: Ban
/// <summary>
/// Adds a player or ip (Exception) to the ban list.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void Ban(ISender sender, ArgumentList args)
{
Player banee;
string playerName = null;
if (args.TryGetOnlinePlayer(0, out banee))
{
playerName = banee.Name;
banee.Kick(Languages.Ban_You);
Server.BanList.addException(NetPlay.slots[banee.whoAmi].
remoteAddress.Split(':')[0]);
}
else if (!args.TryGetString(0, out playerName))
{
throw new CommandError(Languages.IPExpected);
}
Server.BanList.addException(playerName);
Server.notifyOps(playerName + Languages.Ban_Banned + " [" + sender.Name + "]", true);
if (!Server.BanList.Save())
{
Server.notifyOps(Languages.Ban_FailedToSave + sender.Name + "'s " + Languages.Command, true);
}
}
示例10: UnBan
/// <summary>
/// Removes an exception from the ban list.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void UnBan(ISender sender, ArgumentList args)
{
string playerName;
if (!args.TryGetString(0, out playerName))
{
throw new CommandError(Languages.IPExpected);
}
Server.BanList.removeException(playerName);
Server.notifyOps(playerName + Languages.Ban_UnBanned + " [" + sender.Name + "]", true);
if (!Server.BanList.Save())
{
Server.notifyOps(Languages.Ban_FailedToSave + sender.Name + "'s " + Languages.Command, true);
}
}
示例11: Invasion
public void Invasion(ISender sender, ArgumentList args)
{
if (Main.invasionType == 0)
{
var custom = args.TryPop("-custom");
if (custom)
{
if (args.Count > 0)
{
var npcIds = new List<Int32>();
while (args.Count > 0)
{
int npcType;
string npc;
if (args.TryGetInt(0, out npcType))
{
npcIds.Add(npcType);
}
else if (args.TryGetString(0, out npc))
{
var match = Definitions.DefinitionManager.FindNPC(npc);
if (match.Length == 1)
{
npcIds.Add(match[0].Id);
}
else if (match.Length == 0)
{
sender.Message("Cannot find a NPC by `{0}`", npc);
return;
}
else
{
sender.Message("Found too many NPC's containing `{0}`", npc);
return;
}
}
else
{
throw new CommandError("Expected a NPC id or name.");
}
}
//Schedule...
//if (!_customInvasion.IsEmpty()) _customInvasion.Enabled = false;
//_customInvasion = new Task()
//{
// Trigger = 10,
// Data = npcIds,
// Method = (task) =>
// {
// var ids = task.Data as List<Int32>;
// for (var x = 0; x < 5; x++)
// {
// var ix = Main.rand.Next(0, ids.Count - 1);
// var pos = FindPositionOutOfSight();
// if (pos.HasValue)
// {
// }
// }
// }
//};
if (_invasion != null) lock (_invasion) _invasion = npcIds;
else _invasion = npcIds;
Main.StartInvasion(_assignedInvasionType);
}
else throw new CommandError("Expected npc type or name");
}
else
{
var txt = args.GetString(0).ToLower();
var vals = Enum.GetValues(typeof(InvasionType));
foreach (InvasionType it in vals)
{
if (it.ToString().ToLower() == txt)
{
Main.StartInvasion((int)it);
sender.Message("A {0} invasion has begun.", it);
return;
}
}
sender.Message("No such invasion of type {0}", txt);
}
}
else
{
if (args.TryPop("end") || args.TryPop("stop") || args.TryPop("cancel"))
{
//if (!_customInvasion.IsEmpty()) _customInvasion.Enabled = false;
Main.invasionType = 0;
if (_invasion != null) lock (_invasion) _invasion.Clear();
sender.Message("The invasion has now been stopped.");
}
else sender.Message("An invasion is already under way.");
}
//.........这里部分代码省略.........
示例12: ManageApi
void ManageApi(ISender sender, ArgumentList args)
{
if (!Storage.IsAvailable)
throw new CommandError("No permissions plugin or data plugin is attached");
var a = 0;
string name, pass, type, value;
APIAccount acc = null;
var cmd = args.GetString(a++);
switch (cmd)
{
case "addaccount":
//api addaccount "username" "password"
if (!args.TryGetString(a++, out name))
throw new CommandError("Expected username after [" + cmd + "]");
if (!args.TryGetString(a++, out pass))
throw new CommandError("Expected password after username");
acc = APIAccountManager.FindByName(name);
if (acc == null)
{
acc = APIAccountManager.Create(name, pass);
if (acc.Id > 0)
{
sender.SendMessage("Successfully created account.", R: 0, B: 0);
}
else
{
sender.SendMessage("Failed to create account.", G: 0, B: 0);
}
}
else
{
throw new CommandError("Existing API account found by " + name);
}
break;
case "removeaccount":
//api removeaccount "username"
if (!args.TryGetString(a++, out name))
throw new CommandError("Expected username after [" + cmd + "]");
acc = APIAccountManager.FindByName(name);
if (acc != null)
{
if (APIAccountManager.DeleteAccount(acc.Id))
{
sender.SendMessage("Successfully removed account.", R: 0, B: 0);
}
else
{
sender.SendMessage("Failed to remove account.", G: 0, B: 0);
}
}
else
{
throw new CommandError("No API account found by " + name);
}
break;
case "addrole":
//api addrole "account" "type" "value"
if (!args.TryGetString(a++, out name))
throw new CommandError("Expected username after [" + cmd + "]");
if (!args.TryGetString(a++, out type))
throw new CommandError("Expected type after username");
if (!args.TryGetString(a++, out value))
throw new CommandError("Expected value after type");
acc = APIAccountManager.FindByName(name);
if (acc != null)
{
var role = APIAccountManager.AddType(acc.Id, type, value);
if (role != null && role.Id > 0)
{
sender.SendMessage("Successfully added role account.", R: 0, B: 0);
}
else
{
sender.SendMessage("Failed to add role to account.", G: 0, B: 0);
}
}
else
{
throw new CommandError("No API account found by " + name);
}
break;
case "removerole":
//api removerole "account" "type" "value"
if (!args.TryGetString(a++, out name))
throw new CommandError("Expected username after [" + cmd + "]");
if (!args.TryGetString(a++, out type))
throw new CommandError("Expected type after username");
if (!args.TryGetString(a++, out value))
throw new CommandError("Expected value after type");
//.........这里部分代码省略.........
示例13: TestPoint
public static void TestPoint(Server server, ISender sender, ArgumentList args)
{
string param;
Player player = server.GetPlayerByName(sender.Name);
if (args.TryGetString(0, out param))
{
switch (param.ToUpper())
{
case "LOBBY":
player.sendMessage("Teleporting to the lobby", Login.plugin.chatColor);
Login.plugin.TeleportPlayerToPoint(player, Login.LOBBY);
break;
case "VALIDATED":
player.sendMessage("Teleporting to the validated point", Login.plugin.chatColor);
Login.plugin.TeleportPlayerToPoint(player, Login.VALIDATED);
break;
default:
player.sendMessage("You must specify either lobby or validated", Login.plugin.chatColor);
break;
}
}
else
player.sendMessage("You must specify either lobby or validated", Login.plugin.chatColor);
}
示例14: UserPermission
void UserPermission(ISender sender, ArgumentList args)
{
if (!Storage.IsAvailable)
throw new CommandError("No permissions plugin or data plugin is attached");
int a = 0;
string username, groupName, node, password;
DbPlayer user;
Group grp;
bool deny, op;
var cmd = args.GetString(a++);
switch (cmd)
{
case "addgroup":
//user addgroup "username" "group"
if (!args.TryGetString(a++, out username))
throw new CommandError("Expected username name after [" + cmd + "]");
if (!args.TryGetString(a++, out groupName))
throw new CommandError("Expected group name after username");
user = Authentication.GetPlayer(username);
if (null == user)
throw new CommandError("No user found by: " + username);
grp = Storage.FindGroup(groupName);
if (grp == null)
throw new CommandError("Group does not exist: " + groupName);
if (Storage.AddUserToGroup(user.Name, grp.Name))
{
sender.Message(String.Format("Successfully added {0} to group {1} ", user.Name, grp.Name), Color.Green);
}
else
{
sender.Message(String.Format("Failed to add {0} from group {1} ", user.Name, grp.Name), Color.Red);
}
break;
case "removegroup":
//user removegroup "username" "group"
if (!args.TryGetString(a++, out username))
throw new CommandError("Expected username name after [" + cmd + "]");
if (!args.TryGetString(a++, out groupName))
throw new CommandError("Expected group name after username");
user = Authentication.GetPlayer(username);
if (null == user)
throw new CommandError("No user found by: " + username);
grp = Storage.FindGroup(groupName);
if (grp == null)
throw new CommandError("Group does not exist: " + groupName);
if (Storage.RemoveUserFromGroup(user.Name, grp.Name))
{
sender.Message(String.Format("Successfully removed {0} to group {1} ", user.Name, grp.Name), Color.Green);
}
else
{
sender.Message(String.Format("Failed to remove {0} from group {1} ", user.Name, grp.Name), Color.Red);
}
break;
case "addnode":
//user addnode "username" "node" "deny"
if (!args.TryGetString(a++, out username))
throw new CommandError("Expected username name after [" + cmd + "]");
if (!args.TryGetString(a++, out node))
throw new CommandError("Expected node name after username");
if (!args.TryGetBool(a++, out deny))
deny = false;
user = Authentication.GetPlayer(username);
if (null == user)
throw new CommandError("No user found by: " + username);
if (Storage.AddNodeToUser(user.Name, node, deny ? Permission.Denied : Permission.Permitted))
{
sender.Message(String.Format("Successfully added {0} to user {1} ", node, user.Name), Color.Green);
}
else
{
sender.Message(String.Format("Failed to add {0} from user {1} ", node, user.Name), Color.Red);
}
break;
case "removenode":
//user removenode "username" "node" "deny"
if (!args.TryGetString(a++, out username))
throw new CommandError("Expected username name after [" + cmd + "]");
if (!args.TryGetString(a++, out node))
throw new CommandError("Expected node name after username");
if (!args.TryGetBool(a++, out deny))
deny = false;
user = Authentication.GetPlayer(username);
if (null == user)
throw new CommandError("No user found by: " + username);
//.........这里部分代码省略.........
示例15: VariableMan
/// <summary>
/// Allows on the fly variable modifications
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="args">Arguments.</param>
public void VariableMan(ISender sender, ArgumentList args)
{
// var <exec|field>
// var field <namespace.type> <fieldname>
// var field <namespace.type> <fieldname> <valuetobeset>
// var exec <namespace.type> <methodname>
//No arguments supported yet
var cmd = args.GetString(0);
if (cmd == "field")
{
var type = args.GetString(1);
var mem = args.GetString(2);
//Find the type
var at = Type.GetType(type);
if (at == null) at = System.Reflection.Assembly.GetEntryAssembly().GetType(type);
if (at == null) at = System.Reflection.Assembly.GetCallingAssembly().GetType(type);
if (at == null) at = System.Reflection.Assembly.GetExecutingAssembly().GetType(type);
if (at == null) throw new CommandError("Invalid type: " + type);
//Find the field
var am = at.GetField(mem);
if (am == null) throw new CommandError("Invalid field: " + mem);
string val = null;
if (args.TryGetString(3, out val))
{
object data = GetDataValue(am.FieldType, val);
am.SetValue(null, data);
var v = am.GetValue(null);
if (v != null) val = v.ToString();
else val = "null";
sender.Message("Value is now: " + val);
}
else
{
var v = am.GetValue(null);
if (v != null) val = v.ToString();
else val = "null";
sender.Message("Value: " + val);
}
}
else if (cmd == "prop")
{
var type = args.GetString(1);
var prop = args.GetString(2);
//Find the type
var at = Type.GetType(type);
if (at == null) at = System.Reflection.Assembly.GetEntryAssembly().GetType(type);
if (at == null) at = System.Reflection.Assembly.GetCallingAssembly().GetType(type);
if (at == null) at = System.Reflection.Assembly.GetExecutingAssembly().GetType(type);
if (at == null) throw new CommandError("Invalid type: " + type);
//Find the field
var am = at.GetProperty(prop);
if (am == null) throw new CommandError("Invalid property: " + prop);
string val = null;
if (args.TryGetString(3, out val))
{
object data = GetDataValue(am.PropertyType, val);
am.SetValue(null, data, null);
var v = am.GetValue(null, null);
if (v != null) val = v.ToString();
else val = "null";
sender.Message("Value is now: " + val);
}
else
{
var v = am.GetValue(null, null);
if (v != null) val = v.ToString();
else val = "null";
sender.Message("Value: " + val);
}
}
else if (cmd == "exec")
{
var type = args.GetString(1);
var mthd = args.GetString(2);
//Find the type
var at = Type.GetType(type);
if (at == null) at = System.Reflection.Assembly.GetEntryAssembly().GetType(type);
if (at == null) at = System.Reflection.Assembly.GetCallingAssembly().GetType(type);
if (at == null) at = System.Reflection.Assembly.GetExecutingAssembly().GetType(type);
if (at == null) throw new CommandError("Invalid type: " + type);
//Find the field
var am = at.GetMethod(mthd);
if (am == null) throw new CommandError("Invalid method: " + mthd);
//.........这里部分代码省略.........