From f27a79561fcca1db2c53d840b431153854feedc4 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 9 Oct 2016 15:42:53 +0000 Subject: [PATCH] Applied fixes from StyleCI --- src/danog/MadelineProto/DataCenter.php | 46 +++++++++++-------- src/danog/MadelineProto/MTProto.php | 22 ++++----- .../MTProtoTools/AuthKeyHandler.php | 1 + .../MTProtoTools/CallHandler.php | 2 +- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index a589fbce..4c0f3298 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -17,55 +17,65 @@ namespace danog\MadelineProto; */ class DataCenter extends Tools { - public function __construct($dclist, $settings) { + public function __construct($dclist, $settings) + { $this->dclist = $dclist; $this->settings = $settings; - if (isset($this->settings["all"])) { + if (isset($this->settings['all'])) { foreach ($this->range(1, 6) as $n) { - $this->settings[$n] = $this->settings["all"]; + $this->settings[$n] = $this->settings['all']; } - unset($this->settings["all"]); + unset($this->settings['all']); } foreach ($this->range(1, 6) as $n) { if (!isset($this->settings[$n])) { $this->settings[$n] = [ - 'protocol' => 'tcp_full', - 'port' => '443', - 'test_mode' => true + 'protocol' => 'tcp_full', + 'port' => '443', + 'test_mode' => true, ]; } } $this->connect(2); } - public function connnect($dc_number, $settings = []) { + + public function connnect($dc_number, $settings = []) + { if ($settings == []) { $settings = $this->settings[$dc_number]; } - $address = $settings["test_mode"] ? $this->dclist["test"][$dc_number] : $this->dclist["main"][$dc_number]; - if ($settings["protocol"] == "https") { - $subdomain = $this->dclist["ssl_subdomains"][$dc_number] . ($settings["upload"] ? '-1' : ''); - $path = $settings["test_mode"] ? 'apiw_test1' : 'apiw1'; - $address = 'https://' . $subdomain . '.web.telegram.org/' . $path; + $address = $settings['test_mode'] ? $this->dclist['test'][$dc_number] : $this->dclist['main'][$dc_number]; + if ($settings['protocol'] == 'https') { + $subdomain = $this->dclist['ssl_subdomains'][$dc_number].($settings['upload'] ? '-1' : ''); + $path = $settings['test_mode'] ? 'apiw_test1' : 'apiw1'; + $address = 'https://'.$subdomain.'.web.telegram.org/'.$path; } - $this->sockets[$dc_number] = new Connection($address, $settings["port"], $settings["protocol"]); + $this->sockets[$dc_number] = new Connection($address, $settings['port'], $settings['protocol']); $this->curdc = $dc_number; } - public function send_message($message, $dc_number = -1) { + + public function send_message($message, $dc_number = -1) + { if ($dc_number == -1) { $dc_number = $this->curdc; } + return $this->sockets[$dc_number]->send_message($message); } - public function read_message($dc_number = -1) { + + public function read_message($dc_number = -1) + { if ($dc_number == -1) { $dc_number = $this->curdc; } + return $this->sockets[$dc_number]->read_message(); } - public function __destroy() { + public function __destroy() + { foreach ($this->sockets as $n => $socket) { unset($this->sockets[$n]); } } -} \ No newline at end of file +} diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 9703e120..13d979a0 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -38,30 +38,30 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB -----END RSA PUBLIC KEY-----', ], 'connection' => [ - 'ssl_subdomains' => [ + 'ssl_subdomains' => [ 1 => 'pluto', 2 => 'venus', 3 => 'aurora', 4 => 'vesta', - 5 => 'flora' + 5 => 'flora', ], 'test' => [ 1 => '149.154.175.10', 2 => '149.154.167.40', - 3 => '149.154.175.117' + 3 => '149.154.175.117', ], 'main' => [ - 1 => '149.154.175.50', - 2 => '149.154.167.51', - 3 => '149.154.175.100', - 4 => '149.154.167.91', - 5 => '149.154.171.5' - ] + 1 => '149.154.175.50', + 2 => '149.154.167.51', + 3 => '149.154.175.100', + 4 => '149.154.167.91', + 5 => '149.154.171.5', + ], ], 'connection_settings' => [ 'all' => [ - 'protocol' => 'tcp_full', - 'test_mode' => true + 'protocol' => 'tcp_full', + 'test_mode' => true, ], ], 'app_info' => [ diff --git a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php index ad803db7..d1446dd8 100644 --- a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php @@ -431,6 +431,7 @@ class AuthKeyHandler extends AckHandler $this->log->log('Auth key generated'); $this->timedelta = 0; + return $res_authorization; case 'dh_gen_retry': if ($Set_client_DH_params_answer['new_nonce_hash2'] != $new_nonce_hash2) { diff --git a/src/danog/MadelineProto/MTProtoTools/CallHandler.php b/src/danog/MadelineProto/MTProtoTools/CallHandler.php index 43e04ea5..53e78c7d 100644 --- a/src/danog/MadelineProto/MTProtoTools/CallHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/CallHandler.php @@ -73,7 +73,7 @@ class CallHandler extends AuthKeyHandler $this->outgoing_messages[$int_message_id]['content'] = ['object' => $object, 'args' => $args]; // $server_answer = $this->wait_for_response($int_message_id); } catch (Exception $e) { - $this->log->log('An error occurred while calling object '.$object.': '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine().'. Recreating connection and retrying to call object...'); + $this->log->log('An error occurred while calling object '.$object.': '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine().'. Recreating connection and retrying to call object...'); unset($this->connection); $this->connection = new DataCenter($this->settings['connection'], $this->settings['connection_settings']); continue;