コード例 #1
0
  private void waitForAutorization() {
    try {
      is = sock.getInputStream();
      os = sock.getOutputStream();

      Queue<JSONObject> receiveData = new LinkedList<JSONObject>();
      InputStream is = sock.getInputStream();

      NetParser parser = new NetParser(is, receiveData);
      while (receiveData.isEmpty()) {
        parser.goParse();
      }
      JSONObject data = receiveData.remove();
      String action = (String) data.get("action");
      if (!action.isEmpty()) {
        if (action.equals("login")) {
          JSONObject tmp = (JSONObject) data.get("content");
          String email = (String) tmp.get("email");
          String password = (String) tmp.get("md5_password");
          isLogged = true;
          LogException.saveToLog("client loginned as " + email, "main server");
        }
      } else {
        // TODO: add error json processing
        throw new ParseException("Incorrect message", 0);
      }

    } catch (IOException e) {
      LogException.saveToLog(e.getMessage(), e.getStackTrace().toString());
    } catch (ParseException e) {
      LogException.saveToLog(e.getMessage(), e.getStackTrace().toString());
    }
  }