Fixed handling bad_msg_notifications

This commit is contained in:
Daniil Gentili 2017-01-19 22:43:36 +01:00
parent fdca20fa41
commit acd4b86ff6
2 changed files with 24 additions and 3 deletions

View File

@ -480,6 +480,8 @@ trait AuthKeyHandler
public function bind_temp_auth_key($expires_in)
{
for ($retry_id_total = 1; $retry_id_total <= $this->settings['max_tries']['authorization']; $retry_id_total++) {
try {
\danog\MadelineProto\Logger::log('Binding authorization keys...');
$nonce = \danog\PHP\Struct::unpack('<q', \danog\MadelineProto\Tools::random(8))[0];
$expires_at = time() + $expires_in;
@ -504,12 +506,22 @@ trait AuthKeyHandler
$padding = \danog\MadelineProto\Tools::random($this->posmod(-strlen($encrypted_data), 16));
list($aes_key, $aes_iv) = $this->aes_calculate($message_key, $this->datacenter->auth_key['auth_key']);
$encrypted_message = $this->datacenter->auth_key['id'].$message_key.$this->ige_encrypt($encrypted_data.$padding, $aes_key, $aes_iv);
if ($this->method_call('auth.bindTempAuthKey', ['perm_auth_key_id' => $perm_auth_key_id, 'nonce' => $nonce, 'expires_at' => $expires_at, 'encrypted_message' => $encrypted_message], $int_message_id) === true) {
$res = $this->method_call('auth.bindTempAuthKey', ['perm_auth_key_id' => $perm_auth_key_id, 'nonce' => $nonce, 'expires_at' => $expires_at, 'encrypted_message' => $encrypted_message], $int_message_id);
var_dump($res);
if ($res === true) {
\danog\MadelineProto\Logger::log('Successfully binded temporary and permanent authorization keys.');
return true;
}
throw new \danog\MadelineProto\Exception('An error occurred while binding temporary and permanent authorization keys.');
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log('An exception occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...');
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log('An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...');
} finally {
$this->datacenter->new_outgoing = [];
$this->datacenter->new_incoming = [];
}
}
throw new \danog\MadelineProto\Exception('An error occurred while binding temporary and permanent authorization keys.');
}
}

View File

@ -102,6 +102,15 @@ trait CallHandler
case 48:
$this->datacenter->temp_auth_key['server_salt'] = $server_answer['new_server_salt'];
continue 3;
case 16:
case 17:
\danog\MadelineProto\Logger::log('Received bad_msg_notification: '.$this->bad_msg_error_codes[$server_answer['error_code']]);
$this->datacenter->timedelta = ($this->datacenter->outgoing_messages[$int_message_id]['response'] >> 32) - time();
\danog\MadelineProto\Logger::log('Set time delta to '.$this->datacenter->timedelta);
$this->reset_session();
$this->datacenter->temp_auth_key = null;
$this->init_authorization();
throw new \danog\MadelineProto\Exception('Resend message');
}
throw new \danog\MadelineProto\RPCErrorException('Received bad_msg_notification: '.$this->bad_msg_error_codes[$server_answer['error_code']], $server_answer['error_code']);
break;