示例#1
0
        private bool HookCommand(string message)
        {
            try
            {
                var args = new CommandArguments(message.Substring(1));
                switch (args.Command.ToLower())
                {
                case "color":
                {
                    var newColor = Color.FromName(args.Get <string>(0));
                    if (newColor.IsKnownColor)
                    {
                        SendCommand(InterChatCommandType.ChangeColor, newColor.ToArgb());
                    }
                }
                break;

                case "speech":
                {
                    var content = args.GetAll(0);
                    if (!string.IsNullOrWhiteSpace(content))
                    {
                        SendCommand(InterChatCommandType.Speech, content);
                    }
                }
                break;

                case "go":
                {
                    var serverIndex = args.Get <int>(0);
                    var userName    = args.Get <string>(1, _userName);
                    ClientLauncher.Instance.Execute(serverIndex, userName);
                }
                break;

                case "server":
                {
                    var servers = ClientLauncher.Instance.Servers;
                    for (var serverIndex = 0; serverIndex < servers.Count; ++serverIndex)
                    {
                        var server = servers[serverIndex];
                        AppendInternalLog(string.Format("[{0}] {1} ({2}:{3})", serverIndex, server.Name,
                                                        server.Host, server.Port));
                    }
                }
                break;

                default:
                    return(false);
                }
                return(true);
            }
            catch (Exception exception)
            {
                ShowError("Invalid command: {0}", exception.Message);
            }
            return(false);
        }
示例#2
0
 public static Pos GetPos(this CommandArguments args, int index, Pos defaultPos)
 {
     return(new Pos
     {
         X = args.Get(index, defaultPos.X),
         Y = args.Get(index + 1, defaultPos.Y),
         Z = args.Get(index + 2, defaultPos.Z)
     });
 }
示例#3
0
        public void TestArguments()
        {
            var str  = "do something --path /usr/local -path2 \"/usr\" -d /usr -f C:\\Program Files\\Windows NT -url https://dot.net -a Abc 000 -a Xyz";
            var args = new CommandArguments(str);

            Assert.IsFalse(args.IsUrlLike);
            Assert.AreEqual("do something", args.Verb.ToString());
            var param = args.Get("path");

            Assert.AreEqual("/usr/local", param.FirstValue);
            Assert.AreEqual("/usr/local", args.GetFirst("path", "path2").Value);
            Assert.AreEqual("/usr", args.GetFirst("path2").Value);
            Assert.IsTrue(args.GetFirst("d").IsEmpty);
            Assert.AreEqual("/usr", args.GetFirstOrNext("d", true).Value);
            param = args.Get("f");
            Assert.AreEqual("C:\\Program Files\\Windows NT", param.MergedValue);
            Assert.AreEqual("https://dot.net", args.GetFirst("url").Value);
            param = args.Get("a");
            Assert.AreEqual("Abc 000", param.FirstValue);
            Assert.AreEqual("Abc 000 Xyz", param.MergedValue);
            Assert.AreEqual("-a Abc 000 -a Xyz", param.ToString());
            Assert.AreEqual("Abc 000", args.GetFirstOrNext("a").Value);
            Assert.AreEqual("Abc", args.GetFirst("a").Values[0]);

            str  = "do/something?path=%2Fusr%2Flocal&path2=%2Fusr&d=&usr=&f=C%3A%5CProgram%20Files%5CWindows%20NT&url=https%3A%2F%2Fdot.net&a=Abc,000&a=Xyz";
            args = new CommandArguments(str);
            Assert.IsTrue(args.IsUrlLike);
            Assert.AreEqual("do/something", args.Verb.ToString());
            param = args.Get("path");
            Assert.AreEqual("/usr/local", param.FirstValue);
            Assert.AreEqual("/usr/local", args.GetFirst("path", "path2").Value);
            Assert.AreEqual("/usr", args.GetFirst("path2").Value);
            Assert.IsTrue(args.GetFirst("d").IsEmpty);
            Assert.AreEqual("&usr="******"d", true).Value);
            param = args.Get("f");
            Assert.AreEqual("C:\\Program Files\\Windows NT", param.MergedValue);
            Assert.AreEqual("https://dot.net", args.GetFirst("url").Value);
            param = args.Get("a");
            Assert.AreEqual("Abc,000", param.FirstValue);
            Assert.AreEqual("Abc,000,Xyz", param.MergedValue);
            Assert.AreEqual("a=Abc,000&a=Xyz", param.ToString());
            Assert.AreEqual("Abc,000", args.GetFirstOrNext("a").Value);
            Assert.AreEqual("Abc", args.GetFirst("a").Values[0]);

            args = new CommandArguments(string.Empty);
            Assert.AreEqual(0, args.Count);
            args = new CommandArguments(null as string);
            Assert.AreEqual(0, args.Count);
            args = new CommandArguments(new List <string>());
            Assert.AreEqual(0, args.Count);
        }
示例#4
0
        public override void Run(Configuration config, CommandArguments args)
        {
            base.Run(config, args);

            var target            = args.GetTarget(this);
            var configurationName = args.Get(this, "configuration");
            var buildFileName     =
                Path.Combine(config.BuildsDirectory, target, configurationName, config.MacOS.BuildFile);

            ProcessTools.RunProcessAndEnsureSuccess(this, $"Run('{target}')", "open", buildFileName);
        }
示例#5
0
        public override void Run(Configuration config, CommandArguments args)
        {
            base.Run(config, args);

            var target            = args.GetTarget(this);
            var configurationName = args.Get(this, "configuration");
            var platforms         = args.GetAll(this, "platform");

            RunLibraryBuildFor(config, configurationName, platforms);
            RunFrontendBuildFor(config, configurationName);
            CopyBuildResult(config, target, configurationName);
        }
示例#6
0
        public override void Run(Configuration config, CommandArguments args)
        {
            base.Run(config, args);

            var configurationName = args.Get(this, "configuration");

            RunBuildFor(
                configurationName,
                Path.Combine(Directory.GetCurrentDirectory(), config.StagingDirectory, Configuration.AndroidTarget));
            var apkName = GetApkName(configurationName);

            CopyBuildResult(config, config.Android, configurationName.ToLower(), apkName);
        }
示例#7
0
        public override void Run(Configuration config, CommandArguments args)
        {
            base.Run(config, args);

            var projectPath       = config.MacOS.XcodeProjectPath;
            var target            = args.GetTarget(this);
            var configurationName = args.Get(this, "configuration");
            var outputPath        = Path.Combine(Directory.GetCurrentDirectory(), config.BuildsDirectory, target);

            var buildArgs =
                $"-project {projectPath} -scheme {target} -configuration {configurationName} build " +
                $"SYMROOT=\"{outputPath}\"";

            Console.WriteLine("Start Xcode build with args: " + buildArgs);
            ProcessTools.RunProcessAndEnsureSuccess(this, "XCode Build", "xcodebuild", buildArgs);
        }
示例#8
0
        private bool HookCommand(string message)
        {
            try
            {
                var args = new CommandArguments(message.Substring(1));
                switch (args.Command.ToLower())
                {
                    case "color":
                        {
                            var newColor = Color.FromName(args.Get<string>(0));
                            if (newColor.IsKnownColor)
                                SendCommand(InterChatCommandType.ChangeColor, newColor.ToArgb());
                        }
                        break;

                    case "speech":
                        {
                            var content = args.GetAll(0);
                            if (!string.IsNullOrWhiteSpace(content))
                                SendCommand(InterChatCommandType.Speech, content);
                        }
                        break;

                    case "go":
                        {
                            var serverIndex = args.Get<int>(0);
                            var userName = args.Get<string>(1, _userName);
                            ClientLauncher.Instance.Execute(serverIndex, userName);
                        }
                        break;

                    case "server":
                        {
                            var servers = ClientLauncher.Instance.Servers;
                            for (var serverIndex = 0; serverIndex < servers.Count; ++serverIndex)
                            {
                                var server = servers[serverIndex];
                                AppendInternalLog(string.Format("[{0}] {1} ({2}:{3})", serverIndex, server.Name,
                                                                server.Host, server.Port));
                            }

                        }
                        break;

                    default:
                        return false;
                }
                return true;
            }
            catch (Exception exception)
            {
                ShowError("Invalid command: {0}", exception.Message);
            }
            return false;
        }
示例#9
0
        protected void ApplyMode(CommandArguments args)
        {
            _osuMode = OsuMode.Standard;

            if (args.Get("m") != null)
            {
                switch (args.Get("m"))
                {
                case "standard":
                    _osuMode = OsuMode.Standard;
                    break;

                case "mania":
                    _osuMode = OsuMode.Mania;
                    break;

                case "ctb":
                case "catch":
                    _osuMode = OsuMode.Catch;
                    break;

                case "taiko":
                    _osuMode = OsuMode.Taiko;
                    break;

                default:
                    _osuMode = OsuMode.Standard;
                    break;
                }
            }

            // if (string.IsNullOrEmpty(input))
            //     return input;
            // if (input.Contains("-m ") || input.Contains(" -m "))
            // {
            //     string foundMode = "";
            //     if (input.Contains(" -m "))
            //     {
            //         foundMode = input.Substring(input.IndexOf(" -m ", StringComparison.Ordinal) + " -m ".Length);
            //         input = input.Substring(0, input.IndexOf(" -m ", StringComparison.Ordinal));
            //     }
            //     else
            //     {
            //         foundMode = input.Substring(input.IndexOf("-m ", StringComparison.Ordinal) + "-m ".Length);
            //         input = input.Substring(0, input.IndexOf("-m ", StringComparison.Ordinal));
            //     }
            //
            //     switch (foundMode.ToLower())
            //     {
            //         case "standard":
            //             _osuMode = OsuMode.Standard;
            //             break;
            //         case "mania":
            //             _osuMode = OsuMode.Mania;
            //             break;
            //         case "ctb":
            //         case "catch":
            //             _osuMode = OsuMode.Catch;
            //             break;
            //         case "taiko":
            //             _osuMode = OsuMode.Taiko;
            //             break;
            //         default:
            //             _osuMode = OsuMode.Standard;
            //             break;
            //     }
            // }
            // return input;
        }
示例#10
0
        public override object CommandHandler(SocketMessage socketMessage, string input, CommandArguments arguments)
        {
            ApplyMode(arguments);
            ApplyPlayer(socketMessage.Author.Id, input);

            if (_osuUser == null)
            {
                return("No user has been found.");
            }

            bool getRecent = false;
            int  limit     = 3;

            if (arguments.Get("r") != null)
            {
                getRecent = true;
            }

            if (arguments.Get("l") != null || arguments.Get("limit") != null)
            {
                int.TryParse((arguments.Get("l") != null) ? arguments.Get("l") : arguments.Get("limit"), out limit);
            }

            if (limit < 3)
            {
                limit = 3;
            }
            if (limit > 5)
            {
                limit = 5;
            }

            List <OsuPlay> topPlays = OsuApi.GetUserBest(_osuUser, _osuMode, 100, false);

            if (topPlays.Count == 0)
            {
                return("This player has no top plays in osu!" + _osuMode);
            }

            if (topPlays.Count < limit)
            {
                limit = topPlays.Count;
            }

            List <KeyValuePair <int, OsuPlay> > resultPlays = null;

            if (getRecent)
            {
                resultPlays = topPlays.Select((x, i) => new KeyValuePair <int, OsuPlay>(i + 1, x)).OrderBy(i => ((DateTimeOffset)DateTime.Parse(i.Value.DateAchieved)).ToUnixTimeSeconds()).Reverse().Take(limit).ToList();
            }
            else
            {
                resultPlays = topPlays.Select((x, i) => new KeyValuePair <int, OsuPlay>(i + 1, x)).Take(limit).ToList();
            }

            EmbedFieldBuilder topPlaysField = new EmbedFieldBuilder()
            {
                Name     = "\u200B",
                Value    = "a",
                IsInline = false
            };

            EmbedBuilder embed = new EmbedBuilder()
            {
                Color        = ParentManager.bot.BotColor,
                Title        = (getRecent ? "Most " + limit + " recent top plays" : "Top " + limit + " plays") + " from **" + _osuUser.Name + "**",
                ThumbnailUrl = "https://a.ppy.sh/" + _osuUser.ID,
                Description  = "Plays on osu!" + _osuMode,
                Fields       = new List <EmbedFieldBuilder>()
                {
                }
            };

            foreach (KeyValuePair <int, OsuPlay> playPair in resultPlays)
            {
                int     playIndex = playPair.Key;
                OsuPlay play      = playPair.Value;

                play.Beatmap = OsuApi.GetBeatmap(play.MapID, play.Mods, play.Mode);

                EmbedFieldBuilder field = new EmbedFieldBuilder()
                {
                    Name  = "**" + playIndex + ". " + play.Beatmap.Title + " [" + play.Beatmap.DifficultyName + "] +" + (((OsuModsShort)play.Mods).ModParser() + "").Replace(", ", "") + "** (" + Mathf.Round((float)play.Beatmap.Starrating, 2) + "\\*)",
                    Value = OsuRanks.GetEmojiFromRank(play.Rank).ToString() + " " + Mathf.Round(play.Accuracy, 2) + "% • **" + Mathf.Round(play.Performance.CurrentValue, 2) + "pp** " + play.MaxCombo + "x" + (play.Beatmap.MaxCombo != null?"/" + play.Beatmap.MaxCombo + "x":"") + " " + ((play.IsFullcombo == "1"?"":"(For FC: **" + Mathf.Round(play.Performance.CurrentValueIfFC, 2) + "pp**)")) + " • " + play.Score.FormatNumber() + "\n" +
                            "Achieved " + DateTime.Parse(play.DateAchieved).Humanize() + " • [Map](https://osu.ppy.sh/beatmaps/" + play.Beatmap.BeatmapID + ")",
                    IsInline = false
                };

                embed.AddField(field);
            }

            return(embed);
        }
示例#11
0
文件: CommandMap.cs 项目: ktj007/mmo
        private static bool InvokeHandler(Entity admin, CommandArguments args, object handler, CommandHandlerInfo handlerInfo)
        {
            if (handlerInfo.Parameters.Length == 0)
                return (bool) handlerInfo.Method.Invoke(handler, new object[0]);

            var objects = new List<object>();

            // 첫 번재 인자로 admin을 요청할 경우에는 admin을 넣어준다.
            if (handlerInfo.Parameters[0].ParameterType == typeof (Entity))
                objects.Add(admin);

            for (var index = 1; index < handlerInfo.Parameters.Length; ++index)
            {
                var argsIndex = index - 1;
                var parameter = handlerInfo.Parameters[index];

                var isAfterAll = false;
                object value = null;

                // CommandArgument의 속성에 따라 value를 미리 구해본다.
                if (parameter.IsOptional)
                    value = parameter.Default;

                if (parameter.IsAfterAll)
                {
                    // AfterAll은 꼭 마지막에 와야한다.
                    Debug.Assert(index == handlerInfo.Parameters.Length - 1);
                    value = args.GetAll(argsIndex);
                    isAfterAll = true;
                }

                // Attribute로부터 값을 구하지 못했고, 입력된 args도 없다면 인자 부족으로 종료한다.
                if (args.Count <= argsIndex)
                {
                    if (value == null)
                        return false;
                }
                else
                {
                    // AfterAll이 아니면 값을 가져올 수 있다.
                    if (!isAfterAll)
                    {
                        // Entity 형일 경우 int를 받아서 Entity를 가져온다.
                        if (parameter.ParameterType == typeof (Entity))
                        {
                            if (!args.Is<int>(argsIndex))
                                return false;

                            var targetEntityId = args.Get<int>(argsIndex);
                            var targetEntity = EntityManager.Instance.At(targetEntityId);
                            if (targetEntity == null)
                                return false;

                            value = targetEntity;
                        }
                        else
                        {
                            // 잘못된 인자가 넘어왔다면 인자 오류로 종료한다.
                            if (!args.IsType(argsIndex, parameter.ParameterType))
                                return false;

                            value = args.GetValue(argsIndex, parameter.ParameterType);
                        }
                    }
                }

                objects.Add(value);
            }

            return (bool) handlerInfo.Method.Invoke(handler, objects.ToArray());
        }
示例#12
0
 public static Entity GetEntity(this CommandArguments args, int index = 0)
 {
     return(EntityManager.Instance.At(args.Get <int>(index)));
 }