Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2017-12-23 01:04:43 +00:00 committed by StyleCI Bot
parent cca40a34ad
commit 228262e533
5 changed files with 32 additions and 14 deletions

View File

@ -77,14 +77,19 @@ class DataCenter
if (!isset($this->dclist[$test][$ipv6][$dc_number]['ip_address'])) { if (!isset($this->dclist[$test][$ipv6][$dc_number]['ip_address'])) {
unset($this->sockets[$dc_number]); unset($this->sockets[$dc_number]);
return false; return false;
} }
$address = $this->dclist[$test][$ipv6][$dc_number]['ip_address']; $address = $this->dclist[$test][$ipv6][$dc_number]['ip_address'];
$port = $this->dclist[$test][$ipv6][$dc_number]['port']; $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 (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 ($dc_config_number === 'all') {
if (!isset($this->settings[$dc_config_number])) $this->settings[$dc_config_number] = $this->settings['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'; $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']); $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); \danog\MadelineProto\Logger::log(['OK!'], \danog\MadelineProto\Logger::WARNING);
return true; return true;
} catch (\danog\MadelineProto\Exception $e) { } catch (\danog\MadelineProto\Exception $e) {
} catch (\danog\MadelineProto\NothingInTheSocketException $e) { ; } } catch (\danog\MadelineProto\NothingInTheSocketException $e) {
}
switch ($x) { switch ($x) {
case 0: case 0:
@ -146,6 +153,7 @@ class DataCenter
return false; return false;
} }
} while (++$x); } while (++$x);
return false; return false;
} }

View File

@ -307,7 +307,11 @@ class MTProto
$this->reset_session(); $this->reset_session();
if (!isset($this->v) || $this->v !== self::V) { if (!isset($this->v) || $this->v !== self::V) {
\danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['serialization_ofd']], Logger::WARNING); \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; $settings = $this->settings;
if (isset($settings['updates']['callback'][0]) && $settings['updates']['callback'][0] === $this) { if (isset($settings['updates']['callback'][0]) && $settings['updates']['callback'][0] === $this) {
$settings['updates']['callback'] = 'get_updates_update_handler'; $settings['updates']['callback'] = 'get_updates_update_handler';
@ -638,15 +642,19 @@ class MTProto
} }
private $initing_authorization = false; private $initing_authorization = false;
// Creates authorization keys // Creates authorization keys
public function init_authorization() public function init_authorization()
{ {
$this->initing_authorization = true; $this->initing_authorization = true;
$this->updates_state['sync_loading'] = true; $this->updates_state['sync_loading'] = true;
try { try {
foreach ($this->datacenter->sockets as $id => $socket) { foreach ($this->datacenter->sockets as $id => $socket) {
$cdn = strpos($id, 'cdn'); $cdn = strpos($id, 'cdn');
if (strpos($id, 'media') !== false && !$cdn) continue; if (strpos($id, 'media') !== false && !$cdn) {
continue;
}
if ($socket->session_id === null) { if ($socket->session_id === null) {
$socket->session_id = $this->random(8); $socket->session_id = $this->random(8);
$socket->session_in_seq_no = 0; $socket->session_in_seq_no = 0;
@ -673,7 +681,8 @@ class MTProto
$authorization = $this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $id]); $authorization = $this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $id]);
$socket->authorized = true; $socket->authorized = true;
break; 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]); $this->method_call('http_wait', ['max_wait' => 0, 'wait_after' => 0, 'max_delay' => 0], ['datacenter' => $id]);
} }
} }
} }
} finally { } finally {
$this->initing_authorization = false; $this->initing_authorization = false;
$this->updates_state['sync_loading'] = false; $this->updates_state['sync_loading'] = false;
} }
} }

View File

@ -337,7 +337,9 @@ trait ResponseHandler
throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']); throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']);
case 'AUTH_KEY_UNREGISTERED': case 'AUTH_KEY_UNREGISTERED':
case 'AUTH_KEY_INVALID': 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']]->temp_auth_key = null;
$this->datacenter->sockets[$aargs['datacenter']]->auth_key = null; $this->datacenter->sockets[$aargs['datacenter']]->auth_key = null;
$this->datacenter->sockets[$aargs['datacenter']]->authorized = false; $this->datacenter->sockets[$aargs['datacenter']]->authorized = false;

View File

@ -22,6 +22,7 @@ class Serialization
public static function serialize_all($exception) public static function serialize_all($exception)
{ {
echo $exception.PHP_EOL; echo $exception.PHP_EOL;
return; return;
foreach (self::$instances as $instance) { foreach (self::$instances as $instance) {
if (isset($instance->session)) { if (isset($instance->session)) {

View File

@ -19,7 +19,9 @@ trait Login
{ {
public function logout() 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->authorized = self::NOT_LOGGED_IN;
$this->authorization = null; $this->authorization = null;
$this->updates = []; $this->updates = [];
@ -134,7 +136,6 @@ trait Login
$this->datacenter->sockets[$this->datacenter->curdc]->authorized = true; $this->datacenter->sockets[$this->datacenter->curdc]->authorized = true;
$this->init_authorization(); $this->init_authorization();
\danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['login_ok']], \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['login_ok']], \danog\MadelineProto\Logger::NOTICE);
return $this->authorization; return $this->authorization;
@ -162,7 +163,6 @@ trait Login
$this->authorized = self::LOGGED_IN; $this->authorized = self::LOGGED_IN;
$this->init_authorization(); $this->init_authorization();
return $this->get_self(); return $this->get_self();
} }