Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2017-02-11 14:18:18 +00:00 committed by StyleCI Bot
parent f7f37c0888
commit 7a05342e47
11 changed files with 200 additions and 152 deletions

View File

@ -18,48 +18,62 @@ if (file_exists('token.php') && $MadelineProto === false) {
if ($uMadelineProto === false) {
echo 'Loading MadelineProto...'.PHP_EOL;
$uMadelineProto = new \danog\MadelineProto\API(['updates' => ['handle_updates' => false]]);
$sentCode = $uMadelineProto->phone_login(readline());
\danog\MadelineProto\Logger::log([$sentCode], \danog\MadelineProto\Logger::NOTICE);
echo 'Enter the code you received: ';
$code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1);
$authorization = $uMadelineProto->complete_phone_login($code);
\danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE);
if ($authorization['_'] === 'account.noPassword') {
throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!');
}
if ($authorization['_'] === 'account.password') {
\danog\MadelineProto\Logger::log(['2FA is enabled'], \danog\MadelineProto\Logger::NOTICE);
$authorization = $uMadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
}
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $uMadelineProto).' bytes'.PHP_EOL;
$sentCode = $uMadelineProto->phone_login(readline());
\danog\MadelineProto\Logger::log([$sentCode], \danog\MadelineProto\Logger::NOTICE);
echo 'Enter the code you received: ';
$code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1);
$authorization = $uMadelineProto->complete_phone_login($code);
\danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE);
if ($authorization['_'] === 'account.noPassword') {
throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!');
}
if ($authorization['_'] === 'account.password') {
\danog\MadelineProto\Logger::log(['2FA is enabled'], \danog\MadelineProto\Logger::NOTICE);
$authorization = $uMadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
}
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $uMadelineProto).' bytes'.PHP_EOL;
}
function inputify(&$stuff) {
function inputify(&$stuff)
{
$stuff['_'] = 'input'.ucfirst($stuff['_']);
return $stuff;
}
function translatetext (&$value) {
function translatetext(&$value)
{
inputify($value);
if (isset($value['entities'])) {
foreach ($value['entities'] as &$entity) {
if ($entity['_'] === 'messageEntityMentionName') inputify($entity);
if ($entity['_'] === 'messageEntityMentionName') {
inputify($entity);
}
}
}
if (isset($value['geo'])) {
$value['geo_point'] = inputify($value['geo']);
}
}
function translate (&$value, $key) {
function translate(&$value, $key)
{
switch ($value['_']) {
case 'botInlineResult':
$value['_'] = 'inputBotInlineResult';
translatetext($value['send_message']);
return $value;
case 'botInlineMediaResult':
if (isset($value['game'])) throw new \danog\MadelineProto\RPCErrorException('Games are not supported.');
if (isset($value['photo'])) $value['_'] = 'inputBotInlineResultPhoto';
if (isset($value['document'])) $value['_'] = 'inputBotInlineResultDocument';
if (isset($value['game'])) {
throw new \danog\MadelineProto\RPCErrorException('Games are not supported.');
}
if (isset($value['photo'])) {
$value['_'] = 'inputBotInlineResultPhoto';
}
if (isset($value['document'])) {
$value['_'] = 'inputBotInlineResultDocument';
}
translatetext($value['send_message']);
return $value;
}
}
@ -85,7 +99,7 @@ var_dump($update);
continue;
}
try {
if (preg_match('|/start|', $update['update']['message']['message'])){
if (preg_match('|/start|', $update['update']['message']['message'])) {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => $start, 'reply_to_msg_id' => $update['update']['message']['id']]);
}
} catch (\danog\MadelineProto\RPCErrorException $e) {
@ -97,7 +111,7 @@ var_dump($update);
continue;
}
try {
if (preg_match('|/start|', $update['update']['message']['message'])){
if (preg_match('|/start|', $update['update']['message']['message'])) {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['to_id'], 'message' => $start, 'reply_to_msg_id' => $update['update']['message']['id']]);
}
} catch (\danog\MadelineProto\RPCErrorException $e) {
@ -108,75 +122,84 @@ var_dump($update);
break;
case 'updateBotInlineQuery':
try {
$sswitch = ['_' => 'inlineBotSwitchPM', 'text' => 'FAQ', 'start_param' => 'lel'];
if ($update['update']['query'] === '') {
$MadelineProto->messages->setInlineBotResults(['query_id' => $update['update']['query_id'], 'results' => [], 'cache_time' => 0, 'switch_pm' => $sswitch]);
} else {
$toset = ['query_id' => $update['update']['query_id'], 'results' => [], 'cache_time' => 0, 'private' => true];
if (preg_match('|\$\s*$|', $update['update']['query'])) {
$exploded = explode('|', preg_replace('/\$\s*$/', '', $update['update']['query']));
array_walk($exploded, function (&$value, $key) { $value = preg_replace(['/^\s+/', '/\s+$/'], '', $value); });
$query = array_shift($exploded);
foreach ($exploded as $current => $botq) {
$bot = preg_replace('|:.*|', '', $botq);
if ($bot === '' || $uMadelineProto->get_info($bot)['bot_api_id'] === $MadelineProto->API->datacenter->authorization['user']['id']) {
$toset['switch_pm'] = $sswitch;
break;
}
$select = preg_replace('|'.$bot.':|', '', $botq);
$results = $uMadelineProto->messages->getInlineBotResults(['bot' => $bot, 'peer' => $update['update']['user_id'], 'query' => $query, 'offset' => $offset]);
if (isset($results['switch_pm'])) {
$toset['switch_pm'] = $results['switch_pm'];
break;
}
$toset['gallery'] = $results['gallery'];
$toset['results'] = [];
if (is_numeric($select)) {
$toset['results'][0] = $results['results'][$select-1];
} else if ($select === '') {
$toset['results'] = $results['results'];
} else {
foreach ($results['results'] as $result) {
if (isset($result['send_message']['message']) && preg_match('|'.$select.'|', $result['send_message']['message'])) {
$toset['results'][0] = $result;
$sswitch = ['_' => 'inlineBotSwitchPM', 'text' => 'FAQ', 'start_param' => 'lel'];
if ($update['update']['query'] === '') {
$MadelineProto->messages->setInlineBotResults(['query_id' => $update['update']['query_id'], 'results' => [], 'cache_time' => 0, 'switch_pm' => $sswitch]);
} else {
$toset = ['query_id' => $update['update']['query_id'], 'results' => [], 'cache_time' => 0, 'private' => true];
if (preg_match('|\$\s*$|', $update['update']['query'])) {
$exploded = explode('|', preg_replace('/\$\s*$/', '', $update['update']['query']));
array_walk($exploded, function (&$value, $key) {
$value = preg_replace(['/^\s+/', '/\s+$/'], '', $value);
});
$query = array_shift($exploded);
foreach ($exploded as $current => $botq) {
$bot = preg_replace('|:.*|', '', $botq);
if ($bot === '' || $uMadelineProto->get_info($bot)['bot_api_id'] === $MadelineProto->API->datacenter->authorization['user']['id']) {
$toset['switch_pm'] = $sswitch;
break;
}
$select = preg_replace('|'.$bot.':|', '', $botq);
$results = $uMadelineProto->messages->getInlineBotResults(['bot' => $bot, 'peer' => $update['update']['user_id'], 'query' => $query, 'offset' => $offset]);
if (isset($results['switch_pm'])) {
$toset['switch_pm'] = $results['switch_pm'];
break;
}
$toset['gallery'] = $results['gallery'];
$toset['results'] = [];
if (is_numeric($select)) {
$toset['results'][0] = $results['results'][$select - 1];
} elseif ($select === '') {
$toset['results'] = $results['results'];
} else {
foreach ($results['results'] as $result) {
if (isset($result['send_message']['message']) && preg_match('|'.$select.'|', $result['send_message']['message'])) {
$toset['results'][0] = $result;
}
}
}
if (!isset($toset['results'][0])) {
$toset['results'] = $results['results'];
}
if (count($exploded) - 1 === $current || !isset($toset['results'][0]['send_message']['message'])) {
break;
}
$query = $toset['results'][0]['send_message']['message'];
}
}
if (!isset($toset['results'][0])) $toset['results'] = $results['results'];
if (count($exploded) - 1 === $current || !isset($toset['results'][0]['send_message']['message'])) break;
$query = $toset['results'][0]['send_message']['message'];
if (empty($toset['results'])) {
$toset['switch_pm'] = $sswitch;
} else {
array_walk($toset['results'], 'translate');
}
$MadelineProto->messages->setInlineBotResults($toset);
}
}
if (empty($toset['results'])) {
$toset['switch_pm'] = $sswitch;
} else {
array_walk($toset['results'], 'translate');
}
$MadelineProto->messages->setInlineBotResults($toset);
}
} catch (\danog\MadelineProto\RPCErrorException $e) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
try {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['user_id'], 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
$MadelineProto->messages->sendMessage(['peer' => $update['update']['user_id'], 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) { ; }
} catch (\danog\MadelineProto\Exception $e) {
}
try {
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) { ; }
} catch (\danog\MadelineProto\Exception $e) {
}
} catch (\danog\MadelineProto\Exception $e) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
try {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['user_id'], 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
$MadelineProto->messages->sendMessage(['peer' => $update['update']['user_id'], 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) { ; }
} catch (\danog\MadelineProto\Exception $e) {
}
try {
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) { ; }
} catch (\danog\MadelineProto\Exception $e) {
}
}
}
}

View File

@ -203,6 +203,7 @@ class Connection
case 'tcp_intermediate':
$packet_length_data = $this->read(4);
$packet_length = \danog\PHP\Struct::unpack('<I', $packet_length_data)[0];
return $this->read($packet_length);
case 'tcp_abridged':
$packet_length_data = $this->read(1);
@ -213,6 +214,7 @@ class Connection
$packet_length_data = $this->read(3);
$packet_length = \danog\PHP\Struct::unpack('<I', $packet_length_data.pack('x'))[0] << 2;
}
return $this->read($packet_length);
case 'http':
case 'https':
@ -245,6 +247,7 @@ class Connection
if ($close) {
$this->close_and_reopen();
}
return $read;
case 'udp':
throw new Exception("Connection: This protocol wasn't implemented yet.");

View File

@ -202,7 +202,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
'incoming' => 1000,
'outgoing' => 1000,
],
'peer' => ['full_info_cache_time' => 60],
'peer' => ['full_info_cache_time' => 60],
'updates' => [
'handle_updates' => true, // Should I handle updates?
'callback' => [$this, 'get_updates_update_handler'], // A callable function that will be called every time an update is received, must accept an array (for the update) as the only parameter
@ -341,7 +341,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
unset($this->config['dc_options']);
\danog\MadelineProto\Logger::log(['Updated config!', $this->config], Logger::NOTICE);
}
public function parse_dc_options($dc_options) {
public function parse_dc_options($dc_options)
{
foreach ($dc_options as $dc) {
$test = $this->config['test_mode'] ? 'test' : 'main';
$ipv6 = ($dc['ipv6'] ? 'ipv6' : 'ipv4');

View File

@ -32,6 +32,7 @@ trait Crypt
$cipher = new \phpseclib\Crypt\AES(\phpseclib\Crypt\AES::MODE_IGE);
$cipher->setKey($key);
$cipher->setIV($iv);
return $cipher->encrypt($message);
}
@ -40,6 +41,7 @@ trait Crypt
$cipher = new \phpseclib\Crypt\AES(\phpseclib\Crypt\AES::MODE_IGE);
$cipher->setKey($key);
$cipher->setIV($iv);
return $cipher->decrypt($message);
}
}

View File

@ -262,6 +262,7 @@ trait PeerHandler
return $res;
}
public function full_chat_last_updated($id)
{
$id = $this->get_info($id)['bot_api_id'];

View File

@ -111,15 +111,21 @@ trait UpdateHandler
$this->get_channel_state($channel)['pts'] = $data['pts'];
}
}
public function get_msg_id($peer) {
public function get_msg_id($peer)
{
$id = $this->get_info($peer)['bot_api_id'];
return isset($this->msg_ids[$id]) ? $this->msg_ids[$id] : false;
}
public function set_msg_id($peer, $msg_id) {
public function set_msg_id($peer, $msg_id)
{
$id = $this->get_info($peer)['bot_api_id'];
$this->msg_ids[$id] = $msg_id;
$this->should_serialize = true;
}
public function get_channel_difference($channel)
{
if (!$this->settings['updates']['handle_updates']) {
@ -444,11 +450,11 @@ trait UpdateHandler
}
if ($channel === false) {
foreach ($updates as $update) {
$this->handle_update($update, $options);
$this->handle_update($update, $options);
}
} else {
foreach ($updates as $update) {
$this->handle_update($update);
$this->handle_update($update);
}
}
}
@ -468,6 +474,7 @@ trait UpdateHandler
if ($update['_'] === 'updateDcOptions') {
\danog\MadelineProto\Logger::log(['Got new dc options'], \danog\MadelineProto\Logger::VERBOSE);
$this->parse_dc_options($update['dc_options']);
return;
}
if (!$this->settings['updates']['handle_updates']) {

View File

@ -42,15 +42,19 @@ class Serialization
*
* @param string $filename
*
* @return API
*
* @throws \danog\MadelineProto\Exception
*
* @return API
*/
public static function deserialize($filename)
{
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
if (file_exists($filename)) $unserialized = unserialize(file_get_contents($filename)); else throw new Exception('File does not exist');
if (file_exists($filename)) {
$unserialized = unserialize(file_get_contents($filename));
} else {
throw new Exception('File does not exist');
}
//if ($unserialized === false) throw new Exception('An error occurred on deserialization');
return $unserialized;
}

View File

@ -28,6 +28,7 @@ class Stream
{
$d = substr($this->string, $this->pos, $length);
$this->pos += $length;
return $d;
}
}

View File

@ -297,8 +297,8 @@ trait TL
{
if (is_string($bytes_io)) {
$bytes_io = new \danog\MadelineProto\Stream($bytes_io);
} else if (!is_object($bytes_io)) {
throw new Exception('An invalid bytes_io handle was provided.');
} elseif (!is_object($bytes_io)) {
throw new Exception('An invalid bytes_io handle was provided.');
}
//\danog\MadelineProto\Logger::log(['Deserializing '.$type['type'].' at byte '.$bytes_io->pos);
switch ($type['type']) {

View File

@ -18,9 +18,12 @@ namespace danog\MadelineProto\Threads;
class SocketHandler extends Threaded
{
public $payloads = [];
public function __construct(&$me) {
public function __construct(&$me)
{
$this->API = $me;
}
/**
* Reading connection and receiving message from server. Check the CRC32.
*/
@ -31,82 +34,81 @@ class SocketHandler extends Threaded
$thread->wait();
} else {
foreach ($thread->payloads as $payload) {
if (fstat($payload)['size'] === 4) {
$error = \danog\PHP\Struct::unpack('<i', stream_get_contents($payload, 4))[0];
if ($error === -404) {
if ($thread->API->datacenter->temp_auth_key != null) {
\danog\MadelineProto\Logger::log(['WARNING: Resetting auth key...'], \danog\MadelineProto\Logger::WARNING);
$thread->API->datacenter->temp_auth_key = null;
$thread->API->init_authorization();
$thread->API->config = $thread->API->write_client_info('help.getConfig');
$thread->API->parse_config();
continue;
if (fstat($payload)['size'] === 4) {
$error = \danog\PHP\Struct::unpack('<i', stream_get_contents($payload, 4))[0];
if ($error === -404) {
if ($thread->API->datacenter->temp_auth_key != null) {
\danog\MadelineProto\Logger::log(['WARNING: Resetting auth key...'], \danog\MadelineProto\Logger::WARNING);
$thread->API->datacenter->temp_auth_key = null;
$thread->API->init_authorization();
$thread->API->config = $thread->API->write_client_info('help.getConfig');
$thread->API->parse_config();
continue;
//throw new \danog\MadelineProto\Exception('I had to recreate the temporary authorization key');
}
}
throw new \danog\MadelineProto\RPCErrorException($error, $error);
}
$auth_key_id = stream_get_contents($payload, 8);
if ($auth_key_id === str_repeat(chr(0), 8)) {
list($message_id, $message_length) = \danog\PHP\Struct::unpack('<QI', stream_get_contents($payload, 12));
$thread->API->check_message_id($message_id, false);
$message_data = stream_get_contents($payload, $message_length);
} elseif ($auth_key_id === $thread->API->datacenter->temp_auth_key['id']) {
$message_key = stream_get_contents($payload, 16);
$encrypted_data = stream_get_contents($payload);
list($aes_key, $aes_iv) = $thread->API->aes_calculate($message_key, $thread->API->datacenter->temp_auth_key['auth_key'], 'from server');
$decrypted_data = $thread->API->ige_decrypt($encrypted_data, $aes_key, $aes_iv);
}
}
throw new \danog\MadelineProto\RPCErrorException($error, $error);
}
$auth_key_id = stream_get_contents($payload, 8);
if ($auth_key_id === str_repeat(chr(0), 8)) {
list($message_id, $message_length) = \danog\PHP\Struct::unpack('<QI', stream_get_contents($payload, 12));
$thread->API->check_message_id($message_id, false);
$message_data = stream_get_contents($payload, $message_length);
} elseif ($auth_key_id === $thread->API->datacenter->temp_auth_key['id']) {
$message_key = stream_get_contents($payload, 16);
$encrypted_data = stream_get_contents($payload);
list($aes_key, $aes_iv) = $thread->API->aes_calculate($message_key, $thread->API->datacenter->temp_auth_key['auth_key'], 'from server');
$decrypted_data = $thread->API->ige_decrypt($encrypted_data, $aes_key, $aes_iv);
$server_salt = \danog\PHP\Struct::unpack('<q', substr($decrypted_data, 0, 8))[0];
if ($server_salt != $thread->API->datacenter->temp_auth_key['server_salt']) {
//\danog\MadelineProto\Logger::log(['WARNING: Server salt mismatch (my server salt '.$thread->API->datacenter->temp_auth_key['server_salt'].' is not equal to server server salt '.$server_salt.').'], \danog\MadelineProto\Logger::WARNING);
}
$server_salt = \danog\PHP\Struct::unpack('<q', substr($decrypted_data, 0, 8))[0];
if ($server_salt != $thread->API->datacenter->temp_auth_key['server_salt']) {
//\danog\MadelineProto\Logger::log(['WARNING: Server salt mismatch (my server salt '.$thread->API->datacenter->temp_auth_key['server_salt'].' is not equal to server server salt '.$server_salt.').'], \danog\MadelineProto\Logger::WARNING);
}
$session_id = substr($decrypted_data, 8, 8);
if ($session_id != $thread->API->datacenter->session_id) {
throw new \danog\MadelineProto\Exception('Session id mismatch.');
}
$session_id = substr($decrypted_data, 8, 8);
if ($session_id != $thread->API->datacenter->session_id) {
throw new \danog\MadelineProto\Exception('Session id mismatch.');
}
$message_id = \danog\PHP\Struct::unpack('<Q', substr($decrypted_data, 16, 8))[0];
$thread->API->check_message_id($message_id, false);
$message_id = \danog\PHP\Struct::unpack('<Q', substr($decrypted_data, 16, 8))[0];
$thread->API->check_message_id($message_id, false);
$seq_no = \danog\PHP\Struct::unpack('<I', substr($decrypted_data, 24, 4))[0];
$seq_no = \danog\PHP\Struct::unpack('<I', substr($decrypted_data, 24, 4))[0];
// Dunno how to handle any incorrect sequence numbers
$message_data_length = \danog\PHP\Struct::unpack('<I', substr($decrypted_data, 28, 4))[0];
if ($message_data_length > strlen($decrypted_data)) {
throw new \danog\MadelineProto\Exception('message_data_length is too big');
}
if ($message_data_length > strlen($decrypted_data)) {
throw new \danog\MadelineProto\Exception('message_data_length is too big');
}
if ((strlen($decrypted_data) - 32) - $message_data_length > 15) {
throw new \danog\MadelineProto\Exception('difference between message_data_length and the length of the remaining decrypted buffer is too big');
}
if ((strlen($decrypted_data) - 32) - $message_data_length > 15) {
throw new \danog\MadelineProto\Exception('difference between message_data_length and the length of the remaining decrypted buffer is too big');
}
if ($message_data_length < 0) {
throw new \danog\MadelineProto\Exception('message_data_length not positive');
}
if ($message_data_length < 0) {
throw new \danog\MadelineProto\Exception('message_data_length not positive');
}
if ($message_data_length % 4 != 0) {
throw new \danog\MadelineProto\Exception('message_data_length not divisible by 4');
}
if ($message_data_length % 4 != 0) {
throw new \danog\MadelineProto\Exception('message_data_length not divisible by 4');
}
$message_data = substr($decrypted_data, 32, $message_data_length);
if ($message_key != substr(sha1(substr($decrypted_data, 0, 32 + $message_data_length), true), -16)) {
throw new \danog\MadelineProto\Exception('msg_key mismatch');
}
$thread->API->datacenter->incoming_messages[$message_id]['seq_no'] = $seq_no;
} else {
throw new \danog\MadelineProto\Exception('Got unknown auth_key id');
}
$deserialized = $thread->API->deserialize($message_data);
$thread->API->datacenter->incoming_messages[$message_id]['content'] = $deserialized;
$thread->API->datacenter->incoming_messages[$message_id]['response'] = -1;
$thread->API->datacenter->new_incoming[$message_id] = $message_id;
$thread->API->handle_messages();
$message_data = substr($decrypted_data, 32, $message_data_length);
if ($message_key != substr(sha1(substr($decrypted_data, 0, 32 + $message_data_length), true), -16)) {
throw new \danog\MadelineProto\Exception('msg_key mismatch');
}
$thread->API->datacenter->incoming_messages[$message_id]['seq_no'] = $seq_no;
} else {
throw new \danog\MadelineProto\Exception('Got unknown auth_key id');
}
$deserialized = $thread->API->deserialize($message_data);
$thread->API->datacenter->incoming_messages[$message_id]['content'] = $deserialized;
$thread->API->datacenter->incoming_messages[$message_id]['response'] = -1;
$thread->API->datacenter->new_incoming[$message_id] = $message_id;
$thread->API->handle_messages();
}
}
}, $this);
}
}

View File

@ -17,9 +17,11 @@ namespace danog\MadelineProto\Threads;
*/
class SocketReader extends Threaded
{
public function __construct(&$me) {
public function __construct(&$me)
{
$this->API = $me;
}
/**
* Reading connection and receiving message from server. Check the CRC32.
*/
@ -31,6 +33,7 @@ class SocketReader extends Threaded
$thread->payloads[] = $payload;
$thread->notify();
}, $this->API->socket_handler, $payload);
} catch (\danog\MadelineProto\NothingInTheSocketException $e) { ; };
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
}
}
}