Пример #1
0
 static void QuitWithArgs(ExtOutputArgs extOutputArgs)
 {
     try
     {
         string runPath  = Assembly.GetEntryAssembly().Location;
         string jsonFile = Path.Combine(Path.GetDirectoryName(runPath), Path.GetFileNameWithoutExtension(runPath) + ".json");
         SaveTextToFile(GetJson(extOutputArgs ?? new ExtOutputArgs()), jsonFile);
     }
     catch (Exception ex)
     {
         extOutputArgs.Msg = ex.Message;
     }
     finally
     {
         System.Environment.Exit(0);
     }
 }
Пример #2
0
        /// <summary>
        /// 复制本代码文件替换“SuWar3ToolsExt\ExtLogic.cs”后编译生成程序即可使用
        /// </summary>
        /// <param name="launchArgs">程序启动参数</param>
        /// <param name="inputArgs">由SuWar3Tools生成的Json文本参数</param>
        /// <param name="outputArgs">输出的参数,将由SuWar3Tools进行处理</param>
        /// <returns></returns>
        public static async Task <ExtOutputArgs> ProcessLogic(string[] launchArgs, ExtInputArgs inputArgs, ExtOutputArgs outputArgs)
        {
            try
            {
                List <string> names = new List <string>();
                inputArgs.Joiners?.ForEach(n => names.Add(n.Name));
                inputArgs.Players?.ForEach(n => names.Add(n.Name));
                string gameType   = launchArgs != null && launchArgs.Length > 0 ? launchArgs[0] : "1";
                string userName   = launchArgs != null && launchArgs.Length > 1 ? launchArgs[1] : "";
                string passWord   = launchArgs != null && launchArgs.Length > 2 ? launchArgs[2] : "";
                string tryCount   = launchArgs != null && launchArgs.Length > 3 ? launchArgs[3] : "3";
                int    retryCount = 3;
                int.TryParse(tryCount, out retryCount);
                if (string.IsNullOrEmpty(gameType) || string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(passWord))
                {
                    throw new Exception("请配置账号和密码");
                }
                List <Cookie> cookies = GetCookies();
                if (cookies == null || cookies.Count < 1)
                {
                    LoginResult loginResult = await GetLoginResultAsync(userName, passWord);

                    if (loginResult == null || loginResult.code != 1 || loginResult.data == null)
                    {
                        throw new Exception("账号登录失败" + (loginResult != null && !string.IsNullOrEmpty(loginResult.msg) ? (":" + loginResult.msg) : ""));
                    }
                    cookies = await GetPassCookieAsync(loginResult.data);
                }
                if (cookies == null || cookies.Count < 1)
                {
                    throw new Exception("获取Cookie失败");
                }
                //outputArgs.Msg = GetGameTypeDesc(gameType) + "天梯:";
                //批量查询11天梯胜率
                names.RemoveAll(n => n == "蜀国" || n == "魏国" || n == userName);
                if (names.Count > 0)
                {
                    Task <TaskResult>[] tasks = new Task <TaskResult> [names.Count];
                    for (int i = 0; i < tasks.Length; i++)
                    {
                        tasks[i] = GetPlayData(gameType, names[i], cookies, retryCount);
                    }
                    Task.WaitAll(tasks);
                    List <TaskResult> results = new List <TaskResult>();
                    for (int i = 0; i < tasks.Length; i++)
                    {
                        results.Add(await tasks[i]);
                    }
                    bool existSuccess = results.Exists(n => n.success);
                    SaveCookies(existSuccess ? cookies : null);
                    for (int i = 0; i < results.Count; i++)
                    {
                        if ((!existSuccess || results[i].success) && !string.IsNullOrEmpty(results[i].result))
                        {
                            if (string.IsNullOrEmpty(outputArgs.Msg))
                            {
                                outputArgs.Msg = results[i].result;
                            }
                            else
                            {
                                outputArgs.Msg += "\n" + results[i].result;
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(outputArgs.Msg))
                {
                    outputArgs.Msg = outputArgs.Msg.Trim();
                }
            }
            catch (Exception ex)
            {
                outputArgs.Msg = ex.Message;
            }
            return(outputArgs);
        }
Пример #3
0
 /// <summary>
 /// 复制本代码文件替换“SuWar3ToolsExt\ExtLogic.cs”后编译生成程序即可使用
 /// </summary>
 /// <param name="launchArgs">程序启动参数</param>
 /// <param name="inputArgs">由SuWar3Tools生成的Json文本参数</param>
 /// <param name="outputArgs">输出的参数,将由SuWar3Tools进行处理</param>
 /// <returns></returns>
 public static async Task <ExtOutputArgs> ProcessLogic(string[] launchArgs, ExtInputArgs inputArgs, ExtOutputArgs outputArgs)
 {
     try
     {
         List <string> names = new List <string>();
         inputArgs.Joiners?.ForEach(n => names.Add(n.Name));
         inputArgs.Players?.ForEach(n => names.Add(n.Name));
         string gameType = launchArgs != null && launchArgs.Length > 0 ? launchArgs[0] : "1";
         if (string.IsNullOrEmpty(gameType))
         {
             gameType = "1";
         }
         outputArgs.Msg = GetGameTypeDesc(gameType) + "胜率->";
         //下面以批量查询09战绩为例
         if (names.Count > 0)
         {
             Task <string>[] tasks = new Task <string> [names.Count];
             for (int i = 0; i < tasks.Length; i++)
             {
                 tasks[i] = GetPlayData(gameType, names[i]);
             }
             Task.WaitAll(tasks);
             for (int i = 0; i < tasks.Length; i++)
             {
                 string result = await tasks[i];
                 if (!string.IsNullOrEmpty(result))
                 {
                     outputArgs.Msg += result + " ";
                 }
             }
         }
         if (!string.IsNullOrEmpty(outputArgs.Msg))
         {
             outputArgs.Msg = outputArgs.Msg.Trim();
         }
     }
     catch (Exception ex)
     {
         outputArgs.Msg = ex.Message;
     }
     return(outputArgs);
 }
Пример #4
0
 /// <summary>
 /// 使用说明: https://github.com/hegelsu/SuWar3Tools
 /// </summary>
 /// <param name="launchArgs">程序启动参数</param>
 /// <param name="inputArgs">由SuWar3Tools生成的Json文本参数</param>
 /// <param name="outputArgs">输出的参数,将由SuWar3Tools进行处理</param>
 /// <returns></returns>
 public static async Task <ExtOutputArgs> ProcessLogic(string[] launchArgs, ExtInputArgs inputArgs, ExtOutputArgs outputArgs)
 {
     try
     {
         outputArgs.Msg = string.Format("[{0}]我接收到了从SuWar3Tools传来的魔兽版本号:{1}", DateTime.Now.ToString("yyyyMMdd HH:mm:ss"), inputArgs.Version);
     }
     catch (Exception ex)
     {
         outputArgs.Msg = ex.Message;
     }
     return(outputArgs);
 }