From 6fdb63bac266e4cc8ea202a314cbc01e27dcc8ed Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 31 Jul 2017 14:42:24 +0000 Subject: [PATCH] Fixed visualization --- .../MadelineProto/VoIP/AuthKeyHandler.php | 23 +++++++++++++++---- tests/testing.php | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/danog/MadelineProto/VoIP/AuthKeyHandler.php b/src/danog/MadelineProto/VoIP/AuthKeyHandler.php index 44e6d1f33..f990a520f 100644 --- a/src/danog/MadelineProto/VoIP/AuthKeyHandler.php +++ b/src/danog/MadelineProto/VoIP/AuthKeyHandler.php @@ -66,6 +66,11 @@ trait AuthKeyHandler $controller->discard(); } }); + if ($this->call_status($call['id']) !== \danog\MadelineProto\VoIP::CALL_STATE_ACCEPTED) { + \danog\MadelineProto\Logger::log(['Could not find and accept call '.$call['id']]); + + return false; + } \danog\MadelineProto\Logger::log(['Accepting call from '.$this->calls[$call['id']]->getOtherID().'...'], \danog\MadelineProto\Logger::VERBOSE); $dh_config = $this->get_dh_config(); @@ -77,14 +82,21 @@ trait AuthKeyHandler $res = $this->method_call('phone.acceptCall', ['peer' => $call, 'g_b' => $g_b->toBytes(), 'protocol' => ['_' => 'phoneCallProtocol', 'udp_reflector' => true, 'udp_p2p' => true, 'min_layer' => 65, 'max_layer' => 65]], ['datacenter' => $this->datacenter->curdc]); } catch (\danog\MadelineProto\RPCErrorException $e) { if ($e->rpc === 'CALL_ALREADY_ACCEPTED') { + \danog\MadelineProto\Logger::log(['Call '.$call['id'].' already accepted']); return true; } + if ($e->rpc === 'CALL_ALREADY_DECLINED') { + \danog\MadelineProto\Logger::log(['Call '.$call['id'].' already declined']); + $this->calls[$res['phone_call']['id']]->discard(); + return false; + } throw $e; } $this->calls[$res['phone_call']['id']]->storage['b'] = $b; $this->handle_pending_updates(); $this->get_updates_difference(); + return true; } public function confirm_call($params) @@ -113,8 +125,9 @@ trait AuthKeyHandler $visualization = []; $length = new \phpseclib\Math\BigInteger(count($this->emojis)); - foreach (str_split(hash('sha256', $key.$this->calls[$params['id']]->storage['g_a'], true), 8) as $number) { - $visualization[] = $this->emojis[(int) ((new \phpseclib\Math\BigInteger($number, -256))->divide($length)[1]->toString())]; + foreach (str_split(hash('sha256', $key.str_pad($this->calls[$params['id']]->storage['g_a'], 256, chr(0), \STR_PAD_LEFT), true), 8) as $number) { + $number[0] = chr(ord($number[0]) & 0x7F); + $visualization[] = $this->emojis[(int) ((new \phpseclib\Math\BigInteger($number, 256))->divide($length)[1]->toString())]; } $this->calls[$params['id']]->setVisualization($visualization); @@ -172,8 +185,10 @@ trait AuthKeyHandler } $visualization = []; $length = new \phpseclib\Math\BigInteger(count($this->emojis)); - foreach (str_split(hash('sha256', $key.str_pad($params['g_a_or_b'], 256, chr(0), \STR_PAD_LEFT), true), 8) as $number) { - $visualization[] = $this->emojis[(int) ((new \phpseclib\Math\BigInteger($number, -256))->divide($length)[1]->toString())]; + + foreach (str_split(hash('sha256', $key.str_pad($params['g_a_or_b']->toBytes(), 256, chr(0), \STR_PAD_LEFT), true), 8) as $number) { + $number[0] = chr(ord($number[0]) & 0x7F); + $visualization[] = $this->emojis[(int) ((new \phpseclib\Math\BigInteger($number, 256))->divide($length)[1]->toString())]; } $this->calls[$params['id']]->setVisualization($visualization); diff --git a/tests/testing.php b/tests/testing.php index e36d76ddf..54a78d5ff 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -90,7 +90,8 @@ if (stripos(readline('Do you want to make a call? (y/n): '), 'y') !== false) { while ($controller->getCallState() < \danog\MadelineProto\VoIP::CALL_STATE_READY) { $MadelineProto->get_updates(); } - var_dump($controller->getVisualization()); + $MadelineProto->messages->sendMessage(['peer' => $controller->getOtherID(), 'message' => 'Emojis: '.implode('', $controller->getVisualization())]); + var_dump($controller->configuration); while ($controller->getCallState() < \danog\MadelineProto\VoIP::CALL_STATE_ENDED) { $MadelineProto->get_updates(); }