diff --git a/calls.php b/calls.php new file mode 100644 index 000000000..c539f4f88 --- /dev/null +++ b/calls.php @@ -0,0 +1,70 @@ +#!/usr/bin/env php +. +*/ +require_once 'vendor/autoload.php'; +if (file_exists('web_data.php')) { + require_once 'web_data.php'; +} + +echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL; +$MadelineProto = false; +try { + $MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline'); +} catch (\danog\MadelineProto\Exception $e) { +} +if (file_exists('.env')) { + echo 'Loading .env...'.PHP_EOL; + $dotenv = new Dotenv\Dotenv(getcwd()); + $dotenv->load(); +} + +echo 'Loading settings...'.PHP_EOL; +$settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: []; + +if ($MadelineProto === false) { + echo 'Loading MadelineProto...'.PHP_EOL; + $MadelineProto = new \danog\MadelineProto\API($settings); + if (getenv('TRAVIS_COMMIT') == '') { + $checkedPhone = $MadelineProto->auth->checkPhone(// auth.checkPhone becomes auth->checkPhone + [ + 'phone_number' => getenv('MTPROTO_NUMBER'), + ] + ); + \danog\MadelineProto\Logger::log([$checkedPhone], \danog\MadelineProto\Logger::NOTICE); + $sentCode = $MadelineProto->phone_login(getenv('MTPROTO_NUMBER')); + \danog\MadelineProto\Logger::log([$sentCode], \danog\MadelineProto\Logger::NOTICE); + echo 'Enter the code you received: '; + $code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1); + $authorization = $MadelineProto->complete_phone_login($code); + \danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE); + if ($authorization['_'] === 'account.noPassword') { + throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!'); + } + if ($authorization['_'] === 'account.password') { + \danog\MadelineProto\Logger::log(['2FA is enabled'], \danog\MadelineProto\Logger::NOTICE); + $authorization = $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): ')); + } + if ($authorization['_'] === 'account.needSignup') { + \danog\MadelineProto\Logger::log(['Registering new user'], \danog\MadelineProto\Logger::NOTICE); + $authorization = $MadelineProto->complete_signup($code, readline('Please enter your first name: '), readline('Please enter your last name (can be empty): ')); + } + echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL; + echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL; + } else { + $MadelineProto->bot_login(getenv('BOT_TOKEN')); + } +} +$MadelineProto->request_call('@manuel15'); +while (true) { + $MadelineProto->get_updates_difference(); + echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL; +} diff --git a/fuzz/.gitkeep b/fuzz/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php index e19eae5eb..aa63fc144 100644 --- a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php @@ -514,6 +514,9 @@ trait AuthKeyHandler private $temp_requested_secret_chats = []; private $secret_chats = []; + private $temp_requested_calls = []; + private $calls = []; + public function accept_secret_chat($params) { $dh_config = $this->get_dh_config(); @@ -549,6 +552,24 @@ trait AuthKeyHandler return $res['id']; } + public function request_call($user) + { + $user = $this->get_info($user)['InputUser']; + \danog\MadelineProto\Logger::log(['Calling '.$user['user_id'].'...'], \danog\MadelineProto\Logger::VERBOSE); + $dh_config = $this->get_dh_config(); + \danog\MadelineProto\Logger::log(['Generating a...'], \danog\MadelineProto\Logger::VERBOSE); + $a = new \phpseclib\Math\BigInteger($this->random(256), 256); + \danog\MadelineProto\Logger::log(['Generating g_a...'], \danog\MadelineProto\Logger::VERBOSE); + $g_a = $dh_config['g']->powMod($a, $dh_config['p']); + $this->check_G($g_a, $dh_config['p']); +// $res = $this->method_call('phone.requestCall', ['user_id' => $user, 'g_a' => $g_a->toBytes(), 'protocol' => ['_' => 'phoneCallProtocol', 'min_layer' => $this->settings['tl_schema']['layer'], 'max_layer' => $this->settings['tl_schema']['layer']]]); + $res = $this->method_call('phone.requestCall', ['user_id' => $user, 'g_a' => $g_a->toBytes(), 'protocol' => ['_' => 'phoneCallProtocol', 'min_layer' => 65, 'max_layer' => 65, 'udp_reflector' => true]]); + $this->temp_requested_calls[$res['phone_call']['id']] = $a; + $this->handle_pending_updates(); + $this->get_updates_difference(); + + return $res['phone_call']['id']; + } public function complete_secret_chat($params) {