diff --git a/src/danog/MadelineProto/Session.php b/src/danog/MadelineProto/Session.php index a6ec818f..fcb59825 100755 --- a/src/danog/MadelineProto/Session.php +++ b/src/danog/MadelineProto/Session.php @@ -132,6 +132,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB } $packet_length = $this->struct->unpack('sock->read($packet_length - 4); + if ($packet_length == 4) { + throw new Exception("Server response error: " . $this->struct->unpack('newcrc32($packet_length_data.substr($packet, 0, -4)) == $this->struct->unpack('struct->unpack('log->log('Starting Diffie Hellman key exchange'); + $server_dh_params = $this->method_call('req_DH_params', ['nonce' => $nonce, 'server_nonce' => $server_nonce, 'p' => $p_bytes, 'q' => $q_bytes, 'public_key_fingerprint' => $public_key_fingerprint, 'encrypted_data' => $encrypted_data]); + if ($nonce != $server_dh_params['nonce']) { throw new Exception('Handshake: wrong nonce.'); } diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index b58a486f..3a5eb1ad 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -60,10 +60,16 @@ class TL throw new Exception('Could not extract type: '.$type_); } $bytes_io .= \danog\PHP\Struct::pack('id); - foreach ($tl_method->params as $arg) { - $bytes_io .= $this->serialize_param($arg['type'], $kwargs[$arg['name']]); + if (count(array_filter(array_keys($kwargs), 'is_string')) > 0) { + foreach ($tl_method->params as $arg) { + $bytes_io .= $this->serialize_param($arg['type'], $kwargs[$arg['name']]); + } + } else { + $argcount = 0; + foreach ($tl_method->params as $arg) { + $bytes_io .= $this->serialize_param($arg['type'], $kwargs[$argcount++]); + } } - return $bytes_io; }