Пример #1
0
        private static bool CheckArgs(string[] args, out float[] parameters)
        {
            parameters = new float[2];
            bool          parseSuccess = true;
            List <string> exceptions   = new List <string>();

            for (int i = 0; i < args.Length; i++)
            {
                var   parameter = args[i];
                float tmp;
                if (CommandsHelpers.TryParseArgs(args, i, exceptions, parameter, out tmp, ref parseSuccess))
                {
                    continue;
                }
                if (CommandsHelpers.CheckForPresenceInRange(tmp, exceptions, parameter, ref parseSuccess))
                {
                    continue;
                }
                parameters[i] = tmp;
            }
            if (!parseSuccess)
            {
                CommandsHelpers.WriteErrorMessages(exceptions);
                return(true);
            }
            return(false);
        }
        ////////////////

        /// @private
        public override void Action(CommandCaller caller, string input, string[] args)
        {
            IList <Mod> mods   = ModListHelpers.GetAllLoadedModsPreferredOrder().ToList();
            int         argIdx = 1;

            string title;

            if (!CommandsHelpers.GetQuotedStringFromArgsAt(args, argIdx, out argIdx, out title))
            {
                caller.Reply("Invalid issue report title string", Color.Red);
                return;
            }

            string body;

            if (!CommandsHelpers.GetQuotedStringFromArgsAt(args, argIdx, out argIdx, out body))
            {
                caller.Reply("Invalid issue report description string", Color.Red);
                return;
            }

            int modIdx;

            if (!int.TryParse(args[0], out modIdx))
            {
                caller.Reply(args[argIdx] + " is not an integer", Color.Red);
                return;
            }
            if (modIdx <= 0 || modIdx > mods.Count)
            {
                caller.Reply(args[argIdx] + " is not a mod entry; out of range", Color.Red);
                return;
            }

            Action <bool, string> onCompletion = (success, output) => {
                if (output != "Done?")
                {
                    caller.Reply(output, Color.Lime);
                }
                else
                {
                    caller.Reply("Issue report was not sent", Color.Red);
                }
            };
            Action <Exception, string> onFail = (e, output) => {
                caller.Reply(e.Message, Color.Red);
            };

            PostGithubModIssueReports.ReportIssue(mods[modIdx - 1], title, body, onFail, onCompletion);
        }
        ////////////////

        public override void Action(CommandCaller caller, string input, string[] args)
        {
            IList <Mod> mods    = ModHelpers.GetAllMods().ToList();
            int         arg_idx = 1;

            string title = CommandsHelpers.GetQuotedStringFromArgsAt(args, arg_idx, out arg_idx);

            if (arg_idx == -1)
            {
                caller.Reply("Invalid issue report title string", Color.Red);
                return;
            }

            string body = CommandsHelpers.GetQuotedStringFromArgsAt(args, arg_idx, out arg_idx);

            if (arg_idx == -1)
            {
                caller.Reply("Invalid issue report description string", Color.Red);
                return;
            }

            int mod_idx;

            if (!int.TryParse(args[0], out mod_idx))
            {
                caller.Reply(args[arg_idx] + " is not an integer", Color.Red);
                return;
            }
            if (mod_idx <= 0 || mod_idx > mods.Count)
            {
                caller.Reply(args[arg_idx] + " is not a mod entry; out of range", Color.Red);
                return;
            }

            Action <string> on_success = delegate(string output) {
                if (output != "Done?")
                {
                    caller.Reply(output, Color.GreenYellow);
                }
                else
                {
                    caller.Reply("Issue report was not sent", Color.Red);
                }
            };
            Action <Exception, string> on_fail = (e, output) => {
                caller.Reply(e.Message, Color.Red);
            };

            GithubModIssueReports.ReportIssue(mods[mod_idx - 1], title, body, on_success, on_fail);
        }
        ////////////////

        public override void Action(CommandCaller caller, string input, string[] args)
        {
            var mymod = (HamstarHelpersMod)this.mod;

            if (args.Length == 0)
            {
                throw new UsageException("No arguments supplied.");
            }

            int    _;
            string item_name = CommandsHelpers.GetQuotedStringFromArgsAt(args, 0, out _);

            if (!ItemIdentityHelpers.NamesToIds.ContainsKey(item_name))
            {
                throw new UsageException("Invalid item type.");
            }

            caller.Reply("Item id for " + item_name + ": " + ItemIdentityHelpers.NamesToIds[item_name]);
        }
        ////////////////

        /// @private
        public override void Action(CommandCaller caller, string input, string[] args)
        {
            var mymod = (ModHelpersMod)this.mod;

            if (args.Length == 0)
            {
                throw new UsageException("No arguments supplied.");
            }

            int    _;
            string itemName;

            if (CommandsHelpers.GetQuotedStringFromArgsAt(args, 0, out _, out itemName))
            {
                if (!ItemAttributeHelpers.DisplayNamesToIds.ContainsKey(itemName))
                {
                    throw new UsageException("Invalid item type.");
                }

                caller.Reply("Item id for " + itemName + ": " + ItemAttributeHelpers.DisplayNamesToIds[itemName], Color.Lime);
            }
        }
Пример #6
0
        ////////////////

        public override void Action(CommandCaller caller, string input, string[] args)
        {
            var mymod = (IntrinsicsMod)this.mod;

            if (!mymod.Config.DebugModeCheat)
            {
                caller.Reply("Cheat mode not active. See configs.", Color.Red);
                return;
            }

            if (Main.netMode == 1)
            {
                LogHelpers.Warn("Not supposed to run on client.");
                return;
            }

            if (Main.netMode == 2 && caller.CommandType != CommandType.Console)
            {
                bool hasPriv = UserHelpers.HasBasicServerPrivilege(caller.Player);

                if (!hasPriv)
                {
                    caller.Reply("Access denied.", Color.Red);
                    return;
                }
            }

            if (args.Length < 1)
            {
                caller.Reply("Insufficient arguments.", Color.Red);
                return;
            }

            if (args[0].Length == 0 || args[0][0] != '\"')
            {
                caller.Reply("Invalid first item name: " + args[0], Color.Red);
                return;
            }

            IList <Item> items = new List <Item>();

            int    argNextIdx = 0;
            string itemKey;

            while (CommandsHelpers.GetQuotedStringFromArgsAt(args, argNextIdx, out argNextIdx, out itemKey))
            {
                int itemId;

                if (!ItemAttributeHelpers.DisplayNamesToIds.ContainsKey(itemKey))
                {
                    itemId = ItemID.TypeFromUniqueKey(itemKey);

                    if (itemId == 0)
                    {
                        caller.Reply("Invalid item name: " + itemKey, Color.Red);
                        return;
                    }
                }
                else
                {
                    itemId = ItemAttributeHelpers.DisplayNamesToIds[itemKey];
                }

                var item = new Item();
                item.SetDefaults(itemId);

                items.Add(item);
            }

            IEnumerable <string> itemNames = items.Select(i => ItemID.GetUniqueKey(i.type));                   //TODO GetProperUniqueId

            if (ImpartmentContractItem.Create(Main.LocalPlayer, Main.LocalPlayer.Center, new HashSet <string>(itemNames)) != -1)
            {
                caller.Reply("Created Impartment Contract.", Color.Lime);
            }
            else
            {
                caller.Reply("Could not create Impartment Contract.", Color.Red);
            }
        }