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


C# ArgumentList.GetString方法代码示例

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


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

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

示例2: DeopPlayer

        /// <summary>
        /// De-OPs a given Player.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public static void DeopPlayer(ISender sender, ArgumentList args)
        {
            var playerName = args.GetString(0);
            Player player;
            if (args.TryGetOnlinePlayer(0, out player))
            {
                playerName = player.Name;

                if (Player.isInOpList(playerName))
                {
                    player.sendMessage("You have been De-Opped!.", ChatColor.Green);
                }

                player.Op = false;
                if (player.HasClientMod)
                {
                    NetMessage.SendData(Packet.CLIENT_MOD, player.whoAmi);
                }
            }

            if (Player.isInOpList(playerName))
            {
                Server.notifyOps("De-Opping " + playerName + " {" + sender.Name + "}", true);
                Server.OpList.removeException(playerName + ":" + Player.GetPlayerPassword(playerName));
            }

            if (!Server.OpList.Save())
            {
                Server.notifyOps("OpList Failed to Save due. {" + sender.Name + "}", true);
                return;
            }
        }
开发者ID:rakiru,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:37,代码来源:Commands.cs

示例3: DeopPlayer

        /// <summary>
        /// De-OPs a given Player.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public void DeopPlayer(ISender sender, ArgumentList args)
        {
            var playerName = args.GetString(0);
            if (Storage.IsAvailable)
            {
                var existing = Authentication.GetPlayer(playerName);
                if (existing != null)
                {
                    if (!existing.Operator)
                        throw new CommandError("Player is not an operator");

                    var player = Tools.GetPlayerByName(playerName);
                    if (player != null)
                    {
                        player.SendMessage("Your server operator privledges have been revoked.", Color.DarkRed);
                        player.SetOp(false);
                        player.SetAuthentication(null, "tdsm");
                    }

                    if (Authentication.UpdatePlayer(playerName, null, false))
                    {
                        sender.Message("Deop success", Color.DarkGreen);
                    }
                    else
                    {
                        sender.Message("Failed to deop player", Color.DarkRed);
                    }
                }
                else
                {
                    sender.SendMessage("No user found by " + playerName);
                }
            }
            else
            {
                if (Core.Ops.Contains(playerName))
                {
                    var player = Tools.GetPlayerByName(playerName);
                    if (player != null)
                    {
                        player.SendMessage("Your server operator privledges have been revoked.", Color.Green);
                        player.SetOp(false);
                        player.SetAuthentication(null, "tdsm");
                    }

                    Utils.NotifyAllOps("De-Opping " + playerName + " [" + sender.SenderName + "]", true);
                    Core.Ops.Remove(playerName, true);

                    if (!Core.Ops.Save())
                    {
                        Utils.NotifyAllOps("Failed to save op list [" + sender.SenderName + "]", true);
                    }
                }
                else
                    sender.SendMessage("No user found by " + playerName);
            }
        }
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:62,代码来源:OperatorCommand.cs

示例4: 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

示例5: Debug

        void Debug(ISender sender, ArgumentList args)
        {
            var cmd = args.GetString(0);

            switch (cmd)
            {
                case "programlog.debug":
                    ProgramLog.Debug.EnableConsoleOutput = !ProgramLog.Debug.EnableConsoleOutput;
                    sender.Message("ProgramLog.Debug.EnableConsoleOutput: " + ProgramLog.Debug.EnableConsoleOutput);
                    break;
                default:
                    throw new CommandError("Invalid sub command " + cmd);
            }
        }
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:14,代码来源:DebugCommand.cs

示例6: RConCommand

        internal static void RConCommand(ISender sender, ArgumentList args)
        {
            string name;
            if (args.TryParseOne ("cut", out name))
            {
                if (sender is Player || sender is RConSender)
                {
                    sender.sendMessage ("You cannot perform that action.", 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 ("You cannot perform that action.", 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 ("You cannot perform that action.", 255, 238, 130, 238);
                    return;
                }

                LoginDatabase.Load ();
                ProgramLog.Admin.Log ("Reloaded remote console login database.");
            }
            else
            {
                throw new CommandError ("");
            }
        }
开发者ID:rakiru,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:62,代码来源:RConServer.cs

示例7: 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 static void Give(ISender sender, ArgumentList args)
        {
            // /give <player> <stack> <name>

            string _prefix;
            args.TryPopAny("-prefix", out _prefix);

            byte prefix;
            if (!Byte.TryParse(_prefix, out prefix))
            {
                Affix affix;
                if (!AffixExtensions.Parse(_prefix ?? String.Empty, out affix, true)) prefix = 0;
                else prefix = (byte)affix;
            }

            Player receiver = args.GetOnlinePlayer(0);
            int stack = args.GetInt(1);
            string NameOrId = args.GetString(2);

            List<ItemInfo> itemlist;
            if (Server.TryFindItemByName(NameOrId, out itemlist) && itemlist.Count > 0)
            {
                if (itemlist.Count > 1)
                    throw new CommandError(String.Format(Languages.MoreThanOneItemFoundNameId, itemlist.Count));

                var item = itemlist[0];

                var index = receiver.GiveItem(item.Type, stack, sender, item.NetID, true, prefix);

                if (item.NetID < 0)
                    Main.item[index] = Item.netDefaults(item.NetID);

                Main.item[index].Prefix = prefix;
            }
            else
            {
                int Id = -1;
                try
                {
                    Id = Int32.Parse(NameOrId);
                }
                catch
                {
                    throw new CommandError(String.Format(Languages.MoreThanOneItemFoundNameId, itemlist.Count));
                }

                if (Server.TryFindItemByType(Id, out itemlist) && itemlist.Count > 0)
                {
                    if (itemlist.Count > 1)
                        throw new CommandError(String.Format(Languages.MoreThanOneItemFoundType, itemlist.Count));

                    //receiver.GiveItem(itemlist[0].Type, stack, sender);
                    var item = itemlist[0];

                    var index = receiver.GiveItem(item.Type, stack, sender, item.NetID, true, prefix);

                    if (item.NetID < 0)
                        Main.item[index] = Item.netDefaults(item.NetID);

                    Main.item[index].Prefix = prefix;
                }
                else
                {
                    throw new CommandError(String.Format(Languages.MoreThanOneItemFoundNameId, "no"));
                }
            }
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:72,代码来源:Commands.cs

示例8: Timelock

        /// <summary>
        /// Allows an OP to force the time to dtay at a certain point.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public static void Timelock(ISender sender, ArgumentList args)
        {
            var disable = args.TryPop("disable");
            var setNow = args.TryPop("now");
            var setMode = args.TryPop("set");
            var setAt = args.TryPop("setat");

            if (disable)
            {
                if (!Main.UseTimeLock) { sender.sendMessage("Time lock is already disabled", 255, 255, 0, 0); return; }

                Main.UseTimeLock = false;
                sender.sendMessage("Time lock has been disabled.", 255, 0, 255, 0);
                return;
            }
            else if (setNow) Main.UseTimeLock = true;
            else if (setMode)
            {
                string caseType = args.GetString(0);
                switch (caseType)
                {
                    case "day":
                        {
                            World.SetTime(13500.0);
                            break;
                        }
                    case "dawn":
                        {
                            World.SetTime(0);
                            break;
                        }
                    case "dusk":
                        {
                            World.SetTime(0, false, false);
                            break;
                        }
                    case "noon":
                        {
                            World.SetTime(27000.0);
                            break;
                        }
                    case "night":
                        {
                            World.SetTime(16200.0, false, false);
                            break;
                        }
                    default:
                        {
                            sender.sendMessage(Languages.PleaseReview, 255, 255, 0, 0);
                            return;
                        }
                }
                Main.UseTimeLock = true;
            }
            else if (setAt)
            {
                double time;
                if (args.TryParseOne<Double>(out time))
                {
                    Main.Time = time;
                    Main.UseTimeLock = true;
                }
                else throw new CommandError("Double expected.");
            }
            else throw new CommandError("Certain arguments expected.");

            if (Main.UseTimeLock)
            {
                if (!setNow) NetMessage.SendData(Packet.WORLD_DATA);

                sender.sendMessage(
                    String.Format("Time lock has set at {0}.", Main.Time),
                    255, 0, 255, 0
                );
            }
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:81,代码来源:Commands.cs

示例9: Time


//.........这里部分代码省略.........
        //    Tools.NotifyAllOps(playerName + Languages.Ban_Banned + " [" + sender.SenderName + "]", true);
        //    if (!Server.BanList.Save())
        //    {
        //        Tools.NotifyAllOps(Languages.Ban_FailedToSave + sender.SenderName + "'s " + Languages.Command, true);
        //    }
        //}
        ///// <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);
        //    Tools.NotifyAllOps(playerName + Languages.Ban_UnBanned + " [" + sender.SenderName + "]", true);
        //    if (!Server.BanList.Save())
        //    {
        //        Tools.NotifyAllOps(Languages.Ban_FailedToSave + sender.SenderName + "'s " + Languages.Command, true);
        //    }
        //}
        /// <summary>
        /// Sets the time in the game.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public void Time(ISender sender, ArgumentList args)
        {
            double time;
            WorldTime text;
            if (args.TryParseOne<Double>("-set", out time) || args.TryParseOne<Double>("set", out time))
            {
                if (time >= WorldTime.TimeMin && time <= WorldTime.TimeMax)
                {
                    World.SetTime(time);
                }
                else
                {
                    sender.SendMessage(String.Format("Invalid time specified, must be from {0} to {1}", WorldTime.TimeMin, WorldTime.TimeMax));
                    return;
                }
            }
            else if (args.TryParseOne<WorldTime>("-set", out text) || args.TryParseOne<WorldTime>("set", out text))
            {
                time = text.GameTime;
                World.SetParsedTime(time);
            }
            else
            {
                string caseType = args.GetString(0);
                switch (caseType)
                {
                    case "day":
                        {
                            World.SetTime(13500.0);
                            break;
                        }
                    case "dawn":
                        {
                            World.SetTime(0);
                            break;
                        }
                    case "dusk":
                        {
                            World.SetTime(0, false);
                            break;
                        }
                    case "noon":
                        {
                            World.SetTime(27000.0);
                            break;
                        }
                    case "night":
                        {
                            World.SetTime(16200.0, false);
                            break;
                        }
                    case "?":
                    case "now":
                    case "-now":
                        {
                            sender.Message("Current time: " + WorldTime.Parse(World.GetParsableTime()).ToString());
                            return;
                        }
                    default:
                        {
                            sender.Message("Please review your command");
                            return;
                        }
                }
            }

            NetMessage.SendData((int)Packet.WORLD_DATA); //Update Data
            var current = WorldTime.Parse(World.GetParsableTime()).Value;
            Tools.NotifyAllPlayers(String.Format("Time set to {0} ({1}) by {2}", current.ToString(), current.GameTime, sender.SenderName), Color.Green);
        }
开发者ID:Stickiler,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:101,代码来源:Commands.cs

示例10: ShowHelp

        /// <summary>
        /// Shows the help.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="args">Arguments.</param>
        public static void ShowHelp(ISender sender, ArgumentList args)
        {
            var commands = sender.GetAvailableCommands();
            if (commands != null && commands.Count > 0)
            {
                int page = 0;
                if (!args.TryGetInt(0, out page))
                {
                    if (args.Count > 0)
                    {
                        var command = args.GetString(0);
                        if (commands.ContainsKey(command))
                        {
                            sender.SendMessage(commands[command].description);
                            commands[command].ShowHelp(sender, true);
                            return;
                        }
                        else
                            throw new CommandError("No such command: " + command);
                    }
                }
                else
                    page--;

                //				const Int32 MaxLines = 5;
                var maxLines = sender is Player ? 5 : 15;
                var lineOffset = page * maxLines;
                var maxPages = (int)Math.Ceiling(commands.Count / (double)maxLines);

                if (page >= 0 && page < maxPages)
                {
                    var cmds = new List<CommandInfo>();
                    var sorted = commands
                        .OrderBy(x => x.Key.ToLower())
                        .Select(x => x.Value)
                        .ToArray();
                    for (var i = lineOffset; i < lineOffset + maxLines; i++)
                    {
                        if (i < sorted.Length)
                            cmds.Add(sorted[i]);
                    }

                    var prefixMax = cmds
                        .Select(x => x.Prefix.Length)
                        .OrderByDescending(x => x)
                        .First();
                    foreach (var cmd in cmds)
                        cmd.ShowDescription(sender, prefixMax);

                    sender.SendMessage(String.Format("[Page {0} / {1}]", page + 1, maxPages));
                }
                else
                {
                    sender.SendMessage("Usage:");
                    sender.SendMessage("    help <command> - Get help for a command.");
                    sender.SendMessage("    help <page> - View a list of commands. Valid page numbers are 1 to " + maxPages + ".");
                    sender.SendMessage("Examples:");
                    sender.SendMessage("    help oplogin");
                    sender.SendMessage("    help 1");
                }
            }
            else
                sender.SendMessage("You have no available commands.");
        }
开发者ID:claudiofreda,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:69,代码来源:DefaultCommands.cs

示例11: SpawnNPC

        /// <summary>
        /// Spawns specified NPC type.
        /// </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 SpawnNPC(Server server, ISender sender, ArgumentList args)
        {
            Player player = sender as Player;
            if (args.Count > 3)
            {
                throw new CommandError("Too many arguments. NPC and player names with spaces require quotes.");
            }
            else if (sender is ConsoleSender && args.Count <= 2)
            {
                throw new CommandError("As console you need to specify the player to spawn near.");
            }
            else if (args.Count == 3)
            {
                player = args.GetOnlinePlayer(2);
            }

            String npcName = args.GetString(1).ToLower().Trim();

            // Get the class id of the npc
            Int32 realNPCId = 0;
            NPC fclass = Registries.NPC.FindClass(npcName);
            if (fclass.type != Registries.NPC.Default.type)
            {
                realNPCId = fclass.Type;
            }
            else
            {
                try
                {
                    realNPCId = Int32.Parse(npcName);
                }
                catch
                {
                    throw new CommandError("Specified NPC does not exist");
                }
            }

            int NPCAmount = 0;

            try
            {
                NPCAmount = Int32.Parse(args[0]);
                if (NPCAmount > Program.properties.SpawnNPCMax && sender is Player)
                {
                    (sender as Player).Kick ("Don't spawn that many.");
                    return;
                }
            }
            catch
            {
                throw new CommandError("Expected integer for number to spawn.");
            }

            String realNPCName = "";
            for (int i = 0; i < NPCAmount; i++)
            {
                Vector2 location = World.GetRandomClearTile(((int)player.Position.X / 16), ((int)player.Position.Y / 16), 100, true, 100, 50);
                int npcIndex = NPC.NewNPC(((int)location.X * 16), ((int)location.Y * 16), fclass.Name);
                //Registries.NPC.Alter(Main.npcs[npcIndex], fclass.Name);
                realNPCName = Main.npcs[npcIndex].Name;
            }
            Program.server.notifyOps("Spawned " + NPCAmount.ToString() + " of " +
                    realNPCName + " {" + player.Name + "}", true);
        }
开发者ID:Dyrian,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:70,代码来源:Commands.cs

示例12: OpPlayer

        /// <summary>
        /// Sets OP status to a given Player.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public void OpPlayer(ISender sender, ArgumentList args)
        {
            var playerName = args.GetString(0);

            if (Storage.IsAvailable)
            {
                var existing = Authentication.GetPlayer(playerName);

                if (existing == null && (args.Contains("-c") || args.Contains("-create")))
                {
                    var password = args.GetString(1);
                    existing = Authentication.CreatePlayer(playerName, password, true);

                    Utils.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true);
                    var player = Tools.GetPlayerByName(playerName);
                    if (player != null)
                    {
                        player.SendMessage("You are now a server operator.", Color.Green);
                        player.SetOp(true);
                        player.SetAuthentication(player.name, "tdsm");
                    }

                    sender.Message("Op success", Color.DarkGreen);
                }
                else if (existing != null)
                {
                    if (existing.Operator)
                        throw new CommandError("Player is already an operator");

                    if (Authentication.UpdatePlayer(playerName, null, op: true))
                    {
                        Utils.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true);
                        var player = Tools.GetPlayerByName(playerName);
                        if (player != null)
                        {
                            player.SendMessage("You are now a server operator.", Color.Green);
                            player.SetOp(true);
                            player.SetAuthentication(player.name, "tdsm");
                        }

                        sender.Message("Op success", Color.DarkGreen);
                    }
                    else
                    {
                        sender.Message("Failed to op player", Color.DarkRed);
                    }
                }
                else
                {
                    sender.Message("No user found by " + playerName, Color.DarkRed);
                    sender.Message("Please use the `user` command or add the -create switch", Color.DarkRed);
                }
            }
            else
            {
                var password = args.GetString(1);

                Utils.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true);
                Core.Ops.Add(playerName, password);

                var player = Tools.GetPlayerByName(playerName);
                if (player != null)
                {
                    player.SendMessage("You are now a server operator.", Color.Green);
                    player.SetOp(true);
                    player.SetAuthentication(player.name, "tdsm");
                }

                if (!Core.Ops.Save())
                {
                    Utils.NotifyAllOps("Failed to save op list [" + sender.SenderName + "]", true);
                    return;
                }
            }
        }
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:80,代码来源:OperatorCommand.cs

示例13: 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");

//.........这里部分代码省略.........
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:101,代码来源:ApiCommand.cs

示例14: SpawnNPC

        /// <summary>
        /// Spawns specified NPC type.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        /// <remarks>This function also allows NPC custom health.</remarks>
        public void SpawnNPC(ISender sender, ArgumentList args)
        {
            //if (Main.stopSpawns && !Program.properties.NPCSpawnsOverride)
            //    throw new CommandError("NPC Spawing is disabled.");

            //var health = -1;
            //var customHealth = args.TryPopAny<Int32>("-health", out health);

            Player player = sender as Player;
            int amount, offset = -1;
            if (args.Count > 5)
                throw new CommandError("Too many arguments");
            else if (sender is ConsoleSender && args.Count <= 2)
            {
                if (!Netplay.anyClients || !Tools.TryGetFirstOnlinePlayer(out player))
                    throw new CommandError("No players online.");
            }
            else if (args.Count == 3)
                player = args.GetOnlinePlayer(2);
            else if (args.Count >= 4)
            {
                player = args.GetOnlinePlayer(2);
                args.TryPopAny<Int32>("-item", out offset);
            }

            var npcName = args.GetString(1).ToLower().Trim();

            // Get the class id of the npc
            var npcs = DefinitionManager.FindNPC(npcName);
            if (npcs == null || npcs.Length == 0)
            {
                int npcId;
                if (Int32.TryParse(npcName, out npcId))
                {
                    npcs = DefinitionManager.FindNPC(npcId);
                    if (npcs == null || npcs.Length == 0)
                    {
                        throw new CommandError("No npc exists by type {0}", npcId);
                    }
                }
                else throw new CommandError("No npc exists {0}", npcName);
            }

            npcs = npcs.OrderBy(x => x.Name).ToArray();
            if (npcs.Length > 1)
            {
                if (offset == -1)
                {
                    sender.SendMessage("Npcs matching " + npcName + ':');
                    for (var x = 0; x < npcs.Length; x++)
                    {
                        if (sender is ConsoleSender)
                        {
                            sender.SendMessage($"\t{x}\t- {npcs[x].Name}");
                        }
                        else
                        {
                            sender.SendMessage($"{x} - {npcs[x].Name}");
                        }
                    }
                    return;
                }
            }
            else offset = 0;

            var npc = npcs[offset];
            if (npc.Boss.HasValue && npc.Boss == true)
                throw new CommandError("This NPC can only be summoned by the SPAWNBOSS command.");
            try
            {
                amount = args.GetInt(0);
                //if (NPCAmount > Program.properties.SpawnNPCMax && sender is Player)
                //{
                //    (sender as Player).Kick("Don't spawn that many.");
                //    return;
                //}
            }
            catch
            {
                throw new CommandError("Expected amount to spawn");
            }

            var max = Tools.AvailableNPCSlots; //Perhaps remove a few incase of spawns
            if (amount > max)
                throw new CommandError("Cannot spawn that many, available slots: {0}", max);

            string realNPCName = String.Empty;
            for (int i = 0; i < amount; i++)
            {
                Vector2 location = World.GetRandomClearTile(((int)player.position.X / 16), ((int)player.position.Y / 16), 100, 100, 50);
                int npcIndex = NPC.NewNPC(((int)location.X * 16), ((int)location.Y * 16), npc.Id, 0);

                //if (customHealth)
                //{
//.........这里部分代码省略.........
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:101,代码来源:SpawnNpcCommand.cs

示例15: OpPlayer

        /// <summary>
        /// Sets OP status to a given Player.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public void OpPlayer(ISender sender, ArgumentList args)
        {
            var playerName = args.GetString(0);
            var password = args.GetString(1);

            Tools.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true);
            Ops.Add(playerName, password);

            //Player player;
            //if (args.TryGetOnlinePlayer(0, out player))
            //{
            //    playerName = player.Name;

            //    player.SendMessage("You are now a server operator.", Color.Green);
            //    player.Op = true;
            //}

            var player = Tools.GetPlayerByName(playerName);
            if (player != null)
            {
                player.SendMessage("You are now a server operator.", Color.Green);
                player.Op = true;
            }

            if (!Ops.Save())
            {
                Tools.NotifyAllOps("Failed to save op list [" + sender.SenderName + "]", true);
                return;
            }
        }
开发者ID:Stickiler,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:35,代码来源:Commands.cs


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