Yield from even more things
This commit is contained in:
parent
000839a1b5
commit
7ea0d9da91
@ -185,7 +185,7 @@ class API extends InternalDoc
|
||||
$this->APIFactory();
|
||||
$unserialized->oldInstance = true;
|
||||
$deferred->resolve();
|
||||
yield $this->API->initAsynchronously();
|
||||
yield from $this->API->initAsynchronously();
|
||||
$this->APIFactory();
|
||||
//\danog\MadelineProto\Logger::log('Ping...', Logger::ULTRA_VERBOSE);
|
||||
$this->asyncInitPromise = null;
|
||||
@ -199,7 +199,7 @@ class API extends InternalDoc
|
||||
}
|
||||
Logger::constructorFromSettings($settings);
|
||||
if (!isset($params['app_info']['api_id']) || !$params['app_info']['api_id']) {
|
||||
$app = yield $this->APIStart($params);
|
||||
$app = (yield from $this->APIStart($params));
|
||||
$params['app_info']['api_id'] = $app['api_id'];
|
||||
$params['app_info']['api_hash'] = $app['api_hash'];
|
||||
}
|
||||
@ -207,7 +207,7 @@ class API extends InternalDoc
|
||||
$this->APIFactory();
|
||||
$deferred->resolve();
|
||||
Logger::log(\danog\MadelineProto\Lang::$current_lang['apifactory_start'], Logger::VERBOSE);
|
||||
yield $this->API->initAsynchronously();
|
||||
yield from $this->API->initAsynchronously();
|
||||
$this->APIFactory();
|
||||
$this->asyncInitPromise = null;
|
||||
//\danog\MadelineProto\Logger::log('Ping...', Logger::ULTRA_VERBOSE);
|
||||
@ -370,7 +370,7 @@ class API extends InternalDoc
|
||||
return false;
|
||||
}
|
||||
if ($this->API && $this->API->asyncInitPromise) {
|
||||
yield $this->API->initAsynchronously();
|
||||
yield from $this->API->initAsynchronously();
|
||||
}
|
||||
$this->serialized = \time();
|
||||
$realpaths = Serialization::realpaths($filename);
|
||||
|
@ -125,7 +125,7 @@ abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
public function __call_async(string $name, array $arguments): \Generator
|
||||
{
|
||||
if ($this->asyncInitPromise) {
|
||||
yield $this->initAsynchronously();
|
||||
yield from $this->initAsynchronously();
|
||||
$this->API->logger->logger('Finished init asynchronously');
|
||||
}
|
||||
if (Magic::isFork() && !Magic::$processed_fork) {
|
||||
@ -135,7 +135,7 @@ abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
throw new Exception('API did not init!');
|
||||
}
|
||||
if ($this->API->asyncInitPromise) {
|
||||
yield $this->API->initAsynchronously();
|
||||
yield from $this->API->initAsynchronously();
|
||||
$this->API->logger->logger('Finished init asynchronously');
|
||||
}
|
||||
if (isset($this->session) && !\is_null($this->session) && \time() - $this->serialized > $this->API->settings['serialization']['serialization_interval']) {
|
||||
@ -145,10 +145,10 @@ abstract class AbstractAPIFactory extends AsyncConstruct
|
||||
if ($this->API->flushSettings) {
|
||||
$this->API->flushSettings = false;
|
||||
$this->API->__construct($this->API->settings);
|
||||
yield $this->API->initAsynchronously();
|
||||
yield from $this->API->initAsynchronously();
|
||||
}
|
||||
if ($this->API->asyncInitPromise) {
|
||||
yield $this->API->initAsynchronously();
|
||||
yield from $this->API->initAsynchronously();
|
||||
$this->API->logger->logger('Finished init asynchronously');
|
||||
}
|
||||
$lower_name = \strtolower($name);
|
||||
|
@ -329,7 +329,7 @@ class Connection extends Session
|
||||
$this->datacenterId = $this->datacenter . '.' . $this->id;
|
||||
$this->API->logger->logger("Connecting to DC {$this->datacenterId}", \danog\MadelineProto\Logger::WARNING);
|
||||
$ctx->setReadCallback([$this, 'haveRead']);
|
||||
$this->stream = yield $ctx->getStream();
|
||||
$this->stream = (yield from $ctx->getStream());
|
||||
if ($this->needsReconnect) {
|
||||
$this->needsReconnect = false;
|
||||
}
|
||||
@ -407,17 +407,17 @@ class Connection extends Session
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
if (!isset($message['serialized_body'])) {
|
||||
$body = \is_object($message['body']) ? yield $message['body'] : $message['body'];
|
||||
$body = \is_object($message['body']) ? yield from $message['body'] : $message['body'];
|
||||
$refreshNext = isset($message['refreshNext']) && $message['refreshNext'];
|
||||
//$refreshNext = true;
|
||||
if ($refreshNext) {
|
||||
$this->API->referenceDatabase->refreshNext(true);
|
||||
}
|
||||
if ($message['method']) {
|
||||
$body = yield $this->API->getTL()->serializeMethod($message['_'], $body);
|
||||
$body = (yield from $this->API->getTL()->serializeMethod($message['_'], $body));
|
||||
} else {
|
||||
$body['_'] = $message['_'];
|
||||
$body = yield $this->API->getTL()->serializeObject(['type' => ''], $body, $message['_']);
|
||||
$body = (yield from $this->API->getTL()->serializeObject(['type' => ''], $body, $message['_']));
|
||||
}
|
||||
if ($refreshNext) {
|
||||
$this->API->referenceDatabase->refreshNext(false);
|
||||
@ -527,7 +527,7 @@ class Connection extends Session
|
||||
{
|
||||
$this->API->logger->logger("Reconnecting DC {$this->datacenterId}");
|
||||
$this->disconnect(true);
|
||||
yield $this->API->datacenter->dcConnect($this->ctx->getDc(), $this->id);
|
||||
yield from $this->API->datacenter->dcConnect($this->ctx->getDc(), $this->id);
|
||||
}
|
||||
/**
|
||||
* Get name.
|
||||
|
@ -51,7 +51,7 @@ class ContextConnector implements Connector
|
||||
try {
|
||||
$ctx->setIsDns($this->fromDns);
|
||||
$ctx->setCancellationToken($token);
|
||||
$result = yield $ctx->getStream();
|
||||
$result = (yield from $ctx->getStream());
|
||||
$this->logger->logger('OK!', \danog\MadelineProto\Logger::WARNING);
|
||||
return $result->getSocket();
|
||||
} catch (\Throwable $e) {
|
||||
|
@ -238,12 +238,12 @@ class DataCenter
|
||||
if ($old) {
|
||||
$this->API->logger->logger("Reconnecting to DC {$dc_number} ({$id}) from existing", \danog\MadelineProto\Logger::WARNING);
|
||||
$this->sockets[$dc_number]->setExtra($this->API);
|
||||
yield $this->sockets[$dc_number]->connect($ctx, $id);
|
||||
yield from $this->sockets[$dc_number]->connect($ctx, $id);
|
||||
} else {
|
||||
$this->API->logger->logger("Connecting to DC {$dc_number} from scratch", \danog\MadelineProto\Logger::WARNING);
|
||||
$this->sockets[$dc_number] = new DataCenterConnection();
|
||||
$this->sockets[$dc_number]->setExtra($this->API);
|
||||
yield $this->sockets[$dc_number]->connect($ctx);
|
||||
yield from $this->sockets[$dc_number]->connect($ctx);
|
||||
}
|
||||
$this->API->logger->logger('OK!', \danog\MadelineProto\Logger::WARNING);
|
||||
return true;
|
||||
|
@ -42,9 +42,9 @@ trait Constructors
|
||||
}
|
||||
$got[$id] = '';
|
||||
/*
|
||||
if (preg_match('/%/', $type)) {
|
||||
$type = $this->TL->getConstructors($this->td)->findByType(str_replace('%', '', $type))['predicate'];
|
||||
}*/
|
||||
if (preg_match('/%/', $type)) {
|
||||
$type = $this->TL->getConstructors($this->td)->findByType(str_replace('%', '', $type))['predicate'];
|
||||
}*/
|
||||
$layer = isset($data['layer']) && $data['layer'] !== '' ? '_' . $data['layer'] : '';
|
||||
$type = \str_replace(['<', '>'], ['_of_', ''], $data['type']);
|
||||
$php_type = \preg_replace('/.*_of_/', '', $type);
|
||||
|
@ -214,11 +214,11 @@ image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png' . $re
|
||||
|
||||
';
|
||||
/*
|
||||
if (isset(\danog\MadelineProto\MTProto::DISALLOWED_METHODS[$data['method']])) {
|
||||
$header .= '**'.\danog\MadelineProto\MTProto::DISALLOWED_METHODS[$data['method']]."**\n\n\n\n\n";
|
||||
file_put_contents('methods/'.$method.'.md', $header);
|
||||
continue;
|
||||
}*/
|
||||
if (isset(\danog\MadelineProto\MTProto::DISALLOWED_METHODS[$data['method']])) {
|
||||
$header .= '**'.\danog\MadelineProto\MTProto::DISALLOWED_METHODS[$data['method']]."**\n\n\n\n\n";
|
||||
file_put_contents('methods/'.$method.'.md', $header);
|
||||
continue;
|
||||
}*/
|
||||
if ($this->td) {
|
||||
$header .= 'YOU CANNOT USE THIS METHOD IN MADELINEPROTO
|
||||
|
||||
|
@ -143,7 +143,7 @@ class CheckLoop extends ResumableSignalLoop
|
||||
$list .= $connection->outgoing_messages[$message_id]['_'] . ', ';
|
||||
}
|
||||
$API->logger->logger("Still missing {$list} on DC {$datacenter}, sending state request", \danog\MadelineProto\Logger::ERROR);
|
||||
yield $connection->objectCall('msgs_state_req', ['msg_ids' => $message_ids], ['promise' => $deferred]);
|
||||
yield from $connection->objectCall('msgs_state_req', ['msg_ids' => $message_ids], ['promise' => $deferred]);
|
||||
}
|
||||
} else {
|
||||
foreach ($connection->new_outgoing as $message_id) {
|
||||
|
@ -77,7 +77,7 @@ class HttpWaitLoop extends ResumableSignalLoop
|
||||
}
|
||||
$API->logger->logger("DC {$datacenter}: request {$connection->countHttpSent()}, response {$connection->countHttpReceived()}");
|
||||
if ($connection->countHttpSent() === $connection->countHttpReceived() && (!empty($connection->pending_outgoing) || !empty($connection->new_outgoing) && !$connection->hasPendingCalls())) {
|
||||
yield $connection->sendMessage(['_' => 'http_wait', 'body' => ['max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], 'contentRelated' => true, 'unencrypted' => false, 'method' => false]);
|
||||
yield from $connection->sendMessage(['_' => 'http_wait', 'body' => ['max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], 'contentRelated' => true, 'unencrypted' => false, 'method' => false]);
|
||||
}
|
||||
$API->logger->logger("DC {$datacenter}: request {$connection->countHttpSent()}, response {$connection->countHttpReceived()}");
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ class ReadLoop extends SignalLoop
|
||||
Tools::callForkDefer((function () use ($API, $connection, $datacenter, $e): \Generator {
|
||||
$API->logger->logger($e);
|
||||
$API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR);
|
||||
yield $connection->reconnect();
|
||||
yield from $connection->reconnect();
|
||||
})());
|
||||
return;
|
||||
}
|
||||
@ -95,23 +95,23 @@ class ReadLoop extends SignalLoop
|
||||
foreach ($connection->new_outgoing as $message_id) {
|
||||
$connection->outgoing_messages[$message_id]['sent'] = 0;
|
||||
}
|
||||
yield $shared->reconnect();
|
||||
yield $API->initAuthorization();
|
||||
yield from $shared->reconnect();
|
||||
yield from $API->initAuthorization();
|
||||
} else {
|
||||
yield $connection->reconnect();
|
||||
yield from $connection->reconnect();
|
||||
}
|
||||
} elseif ($error === -1) {
|
||||
$API->logger->logger("WARNING: Got quick ack from DC {$datacenter}", \danog\MadelineProto\Logger::WARNING);
|
||||
yield $connection->reconnect();
|
||||
yield from $connection->reconnect();
|
||||
} elseif ($error === 0) {
|
||||
$API->logger->logger("Got NOOP from DC {$datacenter}", \danog\MadelineProto\Logger::WARNING);
|
||||
yield $connection->reconnect();
|
||||
yield from $connection->reconnect();
|
||||
} elseif ($error === -429) {
|
||||
$API->logger->logger("Got -429 from DC {$datacenter}", \danog\MadelineProto\Logger::WARNING);
|
||||
yield Tools::sleep(1);
|
||||
yield $connection->reconnect();
|
||||
yield from $connection->reconnect();
|
||||
} else {
|
||||
yield $connection->reconnect();
|
||||
yield from $connection->reconnect();
|
||||
throw new \danog\MadelineProto\RPCErrorException($error, $error);
|
||||
}
|
||||
})());
|
||||
|
@ -96,7 +96,7 @@ class WriteLoop extends ResumableSignalLoop
|
||||
Tools::callForkDefer((function () use ($API, $connection, $datacenter, $e): \Generator {
|
||||
$API->logger->logger($e);
|
||||
$API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR);
|
||||
yield $connection->reconnect();
|
||||
yield from $connection->reconnect();
|
||||
})());
|
||||
return;
|
||||
} finally {
|
||||
@ -162,7 +162,7 @@ class WriteLoop extends ResumableSignalLoop
|
||||
$temporary_keys = [];
|
||||
if (\count($to_ack = $connection->ack_queue)) {
|
||||
foreach (\array_chunk($connection->ack_queue, 8192) as $acks) {
|
||||
$connection->pending_outgoing[$connection->pending_outgoing_key] = ['_' => 'msgs_ack', 'serialized_body' => yield $this->API->getTL()->serializeObject(['type' => ''], ['_' => 'msgs_ack', 'msg_ids' => $acks], 'msgs_ack'), 'contentRelated' => false, 'unencrypted' => false, 'method' => false];
|
||||
$connection->pending_outgoing[$connection->pending_outgoing_key] = ['_' => 'msgs_ack', 'serialized_body' => yield from $this->API->getTL()->serializeObject(['type' => ''], ['_' => 'msgs_ack', 'msg_ids' => $acks], 'msgs_ack'), 'contentRelated' => false, 'unencrypted' => false, 'method' => false];
|
||||
$temporary_keys[$connection->pending_outgoing_key] = true;
|
||||
$API->logger->logger("Adding msgs_ack {$connection->pending_outgoing_key}", Logger::ULTRA_VERBOSE);
|
||||
$connection->pending_outgoing_key++;
|
||||
@ -180,7 +180,7 @@ class WriteLoop extends ResumableSignalLoop
|
||||
}
|
||||
if (!$has_http_wait) {
|
||||
$API->logger->logger("Adding http_wait {$connection->pending_outgoing_key}", Logger::ULTRA_VERBOSE);
|
||||
$connection->pending_outgoing[$connection->pending_outgoing_key] = ['_' => 'http_wait', 'serialized_body' => yield $this->API->getTL()->serializeObject(['type' => ''], ['_' => 'http_wait', 'max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], 'http_wait'), 'contentRelated' => true, 'unencrypted' => false, 'method' => true];
|
||||
$connection->pending_outgoing[$connection->pending_outgoing_key] = ['_' => 'http_wait', 'serialized_body' => yield from $this->API->getTL()->serializeObject(['type' => ''], ['_' => 'http_wait', 'max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], 'http_wait'), 'contentRelated' => true, 'unencrypted' => false, 'method' => true];
|
||||
$temporary_keys[$connection->pending_outgoing_key] = true;
|
||||
$connection->pending_outgoing_key++;
|
||||
}
|
||||
@ -216,13 +216,13 @@ class WriteLoop extends ResumableSignalLoop
|
||||
if (!$shared->getTempAuthKey()->isInited() && $message['_'] !== 'auth.bindTempAuthKey' && !$inited) {
|
||||
$inited = true;
|
||||
$API->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['write_client_info'], $message['_']), \danog\MadelineProto\Logger::NOTICE);
|
||||
$MTmessage['body'] = yield $API->getTL()->serializeMethod('invokeWithLayer', ['layer' => $API->settings['tl_schema']['layer'], 'query' => yield $API->getTL()->serializeMethod('initConnection', ['api_id' => $API->settings['app_info']['api_id'], 'api_hash' => $API->settings['app_info']['api_hash'], 'device_model' => !$connection->isCDN() ? $API->settings['app_info']['device_model'] : 'n/a', 'system_version' => !$connection->isCDN() ? $API->settings['app_info']['system_version'] : 'n/a', 'app_version' => $API->settings['app_info']['app_version'], 'system_lang_code' => $API->settings['app_info']['lang_code'], 'lang_code' => $API->settings['app_info']['lang_code'], 'lang_pack' => $API->settings['app_info']['lang_pack'], 'proxy' => $connection->getCtx()->getInputClientProxy(), 'query' => $MTmessage['body']])]);
|
||||
$MTmessage['body'] = (yield from $API->getTL()->serializeMethod('invokeWithLayer', ['layer' => $API->settings['tl_schema']['layer'], 'query' => yield from $API->getTL()->serializeMethod('initConnection', ['api_id' => $API->settings['app_info']['api_id'], 'api_hash' => $API->settings['app_info']['api_hash'], 'device_model' => !$connection->isCDN() ? $API->settings['app_info']['device_model'] : 'n/a', 'system_version' => !$connection->isCDN() ? $API->settings['app_info']['system_version'] : 'n/a', 'app_version' => $API->settings['app_info']['app_version'], 'system_lang_code' => $API->settings['app_info']['lang_code'], 'lang_code' => $API->settings['app_info']['lang_code'], 'lang_pack' => $API->settings['app_info']['lang_pack'], 'proxy' => $connection->getCtx()->getInputClientProxy(), 'query' => $MTmessage['body']])]));
|
||||
} else {
|
||||
if (isset($message['queue'])) {
|
||||
if (!isset($connection->call_queue[$message['queue']])) {
|
||||
$connection->call_queue[$message['queue']] = [];
|
||||
}
|
||||
$MTmessage['body'] = yield $API->getTL()->serializeMethod('invokeAfterMsgs', ['msg_ids' => $connection->call_queue[$message['queue']], 'query' => $MTmessage['body']]);
|
||||
$MTmessage['body'] = (yield from $API->getTL()->serializeMethod('invokeAfterMsgs', ['msg_ids' => $connection->call_queue[$message['queue']], 'query' => $MTmessage['body']]));
|
||||
$connection->call_queue[$message['queue']][$message_id] = $message_id;
|
||||
if (\count($connection->call_queue[$message['queue']]) > $API->settings['msg_array_limit']['call_queue']) {
|
||||
\reset($connection->call_queue[$message['queue']]);
|
||||
@ -266,7 +266,7 @@ class WriteLoop extends ResumableSignalLoop
|
||||
$connection->pending_outgoing[$connection->pending_outgoing_key] = ['_' => 'msg_container', 'container' => \array_values($keys), 'contentRelated' => false, 'method' => false, 'unencrypted' => false];
|
||||
//var_dumP("container ".bin2hex($message_id));
|
||||
$keys[$connection->pending_outgoing_key++] = $message_id;
|
||||
$message_data = yield $API->getTL()->serializeObject(['type' => ''], ['_' => 'msg_container', 'messages' => $messages], 'container');
|
||||
$message_data = (yield from $API->getTL()->serializeObject(['type' => ''], ['_' => 'msg_container', 'messages' => $messages], 'container'));
|
||||
$message_data_length = \strlen($message_data);
|
||||
$seq_no = $connection->generateOutSeqNo(false);
|
||||
} elseif ($count) {
|
||||
|
@ -58,7 +58,7 @@ abstract class Loop implements LoopInterface
|
||||
$this->startedLoop();
|
||||
$this->API->logger->logger("Entered {$this}", Logger::ULTRA_VERBOSE);
|
||||
try {
|
||||
yield $this->loop();
|
||||
yield from $this->loop();
|
||||
} finally {
|
||||
$this->exitedLoop();
|
||||
$this->API->logger->logger("Physically exited {$this}", Logger::ULTRA_VERBOSE);
|
||||
|
@ -56,7 +56,7 @@ class FeedLoop extends ResumableSignalLoop
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->state = $this->channelId === false ? yield $API->loadUpdateState() : $API->loadChannelState($this->channelId);
|
||||
$this->state = $this->channelId === false ? yield from $API->loadUpdateState() : $API->loadChannelState($this->channelId);
|
||||
while (true) {
|
||||
while (!$this->API->settings['updates']['handle_updates'] || !$API->hasAllAuth()) {
|
||||
if (yield $this->waitSignal($this->pause())) {
|
||||
@ -80,7 +80,7 @@ class FeedLoop extends ResumableSignalLoop
|
||||
$parsedUpdates = $this->parsedUpdates;
|
||||
$this->parsedUpdates = [];
|
||||
foreach ($parsedUpdates as $update) {
|
||||
yield $API->saveUpdate($update);
|
||||
yield from $API->saveUpdate($update);
|
||||
}
|
||||
$parsedUpdates = null;
|
||||
$this->API->signalUpdate();
|
||||
@ -186,7 +186,7 @@ class FeedLoop extends ResumableSignalLoop
|
||||
$from = false;
|
||||
$via_bot = false;
|
||||
$entities = false;
|
||||
if ($update['message']['_'] !== 'messageEmpty' && (($from = isset($update['message']['from_id']) && !yield $this->API->peerIsset($update['message']['from_id'])) || ($to = !yield $this->API->peerIsset($update['message']['to_id'])) || ($via_bot = isset($update['message']['via_bot_id']) && !yield $this->API->peerIsset($update['message']['via_bot_id'])) || ($entities = isset($update['message']['entities']) && !yield $this->API->entitiesPeerIsset($update['message']['entities'])))) {
|
||||
if ($update['message']['_'] !== 'messageEmpty' && (($from = isset($update['message']['from_id']) && !(yield from $this->API->peerIsset($update['message']['from_id']))) || ($to = !(yield from $this->API->peerIsset($update['message']['to_id']))) || ($via_bot = isset($update['message']['via_bot_id']) && !(yield from $this->API->peerIsset($update['message']['via_bot_id']))) || ($entities = isset($update['message']['entities']) && !(yield from $this->API->entitiesPeerIsset($update['message']['entities']))))) {
|
||||
$log = '';
|
||||
if ($from) {
|
||||
$log .= "from_id {$update['message']['from_id']}, ";
|
||||
@ -208,7 +208,7 @@ class FeedLoop extends ResumableSignalLoop
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ($channelId && !yield $this->API->peerIsset($this->API->toSupergroup($channelId))) {
|
||||
if ($channelId && !(yield from $this->API->peerIsset($this->API->toSupergroup($channelId)))) {
|
||||
$this->API->logger->logger('Skipping update, I do not have the channel id ' . $channelId, \danog\MadelineProto\Logger::ERROR);
|
||||
return false;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class SeqLoop extends ResumableSignalLoop
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->state = yield $API->loadUpdateState();
|
||||
$this->state = (yield from $API->loadUpdateState());
|
||||
while (true) {
|
||||
while (!$this->API->settings['updates']['handle_updates'] || !$API->hasAllAuth()) {
|
||||
if (yield $this->waitSignal($this->pause())) {
|
||||
@ -114,7 +114,7 @@ class SeqLoop extends ResumableSignalLoop
|
||||
}
|
||||
public function save($updates): \Generator
|
||||
{
|
||||
$this->pendingWakeups += yield $this->feeder->feed($updates['updates']);
|
||||
$this->pendingWakeups += (yield from $this->feeder->feed($updates['updates']));
|
||||
}
|
||||
public function addPendingWakeups($wakeups)
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ class UpdateLoop extends ResumableSignalLoop
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->state = $state = $this->channelId === false ? yield $API->loadUpdateState() : $API->loadChannelState($this->channelId);
|
||||
$this->state = $state = $this->channelId === false ? yield from $API->loadUpdateState() : $API->loadChannelState($this->channelId);
|
||||
$timeout = $API->settings['updates']['getdifference_interval'];
|
||||
$first = true;
|
||||
while (true) {
|
||||
@ -109,7 +109,7 @@ class UpdateLoop extends ResumableSignalLoop
|
||||
$API->logger->logger("The PTS ({$difference['pts']}) I got with getDifference is smaller than the PTS I requested " . $state->pts() . ', using ' . ($state->pts() + 1), \danog\MadelineProto\Logger::VERBOSE);
|
||||
$difference['pts'] = $request_pts + 1;
|
||||
}
|
||||
$result += yield $feeder->feed($difference['other_updates']);
|
||||
$result += (yield from $feeder->feed($difference['other_updates']));
|
||||
$state->update($difference);
|
||||
$feeder->saveMessages($difference['new_messages']);
|
||||
if (!$difference['final']) {
|
||||
@ -147,8 +147,8 @@ class UpdateLoop extends ResumableSignalLoop
|
||||
foreach ($difference['new_encrypted_messages'] as &$encrypted) {
|
||||
$encrypted = ['_' => 'updateNewEncryptedMessage', 'message' => $encrypted];
|
||||
}
|
||||
$result += yield $feeder->feed($difference['other_updates']);
|
||||
$result += yield $feeder->feed($difference['new_encrypted_messages']);
|
||||
$result += (yield from $feeder->feed($difference['other_updates']));
|
||||
$result += (yield from $feeder->feed($difference['new_encrypted_messages']));
|
||||
$state->update($difference['state']);
|
||||
$feeder->saveMessages($difference['new_messages']);
|
||||
unset($difference);
|
||||
@ -158,8 +158,8 @@ class UpdateLoop extends ResumableSignalLoop
|
||||
foreach ($difference['new_encrypted_messages'] as &$encrypted) {
|
||||
$encrypted = ['_' => 'updateNewEncryptedMessage', 'message' => $encrypted];
|
||||
}
|
||||
$result += yield $feeder->feed($difference['other_updates']);
|
||||
$result += yield $feeder->feed($difference['new_encrypted_messages']);
|
||||
$result += (yield from $feeder->feed($difference['other_updates']));
|
||||
$result += (yield from $feeder->feed($difference['new_encrypted_messages']));
|
||||
$state->update($difference['intermediate_state']);
|
||||
$feeder->saveMessages($difference['new_messages']);
|
||||
if ($difference['intermediate_state']['pts'] >= $toPts) {
|
||||
|
@ -439,7 +439,7 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
$this->logger->logger(Lang::$current_lang['load_rsa'], Logger::ULTRA_VERBOSE);
|
||||
$this->rsa_keys = [];
|
||||
foreach ($this->settings['authorization']['rsa_keys'] as $key) {
|
||||
$key = yield (new RSA())->load($this->TL, $key);
|
||||
$key = (yield from (new RSA())->load($this->TL, $key));
|
||||
$this->rsa_keys[$key->fp] = $key;
|
||||
}
|
||||
// (re)-initialize TL
|
||||
@ -819,7 +819,7 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
foreach ($this->secret_chats as $chat => $data) {
|
||||
try {
|
||||
if (isset($this->secret_chats[$chat]) && $this->secret_chats[$chat]['InputEncryptedChat'] !== null) {
|
||||
yield $this->notifyLayer($chat);
|
||||
yield from $this->notifyLayer($chat);
|
||||
}
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
}
|
||||
@ -909,7 +909,7 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
}
|
||||
$this->startUpdateSystem(true);
|
||||
if ($this->authorized === self::LOGGED_IN && !$this->authorization['user']['bot'] && $this->settings['peer']['cache_all_peers_on_startup']) {
|
||||
yield $this->getDialogs($force);
|
||||
yield from $this->getDialogs($force);
|
||||
}
|
||||
if ($this->authorized === self::LOGGED_IN && $this->settings['updates']['handle_updates']) {
|
||||
$this->logger->logger(Lang::$current_lang['getupdates_deserialization'], Logger::NOTICE);
|
||||
@ -1383,14 +1383,14 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
$dcs[] = $this->datacenter->dcConnect($new_dc);
|
||||
}
|
||||
yield \danog\MadelineProto\Tools::all($dcs);
|
||||
yield $this->initAuthorization();
|
||||
yield from $this->initAuthorization();
|
||||
yield from $this->parseConfig();
|
||||
$dcs = [];
|
||||
foreach ($this->datacenter->getDcs(false) as $new_dc) {
|
||||
$dcs[] = $this->datacenter->dcConnect($new_dc);
|
||||
}
|
||||
yield \danog\MadelineProto\Tools::all($dcs);
|
||||
yield $this->initAuthorization();
|
||||
yield from $this->initAuthorization();
|
||||
yield from $this->parseConfig();
|
||||
yield from $this->getPhoneConfig();
|
||||
}
|
||||
@ -1547,7 +1547,7 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
{
|
||||
try {
|
||||
foreach ((yield $this->methodCallAsyncRead('help.getCdnConfig', [], ['datacenter' => $datacenter]))['public_keys'] as $curkey) {
|
||||
$curkey = yield (new RSA())->load($this->TL, $curkey['public_key']);
|
||||
$curkey = (yield from (new RSA())->load($this->TL, $curkey['public_key']));
|
||||
$this->cdn_rsa_keys[$curkey->fp] = $curkey;
|
||||
}
|
||||
} catch (\danog\MadelineProto\TL\Exception $e) {
|
||||
|
@ -33,12 +33,12 @@ trait AckHandler
|
||||
}
|
||||
//$this->logger->logger("Ack-ed ".$this->outgoing_messages[$message_id]['_']." with message ID $message_id on DC $datacenter");
|
||||
/*
|
||||
if (isset($this->outgoing_messages[$message_id]['body'])) {
|
||||
unset($this->outgoing_messages[$message_id]['body']);
|
||||
}
|
||||
if (isset($this->new_outgoing[$message_id])) {
|
||||
unset($this->new_outgoing[$message_id]);
|
||||
}*/
|
||||
if (isset($this->outgoing_messages[$message_id]['body'])) {
|
||||
unset($this->outgoing_messages[$message_id]['body']);
|
||||
}
|
||||
if (isset($this->new_outgoing[$message_id])) {
|
||||
unset($this->new_outgoing[$message_id]);
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
public function gotResponseForOutgoingMessageId($message_id): bool
|
||||
|
@ -142,8 +142,8 @@ trait CallHandler
|
||||
if (isset($args['multiple'])) {
|
||||
$aargs['multiple'] = true;
|
||||
}
|
||||
if (isset($args['message']) && \is_string($args['message']) && \mb_strlen($args['message'], 'UTF-8') > (yield $this->API->getConfig())['message_length_max'] && \mb_strlen((yield $this->API->parseMode($args))['message'], 'UTF-8') > (yield $this->API->getConfig())['message_length_max']) {
|
||||
$args = yield $this->API->splitToChunks($args);
|
||||
if (isset($args['message']) && \is_string($args['message']) && \mb_strlen($args['message'], 'UTF-8') > (yield from $this->API->getConfig())['message_length_max'] && \mb_strlen((yield from $this->API->parseMode($args))['message'], 'UTF-8') > (yield from $this->API->getConfig())['message_length_max']) {
|
||||
$args = (yield from $this->API->splitToChunks($args));
|
||||
$promises = [];
|
||||
$aargs['queue'] = $method;
|
||||
$aargs['multiple'] = true;
|
||||
@ -163,7 +163,7 @@ trait CallHandler
|
||||
}
|
||||
return yield all($promises);
|
||||
}
|
||||
$args = yield $this->API->botAPIToMTProto($args);
|
||||
$args = (yield from $this->API->botAPIToMTProto($args));
|
||||
if (isset($args['ping_id']) && \is_int($args['ping_id'])) {
|
||||
$args['ping_id'] = Tools::packSignedLong($args['ping_id']);
|
||||
}
|
||||
@ -179,7 +179,7 @@ trait CallHandler
|
||||
$message['user_related'] = true;
|
||||
}
|
||||
$aargs['postpone'] = $aargs['postpone'] ?? false;
|
||||
$deferred = yield $this->sendMessage($message, !$aargs['postpone']);
|
||||
$deferred = (yield from $this->sendMessage($message, !$aargs['postpone']));
|
||||
$this->checker->resume();
|
||||
return $deferred;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ trait ResponseHandler
|
||||
}
|
||||
$info .= \chr($cur_info);
|
||||
}
|
||||
$this->outgoing_messages[yield $this->objectCall('msgs_state_info', ['req_msg_id' => $req_msg_id, 'info' => $info], ['postpone' => true])]['response'] = $req_msg_id;
|
||||
$this->outgoing_messages[yield from $this->objectCall('msgs_state_info', ['req_msg_id' => $req_msg_id, 'info' => $info], ['postpone' => true])]['response'] = $req_msg_id;
|
||||
}
|
||||
public $n = 0;
|
||||
public function handleMessages()
|
||||
@ -391,7 +391,7 @@ trait ResponseHandler
|
||||
}
|
||||
$this->API->resetSession();
|
||||
\danog\MadelineProto\Tools::callFork((function () use (&$request, &$response): \Generator {
|
||||
yield $this->API->initAuthorization();
|
||||
yield from $this->API->initAuthorization();
|
||||
$this->handleReject($request, new \danog\MadelineProto\RPCErrorException($response['error_message'], $response['error_code'], $request['_'] ?? ''));
|
||||
})());
|
||||
return;
|
||||
@ -400,7 +400,7 @@ trait ResponseHandler
|
||||
if ($this->API->authorized !== MTProto::LOGGED_IN) {
|
||||
$this->gotResponseForOutgoingMessageId($request_id);
|
||||
\danog\MadelineProto\Tools::callFork((function () use (&$request, &$response): \Generator {
|
||||
yield $this->API->initAuthorization();
|
||||
yield from $this->API->initAuthorization();
|
||||
$this->handleReject($request, new \danog\MadelineProto\RPCErrorException($response['error_message'], $response['error_code'], $request['_'] ?? ''));
|
||||
})());
|
||||
return;
|
||||
@ -425,13 +425,13 @@ trait ResponseHandler
|
||||
$this->logger->logger('If you intentionally deleted this account, ignore this message.', \danog\MadelineProto\Logger::FATAL_ERROR);
|
||||
$this->API->resetSession();
|
||||
\danog\MadelineProto\Tools::callFork((function () use (&$request, &$response): \Generator {
|
||||
yield $this->API->initAuthorization();
|
||||
yield from $this->API->initAuthorization();
|
||||
$this->handleReject($request, new \danog\MadelineProto\RPCErrorException($response['error_message'], $response['error_code'], $request['_'] ?? ''));
|
||||
})());
|
||||
return;
|
||||
}
|
||||
\danog\MadelineProto\Tools::callFork((function () use ($request_id): \Generator {
|
||||
yield $this->API->initAuthorization();
|
||||
yield from $this->API->initAuthorization();
|
||||
$this->methodRecall('', ['message_id' => $request_id]);
|
||||
})());
|
||||
return;
|
||||
@ -439,7 +439,7 @@ trait ResponseHandler
|
||||
$this->logger->logger('Temporary auth key not bound, resetting temporary auth key...', \danog\MadelineProto\Logger::ERROR);
|
||||
$this->shared->setTempAuthKey(null);
|
||||
\danog\MadelineProto\Tools::callFork((function () use ($request_id): \Generator {
|
||||
yield $this->API->initAuthorization();
|
||||
yield from $this->API->initAuthorization();
|
||||
$this->methodRecall('', ['message_id' => $request_id]);
|
||||
})());
|
||||
return;
|
||||
@ -483,7 +483,7 @@ trait ResponseHandler
|
||||
$this->API->resetMTProtoSession();
|
||||
$this->shared->setTempAuthKey(null);
|
||||
\danog\MadelineProto\Tools::callFork((function () use ($request_id): \Generator {
|
||||
yield $this->API->initAuthorization();
|
||||
yield from $this->API->initAuthorization();
|
||||
$this->methodRecall('', ['message_id' => $request_id]);
|
||||
})());
|
||||
return;
|
||||
@ -514,7 +514,7 @@ trait ResponseHandler
|
||||
$r = isset($response['_']) ? $response['_'] : \json_encode($response);
|
||||
$this->logger->logger("Deferred: sent {$r} to deferred", Logger::ULTRA_VERBOSE);
|
||||
if ($botAPI) {
|
||||
$response = yield $this->MTProtoToBotAPI($response);
|
||||
$response = (yield from $this->MTProtoToBotAPI($response));
|
||||
}
|
||||
if (isset($this->outgoing_messages[$request_id]['promise'])) {
|
||||
// This should not happen but happens, should debug
|
||||
|
@ -179,7 +179,7 @@ trait AuthKeyHandler
|
||||
$q_bytes = $q->toBytes();
|
||||
$new_nonce = \danog\MadelineProto\Tools::random(32);
|
||||
$data_unserialized = ['_' => 'p_q_inner_data' . ($expires_in < 0 ? '' : '_temp'), 'pq' => $pq_bytes, 'p' => $p_bytes, 'q' => $q_bytes, 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'new_nonce' => $new_nonce, 'expires_in' => $expires_in, 'dc' => \preg_replace('|_.*|', '', $datacenter)];
|
||||
$p_q_inner_data = yield $this->TL->serializeObject(['type' => ''], $data_unserialized, 'p_q_inner_data');
|
||||
$p_q_inner_data = (yield from $this->TL->serializeObject(['type' => ''], $data_unserialized, 'p_q_inner_data'));
|
||||
/*
|
||||
* ***********************************************************************
|
||||
* Encrypt serialized object
|
||||
@ -313,7 +313,7 @@ trait AuthKeyHandler
|
||||
* string $g_b : g^b mod dh_prime
|
||||
* ]
|
||||
*/
|
||||
$data = yield $this->TL->serializeObject(['type' => ''], ['_' => 'client_DH_inner_data', 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'retry_id' => $retry_id, 'g_b' => $g_b_str], 'client_DH_inner_data');
|
||||
$data = (yield from $this->TL->serializeObject(['type' => ''], ['_' => 'client_DH_inner_data', 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'retry_id' => $retry_id, 'g_b' => $g_b_str], 'client_DH_inner_data'));
|
||||
/*
|
||||
* ***********************************************************************
|
||||
* encrypt client_DH_inner_data
|
||||
@ -539,7 +539,7 @@ trait AuthKeyHandler
|
||||
$temp_auth_key_id = $datacenterConnection->getTempAuthKey()->getID();
|
||||
$perm_auth_key_id = $datacenterConnection->getPermAuthKey()->getID();
|
||||
$temp_session_id = $connection->session_id;
|
||||
$message_data = yield $this->TL->serializeObject(['type' => ''], ['_' => 'bind_auth_key_inner', 'nonce' => $nonce, 'temp_auth_key_id' => $temp_auth_key_id, 'perm_auth_key_id' => $perm_auth_key_id, 'temp_session_id' => $temp_session_id, 'expires_at' => $expires_at], 'bindTempAuthKey_inner');
|
||||
$message_data = (yield from $this->TL->serializeObject(['type' => ''], ['_' => 'bind_auth_key_inner', 'nonce' => $nonce, 'temp_auth_key_id' => $temp_auth_key_id, 'perm_auth_key_id' => $perm_auth_key_id, 'temp_session_id' => $temp_session_id, 'expires_at' => $expires_at], 'bindTempAuthKey_inner'));
|
||||
$message_id = $connection->generateMessageId();
|
||||
$seq_no = 0;
|
||||
$encrypted_data = \danog\MadelineProto\Tools::random(16) . $message_id . \pack('VV', $seq_no, \strlen($message_data)) . $message_data;
|
||||
@ -573,7 +573,7 @@ trait AuthKeyHandler
|
||||
*/
|
||||
private function wolframSingle($what): \Generator
|
||||
{
|
||||
$code = yield $this->datacenter->fileGetContents('http://www.wolframalpha.com/api/v1/code');
|
||||
$code = (yield from $this->datacenter->fileGetContents('http://www.wolframalpha.com/api/v1/code'));
|
||||
$query = 'Do prime factorization of ' . $what;
|
||||
$params = ['async' => true, 'banners' => 'raw', 'debuggingdata' => false, 'format' => 'moutput', 'formattimeout' => 8, 'input' => $query, 'output' => 'JSON', 'proxycode' => \json_decode($code, true)['code']];
|
||||
$url = 'https://www.wolframalpha.com/input/json.jsp?' . \http_build_query($params);
|
||||
|
@ -181,7 +181,7 @@ trait Files
|
||||
} else {
|
||||
if (!$stream instanceof BufferedRawStream) {
|
||||
$ctx = (new ConnectionContext())->addStream(PremadeStream::getName(), $stream)->addStream(SimpleBufferedRawStream::getName());
|
||||
$stream = yield $ctx->getStream();
|
||||
$stream = (yield from $ctx->getStream());
|
||||
$created = true;
|
||||
}
|
||||
$callable = static function (int $offset, int $size) use ($stream): \Generator {
|
||||
@ -544,7 +544,7 @@ trait Files
|
||||
} elseif (isset($constructor['InputMedia'])) {
|
||||
return $constructor;
|
||||
} else {
|
||||
$constructor = yield $this->getPwrChat($constructor['Chat'] ?? $constructor['User']);
|
||||
$constructor = (yield from $this->getPwrChat($constructor['Chat'] ?? $constructor['User']));
|
||||
$constructor = $constructor['photo'];
|
||||
}
|
||||
}
|
||||
@ -575,7 +575,7 @@ trait Files
|
||||
*/
|
||||
public function getPropicInfo($data): \Generator
|
||||
{
|
||||
return yield from $this->getDownloadInfo($this->chats[(yield $this->getInfo($data))['bot_api_id']]);
|
||||
return yield from $this->getDownloadInfo($this->chats[(yield from $this->getInfo($data))['bot_api_id']]);
|
||||
}
|
||||
/**
|
||||
* Get download info of file
|
||||
@ -694,7 +694,7 @@ trait Files
|
||||
$message_media['min'] = false;
|
||||
$peer = $this->genAll($message_media)['InputPeer'];
|
||||
} else {
|
||||
$peer = (yield $this->getInfo($message_media))['InputPeer'];
|
||||
$peer = (yield from $this->getInfo($message_media))['InputPeer'];
|
||||
}
|
||||
$res['InputFileLocation'] = ['_' => 'inputPeerPhotoFileLocation', 'big' => $res['big'], 'dc_id' => $res['InputFileLocation']['dc_id'], 'peer' => $peer, 'volume_id' => $res['InputFileLocation']['volume_id'], 'local_id' => $res['InputFileLocation']['local_id']];
|
||||
return $res;
|
||||
@ -795,98 +795,98 @@ trait Files
|
||||
}
|
||||
}
|
||||
/*
|
||||
public function download_to_browser_single_async($message_media, $cb = null)
|
||||
{
|
||||
if (php_sapi_name() === 'cli') {
|
||||
throw new Exception('Cannot download file to browser from command line: start this script from a browser');
|
||||
}
|
||||
if (headers_sent()) {
|
||||
throw new Exception('Headers already sent, cannot stream file to browser!');
|
||||
}
|
||||
public function download_to_browser_single_async($message_media, $cb = null)
|
||||
{
|
||||
if (php_sapi_name() === 'cli') {
|
||||
throw new Exception('Cannot download file to browser from command line: start this script from a browser');
|
||||
}
|
||||
if (headers_sent()) {
|
||||
throw new Exception('Headers already sent, cannot stream file to browser!');
|
||||
}
|
||||
|
||||
if (is_object($message_media) && $message_media instanceof FileCallbackInterface) {
|
||||
$cb = $message_media;
|
||||
$message_media = $message_media->getFile();
|
||||
}
|
||||
if (is_object($message_media) && $message_media instanceof FileCallbackInterface) {
|
||||
$cb = $message_media;
|
||||
$message_media = $message_media->getFile();
|
||||
}
|
||||
|
||||
$message_media = yield $this->getDownloadInfo($message_media);
|
||||
$message_media = yield $this->getDownloadInfo($message_media);
|
||||
|
||||
$servefile = $_SERVER['REQUEST_METHOD'] !== 'HEAD';
|
||||
$servefile = $_SERVER['REQUEST_METHOD'] !== 'HEAD';
|
||||
|
||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||
$range = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
if (count($range) == 1) {
|
||||
$range[1] = '';
|
||||
}
|
||||
list($size_unit, $range_orig) = $range;
|
||||
if ($size_unit == 'bytes') {
|
||||
//multiple ranges could be specified at the same time, but for simplicity only serve the first range
|
||||
//http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt
|
||||
$list = explode(',', $range_orig, 2);
|
||||
if (count($list) == 1) {
|
||||
$list[1] = '';
|
||||
}
|
||||
list($range, $extra_ranges) = $list;
|
||||
} else {
|
||||
$range = '';
|
||||
return Tools::noCache(416, '<html><body><h1>416 Requested Range Not Satisfiable.</h1><br><p>Could not use selected range.</p></body></html>');
|
||||
}
|
||||
} else {
|
||||
$range = '';
|
||||
}
|
||||
$listseek = explode('-', $range, 2);
|
||||
if (count($listseek) == 1) {
|
||||
$listseek[1] = '';
|
||||
}
|
||||
list($seek_start, $seek_end) = $listseek;
|
||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||
$range = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
if (count($range) == 1) {
|
||||
$range[1] = '';
|
||||
}
|
||||
list($size_unit, $range_orig) = $range;
|
||||
if ($size_unit == 'bytes') {
|
||||
//multiple ranges could be specified at the same time, but for simplicity only serve the first range
|
||||
//http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt
|
||||
$list = explode(',', $range_orig, 2);
|
||||
if (count($list) == 1) {
|
||||
$list[1] = '';
|
||||
}
|
||||
list($range, $extra_ranges) = $list;
|
||||
} else {
|
||||
$range = '';
|
||||
return Tools::noCache(416, '<html><body><h1>416 Requested Range Not Satisfiable.</h1><br><p>Could not use selected range.</p></body></html>');
|
||||
}
|
||||
} else {
|
||||
$range = '';
|
||||
}
|
||||
$listseek = explode('-', $range, 2);
|
||||
if (count($listseek) == 1) {
|
||||
$listseek[1] = '';
|
||||
}
|
||||
list($seek_start, $seek_end) = $listseek;
|
||||
|
||||
$seek_end = empty($seek_end) ? ($message_media['size'] - 1) : min(abs(intval($seek_end)), $message_media['size'] - 1);
|
||||
$seek_end = empty($seek_end) ? ($message_media['size'] - 1) : min(abs(intval($seek_end)), $message_media['size'] - 1);
|
||||
|
||||
if (!empty($seek_start) && $seek_end < abs(intval($seek_start))) {
|
||||
return Tools::noCache(416, '<html><body><h1>416 Requested Range Not Satisfiable.</h1><br><p>Could not use selected range.</p></body></html>');
|
||||
}
|
||||
$seek_start = empty($seek_start) ? 0 : abs(intval($seek_start));
|
||||
if ($servefile) {
|
||||
if ($seek_start > 0 || $seek_end < $select['file_size'] - 1) {
|
||||
header('HTTP/1.1 206 Partial Content');
|
||||
header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$select['file_size']);
|
||||
header('Content-Length: '.($seek_end - $seek_start + 1));
|
||||
} else {
|
||||
header('Content-Length: '.$select['file_size']);
|
||||
}
|
||||
header('Content-Type: '.$select['mime']);
|
||||
header('Cache-Control: max-age=31556926;');
|
||||
header('Content-Transfer-Encoding: Binary');
|
||||
header('Accept-Ranges: bytes');
|
||||
//header('Content-disposition: attachment: filename="'.basename($select['file_path']).'"');
|
||||
$MadelineProto->downloadToStream($select['file_id'], fopen('php://output', 'w'), function ($percent) {
|
||||
flush();
|
||||
ob_flush();
|
||||
\danog\MadelineProto\Logger::log('Download status: '.$percent.'%');
|
||||
}, $seek_start, $seek_end + 1);
|
||||
//analytics(true, $file_path, $MadelineProto->getSelf()['id'], $dbuser, $dbpassword);
|
||||
$MadelineProto->API->getting_state = false;
|
||||
$MadelineProto->API->storeDb([], true);
|
||||
$MadelineProto->API->resetSession();
|
||||
} else {
|
||||
if ($seek_start > 0 || $seek_end < $select['file_size'] - 1) {
|
||||
header('HTTP/1.1 206 Partial Content');
|
||||
header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$select['file_size']);
|
||||
header('Content-Length: '.($seek_end - $seek_start + 1));
|
||||
} else {
|
||||
header('Content-Length: '.$select['file_size']);
|
||||
}
|
||||
header('Content-Type: '.$select['mime']);
|
||||
header('Cache-Control: max-age=31556926;');
|
||||
header('Content-Transfer-Encoding: Binary');
|
||||
header('Accept-Ranges: bytes');
|
||||
analytics(true, $file_path, null, $dbuser, $dbpassword);
|
||||
//header('Content-disposition: attachment: filename="'.basename($select['file_path']).'"');
|
||||
}
|
||||
if (!empty($seek_start) && $seek_end < abs(intval($seek_start))) {
|
||||
return Tools::noCache(416, '<html><body><h1>416 Requested Range Not Satisfiable.</h1><br><p>Could not use selected range.</p></body></html>');
|
||||
}
|
||||
$seek_start = empty($seek_start) ? 0 : abs(intval($seek_start));
|
||||
if ($servefile) {
|
||||
if ($seek_start > 0 || $seek_end < $select['file_size'] - 1) {
|
||||
header('HTTP/1.1 206 Partial Content');
|
||||
header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$select['file_size']);
|
||||
header('Content-Length: '.($seek_end - $seek_start + 1));
|
||||
} else {
|
||||
header('Content-Length: '.$select['file_size']);
|
||||
}
|
||||
header('Content-Type: '.$select['mime']);
|
||||
header('Cache-Control: max-age=31556926;');
|
||||
header('Content-Transfer-Encoding: Binary');
|
||||
header('Accept-Ranges: bytes');
|
||||
//header('Content-disposition: attachment: filename="'.basename($select['file_path']).'"');
|
||||
$MadelineProto->downloadToStream($select['file_id'], fopen('php://output', 'w'), function ($percent) {
|
||||
flush();
|
||||
ob_flush();
|
||||
\danog\MadelineProto\Logger::log('Download status: '.$percent.'%');
|
||||
}, $seek_start, $seek_end + 1);
|
||||
//analytics(true, $file_path, $MadelineProto->getSelf()['id'], $dbuser, $dbpassword);
|
||||
$MadelineProto->API->getting_state = false;
|
||||
$MadelineProto->API->storeDb([], true);
|
||||
$MadelineProto->API->resetSession();
|
||||
} else {
|
||||
if ($seek_start > 0 || $seek_end < $select['file_size'] - 1) {
|
||||
header('HTTP/1.1 206 Partial Content');
|
||||
header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$select['file_size']);
|
||||
header('Content-Length: '.($seek_end - $seek_start + 1));
|
||||
} else {
|
||||
header('Content-Length: '.$select['file_size']);
|
||||
}
|
||||
header('Content-Type: '.$select['mime']);
|
||||
header('Cache-Control: max-age=31556926;');
|
||||
header('Content-Transfer-Encoding: Binary');
|
||||
header('Accept-Ranges: bytes');
|
||||
analytics(true, $file_path, null, $dbuser, $dbpassword);
|
||||
//header('Content-disposition: attachment: filename="'.basename($select['file_path']).'"');
|
||||
}
|
||||
|
||||
header('Content-Length: '.$info['size']);
|
||||
header('Content-Type: '.$info['mime']);
|
||||
}*/
|
||||
header('Content-Length: '.$info['size']);
|
||||
header('Content-Type: '.$info['mime']);
|
||||
}*/
|
||||
/**
|
||||
* Extract photo size.
|
||||
*
|
||||
@ -1190,12 +1190,12 @@ trait Files
|
||||
$datacenter = $res['dc_id'] . '_cdn';
|
||||
if (!$this->datacenter->has($datacenter)) {
|
||||
$this->config['expires'] = -1;
|
||||
yield $this->getConfig([], ['datacenter' => $this->datacenter->curdc]);
|
||||
yield from $this->getConfig([], ['datacenter' => $this->datacenter->curdc]);
|
||||
}
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['stored_on_cdn'], \danog\MadelineProto\Logger::NOTICE);
|
||||
} elseif ($res['_'] === 'upload.cdnFileReuploadNeeded') {
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['cdn_reupload'], \danog\MadelineProto\Logger::NOTICE);
|
||||
yield $this->getConfig([], ['datacenter' => $this->datacenter->curdc]);
|
||||
yield from $this->getConfig([], ['datacenter' => $this->datacenter->curdc]);
|
||||
try {
|
||||
$this->addCdnHashes($message_media['file_token'], yield $this->methodCallAsyncRead('upload.reuploadCdnFile', ['file_token' => $message_media['file_token'], 'request_token' => $res['request_token']], ['heavy' => true, 'datacenter' => $old_dc]));
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
|
@ -207,7 +207,7 @@ class MinDatabase implements TLCallback
|
||||
if (isset($this->db[$id])) {
|
||||
$new = \array_merge($object, $this->db[$id]);
|
||||
$new['_'] .= 'FromMessage';
|
||||
$new['peer'] = (yield $this->API->getInfo($new['peer']))['InputPeer'];
|
||||
$new['peer'] = (yield from $this->API->getInfo($new['peer']))['InputPeer'];
|
||||
if ($new['peer']['min']) {
|
||||
$this->API->logger->logger("Don't have origin peer subinfo with min peer {$id}, this may fail");
|
||||
return $object;
|
||||
|
@ -523,7 +523,7 @@ trait PeerHandler
|
||||
if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true && $recursive) {
|
||||
$dbres = [];
|
||||
try {
|
||||
$dbres = \json_decode(yield $this->datacenter->fileGetContents('https://id.pwrtelegram.xyz/db/getusername?id=' . $id), true);
|
||||
$dbres = \json_decode(yield from $this->datacenter->fileGetContents('https://id.pwrtelegram.xyz/db/getusername?id=' . $id), true);
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->logger($e);
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ trait UpdateHandler
|
||||
public function getUpdatesState(): \Generator
|
||||
{
|
||||
$data = yield $this->methodCallAsyncRead('updates.getState', [], ['datacenter' => $this->settings['connection_settings']['default_dc']]);
|
||||
yield $this->getCdnConfig($this->settings['connection_settings']['default_dc']);
|
||||
yield from $this->getCdnConfig($this->settings['connection_settings']['default_dc']);
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
@ -256,7 +256,7 @@ trait UpdateHandler
|
||||
$result = [];
|
||||
foreach ($updates['updates'] as $key => $update) {
|
||||
if ($update['_'] === 'updateNewMessage' || $update['_'] === 'updateReadMessagesContents' || $update['_'] === 'updateEditMessage' || $update['_'] === 'updateDeleteMessages' || $update['_'] === 'updateReadHistoryInbox' || $update['_'] === 'updateReadHistoryOutbox' || $update['_'] === 'updateWebPage' || $update['_'] === 'updateMessageID') {
|
||||
$result[yield $this->feeders[false]->feedSingle($update)] = true;
|
||||
$result[yield from $this->feeders[false]->feedSingle($update)] = true;
|
||||
unset($updates['updates'][$key]);
|
||||
}
|
||||
}
|
||||
@ -272,13 +272,13 @@ trait UpdateHandler
|
||||
$this->seqUpdater->resume();
|
||||
break;
|
||||
case 'updateShort':
|
||||
$this->feeders[yield $this->feeders[false]->feedSingle($updates['update'])]->resume();
|
||||
$this->feeders[yield from $this->feeders[false]->feedSingle($updates['update'])]->resume();
|
||||
break;
|
||||
case 'updateShortSentMessage':
|
||||
if (!isset($updates['request']['body'])) {
|
||||
break;
|
||||
}
|
||||
$updates['user_id'] = (yield $this->getInfo($updates['request']['body']['peer']))['bot_api_id'];
|
||||
$updates['user_id'] = (yield from $this->getInfo($updates['request']['body']['peer']))['bot_api_id'];
|
||||
$updates['message'] = $updates['request']['body']['message'];
|
||||
unset($updates['request']);
|
||||
// no break
|
||||
@ -286,7 +286,7 @@ trait UpdateHandler
|
||||
case 'updateShortChatMessage':
|
||||
$from_id = isset($updates['from_id']) ? $updates['from_id'] : ($updates['out'] ? $this->authorization['user']['id'] : $updates['user_id']);
|
||||
$to_id = isset($updates['chat_id']) ? -$updates['chat_id'] : ($updates['out'] ? $updates['user_id'] : $this->authorization['user']['id']);
|
||||
if (!(yield from $this->peerIsset($from_id) || !(yield from $this->peerIsset($to_id) || isset($updates['via_bot_id']) && !(yield from $this->peerIsset($updates['via_bot_id']) || isset($updates['entities']) && !(yield from $this->entitiesPeerIsset($updates['entities']) || isset($updates['fwd_from']) && !yield $this->fwdPeerIsset($updates['fwd_from'])))))) {
|
||||
if (!(yield from $this->peerIsset($from_id) || !(yield from $this->peerIsset($to_id) || isset($updates['via_bot_id']) && !(yield from $this->peerIsset($updates['via_bot_id']) || isset($updates['entities']) && !(yield from $this->entitiesPeerIsset($updates['entities']) || isset($updates['fwd_from']) && !(yield from $this->fwdPeerIsset($updates['fwd_from']))))))) {
|
||||
yield $this->updaters[false]->resume();
|
||||
return;
|
||||
}
|
||||
@ -294,7 +294,7 @@ trait UpdateHandler
|
||||
$message['_'] = 'message';
|
||||
$message['from_id'] = $from_id;
|
||||
try {
|
||||
$message['to_id'] = (yield $this->getInfo($to_id))['Peer'];
|
||||
$message['to_id'] = (yield from $this->getInfo($to_id))['Peer'];
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
$this->logger->logger('Still did not get user in database, postponing update', \danog\MadelineProto\Logger::ERROR);
|
||||
//$this->pending_updates[] = $updates;
|
||||
@ -305,7 +305,7 @@ trait UpdateHandler
|
||||
break;
|
||||
}
|
||||
$update = ['_' => 'updateNewMessage', 'message' => $message, 'pts' => $updates['pts'], 'pts_count' => $updates['pts_count']];
|
||||
$this->feeders[yield $this->feeders[false]->feedSingle($update)]->resume();
|
||||
$this->feeders[yield from $this->feeders[false]->feedSingle($update)]->resume();
|
||||
break;
|
||||
case 'updatesTooLong':
|
||||
$this->updaters[false]->resume();
|
||||
@ -328,17 +328,17 @@ trait UpdateHandler
|
||||
{
|
||||
if ($update['_'] === 'updateConfig') {
|
||||
$this->config['expires'] = 0;
|
||||
yield $this->getConfig();
|
||||
yield from $this->getConfig();
|
||||
}
|
||||
if (\in_array($update['_'], ['updateUserName', 'updateUserPhone', 'updateUserBlocked', 'updateUserPhoto', 'updateContactRegistered', 'updateContactLink'])) {
|
||||
$id = $this->getId($update);
|
||||
$this->full_chats[$id]['last_update'] = 0;
|
||||
yield $this->getFullInfo($id);
|
||||
yield from $this->getFullInfo($id);
|
||||
}
|
||||
if ($update['_'] === 'updateDcOptions') {
|
||||
$this->logger->logger('Got new dc options', \danog\MadelineProto\Logger::VERBOSE);
|
||||
$this->config['dc_options'] = $update['dc_options'];
|
||||
yield $this->parseConfig();
|
||||
yield from $this->parseConfig();
|
||||
return;
|
||||
}
|
||||
if ($update['_'] === 'updatePhoneCall') {
|
||||
@ -357,13 +357,13 @@ trait UpdateHandler
|
||||
$update['phone_call'] = $this->calls[$update['phone_call']['id']] = $controller;
|
||||
break;
|
||||
case 'phoneCallAccepted':
|
||||
if (!yield $this->confirmCall($update['phone_call'])) {
|
||||
if (!(yield from $this->confirmCall($update['phone_call']))) {
|
||||
return;
|
||||
}
|
||||
$update['phone_call'] = $this->calls[$update['phone_call']['id']];
|
||||
break;
|
||||
case 'phoneCall':
|
||||
if (!yield $this->completeCall($update['phone_call'])) {
|
||||
if (!(yield from $this->completeCall($update['phone_call']))) {
|
||||
return;
|
||||
}
|
||||
$update['phone_call'] = $this->calls[$update['phone_call']['id']];
|
||||
@ -393,7 +393,7 @@ trait UpdateHandler
|
||||
$this->logger->logger('Applying qts: ' . $update['qts'] . ' over current qts ' . $cur_state->qts() . ', chat id: ' . $update['message']['chat_id'], \danog\MadelineProto\Logger::VERBOSE);
|
||||
yield $this->methodCallAsyncRead('messages.receivedQueue', ['max_qts' => $cur_state->qts($update['qts'])], ['datacenter' => $this->settings['connection_settings']['default_dc']]);
|
||||
}
|
||||
yield $this->handleEncryptedUpdate($update);
|
||||
yield from $this->handleEncryptedUpdate($update);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
@ -409,7 +409,7 @@ trait UpdateHandler
|
||||
}
|
||||
$this->logger->logger('Accepting secret chat ' . $update['chat']['id'], \danog\MadelineProto\Logger::NOTICE);
|
||||
try {
|
||||
yield $this->acceptSecretChat($update['chat']);
|
||||
yield from $this->acceptSecretChat($update['chat']);
|
||||
} catch (RPCErrorException $e) {
|
||||
$this->logger->logger("Error while accepting secret chat: {$e}", Logger::FATAL_ERROR);
|
||||
}
|
||||
@ -428,7 +428,7 @@ trait UpdateHandler
|
||||
break;
|
||||
case 'encryptedChat':
|
||||
$this->logger->logger('Completing creation of secret chat ' . $update['chat']['id'], \danog\MadelineProto\Logger::NOTICE);
|
||||
yield $this->completeSecretChat($update['chat']);
|
||||
yield from $this->completeSecretChat($update['chat']);
|
||||
break;
|
||||
}
|
||||
//$this->logger->logger($update, \danog\MadelineProto\Logger::NOTICE);
|
||||
|
@ -62,7 +62,7 @@ class RSA
|
||||
$this->n = Tools::getVar($key, 'modulus');
|
||||
$this->e = Tools::getVar($key, 'exponent');
|
||||
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['computing_fingerprint'], Logger::ULTRA_VERBOSE);
|
||||
$this->fp = \substr(\sha1(yield $TL->serializeObject(['type' => 'bytes'], $this->n->toBytes(), 'key') . yield $TL->serializeObject(['type' => 'bytes'], $this->e->toBytes(), 'key'), true), -8);
|
||||
$this->fp = \substr(\sha1(yield from $TL->serializeObject(['type' => 'bytes'], $this->n->toBytes(), 'key') . (yield from $TL->serializeObject(['type' => 'bytes'], $this->e->toBytes(), 'key')), true), -8);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
|
@ -55,7 +55,7 @@ trait AuthKeyHandler
|
||||
$this->logger->logger("I've already accepted secret chat " . $params['id']);
|
||||
return false;
|
||||
}
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
$b = new \tgseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
||||
$params['g_a'] = new \tgseclib\Math\BigInteger((string) $params['g_a'], 256);
|
||||
@ -81,13 +81,13 @@ trait AuthKeyHandler
|
||||
*/
|
||||
public function requestSecretChat($user): \Generator
|
||||
{
|
||||
$user = yield $this->getInfo($user);
|
||||
$user = (yield from $this->getInfo($user));
|
||||
if (!isset($user['InputUser'])) {
|
||||
throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database');
|
||||
}
|
||||
$user = $user['InputUser'];
|
||||
$this->logger->logger('Creating secret chat with ' . $user['user_id'] . '...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
$a = new \tgseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
||||
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
@ -113,7 +113,7 @@ trait AuthKeyHandler
|
||||
$this->logger->logger('Could not find and complete secret chat ' . $params['id']);
|
||||
return false;
|
||||
}
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
$params['g_a_or_b'] = new \tgseclib\Math\BigInteger((string) $params['g_a_or_b'], 256);
|
||||
$this->checkG($params['g_a_or_b'], $dh_config['p']);
|
||||
$key = ['auth_key' => \str_pad($params['g_a_or_b']->powMod($this->temp_requested_secret_chats[$params['id']], $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT)];
|
||||
@ -153,7 +153,7 @@ trait AuthKeyHandler
|
||||
return;
|
||||
}
|
||||
$this->logger->logger('Rekeying secret chat ' . $chat . '...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
$a = new \tgseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
||||
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
@ -189,7 +189,7 @@ trait AuthKeyHandler
|
||||
}
|
||||
}
|
||||
$this->logger->logger('Accepting rekeying of secret chat ' . $chat . '...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
$b = new \tgseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
||||
$params['g_a'] = new \tgseclib\Math\BigInteger((string) $params['g_a'], 256);
|
||||
@ -220,7 +220,7 @@ trait AuthKeyHandler
|
||||
return;
|
||||
}
|
||||
$this->logger->logger('Committing rekeying of secret chat ' . $chat . '...', \danog\MadelineProto\Logger::VERBOSE);
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
$params['g_b'] = new \tgseclib\Math\BigInteger((string) $params['g_b'], 256);
|
||||
$this->checkG($params['g_b'], $dh_config['p']);
|
||||
$key = ['auth_key' => \str_pad($params['g_b']->powMod($this->temp_rekeyed_secret_chats[$params['exchange_id']], $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT)];
|
||||
|
@ -44,13 +44,13 @@ trait MessageHandler
|
||||
$this->secret_chats[$chat_id]['ttr']--;
|
||||
if ($this->secret_chats[$chat_id]['layer'] > 8) {
|
||||
if (($this->secret_chats[$chat_id]['ttr'] <= 0 || \time() - $this->secret_chats[$chat_id]['updated'] > 7 * 24 * 60 * 60) && $this->secret_chats[$chat_id]['rekeying'][0] === 0) {
|
||||
yield $this->rekey($chat_id);
|
||||
yield from $this->rekey($chat_id);
|
||||
}
|
||||
$message = ['_' => 'decryptedMessageLayer', 'layer' => $this->secret_chats[$chat_id]['layer'], 'in_seq_no' => $this->generateSecretInSeqNo($chat_id), 'out_seq_no' => $this->generateSecretOutSeqNo($chat_id), 'message' => $message];
|
||||
$this->secret_chats[$chat_id]['out_seq_no']++;
|
||||
}
|
||||
$this->secret_chats[$chat_id]['outgoing'][$this->secret_chats[$chat_id]['out_seq_no']] = $message;
|
||||
$message = yield $this->TL->serializeObject(['type' => $constructor = $this->secret_chats[$chat_id]['layer'] === 8 ? 'DecryptedMessage' : 'DecryptedMessageLayer'], $message, $constructor, $this->secret_chats[$chat_id]['layer']);
|
||||
$message = (yield from $this->TL->serializeObject(['type' => $constructor = $this->secret_chats[$chat_id]['layer'] === 8 ? 'DecryptedMessage' : 'DecryptedMessageLayer'], $message, $constructor, $this->secret_chats[$chat_id]['layer']));
|
||||
$message = \danog\MadelineProto\Tools::packUnsignedInt(\strlen($message)) . $message;
|
||||
if ($this->secret_chats[$chat_id]['mtproto'] === 2) {
|
||||
$padding = \danog\MadelineProto\Tools::posmod(-\strlen($message), 16);
|
||||
@ -79,12 +79,12 @@ trait MessageHandler
|
||||
if ($auth_key_id !== $this->secret_chats[$message['message']['chat_id']]['key']['fingerprint']) {
|
||||
if (isset($this->secret_chats[$message['message']['chat_id']]['old_key']['fingerprint'])) {
|
||||
if ($auth_key_id !== $this->secret_chats[$message['message']['chat_id']]['old_key']['fingerprint']) {
|
||||
yield $this->discardSecretChat($message['message']['chat_id']);
|
||||
yield from $this->discardSecretChat($message['message']['chat_id']);
|
||||
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['fingerprint_mismatch']);
|
||||
}
|
||||
$old = true;
|
||||
} else {
|
||||
yield $this->discardSecretChat($message['message']['chat_id']);
|
||||
yield from $this->discardSecretChat($message['message']['chat_id']);
|
||||
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['fingerprint_mismatch']);
|
||||
}
|
||||
}
|
||||
@ -116,12 +116,12 @@ trait MessageHandler
|
||||
$deserialized = $this->TL->deserialize($message_data, ['type' => '']);
|
||||
$this->secret_chats[$message['message']['chat_id']]['ttr']--;
|
||||
if (($this->secret_chats[$message['message']['chat_id']]['ttr'] <= 0 || \time() - $this->secret_chats[$message['message']['chat_id']]['updated'] > 7 * 24 * 60 * 60) && $this->secret_chats[$message['message']['chat_id']]['rekeying'][0] === 0) {
|
||||
yield $this->rekey($message['message']['chat_id']);
|
||||
yield from $this->rekey($message['message']['chat_id']);
|
||||
}
|
||||
unset($message['message']['bytes']);
|
||||
$message['message']['decrypted_message'] = $deserialized;
|
||||
$this->secret_chats[$message['message']['chat_id']]['incoming'][$this->secret_chats[$message['message']['chat_id']]['in_seq_no']] = $message['message'];
|
||||
yield $this->handleDecryptedUpdate($message);
|
||||
yield from $this->handleDecryptedUpdate($message);
|
||||
}
|
||||
private function tryMTProtoV1Decrypt($message_key, $chat_id, $old, $encrypted_data)
|
||||
{
|
||||
|
@ -34,18 +34,18 @@ trait ResponseHandler
|
||||
case 'decryptedMessageService':
|
||||
switch ($update['message']['decrypted_message']['action']['_']) {
|
||||
case 'decryptedMessageActionRequestKey':
|
||||
yield $this->acceptRekey($update['message']['chat_id'], $update['message']['decrypted_message']['action']);
|
||||
yield from $this->acceptRekey($update['message']['chat_id'], $update['message']['decrypted_message']['action']);
|
||||
return;
|
||||
case 'decryptedMessageActionAcceptKey':
|
||||
yield $this->commitRekey($update['message']['chat_id'], $update['message']['decrypted_message']['action']);
|
||||
yield from $this->commitRekey($update['message']['chat_id'], $update['message']['decrypted_message']['action']);
|
||||
return;
|
||||
case 'decryptedMessageActionCommitKey':
|
||||
yield $this->completeRekey($update['message']['chat_id'], $update['message']['decrypted_message']['action']);
|
||||
yield from $this->completeRekey($update['message']['chat_id'], $update['message']['decrypted_message']['action']);
|
||||
return;
|
||||
case 'decryptedMessageActionNotifyLayer':
|
||||
$this->secret_chats[$update['message']['chat_id']]['layer'] = $update['message']['decrypted_message']['action']['layer'];
|
||||
if ($update['message']['decrypted_message']['action']['layer'] >= 17 && \time() - $this->secret_chats[$update['message']['chat_id']]['created'] > 15) {
|
||||
yield $this->notifyLayer($update['message']['chat_id']);
|
||||
yield from $this->notifyLayer($update['message']['chat_id']);
|
||||
}
|
||||
if ($update['message']['decrypted_message']['action']['layer'] >= 73) {
|
||||
$this->secret_chats[$update['message']['chat_id']]['mtproto'] = 2;
|
||||
@ -53,7 +53,7 @@ trait ResponseHandler
|
||||
return;
|
||||
case 'decryptedMessageActionSetMessageTTL':
|
||||
$this->secret_chats[$update['message']['chat_id']]['ttl'] = $update['message']['decrypted_message']['action']['ttl_seconds'];
|
||||
yield $this->saveUpdate($update);
|
||||
yield from $this->saveUpdate($update);
|
||||
return;
|
||||
case 'decryptedMessageActionNoop':
|
||||
return;
|
||||
@ -72,19 +72,19 @@ trait ResponseHandler
|
||||
return;
|
||||
default:
|
||||
// yield $this->saveUpdate(['_' => 'updateNewDecryptedMessage', 'peer' => $this->secret_chats[$update['message']['chat_id']]['InputEncryptedChat'], 'in_seq_no' => $this->get_in_seq_no($update['message']['chat_id']), 'out_seq_no' => $this->get_out_seq_no($update['message']['chat_id']), 'message' => $update['message']['decrypted_message']]);
|
||||
yield $this->saveUpdate($update);
|
||||
yield from $this->saveUpdate($update);
|
||||
}
|
||||
break;
|
||||
case 'decryptedMessage':
|
||||
yield $this->saveUpdate($update);
|
||||
yield from $this->saveUpdate($update);
|
||||
break;
|
||||
case 'decryptedMessageLayer':
|
||||
if (yield $this->checkSecretOutSeqNo($update['message']['chat_id'], $update['message']['decrypted_message']['out_seq_no']) && yield $this->checkSecretInSeqNo($update['message']['chat_id'], $update['message']['decrypted_message']['in_seq_no'])) {
|
||||
if (yield from $this->checkSecretOutSeqNo($update['message']['chat_id'], $update['message']['decrypted_message']['out_seq_no']) && (yield from $this->checkSecretInSeqNo($update['message']['chat_id'], $update['message']['decrypted_message']['in_seq_no']))) {
|
||||
$this->secret_chats[$update['message']['chat_id']]['in_seq_no']++;
|
||||
if ($update['message']['decrypted_message']['layer'] >= 17) {
|
||||
$this->secret_chats[$update['message']['chat_id']]['layer'] = $update['message']['decrypted_message']['layer'];
|
||||
if ($update['message']['decrypted_message']['layer'] >= 17 && \time() - $this->secret_chats[$update['message']['chat_id']]['created'] > 15) {
|
||||
yield $this->notifyLayer($update['message']['chat_id']);
|
||||
yield from $this->notifyLayer($update['message']['chat_id']);
|
||||
}
|
||||
}
|
||||
$update['message']['decrypted_message'] = $update['message']['decrypted_message']['message'];
|
||||
|
@ -31,14 +31,14 @@ trait SeqNoHandler
|
||||
foreach ($this->secret_chats[$chat_id]['incoming'] as $message) {
|
||||
if (isset($message['decrypted_message']['in_seq_no'])) {
|
||||
if (($message['decrypted_message']['in_seq_no'] - $this->secret_chats[$chat_id]['out_seq_no_x']) / 2 < $last) {
|
||||
yield $this->discardSecretChat($chat_id);
|
||||
yield from $this->discardSecretChat($chat_id);
|
||||
throw new \danog\MadelineProto\SecurityException('in_seq_no is not increasing');
|
||||
}
|
||||
$last = ($message['decrypted_message']['in_seq_no'] - $this->secret_chats[$chat_id]['out_seq_no_x']) / 2;
|
||||
}
|
||||
}
|
||||
if ($seqno > $this->secret_chats[$chat_id]['out_seq_no'] + 1) {
|
||||
yield $this->discardSecretChat($chat_id);
|
||||
yield from $this->discardSecretChat($chat_id);
|
||||
throw new \danog\MadelineProto\SecurityException('in_seq_no is too big');
|
||||
}
|
||||
return true;
|
||||
@ -50,7 +50,7 @@ trait SeqNoHandler
|
||||
foreach ($this->secret_chats[$chat_id]['incoming'] as $message) {
|
||||
if (isset($message['decrypted_message']['out_seq_no']) && $C < $this->secret_chats[$chat_id]['in_seq_no']) {
|
||||
if (($message['decrypted_message']['out_seq_no'] - $this->secret_chats[$chat_id]['in_seq_no_x']) / 2 !== $C) {
|
||||
yield $this->discardSecretChat($chat_id);
|
||||
yield from $this->discardSecretChat($chat_id);
|
||||
throw new \danog\MadelineProto\SecurityException('out_seq_no hole: should be ' . $C . ', is ' . ($message['decrypted_message']['out_seq_no'] - $this->secret_chats[$chat_id]['in_seq_no_x']) / 2);
|
||||
}
|
||||
$C++;
|
||||
@ -64,7 +64,7 @@ trait SeqNoHandler
|
||||
}
|
||||
if ($seqno > $C) {
|
||||
// > C+1
|
||||
yield $this->discardSecretChat($chat_id);
|
||||
yield from $this->discardSecretChat($chat_id);
|
||||
throw new \danog\MadelineProto\SecurityException('WARNING: out_seq_no gap detected (' . $seqno . ' > ' . $C . ')!');
|
||||
}
|
||||
return true;
|
||||
|
@ -48,7 +48,7 @@ class ADNLStream implements BufferedStreamInterface, MTProtoBufferInterface
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = yield $ctx->getStream($header);
|
||||
$this->stream = (yield from $ctx->getStream($header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -51,7 +51,7 @@ class BufferedRawStream implements BufferedStreamInterface, BufferInterface, Raw
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = yield $ctx->getStream($header);
|
||||
$this->stream = (yield from $ctx->getStream($header));
|
||||
$this->memory_stream = \fopen('php://memory', 'r+');
|
||||
return true;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class CtrStream implements BufferedProxyStreamInterface, BufferInterface
|
||||
$this->decrypt->enableContinuousBuffer();
|
||||
$this->decrypt->setKey($this->extra['decrypt']['key']);
|
||||
$this->decrypt->setIV($this->extra['decrypt']['iv']);
|
||||
$this->stream = yield $ctx->getStream($header);
|
||||
$this->stream = (yield from $ctx->getStream($header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -197,7 +197,7 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf
|
||||
$this->read_hash = null;
|
||||
$this->read_check_after = 0;
|
||||
$this->read_check_pos = 0;
|
||||
$this->stream = yield $ctx->getStream($header);
|
||||
$this->stream = (yield from $ctx->getStream($header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -421,7 +421,7 @@ class ConnectionContext
|
||||
if ($obj instanceof ProxyStreamInterface) {
|
||||
$obj->setExtra($extra);
|
||||
}
|
||||
yield $obj->connect($this, $buffer);
|
||||
yield from $obj->connect($this, $buffer);
|
||||
return $obj;
|
||||
}
|
||||
/**
|
||||
|
@ -45,7 +45,7 @@ class AbridgedStream implements BufferedStreamInterface, MTProtoBufferInterface
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = yield $ctx->getStream(\chr(239) . $header);
|
||||
$this->stream = (yield from $ctx->getStream(\chr(239) . $header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
@ -87,7 +87,7 @@ class AbridgedStream implements BufferedStreamInterface, MTProtoBufferInterface
|
||||
$buffer = yield $this->stream->getReadBuffer($l);
|
||||
$length = \ord(yield $buffer->bufferRead(1));
|
||||
if ($length >= 127) {
|
||||
$length = \unpack('V', yield $buffer->bufferRead(3) . "\0")[1];
|
||||
$length = \unpack('V', yield from $buffer->bufferRead(3) . "\0")[1];
|
||||
}
|
||||
$length <<= 2;
|
||||
return $buffer;
|
||||
|
@ -56,7 +56,7 @@ class HttpStream implements MTProtoBufferInterface, BufferedProxyStreamInterface
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->ctx = $ctx->getCtx();
|
||||
$this->stream = yield $ctx->getStream($header);
|
||||
$this->stream = (yield from $ctx->getStream($header));
|
||||
$this->uri = $ctx->getUri();
|
||||
}
|
||||
/**
|
||||
@ -147,7 +147,7 @@ class HttpStream implements MTProtoBufferInterface, BufferedProxyStreamInterface
|
||||
}
|
||||
if ($close) {
|
||||
$this->disconnect();
|
||||
yield $this->connect($this->ctx);
|
||||
yield from $this->connect($this->ctx);
|
||||
}
|
||||
\danog\MadelineProto\Logger::log($read);
|
||||
$this->code = \danog\MadelineProto\Tools::packSignedInt(-$code);
|
||||
@ -156,7 +156,7 @@ class HttpStream implements MTProtoBufferInterface, BufferedProxyStreamInterface
|
||||
}
|
||||
if ($close) {
|
||||
$this->stream->disconnect();
|
||||
yield $this->stream->connect($this->ctx);
|
||||
yield from $this->stream->connect($this->ctx);
|
||||
}
|
||||
if (isset($headers['content-length'])) {
|
||||
$length = (int) $headers['content-length'];
|
||||
|
@ -47,7 +47,7 @@ class IntermediatePaddedStream implements BufferedStreamInterface, MTProtoBuffer
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = yield $ctx->getStream(\str_repeat(\chr(221), 4) . $header);
|
||||
$this->stream = (yield from $ctx->getStream(\str_repeat(\chr(221), 4) . $header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -47,7 +47,7 @@ class IntermediateStream implements BufferedStreamInterface, MTProtoBufferInterf
|
||||
*/
|
||||
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
|
||||
{
|
||||
$this->stream = yield $ctx->getStream(\str_repeat(\chr(238), 4) . $header);
|
||||
$this->stream = (yield from $ctx->getStream(\str_repeat(\chr(238), 4) . $header));
|
||||
}
|
||||
/**
|
||||
* Async close.
|
||||
|
@ -53,7 +53,7 @@ class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface
|
||||
$ctx->setSocketContext($ctx->getSocketContext()->withTlsContext(new ClientTlsContext($uri->getHost())));
|
||||
}
|
||||
$ctx->setUri('tcp://' . $this->extra['address'] . ':' . $this->extra['port'])->secure(false);
|
||||
$this->stream = yield $ctx->getStream();
|
||||
$this->stream = (yield from $ctx->getStream());
|
||||
$address = $uri->getHost();
|
||||
$port = $uri->getPort();
|
||||
try {
|
||||
@ -106,14 +106,14 @@ class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface
|
||||
}
|
||||
if ($close) {
|
||||
$this->disconnect();
|
||||
yield $this->connect($ctx);
|
||||
yield from $this->connect($ctx);
|
||||
}
|
||||
\danog\MadelineProto\Logger::log(\trim($read));
|
||||
throw new \danog\MadelineProto\Exception($description, $code);
|
||||
}
|
||||
if ($close) {
|
||||
yield $this->stream->disconnect();
|
||||
yield $this->stream->connect($ctx);
|
||||
yield from $this->stream->connect($ctx);
|
||||
}
|
||||
if (isset($headers['content-length'])) {
|
||||
$length = (int) $headers['content-length'];
|
||||
|
@ -58,7 +58,7 @@ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterfac
|
||||
if (isset($this->extra['username']) && isset($this->extra['password'])) {
|
||||
$methods .= \chr(2);
|
||||
}
|
||||
$this->stream = yield $ctx->getStream(\chr(5) . \chr(\strlen($methods)) . $methods);
|
||||
$this->stream = (yield from $ctx->getStream(\chr(5) . \chr(\strlen($methods)) . $methods));
|
||||
$l = 2;
|
||||
$buffer = yield $this->stream->getReadBuffer($l);
|
||||
$version = \ord(yield $buffer->bufferRead(1));
|
||||
|
@ -68,7 +68,7 @@ class DefaultStream implements RawStreamInterface, ProxyStreamInterface
|
||||
if ($secure) {
|
||||
$ctx->setSocketContext($ctx->getSocketContext()->withTlsContext(new ClientTlsContext($uri->getHost())));
|
||||
}
|
||||
$this->stream = yield ($this->connector ?? connector())->connect((string) $uri, $ctx->getSocketContext(), $ctx->getCancellationToken());
|
||||
$this->stream = (yield from ($this->connector ?? connector())->connect((string) $uri, $ctx->getSocketContext(), $ctx->getCancellationToken()));
|
||||
if ($secure) {
|
||||
yield $this->stream->setupTls();
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class WsStream implements RawStreamInterface, ProxyStreamInterface
|
||||
}
|
||||
$this->dc = $ctx->getIntDc();
|
||||
$handshake = new Handshake(\str_replace('tcp://', $ctx->isSecure() ? 'wss://' : 'ws://', $ctx->getStringUri()));
|
||||
$this->stream = yield ($this->connector ?? connector())->connect($handshake, $ctx->getCancellationToken());
|
||||
$this->stream = (yield from ($this->connector ?? connector())->connect($handshake, $ctx->getCancellationToken()));
|
||||
if (\strlen($header)) {
|
||||
yield $this->write($header);
|
||||
}
|
||||
|
@ -193,9 +193,9 @@ trait BotAPI
|
||||
$newd['date'] = $data['date'];
|
||||
$newd['text'] = $sent_arguments['message'];
|
||||
if ($data['out']) {
|
||||
$newd['from'] = yield $this->getPwrChat($this->authorization['user']);
|
||||
$newd['from'] = (yield from $this->getPwrChat($this->authorization['user']));
|
||||
}
|
||||
$newd['chat'] = yield $this->getPwrChat($sent_arguments['peer']);
|
||||
$newd['chat'] = (yield from $this->getPwrChat($sent_arguments['peer']));
|
||||
if (isset($data['entities'])) {
|
||||
$newd['entities'] = (yield from $this->MTProtoToBotAPI($data['entities'], $sent_arguments));
|
||||
}
|
||||
@ -213,9 +213,9 @@ trait BotAPI
|
||||
$newd['post'] = $data['post'];
|
||||
$newd['silent'] = $data['silent'];
|
||||
if (isset($data['from_id'])) {
|
||||
$newd['from'] = yield $this->getPwrChat($data['from_id']);
|
||||
$newd['from'] = (yield from $this->getPwrChat($data['from_id']));
|
||||
}
|
||||
$newd['chat'] = yield $this->getPwrChat($data['to_id']);
|
||||
$newd['chat'] = (yield from $this->getPwrChat($data['to_id']));
|
||||
if (isset($data['entities'])) {
|
||||
$newd['entities'] = (yield from $this->MTProtoToBotAPI($data['entities'], $sent_arguments));
|
||||
}
|
||||
@ -226,13 +226,13 @@ trait BotAPI
|
||||
$newd['edit_date'] = $data['edit_date'];
|
||||
}
|
||||
if (isset($data['via_bot_id'])) {
|
||||
$newd['via_bot'] = yield $this->getPwrChat($data['via_bot_id']);
|
||||
$newd['via_bot'] = (yield from $this->getPwrChat($data['via_bot_id']));
|
||||
}
|
||||
if (isset($data['fwd_from']['from_id'])) {
|
||||
$newd['forward_from'] = yield $this->getPwrChat($data['fwd_from']['from_id']);
|
||||
$newd['forward_from'] = (yield from $this->getPwrChat($data['fwd_from']['from_id']));
|
||||
}
|
||||
if (isset($data['fwd_from']['channel_id'])) {
|
||||
$newd['forward_from_chat'] = yield $this->getPwrChat($data['fwd_from']['channel_id']);
|
||||
$newd['forward_from_chat'] = (yield from $this->getPwrChat($data['fwd_from']['channel_id']));
|
||||
}
|
||||
if (isset($data['fwd_from']['date'])) {
|
||||
$newd['forward_date'] = $data['fwd_from']['date'];
|
||||
@ -287,7 +287,7 @@ trait BotAPI
|
||||
case 'messageEntityMentionName':
|
||||
unset($data['_']);
|
||||
$data['type'] = 'text_mention';
|
||||
$data['user'] = yield $this->getPwrChat($data['user_id']);
|
||||
$data['user'] = (yield from $this->getPwrChat($data['user_id']));
|
||||
unset($data['user_id']);
|
||||
return $data;
|
||||
case 'messageMediaPhoto':
|
||||
@ -297,7 +297,7 @@ trait BotAPI
|
||||
$res['photo'] = [];
|
||||
foreach ($data['photo']['sizes'] as $key => $photo) {
|
||||
if (\in_array($photo['_'], ['photoCachedSize', 'photoSize'])) {
|
||||
$res['photo'][$key] = yield $this->photosizeToBotAPI($photo, $data['photo']);
|
||||
$res['photo'][$key] = (yield from $this->photosizeToBotAPI($photo, $data['photo']));
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
@ -307,7 +307,7 @@ trait BotAPI
|
||||
$type_name = 'document';
|
||||
$res = [];
|
||||
if (isset($data['document']['thumbs']) && $data['document']['thumbs'] && \in_array(\end($data['document']['thumbs'])['_'], ['photoCachedSize', 'photoSize'])) {
|
||||
$res['thumb'] = yield $this->photosizeToBotAPI(\end($data['document']['thumbs']), [], true);
|
||||
$res['thumb'] = (yield from $this->photosizeToBotAPI(\end($data['document']['thumbs']), [], true));
|
||||
}
|
||||
foreach ($data['document']['attributes'] as $attribute) {
|
||||
switch ($attribute['_']) {
|
||||
@ -380,7 +380,7 @@ trait BotAPI
|
||||
$data['document']['_'] = 'bot_' . $type_name;
|
||||
$res['file_size'] = $data['document']['size'];
|
||||
$res['mime_type'] = $data['document']['mime_type'];
|
||||
$res['file_id'] = \danog\MadelineProto\Tools::base64urlEncode(\danog\MadelineProto\Tools::rleEncode(yield $this->TL->serializeObject(['type' => 'File'], $data['document'], 'File') . \chr(2)));
|
||||
$res['file_id'] = \danog\MadelineProto\Tools::base64urlEncode(\danog\MadelineProto\Tools::rleEncode(yield from $this->TL->serializeObject(['type' => 'File'], $data['document'], 'File') . \chr(2)));
|
||||
return [$type_name => $res, 'caption' => isset($data['caption']) ? $data['caption'] : ''];
|
||||
default:
|
||||
throw new Exception(\sprintf(\danog\MadelineProto\Lang::$current_lang['botapi_conversion_error'], $data['_']));
|
||||
@ -483,7 +483,7 @@ trait BotAPI
|
||||
$length = $this->mbStrlen($text);
|
||||
$href = $node->getAttribute('href');
|
||||
if (\preg_match('|mention:(.*)|', $href, $matches) || \preg_match('|tg://user\\?id=(.*)|', $href, $matches)) {
|
||||
$mention = yield $this->getInfo($matches[1]);
|
||||
$mention = (yield from $this->getInfo($matches[1]));
|
||||
if (!isset($mention['InputUser'])) {
|
||||
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['peer_not_in_db']);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ trait BotAPIFiles
|
||||
$photoSize['location']['secret'] = $photo['location']['secret'] ?? 0;
|
||||
$photoSize['location']['dc_id'] = $photo['dc_id'] ?? 0;
|
||||
$photoSize['location']['_'] = $thumbnail ? 'bot_thumbnail' : 'bot_photo';
|
||||
$data = yield $this->TL->serializeObject(['type' => 'File'], $photoSize['location'], 'File') . \chr(2);
|
||||
$data = (yield from $this->TL->serializeObject(['type' => 'File'], $photoSize['location'], 'File') . \chr(2));
|
||||
return ['file_id' => \danog\MadelineProto\Tools::base64urlEncode(\danog\MadelineProto\Tools::rleEncode($data)), 'width' => $photoSize['w'], 'height' => $photoSize['h'], 'file_size' => isset($photoSize['size']) ? $photoSize['size'] : \strlen($photoSize['bytes']), 'mime_type' => 'image/jpeg', 'file_name' => $photoSize['location']['volume_id'] . '_' . $photoSize['location']['local_id'] . $ext];
|
||||
}
|
||||
/**
|
||||
|
@ -122,7 +122,7 @@ trait TD
|
||||
} else {
|
||||
switch (\end($mtproto)) {
|
||||
case 'choose_chat_id_from_botapi':
|
||||
$newparams[$td] = (yield $this->getInfo($params[$mtproto[0]]))['bot_api_id'] == $this->authorization['user']['id'] ? $params['from_id'] : yield $this->getInfo($params[$mtproto[0]])['bot_api_id'];
|
||||
$newparams[$td] = (yield from $this->getInfo($params[$mtproto[0]]))['bot_api_id'] == $this->authorization['user']['id'] ? $params['from_id'] : (yield from $this->getInfo($params[$mtproto[0]])['bot_api_id']);
|
||||
break;
|
||||
case 'choose_incoming_or_sent':
|
||||
$newparams[$td] = ['_' => $params['out'] ? 'messageIsSuccessfullySent' : 'messageIsIncoming'];
|
||||
|
@ -600,7 +600,7 @@ class TL
|
||||
} elseif ($method === 'messages.sendEncryptedFile') {
|
||||
if (isset($arguments['file'])) {
|
||||
if ((!\is_array($arguments['file']) || !(isset($arguments['file']['_']) && $this->constructors->findByPredicate($arguments['file']['_']) === 'InputEncryptedFile')) && $this->API->settings['upload']['allow_automatic_upload']) {
|
||||
$arguments['file'] = yield $this->API->uploadEncrypted($arguments['file']);
|
||||
$arguments['file'] = (yield from $this->API->uploadEncrypted($arguments['file']));
|
||||
}
|
||||
if (isset($arguments['file']['key'])) {
|
||||
$arguments['message']['media']['key'] = $arguments['file']['key'];
|
||||
@ -610,7 +610,7 @@ class TL
|
||||
}
|
||||
}
|
||||
} elseif (\in_array($method, ['messages.addChatUser', 'messages.deleteChatUser', 'messages.editChatAdmin', 'messages.editChatPhoto', 'messages.editChatTitle', 'messages.getFullChat', 'messages.exportChatInvite', 'messages.editChatAdmin', 'messages.migrateChat']) && isset($arguments['chat_id']) && (!\is_numeric($arguments['chat_id']) || $arguments['chat_id'] < 0)) {
|
||||
$res = yield $this->API->getInfo($arguments['chat_id']);
|
||||
$res = (yield from $this->API->getInfo($arguments['chat_id']));
|
||||
if ($res['type'] !== 'chat') {
|
||||
throw new \danog\MadelineProto\Exception('chat_id is not a chat id (only normal groups allowed, not supergroups)!');
|
||||
}
|
||||
@ -653,7 +653,7 @@ class TL
|
||||
private function serializeParams(array $tl, $arguments, $ctx, int $layer = -1): \Generator
|
||||
{
|
||||
$serialized = '';
|
||||
$arguments = yield $this->API->botAPIToMTProto($arguments);
|
||||
$arguments = (yield from $this->API->botAPIToMTProto($arguments));
|
||||
$flags = 0;
|
||||
foreach ($tl['params'] as $cur_flag) {
|
||||
if (isset($cur_flag['pow'])) {
|
||||
@ -687,7 +687,7 @@ class TL
|
||||
continue;
|
||||
}
|
||||
if ($current_argument['name'] === 'data' && isset($tl['method']) && \in_array($tl['method'], ['messages.sendEncrypted', 'messages.sendEncryptedFile', 'messages.sendEncryptedService']) && isset($arguments['message'])) {
|
||||
$serialized .= (yield from $this->serializeObject($current_argument, yield $this->API->encryptSecretMessage($arguments['peer']['chat_id'], $arguments['message']), 'data'));
|
||||
$serialized .= (yield from $this->serializeObject($current_argument, yield from $this->API->encryptSecretMessage($arguments['peer']['chat_id'], $arguments['message']), 'data'));
|
||||
continue;
|
||||
}
|
||||
if ($current_argument['name'] === 'random_id') {
|
||||
@ -747,11 +747,11 @@ class TL
|
||||
});
|
||||
}
|
||||
if ($current_argument['type'] === 'InputFile' && (!\is_array($arguments[$current_argument['name']]) || !(isset($arguments[$current_argument['name']]['_']) && $this->constructors->findByPredicate($arguments[$current_argument['name']]['_'])['type'] === 'InputFile'))) {
|
||||
$arguments[$current_argument['name']] = yield $this->API->upload($arguments[$current_argument['name']]);
|
||||
$arguments[$current_argument['name']] = (yield from $this->API->upload($arguments[$current_argument['name']]));
|
||||
}
|
||||
if ($current_argument['type'] === 'InputEncryptedChat' && (!\is_array($arguments[$current_argument['name']]) || isset($arguments[$current_argument['name']]['_']) && $this->constructors->findByPredicate($arguments[$current_argument['name']]['_'])['type'] !== $current_argument['type'])) {
|
||||
if (\is_array($arguments[$current_argument['name']])) {
|
||||
$arguments[$current_argument['name']] = (yield $this->API->getInfo($arguments[$current_argument['name']]))['InputEncryptedChat'];
|
||||
$arguments[$current_argument['name']] = (yield from $this->API->getInfo($arguments[$current_argument['name']]))['InputEncryptedChat'];
|
||||
} else {
|
||||
if (!$this->API->hasSecretChat($arguments[$current_argument['name']])) {
|
||||
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['sec_peer_not_in_db']);
|
||||
|
@ -117,14 +117,14 @@ class ADNLConnection
|
||||
$iv = \substr($digest, 0, 4) . \substr($secret, 20, 12);
|
||||
$encryptedRandom = Crypt::ctrEncrypt($random, $key, $iv);
|
||||
// Generating plaintext init payload
|
||||
$payload = \hash('sha256', yield $this->TL->serializeObject(['type' => ''], $endpoint['id'], 'key'), true);
|
||||
$payload = \hash('sha256', yield from $this->TL->serializeObject(['type' => ''], $endpoint['id'], 'key'), true);
|
||||
$payload .= $public;
|
||||
$payload .= $digest;
|
||||
$payload .= $encryptedRandom;
|
||||
$ip = \long2ip(\unpack('V', Tools::packSignedInt($endpoint['ip']))[1]);
|
||||
$port = $endpoint['port'];
|
||||
$ctx = (new ConnectionContext())->setSocketContext(new ConnectContext())->setUri("tcp://{$ip}:{$port}")->addStream(DefaultStream::getName())->addStream(BufferedRawStream::getName())->addStream(CtrStream::getName(), $obf)->addStream(HashedBufferedStream::getName(), 'sha256')->addStream(ADNLStream::getName());
|
||||
$this->stream = yield $ctx->getStream($payload);
|
||||
$this->stream = (yield from $ctx->getStream($payload));
|
||||
Tools::callFork((function (): \Generator {
|
||||
//yield Tools::sleep(1);
|
||||
while (true) {
|
||||
@ -149,7 +149,7 @@ class ADNLConnection
|
||||
*/
|
||||
public function query(string $payload): \Generator
|
||||
{
|
||||
$data = yield $this->TL->serializeObject(['type' => ''], ['_' => 'adnl.message.query', 'query_id' => $id = Tools::random(32), 'query' => $payload], '');
|
||||
$data = (yield from $this->TL->serializeObject(['type' => ''], ['_' => 'adnl.message.query', 'query_id' => $id = Tools::random(32), 'query' => $payload], ''));
|
||||
(yield $this->stream->getWriteBuffer(\strlen($data)))->bufferWrite($data);
|
||||
$this->requests[$id] = new Deferred();
|
||||
return $this->requests[$id]->promise();
|
||||
|
@ -93,7 +93,7 @@ class APIFactory extends AbstractAPIFactory
|
||||
$aargs = isset($arguments[1]) && \is_array($arguments[1]) ? $arguments[1] : [];
|
||||
$aargs['apifactory'] = true;
|
||||
$args = isset($arguments[0]) && \is_array($arguments[0]) ? $arguments[0] : [];
|
||||
return yield $this->API->methodCall($name, $args, $aargs);
|
||||
return yield from $this->API->methodCall($name, $args, $aargs);
|
||||
}
|
||||
return yield $this->methods[$lower_name](...$arguments);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class Lite
|
||||
$config['_'] = 'liteclient.config.global';
|
||||
$config = Tools::convertJsonTL($config);
|
||||
$config['validator']['init_block'] = $config['validator']['init_block'] ?? $config['validator']['zero_state'];
|
||||
$this->config = yield $this->TL->deserialize(yield $this->TL->serializeObject(['type' => ''], $config, 'cleanup'));
|
||||
$this->config = yield $this->TL->deserialize(yield from $this->TL->serializeObject(['type' => ''], $config, 'cleanup'));
|
||||
foreach ($this->config['liteservers'] as $lite) {
|
||||
$this->connections[] = $connection = new ADNLConnection($this->TL);
|
||||
yield from $connection->connect($lite);
|
||||
@ -116,9 +116,9 @@ class Lite
|
||||
*/
|
||||
public function methodCall(string $methodName, array $args = [], array $aargs = []): \Generator
|
||||
{
|
||||
$data = yield $this->TL->serializeMethod($methodName, $args);
|
||||
$data = yield $this->TL->serializeMethod('liteServer.query', ['data' => $data]);
|
||||
return yield $this->connections[\rand(0, \count($this->connections) - 1)]->query($data);
|
||||
$data = (yield from $this->TL->serializeMethod($methodName, $args));
|
||||
$data = (yield from $this->TL->serializeMethod('liteServer.query', ['data' => $data]));
|
||||
return yield from $this->connections[\rand(0, \count($this->connections) - 1)]->query($data);
|
||||
}
|
||||
/**
|
||||
* Asynchronously run async callable.
|
||||
|
@ -80,13 +80,13 @@ trait AuthKeyHandler
|
||||
if (!\class_exists('\\danog\\MadelineProto\\VoIP')) {
|
||||
throw \danog\MadelineProto\Exception::extension('libtgvoip');
|
||||
}
|
||||
$user = yield $this->getInfo($user);
|
||||
$user = (yield from $this->getInfo($user));
|
||||
if (!isset($user['InputUser']) || $user['InputUser']['_'] === 'inputUserSelf') {
|
||||
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['peer_not_in_db']);
|
||||
}
|
||||
$user = $user['InputUser'];
|
||||
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['calling_user'], $user['user_id']), \danog\MadelineProto\Logger::VERBOSE);
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_a'], \danog\MadelineProto\Logger::VERBOSE);
|
||||
$a = \tgseclib\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_g_a'], \danog\MadelineProto\Logger::VERBOSE);
|
||||
@ -117,7 +117,7 @@ trait AuthKeyHandler
|
||||
return false;
|
||||
}
|
||||
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['accepting_call'], $this->calls[$call['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_b'], \danog\MadelineProto\Logger::VERBOSE);
|
||||
$b = \tgseclib\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
|
||||
$g_b = $dh_config['g']->powMod($b, $dh_config['p']);
|
||||
@ -157,7 +157,7 @@ trait AuthKeyHandler
|
||||
return false;
|
||||
}
|
||||
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['call_confirming'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
$params['g_b'] = new \tgseclib\Math\BigInteger((string) $params['g_b'], 256);
|
||||
$this->checkG($params['g_b'], $dh_config['p']);
|
||||
$key = \str_pad($params['g_b']->powMod($this->calls[$params['id']]->storage['a'], $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT);
|
||||
@ -205,7 +205,7 @@ trait AuthKeyHandler
|
||||
return false;
|
||||
}
|
||||
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['call_completing'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
|
||||
$dh_config = yield $this->getDhConfig();
|
||||
$dh_config = (yield from $this->getDhConfig());
|
||||
if (\hash('sha256', $params['g_a_or_b'], true) != $this->calls[$params['id']]->storage['g_a_hash']) {
|
||||
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['invalid_g_a']);
|
||||
}
|
||||
|
@ -47,16 +47,16 @@ Note that you can also provide the API parameters directly in the code using the
|
||||
return $app;
|
||||
}
|
||||
$this->my_telegram_org_wrapper = new \danog\MadelineProto\MyTelegramOrgWrapper($settings);
|
||||
yield $this->my_telegram_org_wrapper->login(yield Tools::readLine('Enter a phone number that is already registered on Telegram: '));
|
||||
yield $this->my_telegram_org_wrapper->completeLogin(yield Tools::readLine('Enter the verification code you received in telegram: '));
|
||||
if (!yield $this->my_telegram_org_wrapper->hasApp()) {
|
||||
yield from $this->my_telegram_org_wrapper->login(yield Tools::readLine('Enter a phone number that is already registered on Telegram: '));
|
||||
yield from $this->my_telegram_org_wrapper->completeLogin(yield Tools::readLine('Enter the verification code you received in telegram: '));
|
||||
if (!(yield from $this->my_telegram_org_wrapper->hasApp())) {
|
||||
$app_title = yield Tools::readLine('Enter the app\'s name, can be anything: ');
|
||||
$short_name = yield Tools::readLine('Enter the app\'s short name, can be anything: ');
|
||||
$url = yield Tools::readLine('Enter the app/website\'s URL, or t.me/yourusername: ');
|
||||
$description = yield Tools::readLine('Describe your app: ');
|
||||
$app = yield $this->my_telegram_org_wrapper->createApp(['app_title' => $app_title, 'app_shortname' => $short_name, 'app_url' => $url, 'app_platform' => 'web', 'app_desc' => $description]);
|
||||
$app = (yield from $this->my_telegram_org_wrapper->createApp(['app_title' => $app_title, 'app_shortname' => $short_name, 'app_url' => $url, 'app_platform' => 'web', 'app_desc' => $description]));
|
||||
} else {
|
||||
$app = yield $this->my_telegram_org_wrapper->getApp();
|
||||
$app = (yield from $this->my_telegram_org_wrapper->getApp());
|
||||
}
|
||||
return $app;
|
||||
}
|
||||
@ -70,15 +70,15 @@ Note that you can also provide the API parameters directly in the code using the
|
||||
} elseif (isset($_POST['phone_number'])) {
|
||||
yield from $this->webAPIPhoneLogin($settings);
|
||||
} else {
|
||||
yield $this->webAPIEcho();
|
||||
yield from $this->webAPIEcho();
|
||||
}
|
||||
} elseif (!$this->my_telegram_org_wrapper->loggedIn()) {
|
||||
if (isset($_POST['code'])) {
|
||||
yield from $this->webAPICompleteLogin();
|
||||
if (yield $this->my_telegram_org_wrapper->hasApp()) {
|
||||
return yield $this->my_telegram_org_wrapper->getApp();
|
||||
if (yield from $this->my_telegram_org_wrapper->hasApp()) {
|
||||
return yield from $this->my_telegram_org_wrapper->getApp();
|
||||
}
|
||||
yield $this->webAPIEcho();
|
||||
yield from $this->webAPIEcho();
|
||||
} elseif (isset($_POST['api_id']) && isset($_POST['api_hash'])) {
|
||||
$app['api_id'] = (int) $_POST['api_id'];
|
||||
$app['api_hash'] = $_POST['api_hash'];
|
||||
@ -88,7 +88,7 @@ Note that you can also provide the API parameters directly in the code using the
|
||||
yield from $this->webAPIPhoneLogin($settings);
|
||||
} else {
|
||||
$this->my_telegram_org_wrapper = null;
|
||||
yield $this->webAPIEcho();
|
||||
yield from $this->webAPIEcho();
|
||||
}
|
||||
} else {
|
||||
if (isset($_POST['app_title'], $_POST['app_shortname'], $_POST['app_url'], $_POST['app_platform'], $_POST['app_desc'])) {
|
||||
@ -96,7 +96,7 @@ Note that you can also provide the API parameters directly in the code using the
|
||||
$this->getting_api_id = false;
|
||||
return $app;
|
||||
}
|
||||
yield $this->webAPIEcho("You didn't provide all of the required parameters!");
|
||||
yield from $this->webAPIEcho("You didn't provide all of the required parameters!");
|
||||
}
|
||||
$this->asyncInitPromise = null;
|
||||
exit;
|
||||
@ -105,20 +105,20 @@ Note that you can also provide the API parameters directly in the code using the
|
||||
{
|
||||
try {
|
||||
$this->my_telegram_org_wrapper = new \danog\MadelineProto\MyTelegramOrgWrapper($settings);
|
||||
yield $this->my_telegram_org_wrapper->login($_POST['phone_number']);
|
||||
yield $this->webAPIEcho();
|
||||
yield from $this->my_telegram_org_wrapper->login($_POST['phone_number']);
|
||||
yield from $this->webAPIEcho();
|
||||
} catch (\Throwable $e) {
|
||||
yield $this->webAPIEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webAPIEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
}
|
||||
}
|
||||
private function webAPICompleteLogin(): \Generator
|
||||
{
|
||||
try {
|
||||
yield $this->my_telegram_org_wrapper->completeLogin($_POST['code']);
|
||||
yield from $this->my_telegram_org_wrapper->completeLogin($_POST['code']);
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
yield $this->webAPIEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webAPIEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
yield $this->webAPIEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webAPIEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
}
|
||||
}
|
||||
private function webAPICreateApp(): \Generator
|
||||
@ -126,12 +126,12 @@ Note that you can also provide the API parameters directly in the code using the
|
||||
try {
|
||||
$params = $_POST;
|
||||
unset($params['creating_app']);
|
||||
$app = yield $this->my_telegram_org_wrapper->createApp($params);
|
||||
$app = (yield from $this->my_telegram_org_wrapper->createApp($params));
|
||||
return $app;
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
yield $this->webAPIEcho('ERROR: ' . $e->getMessage() . ' Try again.');
|
||||
yield from $this->webAPIEcho('ERROR: ' . $e->getMessage() . ' Try again.');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
yield $this->webAPIEcho('ERROR: ' . $e->getMessage() . ' Try again.');
|
||||
yield from $this->webAPIEcho('ERROR: ' . $e->getMessage() . ' Try again.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ trait Login
|
||||
$this->datacenter->getDataCenterConnection($this->datacenter->curdc)->authorized(true);
|
||||
$this->updates = [];
|
||||
$this->updates_key = 0;
|
||||
yield $this->initAuthorization();
|
||||
yield from $this->initAuthorization();
|
||||
$this->startUpdateSystem();
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE);
|
||||
return $this->authorization;
|
||||
@ -136,8 +136,8 @@ trait Login
|
||||
$this->authorized = self::LOGGED_IN;
|
||||
$this->authorization = $authorization;
|
||||
$this->datacenter->getDataCenterConnection($this->datacenter->curdc)->authorized(true);
|
||||
yield $this->initAuthorization();
|
||||
yield $this->getPhoneConfig();
|
||||
yield from $this->initAuthorization();
|
||||
yield from $this->getPhoneConfig();
|
||||
$this->startUpdateSystem();
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE);
|
||||
return $this->authorization;
|
||||
@ -167,9 +167,9 @@ trait Login
|
||||
$dataCenterConnection->setPermAuthKey($auth_key);
|
||||
$dataCenterConnection->authorized(true);
|
||||
$this->authorized = self::LOGGED_IN;
|
||||
yield $this->initAuthorization();
|
||||
yield $this->getPhoneConfig();
|
||||
$res = yield $this->getSelf();
|
||||
yield from $this->initAuthorization();
|
||||
yield from $this->getPhoneConfig();
|
||||
$res = (yield from $this->getSelf());
|
||||
$callbacks = [$this, $this->referenceDatabase];
|
||||
if (!($this->authorization['user']['bot'] ?? false)) {
|
||||
$callbacks[] = $this->minDatabase;
|
||||
@ -188,7 +188,7 @@ trait Login
|
||||
if ($this->authorized !== self::LOGGED_IN) {
|
||||
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['not_loggedIn']);
|
||||
}
|
||||
yield $this->getSelf();
|
||||
yield from $this->getSelf();
|
||||
$this->authorized_dc = $this->datacenter->curdc;
|
||||
return [$this->datacenter->curdc, $this->datacenter->getDataCenterConnection($this->datacenter->curdc)->getPermAuthKey()->getAuthKey()];
|
||||
}
|
||||
@ -210,8 +210,8 @@ trait Login
|
||||
$this->authorization = yield $this->methodCallAsyncRead('auth.signUp', ['phone_number' => $this->authorization['phone_number'], 'phone_code_hash' => $this->authorization['phone_code_hash'], 'phone_code' => $this->authorization['phone_code'], 'first_name' => $first_name, 'last_name' => $last_name], ['datacenter' => $this->datacenter->curdc]);
|
||||
$this->authorized = self::LOGGED_IN;
|
||||
$this->datacenter->getDataCenterConnection($this->datacenter->curdc)->authorized(true);
|
||||
yield $this->initAuthorization();
|
||||
yield $this->getPhoneConfig();
|
||||
yield from $this->initAuthorization();
|
||||
yield from $this->getPhoneConfig();
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['signup_ok'], \danog\MadelineProto\Logger::NOTICE);
|
||||
$this->startUpdateSystem();
|
||||
return $this->authorization;
|
||||
@ -235,9 +235,9 @@ trait Login
|
||||
$this->authorization = yield $this->methodCallAsyncRead('auth.checkPassword', ['password' => $hasher->getCheckPassword($password)], ['datacenter' => $this->datacenter->curdc]);
|
||||
$this->authorized = self::LOGGED_IN;
|
||||
$this->datacenter->getDataCenterConnection($this->datacenter->curdc)->authorized(true);
|
||||
yield $this->initAuthorization();
|
||||
yield from $this->initAuthorization();
|
||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE);
|
||||
yield $this->getPhoneConfig();
|
||||
yield from $this->getPhoneConfig();
|
||||
$this->startUpdateSystem();
|
||||
return $this->authorization;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ trait Loop
|
||||
$callback = $this->loop_callback;
|
||||
Tools::callForkDefer($callback());
|
||||
}
|
||||
yield $this->waitUpdate();
|
||||
yield from $this->waitUpdate();
|
||||
} while (!$this->stopLoop);
|
||||
$this->stopLoop = false;
|
||||
}
|
||||
|
@ -34,23 +34,23 @@ trait Start
|
||||
public function start(): \Generator
|
||||
{
|
||||
if ($this->authorized === self::LOGGED_IN) {
|
||||
return yield $this->getSelf();
|
||||
return yield from $this->getSelf();
|
||||
}
|
||||
if (PHP_SAPI === 'cli') {
|
||||
if (\strpos(yield Tools::readLine('Do you want to login as user or bot (u/b)? '), 'b') !== false) {
|
||||
yield $this->botLogin(yield Tools::readLine('Enter your bot token: '));
|
||||
yield from $this->botLogin(yield Tools::readLine('Enter your bot token: '));
|
||||
} else {
|
||||
yield $this->phoneLogin(yield Tools::readLine('Enter your phone number: '));
|
||||
$authorization = yield $this->completePhoneLogin(yield Tools::readLine('Enter the phone code: '));
|
||||
yield from $this->phoneLogin(yield Tools::readLine('Enter your phone number: '));
|
||||
$authorization = (yield from $this->completePhoneLogin(yield Tools::readLine('Enter the phone code: ')));
|
||||
if ($authorization['_'] === 'account.password') {
|
||||
$authorization = yield $this->complete2faLogin(yield Tools::readLine('Please enter your password (hint ' . $authorization['hint'] . '): '));
|
||||
$authorization = (yield from $this->complete2faLogin(yield Tools::readLine('Please enter your password (hint ' . $authorization['hint'] . '): ')));
|
||||
}
|
||||
if ($authorization['_'] === 'account.needSignup') {
|
||||
$authorization = yield $this->completeSignup(yield Tools::readLine('Please enter your first name: '), yield Tools::readLine('Please enter your last name (can be empty): '));
|
||||
$authorization = (yield from $this->completeSignup(yield Tools::readLine('Please enter your first name: '), yield Tools::readLine('Please enter your last name (can be empty): ')));
|
||||
}
|
||||
}
|
||||
$this->serialize();
|
||||
return yield $this->getSelf();
|
||||
return yield from $this->getSelf();
|
||||
}
|
||||
if ($this->authorized === self::NOT_LOGGED_IN) {
|
||||
if (isset($_POST['phone_number'])) {
|
||||
@ -58,86 +58,86 @@ trait Start
|
||||
} elseif (isset($_POST['token'])) {
|
||||
yield from $this->webBotLogin();
|
||||
} else {
|
||||
yield $this->webEcho();
|
||||
yield from $this->webEcho();
|
||||
}
|
||||
} elseif ($this->authorized === self::WAITING_CODE) {
|
||||
if (isset($_POST['phone_code'])) {
|
||||
yield from $this->webCompletePhoneLogin();
|
||||
} else {
|
||||
yield $this->webEcho("You didn't provide a phone code!");
|
||||
yield from $this->webEcho("You didn't provide a phone code!");
|
||||
}
|
||||
} elseif ($this->authorized === self::WAITING_PASSWORD) {
|
||||
if (isset($_POST['password'])) {
|
||||
yield from $this->webComplete2faLogin();
|
||||
} else {
|
||||
yield $this->webEcho("You didn't provide the password!");
|
||||
yield from $this->webEcho("You didn't provide the password!");
|
||||
}
|
||||
} elseif ($this->authorized === self::WAITING_SIGNUP) {
|
||||
if (isset($_POST['first_name'])) {
|
||||
yield from $this->webCompleteSignup();
|
||||
} else {
|
||||
yield $this->webEcho("You didn't provide the first name!");
|
||||
yield from $this->webEcho("You didn't provide the first name!");
|
||||
}
|
||||
}
|
||||
if ($this->authorized === self::LOGGED_IN) {
|
||||
$this->serialize();
|
||||
return yield $this->getSelf();
|
||||
return yield from $this->getSelf();
|
||||
}
|
||||
exit;
|
||||
}
|
||||
private function webPhoneLogin(): \Generator
|
||||
{
|
||||
try {
|
||||
yield $this->phoneLogin($_POST['phone_number']);
|
||||
yield $this->webEcho();
|
||||
yield from $this->phoneLogin($_POST['phone_number']);
|
||||
yield from $this->webEcho();
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
}
|
||||
}
|
||||
private function webCompletePhoneLogin(): \Generator
|
||||
{
|
||||
try {
|
||||
yield $this->completePhoneLogin($_POST['phone_code']);
|
||||
yield $this->webEcho();
|
||||
yield from $this->completePhoneLogin($_POST['phone_code']);
|
||||
yield from $this->webEcho();
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
}
|
||||
}
|
||||
private function webComplete2faLogin(): \Generator
|
||||
{
|
||||
try {
|
||||
yield $this->complete2faLogin($_POST['password']);
|
||||
yield $this->webEcho();
|
||||
yield from $this->complete2faLogin($_POST['password']);
|
||||
yield from $this->webEcho();
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
}
|
||||
}
|
||||
private function webCompleteSignup(): \Generator
|
||||
{
|
||||
try {
|
||||
yield $this->completeSignup($_POST['first_name'], isset($_POST['last_name']) ? $_POST['last_name'] : '');
|
||||
yield $this->webEcho();
|
||||
yield from $this->completeSignup($_POST['first_name'], isset($_POST['last_name']) ? $_POST['last_name'] : '');
|
||||
yield from $this->webEcho();
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
}
|
||||
}
|
||||
private function webBotLogin(): \Generator
|
||||
{
|
||||
try {
|
||||
yield $this->botLogin($_POST['token']);
|
||||
yield $this->webEcho();
|
||||
yield from $this->botLogin($_POST['token']);
|
||||
yield from $this->webEcho();
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
yield $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
yield from $this->webEcho('ERROR: ' . $e->getMessage() . '. Try again.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,6 @@ trait TOS
|
||||
public function declineTos(): \Generator
|
||||
{
|
||||
yield $this->methodCallAsyncRead('account.deleteAccount', ['reason' => 'Decline ToS update'], ['datacenter' => $this->datacenter->curdc]);
|
||||
yield $this->logout();
|
||||
yield from $this->logout();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user