diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index d333019cc..cfdaa87ea 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -77,14 +77,19 @@ class DataCenter if (!isset($this->dclist[$test][$ipv6][$dc_number]['ip_address'])) { unset($this->sockets[$dc_number]); + return false; } $address = $this->dclist[$test][$ipv6][$dc_number]['ip_address']; $port = $this->dclist[$test][$ipv6][$dc_number]['port']; if (isset($this->dclist[$test][$ipv6][$dc_number]['tcpo_only']) && $this->dclist[$test][$ipv6][$dc_number]['tcpo_only']) { - if ($dc_config_number === 'all') $dc_config_number = $dc_number; - if (!isset($this->settings[$dc_config_number])) $this->settings[$dc_config_number] = $this->settings['all']; + if ($dc_config_number === 'all') { + $dc_config_number = $dc_number; + } + if (!isset($this->settings[$dc_config_number])) { + $this->settings[$dc_config_number] = $this->settings['all']; + } $this->settings[$dc_config_number]['protocol'] = 'obfuscated2'; } @@ -110,9 +115,11 @@ class DataCenter $this->sockets[$dc_number] = new Connection($this->settings[$dc_config_number]['proxy'], $this->settings[$dc_config_number]['proxy_extra'], $address, $port, $this->settings[$dc_config_number]['protocol'], $this->settings[$dc_config_number]['timeout'], $this->settings[$dc_config_number]['ipv6']); } \danog\MadelineProto\Logger::log(['OK!'], \danog\MadelineProto\Logger::WARNING); + return true; } catch (\danog\MadelineProto\Exception $e) { - } catch (\danog\MadelineProto\NothingInTheSocketException $e) { ; } + } catch (\danog\MadelineProto\NothingInTheSocketException $e) { + } switch ($x) { case 0: @@ -146,6 +153,7 @@ class DataCenter return false; } } while (++$x); + return false; } diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 8cb68b20c..87930a642 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -205,7 +205,7 @@ class MTProto // Connect to servers \danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['inst_dc']], Logger::ULTRA_VERBOSE); if (isset($this->datacenter)) { - $this->connect_to_all_dcs();//datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']); + $this->connect_to_all_dcs(); //datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']); } else { $this->datacenter = new DataCenter($this->settings['connection'], $this->settings['connection_settings']); } @@ -307,7 +307,11 @@ class MTProto $this->reset_session(); if (!isset($this->v) || $this->v !== self::V) { \danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['serialization_ofd']], Logger::WARNING); - foreach ($this->datacenter->sockets as $dc_id => $socket) { if ($this->authorized === self::LOGGED_IN && strpos($dc_id, '_') === false) $socket->authorized = true; } //$this->authorized === self::LOGGED_IN; } + foreach ($this->datacenter->sockets as $dc_id => $socket) { + if ($this->authorized === self::LOGGED_IN && strpos($dc_id, '_') === false) { + $socket->authorized = true; + } + } //$this->authorized === self::LOGGED_IN; } $settings = $this->settings; if (isset($settings['updates']['callback'][0]) && $settings['updates']['callback'][0] === $this) { $settings['updates']['callback'] = 'get_updates_update_handler'; @@ -358,7 +362,7 @@ class MTProto $this->channels_state = []; $this->got_state = false; } - $this->connect_to_all_dcs();//datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']); + $this->connect_to_all_dcs(); //datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']); foreach ($this->calls as $id => $controller) { if (!is_object($controller)) { unset($this->calls[$id]); @@ -638,15 +642,19 @@ class MTProto } private $initing_authorization = false; + // Creates authorization keys public function init_authorization() { $this->initing_authorization = true; $this->updates_state['sync_loading'] = true; + try { foreach ($this->datacenter->sockets as $id => $socket) { $cdn = strpos($id, 'cdn'); - if (strpos($id, 'media') !== false && !$cdn) continue; + if (strpos($id, 'media') !== false && !$cdn) { + continue; + } if ($socket->session_id === null) { $socket->session_id = $this->random(8); $socket->session_in_seq_no = 0; @@ -673,7 +681,8 @@ class MTProto $authorization = $this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $id]); $socket->authorized = true; break; - } catch (\danog\MadelineProto\RPCErrorException $e) {} // Turns out this DC isn't authorized after all + } catch (\danog\MadelineProto\RPCErrorException $e) { + } // Turns out this DC isn't authorized after all } } } @@ -683,12 +692,10 @@ class MTProto $this->method_call('http_wait', ['max_wait' => 0, 'wait_after' => 0, 'max_delay' => 0], ['datacenter' => $id]); } } - } } finally { $this->initing_authorization = false; $this->updates_state['sync_loading'] = false; - } } diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index 62ff00e43..5154c54e8 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -337,7 +337,9 @@ trait ResponseHandler throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']); case 'AUTH_KEY_UNREGISTERED': case 'AUTH_KEY_INVALID': - if ($this->authorized !== self::LOGGED_IN) throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']); + if ($this->authorized !== self::LOGGED_IN) { + throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']); + } $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null; $this->datacenter->sockets[$aargs['datacenter']]->auth_key = null; $this->datacenter->sockets[$aargs['datacenter']]->authorized = false; diff --git a/src/danog/MadelineProto/Serialization.php b/src/danog/MadelineProto/Serialization.php index 9024aec2b..c6e2a60bf 100644 --- a/src/danog/MadelineProto/Serialization.php +++ b/src/danog/MadelineProto/Serialization.php @@ -22,6 +22,7 @@ class Serialization public static function serialize_all($exception) { echo $exception.PHP_EOL; + return; foreach (self::$instances as $instance) { if (isset($instance->session)) { diff --git a/src/danog/MadelineProto/Wrappers/Login.php b/src/danog/MadelineProto/Wrappers/Login.php index e6c025276..98b3e79fd 100644 --- a/src/danog/MadelineProto/Wrappers/Login.php +++ b/src/danog/MadelineProto/Wrappers/Login.php @@ -19,7 +19,9 @@ trait Login { public function logout() { - foreach ($this->datacenter->sockets as $socket) { $socket->authorized = false; } + foreach ($this->datacenter->sockets as $socket) { + $socket->authorized = false; + } $this->authorized = self::NOT_LOGGED_IN; $this->authorization = null; $this->updates = []; @@ -134,7 +136,6 @@ trait Login $this->datacenter->sockets[$this->datacenter->curdc]->authorized = true; $this->init_authorization(); - \danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['login_ok']], \danog\MadelineProto\Logger::NOTICE); return $this->authorization; @@ -162,7 +163,6 @@ trait Login $this->authorized = self::LOGGED_IN; $this->init_authorization(); - return $this->get_self(); }