diff --git a/layerdiff.php b/layerdiff.php index de8101be..58f1dd19 100644 --- a/layerdiff.php +++ b/layerdiff.php @@ -89,12 +89,12 @@ foreach (['methods', 'constructors'] as $type) { $url = getUrl($name, $type); foreach ($final_new_args as $name => $ttype) { - if (!isset($final_old_args[$name])) { + if (!isset($final_old_args[$name]) && $name !== 'flags') { $res .= "Added $name param to $url\n"; } } foreach ($final_old_args as $name => $ttype) { - if (!isset($final_new_args[$name])) { + if (!isset($final_new_args[$name]) && $name !== 'flags') { $res .= "Removed $name param from $url\n"; } } diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 299e2ae1..c6dc9369 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -55,6 +55,7 @@ use danog\MadelineProto\Stream\Transport\WssStream; use danog\MadelineProto\Stream\Transport\WsStream; use function Amp\call; use function Amp\Socket\Internal\parseUri; +use Amp\Artax\Cookie\CookieJar; /** * Manages datacenters. @@ -71,13 +72,14 @@ class DataCenter private $HTTPClient; private $DoHClient; private $NonProxiedDoHClient; + private $CookieJar; public function __sleep() { return ['sockets', 'curdc', 'dclist', 'settings']; } - public function __magic_construct($API, $dclist, $settings) + public function __magic_construct($API, $dclist, $settings, CookieJar $jar = null) { $this->API = $API; $this->dclist = $dclist; @@ -92,10 +94,11 @@ class DataCenter unset($this->sockets[$key]); } } - $this->HTTPClient = new DefaultClient(new ArrayCookieJar(), new HttpSocketPool(new ProxySocketPool([$this, 'rawConnectAsync']))); + $this->CookieJar = $jar ?? new ArrayCookieJar; + $this->HTTPClient = new DefaultClient($this->CookieJar, new HttpSocketPool(new ProxySocketPool([$this, 'rawConnectAsync']))); $DoHHTTPClient = new DefaultClient( - new ArrayCookieJar(), + $this->CookieJar, new HttpSocketPool( new ProxySocketPool( function (string $uri, CancellationToken $token = null, ClientConnectContext $ctx = null) { @@ -679,6 +682,16 @@ class DataCenter { return $this->HTTPClient; } + + /** + * Get Artax async HTTP client. + * + * @return \Amp\Artax\CookieJar + */ + public function getCookieJar(): CookieJar + { + return $this->CookieJar; + } /** * Get DNS over HTTPS async DNS client. * diff --git a/src/danog/MadelineProto/MyTelegramOrgWrapper.php b/src/danog/MadelineProto/MyTelegramOrgWrapper.php index 76ec2399..638a9c8e 100644 --- a/src/danog/MadelineProto/MyTelegramOrgWrapper.php +++ b/src/danog/MadelineProto/MyTelegramOrgWrapper.php @@ -19,6 +19,7 @@ namespace danog\MadelineProto; use Amp\Artax\Request; +use Amp\Artax\Cookie\ArrayCookieJar; /** * Wrapper for my.telegram.org. @@ -29,16 +30,16 @@ class MyTelegramOrgWrapper private $logged = false; private $hash = ''; - private $token; private $number; private $creation_hash; private $settings = []; private $async = true; + private $jar; const MY_TELEGRAM_URL = 'https://my.telegram.org'; public function __sleep() { - return ['logged', 'hash', 'token', 'number', 'creation_hash', 'settings', 'async']; + return ['logged', 'hash', 'number', 'creation_hash', 'settings', 'async', 'jar']; } public function __construct($settings = []) @@ -52,6 +53,9 @@ class MyTelegramOrgWrapper if ($this->settings === null) { $this->settings = []; } + if (!$this->jar) { + $this->jar = new ArrayCookieJar; + } $this->settings = MTProto::getSettings($this->settings); $this->datacenter = new DataCenter( new class($this->settings) @@ -62,7 +66,8 @@ class MyTelegramOrgWrapper } }, [], - $this->settings['connection_settings'] + $this->settings['connection_settings'], + $this->jar ); } @@ -94,7 +99,8 @@ class MyTelegramOrgWrapper $request = $request->withHeader('user-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); $response = yield $this->datacenter->getHTTPClient()->request($request); $result = yield $response->getBody(); - + + switch ($result) { case 'true': //Logger::log(['Login OK'], Logger::VERBOSE); @@ -103,8 +109,6 @@ class MyTelegramOrgWrapper throw new Exception($result); } - $this->token = explode(';', explode('stel_token=', $response->getHeader('Set-Cookie'))[1])[0]; - return $this->logged = true; } @@ -126,13 +130,16 @@ class MyTelegramOrgWrapper $title = explode('', explode('