1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 02:34:39 +01:00

Do not delete secret chat/call creation updates

This commit is contained in:
Daniil Gentili 2017-07-06 18:36:02 +02:00
parent d1bed9e6a0
commit 890e4d65cc
5 changed files with 40 additions and 26 deletions

View File

@ -39,6 +39,8 @@ class Logger
self::$has_thread = class_exists('\Thread') && method_exists('\Thread', 'getCurrentThread'); self::$has_thread = class_exists('\Thread') && method_exists('\Thread', 'getCurrentThread');
self::$BIG_ENDIAN = (pack('L', 1) === pack('N', 1)); self::$BIG_ENDIAN = (pack('L', 1) === pack('N', 1));
self::$bigint = PHP_INT_SIZE < 8; self::$bigint = PHP_INT_SIZE < 8;
if (class_exists('\danog\MadelineProto\VoIP')) \Threaded::extend('\danog\MadelineProto\VoIP');
} }
/* /*

View File

@ -65,12 +65,12 @@ class MTProto extends \Volatile
'messages.acceptEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats', 'messages.acceptEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats',
'messages.discardEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats', 'messages.discardEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats',
'messages.requestEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats', 'messages.requestEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats',
/*
'phone.requestCall' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling calls', 'phone.requestCall' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling calls',
'phone.acceptCall' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling calls', 'phone.acceptCall' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling calls',
'phone.confirmCall' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling calls', 'phone.confirmCall' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling calls',
'phone.discardCall' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling calls', 'phone.discardCall' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling calls',
*/
'updates.getChannelDifference' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates', 'updates.getChannelDifference' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates',
'updates.getDifference' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates', 'updates.getDifference' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates',
'updates.getState' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates', 'updates.getState' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates',

View File

@ -452,6 +452,7 @@ trait UpdateHandler
return; return;
} }
if ($update['_'] === 'updatePhoneCall') { if ($update['_'] === 'updatePhoneCall') {
\danog\MadelineProto\Logger::log([$update], \danog\MadelineProto\Logger::WARNING);
switch ($update['phone_call']['_']) { switch ($update['phone_call']['_']) {
case 'phoneCallRequested': case 'phoneCallRequested':
return $this->accept_call($update['phone_call']); return $this->accept_call($update['phone_call']);
@ -463,10 +464,7 @@ trait UpdateHandler
$this->complete_call($update['phone_call']); $this->complete_call($update['phone_call']);
break; break;
case 'phoneCallDiscarded': case 'phoneCallDiscarded':
\danog\MadelineProto\Logger::log(['Revoking call '.$update['phone_call']['id']], \danog\MadelineProto\Logger::NOTICE); $this->discard_call($update['phone_call']['id']);
if (isset($this->secret_chats[$update['phone_call']['id']])) {
unset($this->secret_chats[$update['phone_call']['id']]);
}
break; break;
} }
} }
@ -505,7 +503,9 @@ trait UpdateHandler
} }
\danog\MadelineProto\Logger::log(['Accepting secret chat '.$update['chat']['id']], \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log(['Accepting secret chat '.$update['chat']['id']], \danog\MadelineProto\Logger::NOTICE);
return $this->accept_secret_chat($update['chat']); $this->accept_secret_chat($update['chat']);
break;
case 'encryptedChatDiscarded': case 'encryptedChatDiscarded':
\danog\MadelineProto\Logger::log(['Deleting secret chat '.$update['chat']['id'].' because it was revoked by the other user'], \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log(['Deleting secret chat '.$update['chat']['id'].' because it was revoked by the other user'], \danog\MadelineProto\Logger::NOTICE);
if (isset($this->secret_chats[$update['chat']['id']])) { if (isset($this->secret_chats[$update['chat']['id']])) {
@ -514,14 +514,13 @@ trait UpdateHandler
if (isset($this->temp_requested_secret_chats[$update['chat']['id']])) { if (isset($this->temp_requested_secret_chats[$update['chat']['id']])) {
unset($this->temp_requested_secret_chats[$update['chat']['id']]); unset($this->temp_requested_secret_chats[$update['chat']['id']]);
} }
break; break;
case 'encryptedChat': case 'encryptedChat':
\danog\MadelineProto\Logger::log(['Completing creation of secret chat '.$update['chat']['id']], \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log(['Completing creation of secret chat '.$update['chat']['id']], \danog\MadelineProto\Logger::NOTICE);
$this->complete_secret_chat($update['chat']); $this->complete_secret_chat($update['chat']);
return; break;
} }
//\danog\MadelineProto\Logger::log([$update], \danog\MadelineProto\Logger::NOTICE); //\danog\MadelineProto\Logger::log([$update], \danog\MadelineProto\Logger::NOTICE);
} }

View File

@ -85,12 +85,10 @@ trait AuthKeyHandler
foreach (str_split(strrev(substr(hash('sha256', $this->calls[$params['id']]['g_a']->toBytes().$key['auth_key'], true), 20)), 8) as $number) { foreach (str_split(strrev(substr(hash('sha256', $this->calls[$params['id']]['g_a']->toBytes().$key['auth_key'], true), 20)), 8) as $number) {
$key['visualization'] .= self::EMOJIS[(int) ((new \phpseclib\Math\BigInteger($number, -256))->divide($length)[1]->toString())]; $key['visualization'] .= self::EMOJIS[(int) ((new \phpseclib\Math\BigInteger($number, -256))->divide($length)[1]->toString())];
} }
var_dump($this->calls[$params['id']]['class']); $this->calls[$params['id']] = ['status' => self::READY, 'key' => $key, 'admin' => true, 'user_id' => $params['participant_id'], 'InputPhoneCall' => ['id' => $params['id'], 'access_hash' => $params['access_hash'], '_' => 'inputPhoneCall'], 'in_seq_no_x' => 0, 'out_seq_no_x' => 1, 'layer' => 65, 'updated' => time(), 'incoming' => [], 'outgoing' => [], 'created' => time(), 'protocol' => $params['protocol'], 'controller' => new $this->calls[$params['id']]['class']()];
$this->calls[$params['id']] = ['status' => self::READY, 'key' => $key, 'admin' => true, 'user_id' => $params['participant_id'], 'InputPhoneCall' => ['id' => $params['id'], 'access_hash' => $params['access_hash'], '_' => 'inputPhoneCall'], 'in_seq_no_x' => 0, 'out_seq_no_x' => 1, 'layer' => 65, 'updated' => time(), 'incoming' => [], 'outgoing' => [], 'created' => time(), 'protocol' => $params['protocol'], 'controller' => new $this->calls[$params['id']]['class']($this, $params['id'])];
$this->calls[$params['id']]['controller']->setConfig($this->config['call_receive_timeout_ms'] / 1000, $this->config['call_connect_timeout_ms'] / 1000, \danog\MadelineProto\VoIP::DATA_SAVING_NEVER, true, true, true, $this->settings['calls']['log_file_path'], $this->settings['calls']['stats_dump_file_path']); $this->calls[$params['id']]['controller']->setConfig($this->config['call_receive_timeout_ms'] / 1000, $this->config['call_connect_timeout_ms'] / 1000, \danog\MadelineProto\VoIP::DATA_SAVING_NEVER, true, true, true, $this->settings['calls']['log_file_path'], $this->settings['calls']['stats_dump_file_path']);
$this->calls[$params['id']]['controller']->setEncryptionKey($key['auth_key'], true); $this->calls[$params['id']]['controller']->setEncryptionKey($key['auth_key'], true);
$this->calls[$params['id']]['controller']->setNetworkType($this->settings['calls']['network_type']); $this->calls[$params['id']]['controller']->setNetworkType($this->settings['calls']['network_type']);
$this->calls[$params['id']]['controller']->setSharedConfig($this->method_call('phone.getCallConfig', [], ['datacenter' => $this->datacenter->curdc])); $this->calls[$params['id']]['controller']->setSharedConfig($this->method_call('phone.getCallConfig', [], ['datacenter' => $this->datacenter->curdc]));
$this->calls[$params['id']]['controller']->setRemoteEndpoints(array_merge([$res['connection']], $res['alternative_connections']), $params['protocol']['udp_p2p']); $this->calls[$params['id']]['controller']->setRemoteEndpoints(array_merge([$res['connection']], $res['alternative_connections']), $params['protocol']['udp_p2p']);
$this->calls[$params['id']]['controller']->start(); $this->calls[$params['id']]['controller']->start();
@ -162,8 +160,28 @@ trait AuthKeyHandler
return -1; return -1;
} }
public function get_call($chat) public function get_call($call)
{ {
return $this->calls[$chat]; return $this->calls[$call];
}
public function discard_call($call)
{
\danog\MadelineProto\Logger::log(['Discarding call '.$call.'...'], \danog\MadelineProto\Logger::VERBOSE);
//var_dump(debug_backtrace(0)[0]);
if (isset($this->calls[$call])) {
if (isset($this->calls[$call]['InputPhoneCall'])) {
try {
$this->method_call('calls.discardCall', ['peer' => $this->calls[$call]['InputPhoneCall']], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc !== 'CALL_ALREADY_DECLINED') {
throw $e;
}
}
}
unset($this->calls[$call]);
}
} }
} }

View File

@ -96,27 +96,22 @@ class pony extends \danog\MadelineProto\VoIP
var_dump('STOP WRITING DATA'); var_dump('STOP WRITING DATA');
} }
public function configureAudioOutput(int $sampleRate, int $bitsPerSample, int $channels)
{
var_dump("CONFIGURE AUDIO OUTPUT: sampleRate: $sampleRate, bitsPerSample: $bitsPerSample, channels: $channels");
}
public function configureAudioInput(int $sampleRate, int $bitsPerSample, int $channels)
{
var_dump("CONFIGURE AUDIO INPUT: sampleRate: $sampleRate, bitsPerSample: $bitsPerSample, channels: $channels");
}
public function getOutputLevel() public function getOutputLevel()
{ {
return 0; return 0;
} }
public function debug($state) {
var_dump("DEBUG $state"); flush();
}
} }
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL; echo 'Wrote echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL; echo 'Wrote
'.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL; '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
if (stripos(readline('Do you want to make the secret chat tests? (y/n): '), 'y') !== false) { if (stripos(readline('Do you want to make the secret chat tests? (y/n): '), 'y') !== false) {
$start = false; $start = false;
var_dump($id = $MadelineProto->request_call('@magnaluna', '\pony')); var_dump($id = $MadelineProto->request_call('@danogentili', '\pony'));
while (!$start) { while (!$start) {
$MadelineProto->get_updates(); $MadelineProto->get_updates();
} }