Esempio n. 1
0
  /**
   * 逻辑:<br>
   * 1.若跑日常图,进度不为100%时跑日常图<br>
   * 2.若初始里图编号大于10万,分表里图存储;否则全存到表图<br>
   * 3.获取area信息
   */
  public static boolean run() throws Exception {
    response = null;
    try {
      response = Process.network.ConnectToServer(URL_AREA, new ArrayList<NameValuePair>(), false);
    } catch (Exception ex) {
      ErrorData.currentDataType = ErrorData.DataType.text;
      ErrorData.currentErrorType = ErrorData.ErrorType.ConnectionError;
      ErrorData.text = ex.getMessage();
      throw ex;
    }

    Document doc;
    try {
      doc = Process.ParseXMLBytes(response, Name.name());
    } catch (Exception ex) {
      ErrorData.currentDataType = ErrorData.DataType.bytes;
      ErrorData.currentErrorType = ErrorData.ErrorType.AreaDataError;
      ErrorData.bytes = response;
      throw ex;
    }

    try {
      XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();
      if (!xpath.evaluate("/response/header/error/code", doc).equals("0")) {
        ErrorData.currentErrorType = ErrorData.ErrorType.AreaResponse;
        ErrorData.currentDataType = ErrorData.DataType.text;
        ErrorData.text = xpath.evaluate("/response/header/error/message", doc);
        return false;
      }

      int areaCount =
          ((NodeList) xpath.evaluate("//area_info_list/area_info", doc, XPathConstants.NODESET))
              .getLength();

      // area按编号从小到大排序
      for (int i = areaCount; i > 0; i--) {
        Area a = new Area();
        String p = String.format("//area_info_list/area_info[%d]/", i);
        a.areaId = Integer.parseInt(xpath.evaluate(p + "id", doc));

        if (Process.info.area.containsKey(a.areaId) == false) {
          a.areaName = xpath.evaluate(p + "name", doc);
          a.exploreProgress = Integer.parseInt(xpath.evaluate(p + "prog_area", doc));

          // 输出地图信息
          Go.log("地圖:" + a.areaName + ",編號:" + a.areaId, LogType.INFO);

          // 跑日常图
          if (Info.DailyMap == true
              && Info.DailyMapNo.contains(Integer.valueOf(a.areaId)) == true
              && a.exploreProgress < 100) {
            Process.info.area.put(a.areaId, a);
          }

          // 跑活动图
          if (a.areaId > MAP_NO) {
            // 判断第一张里图编号是否有效
            if (Info.firstInnerMapNo > MAP_NO) {
              // 里图 or 表图
              if (a.areaId >= Info.firstInnerMapNo) {
                Process.info.areaInner.put(a.areaId, a);
              } else {
                Process.info.area.put(a.areaId, a);
              }
            } else {
              Process.info.area.put(a.areaId, a);
            }
          }
        }
      } // end for

      return areaCount > 0;
    } catch (Exception ex) {
      if (ErrorData.currentErrorType == ErrorData.ErrorType.none) {
        throw ex;
      }
    }

    return false;
  }
Esempio n. 2
0
  public static void main(String[] args) {
    if (args.length < 1) {
      printHelp();
      return;
    }
    try {
      GetConfig.parse(Process.ParseXMLBytes1(ReadFileAll(args[0])));
    } catch (Exception e) {
      Go.log("[User] Configure paraments reading error, please check your xml file.");
      return;
    }
    if (args.length < 3) {
      System.out.println(Version.strVersion());
      System.out.println(Version.strThanks());
      Go.log(String.format("Read cards that can be sold (%d).", Info.CanBeSold.size()));
    }
    if (args.length == 1) {
      // auto mode
      while (true) {
        Process proc = new Process();
        Profile2 prof = new Profile2();
        while (true) {
          try {
            switch (Info.Profile) {
              case 1:
                proc.auto();
                break;
              case 2:
                prof.auto();
                break;
            }
          } catch (Exception ex) {
            boolean printed = false;
            if (ErrorData.text != null) {
              Go.log("[User] " + ErrorData.text);
              ErrorData.clear();
              printed = true;
            }
            if (ErrorData.bytes != null && printed == false) {
              Go.log("[User] " + new String(ErrorData.bytes));
              ErrorData.clear();
              printed = true;
            }
            if (ex.getMessage() != null && printed == false) {
              Go.log("[System] " + ex.getMessage());
              printed = true;
            }
            if (printed == false) {
              Go.log("[System] Unexpected Error:");
              ex.printStackTrace();
            }
            Process.info.events.add(EventType.cookieOutOfDate);
            Go.log("[Global] Restart");
          }
        }
      }

    } else if (args.length == 2) {
      if (args[1].equals("-m")) {
        // manual operation
        System.out.println("come soon");
      } else {
        printHelp();
      }
    } else if (args.length == 3) {
      try {
        if (args[1].startsWith("-f")) {
          if (args[1].charAt(2) == '1') {
            System.out.println(new String(Crypto.DecryptNoKey(ReadFileAll(args[2]))));
          } else if (args[1].charAt(2) == '2') {
            System.out.println(new String(Crypto.DecryptWithKey(ReadFileAll(args[2]))));
          }
        } else if (args[1].equals("-t")) {
          // 用作测试使用
          try {
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        } else if (args[1].startsWith("-d")) {
          if (args[1].charAt(2) == '1') {
            System.out.println(new String(Crypto.DecryptBase64NoKey2Str(args[2])));
          } else if (args[1].charAt(2) == '2') {
            System.out.println(new String(Crypto.DecryptBase64WithKey2Str(args[2])));
          }
        }
      } catch (Exception ex) {
        ex.printStackTrace();
        printHelp();
      }
    } else {
      printHelp();
    }
  }