From b4f4fa5fb264710da47ea54e80728d2ca094ddc1 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 22 Aug 2016 15:19:10 +0200 Subject: [PATCH] Trying to fix msg ids --- README.md | 1 + src/danog/MadelineProto/API.php | 1 + src/danog/MadelineProto/Session.php | 17 ++++++++++------- src/danog/MadelineProto/TL/TL.php | 5 +++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4f029aba4..be6fe61d8 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Here all of the things that still have to be done in this library. You can (and you are also encouraged to) contribute by completing any of the following points. The importance of each item will range from 1 to 5. It's better to start from the most important items. +* In Session.php fix the management of sequence numbers (5). * In Session.php and TL, manage rpc errors, notifications, error codes and basically everything that isn't a normal response (4). * In Connection.php and Session.php, add support for http, https and (maybe) udp connections (3). * In API.php, complete a decent authorization flow that supports both bots and normal users (2). diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 35e83f608..652dfab17 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -21,6 +21,7 @@ class API set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']); $this->session = new Session($params); $future_salts = $this->get_future_salts(3); + $this->session->log->log($future_salts); $future_salts = $this->get_future_salts(3); $this->session->log->log($future_salts); } diff --git a/src/danog/MadelineProto/Session.php b/src/danog/MadelineProto/Session.php index 30574e7f0..e230e0b0d 100644 --- a/src/danog/MadelineProto/Session.php +++ b/src/danog/MadelineProto/Session.php @@ -141,14 +141,13 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB $in = $content_related ? 1 : 0; $value = $this->seq_no; $this->seq_no += $in; - var_dump(($value * 2) + $in); - - return ($value * 2) + $in; +var_dump((($value*2)+ $in)); + return (($value*2) + $in); } public function anknowledge($msg_id) { - return $this->method_call('msgs_ack', [$msg_id]); + return $this->send_message($this->tl->serialize_obj("msgs_ack", ["msg_ids" => [$msg_id]])); } /** @@ -159,10 +158,11 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB { $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('settings['authorization']['temp_auth_key']['server_salt'].$this->settings['authorization']['session_id'].$message_id.$this->struct->pack('generate_seq_no(), strlen($message_data)).$message_data; + $encrypted_data = $this->settings['authorization']['temp_auth_key']['server_salt'].$this->settings['authorization']['session_id'].$message_id.$this->struct->pack('aes_calculate($message_key); @@ -229,7 +229,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB if ($message_key != substr(sha1(substr($decrypted_data, 0, 32 + $message_data_length), true), -16)) { throw new Exception('msg_key mismatch'); } - var_dump($this->anknowledge($message_id)); + $this->anknowledge($message_id); } else { throw new Exception('Got unknown auth_key id'); } @@ -241,6 +241,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)); $server_answer = $this->recv_message(); } catch (Exception $e) { @@ -261,6 +262,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB public function create_auth_key($expires_in = -1) { + foreach (Tools::range(0, $this->settings['max_tries']['authorization']) as $retry_id_total) { // Make pq request $nonce = \phpseclib\Crypt\Random::string(16); $this->log->log('Handshake: Requesting pq'); @@ -474,11 +476,12 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB throw new Exception('Handshake: wrong new_nonce_hash_3'); } $this->log->log('Auth Failed'); - throw new Exception('Auth Failed'); + break; } else { throw new Exception('Response Error'); } } + } throw new Exception('Auth Failed'); } diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index 987763907..d5fa980d6 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -17,9 +17,10 @@ class TL public function __construct($filename) { if (is_array($filename)) { - $TL_dict = []; + $TL_dict = ["constructors" => [], "methods" => []]; foreach ($filename as $file) { - $TL_dict = array_merge(json_decode(file_get_contents($file), true), $TL_dict); + $TL_dict["constructors"] = array_merge(json_decode(file_get_contents($file), true)["constructors"], $TL_dict["constructors"]); + $TL_dict["methods"] = array_merge(json_decode(file_get_contents($file), true)["methods"], $TL_dict["methods"]); } } else { $TL_dict = json_decode(file_get_contents($file), true);