From a9ba7a659e3067777f2b4adfe2ba802f3e91c7c5 Mon Sep 17 00:00:00 2001 From: danogentili Date: Mon, 22 Aug 2016 19:22:06 +0200 Subject: [PATCH] Trying to fix seqno --- src/danog/MadelineProto/Session.php | 38 +++++++++++++++++++++++------ src/danog/MadelineProto/TL/TL.php | 34 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/danog/MadelineProto/Session.php b/src/danog/MadelineProto/Session.php index 62d0bfae..c3d2107c 100644 --- a/src/danog/MadelineProto/Session.php +++ b/src/danog/MadelineProto/Session.php @@ -146,23 +146,23 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB return ($value * 2) + $in; } - public function anknowledge($msg_id) + public function acknowledge($msg_id) { - return $this->send_message($this->tl->serialize_obj('msgs_ack', ['msg_ids' => [$msg_id]])); + return $this->object_call('msgs_ack', ['msg_ids' => [$msg_id]]); } /** * Forming the message frame and sending message to server * :param message: byte string to send. */ - public function send_message($message_data) + public function send_message($message_data, $content_related) { $message_id = $this->struct->pack('timedelta) * pow(2, 30)) * 4); $this->check_message_id($message_id, true); - $seq_no = $this->generate_seq_no(true); if (($this->settings['authorization']['temp_auth_key']['auth_key'] == null) || ($this->settings['authorization']['temp_auth_key']['server_salt'] == null)) { $message = Tools::string2bin('\x00\x00\x00\x00\x00\x00\x00\x00').$message_id.$this->struct->pack('generate_seq_no($content_related); $encrypted_data = $this->settings['authorization']['temp_auth_key']['server_salt'].$this->settings['authorization']['session_id'].$message_id.$this->struct->pack('anknowledge($message_id); + //$this->acknowledge($message_id); } else { throw new Exception('Got unknown auth_key id'); } @@ -242,8 +242,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB { foreach (range(1, $this->settings['max_tries']['query']) as $i) { try { - var_dump($method); - $this->send_message($this->tl->serialize_method($method, $kwargs)); + $this->send_message($this->tl->serialize_method($method, $kwargs), $this->tl->content_related($method)); $server_answer = $this->recv_message(); } catch (Exception $e) { $this->log->log('An error occurred while calling method '.$method.': '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine().'. Recreating connection and retrying to call method...'); @@ -255,12 +254,35 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB throw new Exception('An error occurred while calling method '.$method.'.'); } $deserialized = $this->tl->deserialize(Tools::fopen_and_write('php://memory', 'rw+b', $server_answer)); - + switch ($deserialized["_"]) { + + } return $deserialized; } throw new Exception('An error occurred while calling method '.$method.'.'); } + public function object_call($object, $kwargs) + { + foreach (range(1, $this->settings['max_tries']['query']) as $i) { + try { + $this->send_message($this->tl->serialize_obj($object, $kwargs), $this->tl->content_related($object)); + $server_answer = $this->recv_message(); + } catch (Exception $e) { + $this->log->log('An error occurred while calling object '.$object.': '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine().'. Recreating connection and retrying to call object...'); + unset($this->sock); + $this->sock = new Connection($this->settings['connection']['ip_address'], $this->settings['connection']['port'], $this->settings['connection']['protocol']); + continue; + } + if ($server_answer == null) { + throw new Exception('An error occurred while calling object '.$object.'.'); + } + $deserialized = $this->tl->deserialize(Tools::fopen_and_write('php://memory', 'rw+b', $server_answer)); + return $deserialized; + } + throw new Exception('An error occurred while calling object '.$object.'.'); + } + public function create_auth_key($expires_in = -1) { foreach (Tools::range(0, $this->settings['max_tries']['authorization']) as $retry_id_total) { diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index 8f9ff5a3..1aff6fd5 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -227,4 +227,38 @@ class TL return $x; } + public function content_related($method) { + return !in_array($method, [ + "rpc_result", + "rpc_error", + "rpc_drop_answer", + "rpc_answer_unknown", + "rpc_answer_dropped_running", + "rpc_answer_dropped", + "get_future_salts", + "future_salt", + "future_salts", + "ping", + "pong", + "ping_delay_disconnect", + "destroy_session", + "destroy_session_ok", + "destroy_session_none", + "new_session_created", + "msg_container", + "msg_copy", + "gzip_packed", + "http_wait", + "msgs_ack", + "bad_msg_notification", + "bad_server_salt", + "msgs_state_req", + "msgs_state_info", + "msgs_all_info", + "msg_detailed_info", + "msg_new_detailed_info", + "msg_resend_req", + "msg_resend_ans_req" + ]); + } }