mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-26 21:14:43 +01:00
Trying to fix msg ids
This commit is contained in:
parent
01e54fe5ff
commit
b4f4fa5fb2
@ -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).
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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('<Q', (int) ((time() + $this->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('<I', strlen($message_data)).$message_data;
|
||||
} else {
|
||||
$encrypted_data = $this->settings['authorization']['temp_auth_key']['server_salt'].$this->settings['authorization']['session_id'].$message_id.$this->struct->pack('<II', $this->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('<II', $seq_no, strlen($message_data)).$message_data;
|
||||
$message_key = substr(sha1($encrypted_data, true), -16);
|
||||
$padding = \phpseclib\Crypt\Random::string(Tools::posmod(-strlen($encrypted_data), 16));
|
||||
list($aes_key, $aes_iv) = $this->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');
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user