diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index a3be84e59..c31ade478 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -679,9 +679,10 @@ class MTProto extends \Volatile \danog\MadelineProto\Logger::log(['Copying authorization from dc '.$authorized_dc.' to dc '.$new_dc.'...'], Logger::VERBOSE); $exported_authorization = $this->method_call('auth.exportAuthorization', ['dc_id' => $new_dc], ['datacenter' => $authorized_dc]); $this->method_call('auth.logOut', [], ['datacenter' => $new_dc]); - $this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $new_dc]); + $authorization = $this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $new_dc]); } $this->updates_state['sync_loading'] = false; + return $authorization; } public function write_client_info($method, $arguments = [], $options = []) diff --git a/src/danog/MadelineProto/Wrappers/Login.php b/src/danog/MadelineProto/Wrappers/Login.php index aa9bc89b3..be15d7d21 100644 --- a/src/danog/MadelineProto/Wrappers/Login.php +++ b/src/danog/MadelineProto/Wrappers/Login.php @@ -37,7 +37,7 @@ trait Login public function bot_login($token) { - if ($this->authorized) { + if ($this->authorized === self::LOGGED_IN) { \danog\MadelineProto\Logger::log(['This instance of MadelineProto is already logged in. Logging out first...'], \danog\MadelineProto\Logger::NOTICE); $this->logout(); } @@ -64,7 +64,7 @@ trait Login public function phone_login($number, $sms_type = 5) { - if ($this->authorized) { + if ($this->authorized === self::LOGGED_IN) { \danog\MadelineProto\Logger::log(['This instance of MadelineProto is already logged in. Logging out first...'], \danog\MadelineProto\Logger::NOTICE); $this->logout(); } @@ -132,6 +132,36 @@ trait Login return $this->authorization; } + public function import_authorization($authorization) + { + if ($this->authorized === self::LOGGED_IN) { + \danog\MadelineProto\Logger::log(['This instance of MadelineProto is already logged in. Logging out first...'], \danog\MadelineProto\Logger::NOTICE); + $this->logout(); + } + \danog\MadelineProto\Logger::log(['Logging in using auth key...'], \danog\MadelineProto\Logger::NOTICE); + list($dc_id, $auth_key) = $authorization; + $this->datacenter->sockets[$dc_id]->session_id = $this->random(8); + $this->datacenter->sockets[$dc_id]->session_in_seq_no = 0; + $this->datacenter->sockets[$dc_id]->session_out_seq_no = 0; + $this->datacenter->sockets[$dc_id]->auth_key = $auth_key; + $this->datacenter->sockets[$dc_id]->temp_auth_key = null; + $this->datacenter->sockets[$dc_id]->incoming_messages = []; + $this->datacenter->sockets[$dc_id]->outgoing_messages = []; + $this->datacenter->sockets[$dc_id]->new_outgoing = []; + $this->datacenter->sockets[$dc_id]->new_incoming = []; + + $this->authorized = self::LOGGED_IN; + $this->init_authorization(); + return $this->authorization = $this->sync_authorization($dc_id); + } + + public function export_authorization() + { + if ($this->authorized !== self::LOGGED_IN) { + throw new \danog\MadelineProto\Exception("I'm not logged in!"); + } + return [$this->datacenter->curdc, $this->datacenter->sockets[$this->datacenter->curdc]->auth_key]; + } public function complete_signup($first_name, $last_name) { @@ -151,7 +181,6 @@ trait Login ], ['datacenter' => $this->datacenter->curdc] ); $this->authorized = self::LOGGED_IN; - $this->authorized = true; $this->sync_authorization($this->datacenter->curdc); \danog\MadelineProto\Logger::log(['Signed up in successfully!'], \danog\MadelineProto\Logger::NOTICE); diff --git a/tests/testing.php b/tests/testing.php index 161cf8cce..21f8d271a 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -78,9 +78,11 @@ if ($MadelineProto === false) { $message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sembre) (yo lavorar siempre) (mi labori ĉiam) (я всегда работать) (Ik werkuh altijd) (Ngimbonga ngaso sonke isikhathi ukusebenza)' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION')); -echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL; echo 'Wrote -'.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL; - +echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL; echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL; +/* +$m = new \danog\MadelineProto\API($settings); +$m->import_authorization($MadelineProto->export_authorization()); +*/ if (stripos(readline('Do you want to make a call? (y/n): '), 'y') !== false) { $controller = $MadelineProto->request_call(getenv('TEST_SECRET_CHAT'))->play('input.raw')->then('input.raw')->playOnHold(['input.raw'])->setOutputFile('output.raw'); }