当前位置: 首页>>代码示例>>C#>>正文


C# ArgumentList.TryPop方法代码示例

本文整理汇总了C#中ArgumentList.TryPop方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentList.TryPop方法的具体用法?C# ArgumentList.TryPop怎么用?C# ArgumentList.TryPop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArgumentList的用法示例。


在下文中一共展示了ArgumentList.TryPop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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);
        }
开发者ID:emreuyls,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:50,代码来源:Commands.cs

示例2: 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");
                }
            }
        }
开发者ID:Dyrian,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:49,代码来源:Commands.cs

示例3: Heal

        /// <summary>
        /// Heals one or all players.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="message">Message to send</param>
        public void Heal(ISender sender, ArgumentList args)
        {
            Player subject;

            if (args.TryPopOne(out subject))
            {
                subject = sender as Player;
                if (subject == null)
                {
                    sender.Message("Need a heal target");
                    return;
                }

                NetMessage.SendData((int)Packet.HEAL_PLAYER, -1, -1, String.Empty, subject.whoAmI, (float)subject.statLifeMax);
                subject.Message("You have been healed!", Color.Green);
            }
            else if (args.TryPop("-all"))
            {
                foreach (var plr in Main.player)
                {
                    if (plr.active)
                    {
                        NetMessage.SendData((int)Packet.HEAL_PLAYER, -1, -1, String.Empty, plr.whoAmI, (float)plr.statLifeMax);
                        plr.Message("You have been healed!", Color.Green);
                    }
                }
            }
            else if (sender is Player)
            {
                var plr = sender as Player;
                NetMessage.SendData((int)Packet.HEAL_PLAYER, -1, -1, String.Empty, plr.whoAmI, (float)plr.statLifeMax);
                plr.Message("You have been healed!", Color.Green);
            }
            else throw new CommandError("Nobody specified to heal");
        }
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:40,代码来源:HealCommand.cs

示例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.");
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:42,代码来源:Commands.cs

示例5: Kick

        /// <summary>
        /// Kicks a given Player from the server
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public void Kick(ISender sender, ArgumentList args)
        {
            if (args.TryPop("-s"))
            {
                int s;
                args.ParseOne(out s);

                var slot = Terraria.Netplay.Clients[s];

                #if TDSMServer
                if (slot.State() != SlotState.VACANT)
                {
                slot.Kick("You have been kicked by " + sender.SenderName + ".");

                var player = Main.player[s];
                if (player != null && player.name != null)
                NewNetMessage.SendData(25, -1, -1, player.name + " has been kicked by " + sender.SenderName + ".", 255);
                }
                else
                {
                sender.Message("Kick slot is empty");
                }
                #else
                NetMessage.SendData(2, slot.Id, -1, "Kicked from server.", 0, 0f, 0f, 0f, 0, 0, 0);
                #endif
            }
            else
            {
                Player player;
                args.ParseOne<Player>(out player);

                if (player.name == null)
                {
                    sender.Message("Kick player name is not set.");
                    return;
                }

                player.Kick("You have been kicked by " + sender.SenderName + ".");
                NetMessage.SendData(25, -1, -1, player.name + " has been kicked by " + sender.SenderName + ".", 255);
            }
        }
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:46,代码来源:KickCommand.cs

示例6: GroupAttributes

        public void GroupAttributes(ISender sender, ArgumentList args)
        {
            var save = args.TryPop("-save");
            var requestedGroup = args.GetString(0);
            var attribute = args.GetString(1);
            var value = args.GetString(2);

            if (!XmlParser.HasGroup(requestedGroup))
                throw new CommandError("{1} `{0}`", requestedGroup, Languages.NoGroup);

            IPermission group = XmlParser.GetGroup(requestedGroup);

            SetAttribute(ref group, attribute, value);

            var res = XmlParser.UpdateDefiniton(group);

            if (save) XmlParser.Save();

            sender.sendMessage(
                String.Format("{0} {1}", res ? Languages.Success : Languages.Failure, Languages.UpdatingAttribute)
            );
        }
开发者ID:emreuyls,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:22,代码来源:Commands.cs

示例7: NPCSpawns

        /// <summary>
        /// Enables or disables NPC spawning
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public static void NPCSpawns(ISender sender, ArgumentList args)
        {
            Main.stopSpawns = !Main.stopSpawns;
            sender.sendMessage(Languages.NPCSpawningIsNow + ((Main.stopSpawns) ? "off" : "on") + "!");

            Program.properties.StopNPCSpawning = Main.stopSpawns;
            Program.properties.Save(false);

            if (args.TryPop("-clear"))
                Purge(sender, new ArgumentList() { "all" });
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:16,代码来源:Commands.cs

示例8: Server

        public void Server(ISender sender, ArgumentList args)
        {
            var webKit = (WebKit)args.Plugin;
            if (webKit == null)
                throw new CommandError("Unable to get WebKit instance.");

            var restart = args.TryPop("restart");
            var stop	= args.TryPop("stop");
            var start	= args.TryPop("start");

            if (restart)
            {
                WebKit.Log("Stopping Http server...");
                webKit.WebServer.StopServer();
                WebKit.Log("Starting Http server...");
                webKit.WebServer.StartServer();
                WebKit.Log("Http server started.");
            }
            else if (stop)
            {
                WebKit.Log("Stopping Http server...");
                webKit.WebServer.StopServer();
                WebKit.Log("Http server stopped.");
            }
            else if (start)
            {
                WebKit.Log("Starting Http server...");
                webKit.WebServer.StartServer();
                WebKit.Log("Http server started.");

                //Wow...that was a lot of http.
            }
            else
                throw new CommandError("Unknown http option.");
        }
开发者ID:DeathCradle,项目名称:TDSM-Web-Kit,代码行数:35,代码来源:BaseWebKit.cs

示例9: Kick

        /// <summary>
        /// Kicks a given Player from the server
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public static void Kick(ISender sender, ArgumentList args)
        {
            if (args.TryPop("-s"))
            {
                int s;
                args.ParseOne(out s);

                var slot = NetPlay.slots[s];

                if (slot.state != SlotState.VACANT)
                {
                    slot.Kick(Languages.YouHaveBeenKickedBy + sender.Name + ".");

                    var player = Main.players[s];
                    if (player != null && player.Name != null)
                        NetMessage.SendData(25, -1, -1, player.Name + Languages.HasBeenKickedBy + sender.Name + ".", 255);
                }
                else
                {
                    sender.sendMessage(Languages.KickSlotIsEmpty);
                }
            }
            else
            {
                Player player;
                args.ParseOne<Player>(out player);

                if (player.Name == null)
                {
                    sender.sendMessage(Languages.KickPlayerNameNull);
                    return;
                }

                player.Kick(Languages.YouHaveBeenKickedBy + sender.Name + ".");
                NetMessage.SendData(25, -1, -1, player.Name + Languages.HasBeenKickedBy + sender.Name + ".", 255);
            }
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:42,代码来源:Commands.cs

示例10: ItemRejection

 /// <summary>
 /// Disallow an item from the server
 /// </summary>
 /// <param name="sender">Sending player</param>
 /// <param name="args">Arguments sent with command</param>
 public static void ItemRejection(ISender sender, ArgumentList args)
 {
     string exception;
     if (args.TryParseOne<String>(Languages.Add, out exception))
     {
         if (!Server.RejectedItems.Contains(exception))
         {
             Server.RejectedItems.Add(exception);
             sender.sendMessage(exception + Languages.ItemRejection_Added);
         }
         else
         {
             throw new CommandError(Languages.ItemRejection_ItemExists);
         }
     }
     else if (args.TryParseOne<String>(Languages.Remove, out exception))
     {
         if (Server.RejectedItems.Contains(exception))
         {
             Server.RejectedItems.Remove(exception);
             sender.sendMessage(exception + Languages.ItemRejection_Removed);
         }
         else
         {
             throw new CommandError(Languages.ItemRejection_ItemDoesntExist);
         }
     }
     else if (args.TryPop(Languages.Clear))
     {
         Server.RejectedItems.Clear();
         sender.sendMessage(Languages.ItemRejection_Removed);
     }
     else
     {
         throw new CommandError(Languages.NoItemIDNameProvided);
     }
     Program.properties.RejectedItems = String.Join(",", Server.RejectedItems);
     Program.properties.Save(false);
 }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:44,代码来源:Commands.cs

示例11: SetSpawn

        public static void SetSpawn(ISender sender, ArgumentList args)
        {
            if (sender is Player)
            {
                var player = sender as Player;
                var saveWorld = args.TryPop("-save");

                Main.spawnTileX = (int)(player.Position.X / 16);
                Main.spawnTileY = (int)(player.Position.Y / 16);

                if (saveWorld)
                    WorldIO.saveWorld(Server.World.SavePath);

                Server.notifyOps(String.Format("{0} set Spawn to {1}, {2}.", sender.Name, Main.spawnTileX, Main.spawnTileY));
            }
        }
开发者ID:Stickiler,项目名称:Essentials-TDSM,代码行数:16,代码来源:Commands.cs

示例12: Purge

        /// <summary>
        /// Purge Server data
        /// </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 Purge(Server server, ISender sender, ArgumentList args)
        {
            var all = args.TryPop("all");
            var something = false;

            if (all || args.TryPop("proj") || args.TryPop("projectiles"))
            {
                something = true;

                ProgramLog.Admin.Log("Purging all projectiles.");

                var msg = NetMessage.PrepareThreadInstance();

                msg.PlayerChat(255, "<Server> Purging all projectiles.", 255, 180, 100);

                lock (Main.updatingProjectiles)
                {
                    foreach (var projectile in Main.projectile)
                    {
                        projectile.Active = false;
                        projectile.type = ProjectileType.UNKNOWN;

                        msg.Projectile(projectile);
                    }

                    msg.Broadcast();
                }
            }

            if (all || args.TryPop("npc") || args.TryPop("npcs"))
            {
                something = true;

                ProgramLog.Admin.Log("Purging all NPCs.");

                var msg = NetMessage.PrepareThreadInstance();

                msg.PlayerChat(255, "<Server> Purging all NPCs.", 255, 180, 100);

                lock (Main.updatingNPCs)
                {
                    foreach (var npc in Main.npcs)
                    {
                        if (npc.Active)
                        {
                            npc.Active = false;
                            npc.life = 0;
                            npc.netUpdate = false;
                            npc.Name = "";

                            msg.NPCInfo(npc.whoAmI);
                        }
                    }

                    msg.Broadcast();
                }
            }

            if (all || args.TryPop("item") || args.TryPop("items"))
            {
                something = true;

                ProgramLog.Admin.Log("Purging all items.");

                var msg = NetMessage.PrepareThreadInstance();

                msg.PlayerChat(255, "<Server> Purging all items.", 255, 180, 100);

                lock (Main.updatingItems)
                {
                    for (int i = 0; i < 200; i++)
                    {
                        var item = Main.item[i];
                        if (item.Active)
                        {
                            Main.item[i] = new Item(); // this is what Main does when ignoreErrors is on *shrug*
                            msg.ItemInfo(i);
                            msg.ItemOwnerInfo(i);
                        }
                    }

                    msg.Broadcast();
                }
            }

            if (!something)
                throw new CommandError("");
        }
开发者ID:Dyrian,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:94,代码来源:Commands.cs

示例13: ItemRejection

        public static void ItemRejection(Server server, ISender sender, ArgumentList args)
        {
            Boolean Add = args.TryPop("-add");
            Boolean Remove = args.TryPop("-remove");

            if (Add)
            {
                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!");
                        return;
                    }
                    else
                    {
                        throw new CommandError("That item already exists in the list.");
                    }
                }
                else
                {
                    throw new CommandError("No item/id provided with your command");
                }
            }
            if (Remove)
            {
                String exception;
                if (args.TryParseOne<String>("-remove", out exception))
                {
                    if (server.RejectedItems.Contains(exception))
                    {
                        server.RejectedItems.Add(exception);
                        sender.sendMessage(exception + " was removed from the Item Rejection list!");
                        return;
                    }
                    else
                    {
                        throw new CommandError("That item already does not exist in the list.");
                    }
                }
                else
                {
                    throw new CommandError("No item/id provided with your command");
                }
            }
            String prop = String.Join(",", server.RejectedItems);
            Program.properties.RejectedItems = prop;
            Program.properties.Save();
        }
开发者ID:Dyrian,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:51,代码来源:Commands.cs

示例14: Heal

        /// <summary>
        /// Heals one or all players.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="message">Message to send</param>
        public void Heal(ISender sender, ArgumentList args)
        {
            Player subject;

            if (args.TryPopOne(out subject))
            {
                subject = sender as Player;
                if (subject == null)
                {
                    sender.Message("Need a heal target");
                    return;
                }

                //subject.HealEffect(subject.statLifeMax, true);
                NetMessage.SendData(35, -1, -1, String.Empty, subject.whoAmI, (float)subject.statLifeMax, 0f, 0f, 0);
            }
            else if (args.TryPop("-all"))
            {
                foreach (var plr in Main.player)
                {
                    if (plr.active)
                    {
                        NetMessage.SendData(35, -1, -1, String.Empty, plr.whoAmI, (float)plr.statLifeMax, 0f, 0f, 0);
                    }
                }
            }
            else throw new CommandError("No player or options were specified");
        }
开发者ID:Stickiler,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:33,代码来源:Commands.cs

示例15: ItemRejection

 /// <summary>
 /// Manage item rejections
 /// </summary>
 /// <param name="sender">Sending player</param>
 /// <param name="args">Arguments sent with command</param>
 public void ItemRejection(ISender sender, ArgumentList args)
 {
     #if TDSMServer
     string exception;
     if (args.TryParseOne<String>("-add", out exception))
     {
         if (!Server.ItemRejections.Contains(exception))
         {
             Server.ItemRejections.Add(exception);
             sender.Message(exception + " was successfully added.");
         }
         else
         {
             throw new CommandError("Item already exists.");
         }
     }
     else if (args.TryParseOne<String>("-remove", out exception))
     {
         if (Server.ItemRejections.Contains(exception))
         {
             Server.ItemRejections.Remove(exception);
             sender.Message(exception + " was successfully removed.");
         }
         else
         {
             throw new CommandError("Item does not exist.");
         }
     }
     else if (args.TryPop("-clear"))
     {
         Server.ItemRejections.Clear();
         sender.Message("Item rejection list cleared.");
     }
     else
     {
         throw new CommandError("Expected argument -add|-remove|-clear");
     }
     #endif
 }
开发者ID:Stickiler,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:44,代码来源:Commands.cs


注:本文中的ArgumentList.TryPop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。