diff --git a/bot.php b/bot.php index e0dc41a67..fa2664208 100755 --- a/bot.php +++ b/bot.php @@ -12,6 +12,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with MadelineProto. If not, see . */ + +use danog\MadelineProto\Stream\Proxy\SocksProxy; + \set_include_path(\get_include_path().':'.\realpath(\dirname(__FILE__).'/MadelineProto/')); /* @@ -63,7 +66,15 @@ class EventHandler extends \danog\MadelineProto\EventHandler } } } -$settings = ['logger' => ['logger_level' => 5], 'serialization' => ['serialization_interval' => 30, 'cleanup_before_serialization' => true]]; +$settings = [ + 'logger' => [ + 'logger_level' => 5 + ], + 'serialization' => [ + 'serialization_interval' => 30, + 'cleanup_before_serialization' => true + ], +]; $MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings); $MadelineProto->async(true); diff --git a/src/danog/MadelineProto/Connection.php b/src/danog/MadelineProto/Connection.php index dfd0cc794..5e150262b 100644 --- a/src/danog/MadelineProto/Connection.php +++ b/src/danog/MadelineProto/Connection.php @@ -523,9 +523,11 @@ class Connection extends Session /** * Disconnect from DC. * + * @param bool $temporary Whether the disconnection is temporary, triggered by the reconnect method + * * @return void */ - public function disconnect() + public function disconnect(bool $temporary = false) { $this->API->logger->logger("Disconnecting from DC {$this->datacenterId}"); $this->needsReconnect = true; @@ -541,7 +543,9 @@ class Connection extends Session $this->API->logger->logger($e); } } - $this->shared->signalDisconnect($this->id); + if (!$temporary) { + $this->shared->signalDisconnect($this->id); + } $this->API->logger->logger("Disconnected from DC {$this->datacenterId}"); } @@ -553,17 +557,8 @@ class Connection extends Session public function reconnect(): \Generator { $this->API->logger->logger("Reconnecting DC {$this->datacenterId}"); - $this->disconnect(); + $this->disconnect(true); yield $this->API->datacenter->dcConnectAsync($this->ctx->getDc(), $this->id); - if ($this->API->hasAllAuth() && !$this->hasPendingCalls()) { - /*$this->callFork((function () { - try { - $this->API->method_call_async_read('ping', ['ping_id' => $this->random_int()], ['datacenter' => $this->datacenter]); - } catch (\Throwable $e) { - $this->API->logger("Got an error while pinging on reconnect: $e", Logger::FATAL_ERROR); - } - })());*/ - } } /** diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 8aaa692da..372248795 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -233,10 +233,10 @@ class DataCenter $this->CookieJar, new HttpSocketPool( new ProxySocketPool( - function (string $uri, CancellationToken $token = null, ClientConnectContext $ctx = null) { - return $this->rawConnectAsync($uri, $token, $ctx, true); - } - ) + function (string $uri, CancellationToken $token = null, ClientConnectContext $ctx = null) { + return $this->rawConnectAsync($uri, $token, $ctx, true); + } + ) ) ); $DoHConfig = new DoHConfig( @@ -528,7 +528,11 @@ class DataCenter { $old = isset($this->sockets[$dc_number]) && ( $this->sockets[$dc_number]->shouldReconnect() || - ($id !== -1 && $this->sockets[$dc_number]->hasConnection($id) && $this->sockets[$dc_number]->getConnection($id)->shouldReconnect()) + ( + $id !== -1 + && $this->sockets[$dc_number]->hasConnection($id) + && $this->sockets[$dc_number]->getConnection($id)->shouldReconnect() + ) ); if (isset($this->sockets[$dc_number]) && !$old) { $this->API->logger("Not reconnecting to DC $dc_number ($id)");