This commit is contained in:
Daniil Gentili 2017-05-31 10:22:42 +01:00
parent 1858b7f8c8
commit 56ae262738
2 changed files with 12 additions and 8 deletions

View File

@ -34,8 +34,8 @@ class DataCenter extends \Volatile
{
$this->dclist = $dclist;
$this->settings = $settings;
foreach ($this->sockets as $socket) {
$socket->close_and_reopen();
foreach ($this->sockets as $key => $socket) {
if ($socket instanceof Connection) $socket->close_and_reopen(); else unset($this->sockets[$key]);
}
}

View File

@ -237,13 +237,17 @@ class MTProto extends \Volatile
$this->datacenter->curdc = 2;
if (!isset($this->authorization['user']['bot']) || !$this->authorization['user']['bot']) {
$nearest_dc = $this->method_call('help.getNearestDc', [], ['datacenter' => $this->datacenter->curdc]);
\danog\MadelineProto\Logger::log(["We're in ".$nearest_dc['country'].', current dc is '.$nearest_dc['this_dc'].', nearest dc is '.$nearest_dc['nearest_dc'].'.'], Logger::NOTICE);
try {
$nearest_dc = $this->method_call('help.getNearestDc', [], ['datacenter' => $this->datacenter->curdc]);
\danog\MadelineProto\Logger::log(["We're in ".$nearest_dc['country'].', current dc is '.$nearest_dc['this_dc'].', nearest dc is '.$nearest_dc['nearest_dc'].'.'], Logger::NOTICE);
if ($nearest_dc['nearest_dc'] != $nearest_dc['this_dc']) {
$this->datacenter->curdc = $nearest_dc['nearest_dc'];
$this->settings['connection_settings']['default_dc'] = $nearest_dc['nearest_dc'];
$this->should_serialize = true;
if ($nearest_dc['nearest_dc'] != $nearest_dc['this_dc']) {
$this->datacenter->curdc = $nearest_dc['nearest_dc'];
$this->settings['connection_settings']['default_dc'] = $nearest_dc['nearest_dc'];
$this->should_serialize = true;
}
} catch (RPCErrorException $e) {
if ($e->rpc !== "BOT_METHOD_INVALID") throw $e;
}
}
$this->get_config([], ['datacenter' => $this->datacenter->curdc]);