Ejemplo n.º 1
0
  public void onAuthorized() {
    dcState.set("auth_key", auth_key);
    dcState.set("server_salt", server_salt);

    long upd_delta = (long) Common.getUnixTime() - (long) dc_date;
    if (Main.mtp == this && upd_delta > 5 * 60) api_help_getConfig();

    if (!bind && this != Main.mtp) {
      final MTProto m = this;
      Common.logError("exportAuthorization");
      Main.mtp.api(
          new TL.OnResultRPC() {
            @Override
            public void onResultRPC(TL.Object result, Object param, boolean error) {
              if (!error) return;
              if (result.id != 0xdf969c2d) return; // auth.ExportedAuthorization
              Common.logError("importAuthorization");
              m.api(
                  null,
                  null,
                  "auth.importAuthorization",
                  result.getInt("id"),
                  result.getBytes("bytes"));
            }
          },
          null,
          "auth.exportAuthorization",
          dcState.getInt("id"));
      return;
    }

    if (bind) cb.onBind();
    send_queue();
  }
Ejemplo n.º 2
0
 private void TL_auth_Authorization(TL.Object obj) {
   //	int expires = obj.getInt("expires");
   bind = true;
   dcState.set("bind", bind);
   cb.onAuth(obj.getObject("user"));
   cb.onBind();
 }
Ejemplo n.º 3
0
  private void TL_BadMsgNotification(TL.Object obj) {
    int error_code = obj.getInt("error_code");

    Message msg = TLMessage.get(obj.getLong("bad_msg_id"));
    Common.logError("bad_msg: " + error_code + " " + msg.obj.name + ":" + msg.obj.type);

    if (error_code == 16 || error_code == 17) {
      time_delta = (int) ((cur_message_id >> 32) - Common.getUnixTime());
      last_message_id = 0;
    }

    if (error_code == 32 || error_code == 33) {
      Common.logError("cur seq: " + cur_msg_seq);
      Common.logError("old seq: " + seqno);
      if (!bad_seq) {
        session = GEN_session_id();
        seqno = 0;
        send_ping();
        bad_seq = true;
      }

      // seqno = cur_msg_seq + (cur_msg_seq % 2) + 100;
      //	session = GEN_session_id();
      //	seqno = 0;
    }

    if (obj.id == 0xedab447b) { // bad_server_salt
      server_salt = obj.getLong("new_server_salt");
      dcState.set("server_salt", server_salt);
    }

    retry(obj.getLong("bad_msg_id"));
  }
Ejemplo n.º 4
0
 public void updateDcStates() {
   dcState.set("auth_key", auth_key);
   dcState.set("bind", bind);
   dcState.set("server_salt", server_salt);
   if (reuseFlag == REUSE_MAIN) {
     dcState.set("session", session);
     dcState.set("seqno", seqno);
   }
   for (int i = 0; i < dcStates.size(); i++) {
     TL.Object state = dcStates.get(i);
     if (state.getInt("id") == dc_this) {
       state.set("auth_key", auth_key);
       state.set("bind", bind);
       state.set("server_salt", server_salt);
       if (reuseFlag == REUSE_MAIN) {
         state.set("session", session);
         state.set("seqno", seqno);
       }
     }
   }
 }
Ejemplo n.º 5
0
  public void setAuthKey(byte[] value) {
    if (value == null || value.length == 0) {
      auth_key = new byte[0];
      auth_key_aux_hash = auth_key_id = 0;
      return;
    }
    auth_key = value;
    dcState.set("auth_key", auth_key);

    byte[] auth_hash = Common.getSHA1(auth_key);
    auth_key_aux_hash = Common.toLong(Common.ASUB(auth_hash, 0, 8));
    auth_key_id = Common.toLong(Common.ASUB(auth_hash, 12, 8));
  }
Ejemplo n.º 6
0
  private void TL_Config(TL.Object obj) {
    dc_date = obj.getInt("date");
    MTProto.dc_this = obj.getInt("this_dc");
    dcState.set("id", dc_this);
    updateDcStates();

    TL.Vector dc_options = obj.getVector("dc_options");

    ArrayList<TL.Object> new_dcStates = new ArrayList<TL.Object>();

    for (int i = 0; i < dc_options.count; i++) {
      TL.Object dcObj = dc_options.getObject(i);
      int id = dcObj.getInt("id");

      TL.Object state =
          TL.newObject(
              "joim.dcState",
              id,
              dcObj.getString("ip_address"),
              dcObj.getInt("port"),
              new byte[0],
              false,
              GEN_session_id(),
              0L,
              0);

      for (int j = 0; j < MTProto.dcStates.size(); j++) {
        TL.Object item = MTProto.dcStates.get(j);
        if (id == item.getInt("id") && state.getString("ip").equals(item.getString("ip"))) {
          state.set("auth_key", item.getBytes("auth_key"));
          state.set("bind", item.getBool("bind"));
          state.set("session", item.getLong("session"));
          state.set("server_salt", item.getLong("server_salt"));
          state.set("seqno", item.getInt("seqno"));
          if (state.getInt("port") == item.getInt("port")) dcState = state;
          break;
        }
      }

      new_dcStates.add(state);
    }

    dcStates = new_dcStates;
    send_queue();
    cb.onReady();
  }