Fixed bugs

This commit is contained in:
Daniil Gentili 2016-11-30 21:46:46 +00:00
parent 80ae7e9478
commit 1611c0f8ec
7 changed files with 24 additions and 15 deletions

Binary file not shown.

View File

@ -22,7 +22,7 @@ class AuthKeyHandler extends AckHandler
{
public function create_auth_key($expires_in = -1)
{
foreach ($this->range(0, $this->settings['max_tries']['authorization']) as $retry_id_total) {
for ($retry_id_total = 1; $retry_id_total <= $this->settings['max_tries']['authorization']; $retry_id_total++) {
try {
\danog\MadelineProto\Logger::log('Requesting pq');
@ -469,9 +469,9 @@ class AuthKeyHandler extends AckHandler
}
}
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log('An exception occurred while generating the authorization key: '.$e->getMessage().' Retrying...');
\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...');
\danog\MadelineProto\Logger::log('An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...');
}
}
@ -505,7 +505,7 @@ class AuthKeyHandler extends AckHandler
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)) {
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) {
\danog\MadelineProto\Logger::log('Successfully binded temporary and permanent authorization keys.');
return true;

View File

@ -57,12 +57,11 @@ class CallHandler extends AuthKeyHandler
switch ($server_answer['error_message']) {
case 'AUTH_KEY_UNREGISTERED':
case 'AUTH_KEY_INVALID':
unset($this->datacenter->temp_auth_key);
unset($this->datacenter->auth_key);
$this->init_authorization();
case 'USER_DEACTIVATED':
case 'SESSION_REVOKED':
case 'SESSION_EXPIRED':
unset($this->datacenter->temp_auth_key);
unset($this->datacenter->auth_key);
$this->datacenter->authorized = false;
$this->datacenter->authorization = null;
throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']);
@ -88,6 +87,10 @@ class CallHandler extends AuthKeyHandler
}
throw new \danog\MadelineProto\RPCErrorException('Received bad_msg_notification: '.$this->bad_msg_error_codes[$server_answer['error_code']], $server_answer['error_code']);
break;
case 'boolTrue':
case 'boolFalse':
$server_answer = $server_answer['_'] === 'boolTrue';
break;
}
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log('An error occurred while calling method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Recreating connection and retrying to call method...');

View File

@ -56,6 +56,13 @@ class MessageHandler extends Crypt
$payload = $this->datacenter->read_message();
if (fstat($payload)['size'] == 4) {
$error = \danog\PHP\Struct::unpack('<i', fread($payload, 4))[0];
if ($error == -404) {
unset($this->datacenter->temp_auth_key);
unset($this->datacenter->auth_key);
$this->datacenter->authorized = false;
$this->datacenter->authorization = null;
throw new \danog\MadelineProto\RPCErrorException('Please login again', $error);
}
throw new \danog\MadelineProto\RPCErrorException($error, $error);
}
$auth_key_id = fread($payload, 8);

View File

@ -21,7 +21,6 @@ class ResponseHandler extends MsgIdHandler
{
foreach ($this->datacenter->new_incoming as $current_msg_id) {
$response = $this->datacenter->incoming_messages[$current_msg_id]['content'];
switch ($response['_']) {
case 'msgs_ack':
foreach ($response['msg_ids'] as $msg_id) {
@ -101,10 +100,11 @@ class ResponseHandler extends MsgIdHandler
$this->ack_outgoing_message_id($response['req_msg_id']); // Acknowledge that the server received the original query (the same one, the response to which we wish to forget)
default:
$this->ack_incoming_message_id($current_msg_id); // Acknowledge that I received the server's response
foreach ($this->datacenter->new_outgoing as $expecting) {
if ($this->tl->constructors->find_by_predicate($response['_'])['type'] == $expecting['type']) {
$response_type = $this->tl->constructors->find_by_predicate($response['_'])['type'];
foreach ($this->datacenter->new_outgoing as $key => $expecting) {
if ($response_type == $expecting['type']) {
$this->datacenter->outgoing_messages[$expecting['msg_id']]['response'] = $current_msg_id;
unset($this->datacenter->new_outgoing[$expecting['msg_id']]);
unset($this->datacenter->new_outgoing[$key]);
unset($this->datacenter->new_incoming[$current_msg_id]);
return;

View File

@ -79,7 +79,7 @@ class PrimeModule extends Tools
public function PrimeFactors($pq)
{
$pqstr = (string) $pq;
/*
\danog\MadelineProto\Logger::log('Trying to use the python factorization module');
if (function_exists('shell_exec')) {
try {
@ -119,7 +119,7 @@ class PrimeModule extends Tools
if (count($res) == 2) {
return $res;
}
*/
\danog\MadelineProto\Logger::log('Trying to use the native factorization module');
$res = $this->find_small_multiplier_lopatin((int) $pqstr);
$res = [$res, $pqstr / $res];

View File

@ -39,7 +39,7 @@ if (file_exists('number.php') && !file_exists('session.madeline')) {
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
$MadelineProto = unserialize(file_get_contents('session.madeline'));
$message = 'Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION');
$message = (getenv('TRAVIS_COMMIT') == '') ? 'https://storage.pwrtelegram.xyz/pwrtelegrambot/document/file_6570.mp4' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION'));
$peers = [];
foreach (['pwrtelegramgroup', 'pwrtelegramgroupita'] as $user) {
$username = $MadelineProto->contacts->resolveUsername(['username' => $user]);
@ -53,7 +53,6 @@ foreach ($peers as $peer) {
}
echo 'Size of MadelineProto instance is '.strlen(serialize($MadelineProto)).' bytes'.PHP_EOL;
if (file_exists('token.php')) {
include_once 'token.php';
$MadelineProto = new \danog\MadelineProto\API();