diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 0f69a822..816d01b6 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -86,8 +86,6 @@ class API extends APIFactory \danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['madelineproto_ready']], Logger::NOTICE); Serialization::$instances[spl_object_hash($this)] = $this; - - } public function __wakeup() diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index e50ad26b..b3309968 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -241,8 +241,6 @@ class MTProto $this->connect_to_all_dcs(); $this->datacenter->curdc = 2; - - if (!isset($this->authorization['user']['bot']) || !$this->authorization['user']['bot']) { try { $nearest_dc = $this->method_call('help.getNearestDc', [], ['datacenter' => $this->datacenter->curdc]); @@ -369,8 +367,11 @@ class MTProto $force = true; foreach ($this->secret_chats as $chat => $data) { try { - if (isset($this->secret_chats[$chat]) && $this->secret_chats[$chat]['InputEncryptedChat'] !== NULL) $this->notify_layer($chat); - } catch (\danog\MadelineProto\RPCErrorException $e) {} + if (isset($this->secret_chats[$chat]) && $this->secret_chats[$chat]['InputEncryptedChat'] !== null) { + $this->notify_layer($chat); + } + } catch (\danog\MadelineProto\RPCErrorException $e) { + } } } if (!$this->settings['updates']['handle_old_updates']) { diff --git a/src/danog/MadelineProto/SecretChats/AuthKeyHandler.php b/src/danog/MadelineProto/SecretChats/AuthKeyHandler.php index 20ba0a37..b18cd796 100644 --- a/src/danog/MadelineProto/SecretChats/AuthKeyHandler.php +++ b/src/danog/MadelineProto/SecretChats/AuthKeyHandler.php @@ -170,6 +170,7 @@ trait AuthKeyHandler { if ($this->secret_chats[$chat]['rekeying'][0] !== 1 || !isset($this->temp_rekeyed_secret_chats[$params['exchange_id']])) { $this->secret_chats[$chat]['rekeying'] = [0]; + return; } \danog\MadelineProto\Logger::log(['Committing rekeying of secret chat '.$chat.'...'], \danog\MadelineProto\Logger::VERBOSE); diff --git a/src/danog/MadelineProto/SecretChats/MessageHandler.php b/src/danog/MadelineProto/SecretChats/MessageHandler.php index e49bc94b..cb3e5098 100644 --- a/src/danog/MadelineProto/SecretChats/MessageHandler.php +++ b/src/danog/MadelineProto/SecretChats/MessageHandler.php @@ -87,6 +87,7 @@ trait MessageHandler if ($this->secret_chats[$message['message']['chat_id']]['mtproto'] === 2) { \danog\MadelineProto\Logger::log(['Trying MTProto v2 decryption for chat '.$message['message']['chat_id'].'...'], \danog\MadelineProto\Logger::NOTICE); + try { $message_data = $this->try_mtproto_v2_decrypt($message_key, $message['message']['chat_id'], $old, $encrypted_data); \danog\MadelineProto\Logger::log(['MTProto v2 decryption OK for chat '.$message['message']['chat_id'].'...'], \danog\MadelineProto\Logger::NOTICE); @@ -98,6 +99,7 @@ trait MessageHandler } } else { \danog\MadelineProto\Logger::log(['Trying MTProto v1 decryption for chat '.$message['message']['chat_id'].'...'], \danog\MadelineProto\Logger::NOTICE); + try { $message_data = $this->try_mtproto_v1_decrypt($message_key, $message['message']['chat_id'], $old, $encrypted_data); \danog\MadelineProto\Logger::log(['MTProto v1 decryption OK for chat '.$message['message']['chat_id'].'...'], \danog\MadelineProto\Logger::NOTICE); @@ -121,7 +123,9 @@ trait MessageHandler $this->handle_decrypted_update($message); } - public function try_mtproto_v1_decrypt($message_key, $chat_id, $old, $encrypted_data) { + + public function try_mtproto_v1_decrypt($message_key, $chat_id, $old, $encrypted_data) + { list($aes_key, $aes_iv) = $this->old_aes_calculate($message_key, $this->secret_chats[$chat_id][$old ? 'old_key' : 'key']['auth_key'], true); $decrypted_data = $this->ige_decrypt($encrypted_data, $aes_key, $aes_iv); @@ -143,7 +147,9 @@ trait MessageHandler return $message_data; } - public function try_mtproto_v2_decrypt($message_key, $chat_id, $old, $encrypted_data) { + + public function try_mtproto_v2_decrypt($message_key, $chat_id, $old, $encrypted_data) + { list($aes_key, $aes_iv) = $this->aes_calculate($message_key, $this->secret_chats[$chat_id][$old ? 'old_key' : 'key']['auth_key'], !$this->secret_chats[$chat_id]['admin']); $decrypted_data = $this->ige_decrypt($encrypted_data, $aes_key, $aes_iv); @@ -170,5 +176,4 @@ trait MessageHandler return $message_data; } - } diff --git a/src/danog/MadelineProto/SecretChats/ResponseHandler.php b/src/danog/MadelineProto/SecretChats/ResponseHandler.php index 3845ec12..b2ad9772 100644 --- a/src/danog/MadelineProto/SecretChats/ResponseHandler.php +++ b/src/danog/MadelineProto/SecretChats/ResponseHandler.php @@ -45,7 +45,9 @@ trait ResponseHandler if ($update['message']['decrypted_message']['action']['layer'] >= 17 && time() - $this->secret_chats[$update['message']['chat_id']]['created'] > 15) { $this->notify_layer($update['message']['chat_id']); } - if ($update['message']['decrypted_message']['action']['layer'] >= 73) $this->secret_chats[$update['message']['chat_id']]['mtproto'] = 2; + if ($update['message']['decrypted_message']['action']['layer'] >= 73) { + $this->secret_chats[$update['message']['chat_id']]['mtproto'] = 2; + } return; diff --git a/src/danog/MadelineProto/Serialization.php b/src/danog/MadelineProto/Serialization.php index d0fd4e51..f141e791 100644 --- a/src/danog/MadelineProto/Serialization.php +++ b/src/danog/MadelineProto/Serialization.php @@ -17,11 +17,18 @@ namespace danog\MadelineProto; */ class Serialization { - static public $instances = []; - static public function serialize_all($exception) { + public static $instances = []; + + public static function serialize_all($exception) + { echo $exception.PHP_EOL; - foreach (self::$instances as $instance) { if (isset($instance->session)) $instance->serialize(); } + foreach (self::$instances as $instance) { + if (isset($instance->session)) { + $instance->serialize(); + } + } } + /** * Serialize API class. * @@ -31,7 +38,7 @@ class Serialization * * @return number */ - static public function serialize($filename, $instance, $force = false) + public static function serialize($filename, $instance, $force = false) { if (isset($instance->API->setdem) && $instance->API->setdem) { $instance->API->setdem = false; @@ -61,7 +68,7 @@ class Serialization * * @return API */ - static public function deserialize($filename, $no_updates = false) + public static function deserialize($filename, $no_updates = false) { if (file_exists($filename)) { if (!file_exists($lock = $filename.'.lock')) {