Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2017-08-13 16:52:32 +00:00 committed by StyleCI Bot
parent 913fc912ee
commit f16aa7c63a
34 changed files with 123 additions and 50 deletions

View File

@ -47,11 +47,13 @@ while (true) {
if ($res == '') {
$res = var_export($update, true);
}
try {
// $MadelineProto->messages->sendMessage(['peer' => $update['update']['_'] === 'updateNewMessage' ? $update['update']['message']['from_id'] : $update['update']['message']['to_id'], 'message' => $res, 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
}
try {
if (isset($update['update']['message']['media']) && ($update['update']['message']['media']['_'] == 'messageMediaPhoto' || $update['update']['message']['media']['_'] == 'messageMediaDocument')) {
$time = time();

View File

@ -15,6 +15,7 @@ require '../vendor/autoload.php';
$settings = [];
$settings = ['app_info'=>['api_id'=>6, 'api_hash'=>'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
$MadelineProto = false;
try {
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('MadelineProto_bot.madeline');
} catch (\danog\MadelineProto\Exception $e) {
@ -66,6 +67,7 @@ while (true) {
if (isset($update['update']['message']['out']) && $update['update']['message']['out']) {
continue;
}
try {
if (isset($update['update']['message']['message']) && 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'], 'parse_mode' => 'markdown', 'reply_markup' => $reply_markup]);
@ -78,6 +80,7 @@ while (true) {
if (isset($update['update']['message']['out']) && $update['update']['message']['out']) {
continue;
}
try {
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'], 'parse_mode' => 'markdown', 'reply_markup' => $reply_markup]);
@ -112,11 +115,13 @@ while (true) {
}
} 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()]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) {
}
try {
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);
@ -130,6 +135,7 @@ while (true) {
} catch (\danog\MadelineProto\RPCErrorException $e) {
} catch (\danog\MadelineProto\Exception $e) {
}
try {
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);

View File

@ -15,11 +15,13 @@ require '../vendor/autoload.php';
$settings = ['app_info'=>['api_id'=>6, 'api_hash'=>'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
$MadelineProto = false;
$uMadelineProto = false;
try {
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('pipesbot.madeline');
} catch (\danog\MadelineProto\Exception $e) {
var_dump($e->getMessage());
}
try {
$uMadelineProto = \danog\MadelineProto\Serialization::deserialize('pwr.madeline');
} catch (\danog\MadelineProto\Exception $e) {
@ -114,6 +116,7 @@ while (true) {
if (isset($update['update']['message']['out']) && $update['update']['message']['out']) {
continue;
}
try {
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']]);
@ -126,6 +129,7 @@ while (true) {
if (isset($update['update']['message']['out']) && $update['update']['message']['out']) {
continue;
}
try {
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']]);
@ -199,6 +203,7 @@ while (true) {
} catch (\danog\MadelineProto\Exception $e) {
var_dump($e->getMessage());
}
try {
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);
@ -216,6 +221,7 @@ while (true) {
} catch (\danog\MadelineProto\Exception $e) {
var_dump($e->getMessage());
}
try {
$toset['switch_pm'] = $sswitch;
$MadelineProto->messages->setInlineBotResults($toset);

View File

@ -13,6 +13,7 @@ If not, see <http://www.gnu.org/licenses/>.
require '../vendor/autoload.php';
$settings = ['app_info'=>['api_id'=>6, 'api_hash'=>'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
include_once 'token.php';
try {
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('b.madeline');
} catch (\danog\MadelineProto\Exception $e) {
@ -184,10 +185,11 @@ while (true) {
} catch (\danog\MadelineProto\Exception $e) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
}
try {
if (isset($update['update']['message']['media']) && $update['update']['message']['media'] == 'messageMediaPhoto' && $update['update']['message']['media'] == 'messageMediaDocument') {
$time = time();
// $file = $MadelineProto->download_to_dir($update['update']['message']['media'], '/tmp');
// $file = $MadelineProto->download_to_dir($update['update']['message']['media'], '/tmp');
// $MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => 'Downloaded to '.$file.' in '.(time() - $time).' seconds', 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
}
} catch (\danog\MadelineProto\RPCErrorException $e) {

View File

@ -29,6 +29,7 @@ while (true) {
if (isset($update['update']['message']['out']) && $update['update']['message']['out']) {
continue;
}
try {
if ($update['update']['message']['message'] === 'callstorm') {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['from_id'], 'message' => 'callstorming you', 'reply_to_msg_id' => $update['update']['message']['id']]);

View File

@ -17,6 +17,7 @@ if (file_exists('web_data.php')) {
echo 'Deserializing MadelineProto from calls.madeline...'.PHP_EOL;
$MadelineProto = false;
try {
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('calls.madeline');
} catch (\danog\MadelineProto\Exception $e) {

View File

@ -14,6 +14,7 @@ If not, see <http://www.gnu.org/licenses/>.
require '../vendor/autoload.php';
$settings = [];
$Lua = false;
try {
$Lua = \danog\MadelineProto\Serialization::deserialize('bot.madeline');
} catch (\danog\MadelineProto\Exception $e) {

View File

@ -13,6 +13,7 @@ If not, see <http://www.gnu.org/licenses/>.
require '../vendor/autoload.php';
$settings = [];
try {
$Lua = \danog\MadelineProto\Serialization::deserialize('td.madeline');
} catch (\danog\MadelineProto\Exception $e) {

View File

@ -17,6 +17,7 @@ if (file_exists('web_data.php')) {
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
$MadelineProto = false;
try {
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
} catch (\danog\MadelineProto\Exception $e) {
@ -107,6 +108,7 @@ $users = [];
if ($update['update']['message']['out'] || $update['update']['message']['to_id']['_'] !== 'peerUser' || !isset($update['update']['message']['from_id'])) {
continue;
}
try {
if (!isset($users[$update['update']['message']['from_id']])) {
$users[$update['update']['message']['from_id']] = true;

View File

@ -17,6 +17,7 @@ if (file_exists('web_data.php')) {
echo 'Deserializing MadelineProto from s.madeline...'.PHP_EOL;
$MadelineProto = false;
try {
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('s.madeline');
} catch (\danog\MadelineProto\Exception $e) {

View File

@ -134,6 +134,7 @@ class APIFactory
if ($this->lua === false) {
return method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && $this->is_array($arguments[0])) ? $arguments[0] : [], $aargs);
}
try {
$deserialized = method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && $this->is_array($arguments[0])) ? $arguments[0] : [], $aargs);
Lua::convert_objects($deserialized);

View File

@ -46,13 +46,13 @@ class Connection extends \Volatile
public $call_queue = [];
public $i = [];
/* public function __get($name) {
echo "GETTING $name\n";
if (isset($this->i[$name]) && $this->{$name} === null) var_dump($this->i[$name]);
if ($this->{$name} instanceof \Volatile) $this->i[$name] = debug_backtrace(0);
var_dump(is_null($this->{$name}));
return $this->{$name};
}*/
/* public function __get($name) {
echo "GETTING $name\n";
if (isset($this->i[$name]) && $this->{$name} === null) var_dump($this->i[$name]);
if ($this->{$name} instanceof \Volatile) $this->i[$name] = debug_backtrace(0);
var_dump(is_null($this->{$name}));
return $this->{$name};
}*/
public function ___construct($proxy, $extra, $ip, $port, $protocol, $timeout, $ipv6)
{
@ -290,6 +290,7 @@ var_dump(is_null($this->{$name}));
}
if (strlen($packet) !== $length) {
$this->close_and_reopen();
throw new Exception("WARNING: Wrong length was read (should've read ".($length).', read '.strlen($packet).')!');
}
@ -309,6 +310,7 @@ var_dump(is_null($this->{$name}));
}
if (strlen($packet) !== $length) {
$this->close_and_reopen();
throw new Exception("WARNING: Wrong length was read (should've read ".($length).', read '.strlen($packet).')!');
}

View File

@ -25,16 +25,16 @@ class DataCenter extends \Volatile
public $dclist = [];
public $settings = [];
/*
public $i = [];
public function __get($name) {
echo "GETTING $name\n";
if (isset($this->i[$name]) && $this->{$name} === null) var_dump($this->i[$name]);
if ($this->{$name} instanceof \Volatile) $this->i[$name] = debug_backtrace(0);
var_dump(is_null($this->{$name}));
return $this->{$name};
}
*/
/*
public $i = [];
public function __get($name) {
echo "GETTING $name\n";
if (isset($this->i[$name]) && $this->{$name} === null) var_dump($this->i[$name]);
if ($this->{$name} instanceof \Volatile) $this->i[$name] = debug_backtrace(0);
var_dump(is_null($this->{$name}));
return $this->{$name};
}
*/
public function __sleep()
{
return ['sockets', 'curdc', 'dclist', 'settings'];

View File

@ -59,6 +59,7 @@ class Exception extends \Exception
if (error_reporting() === 0) {
return true; // return true to continue through the others error handlers
}
throw new self($errstr, $errno, null, $errfile, $errline);
}
}

View File

@ -114,6 +114,7 @@ class Logger
if (!defined('\danog\MadelineProto\VoIP::PHP_LIBTGVOIP_VERSION') || \danog\MadelineProto\VoIP::PHP_LIBTGVOIP_VERSION !== '1.1.2') {
throw new \danog\MadelineProto\Exception(hex2bin('506c6561736520757064617465207068702d6c69627467766f6970'), 0, null, 'MadelineProto', 1);
}
try {
\Threaded::extend('\danog\MadelineProto\VoIP');
} catch (\RuntimeException $e) {
@ -125,6 +126,7 @@ class Logger
self::$colors[self::WARNING] = implode(';', [self::foreground['white'], self::set['dim'], self::background['red']]);
self::$colors[self::ERROR] = implode(';', [self::foreground['white'], self::set['bold'], self::background['red']]);
self::$colors[self::FATAL_ERROR] = implode(';', [self::foreground['red'], self::set['bold'], self::background['light_gray']]);
try {
self::$isatty = defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT);
} catch (\danog\MadelineProto\Exception $e) {

View File

@ -127,6 +127,7 @@ class Lua
public function __call($name, $params)
{
self::convert_objects($params);
try {
return $this->Lua->{$name}(...$params);
} catch (\danog\MadelineProto\RPCErrorException $e) {

View File

@ -20,7 +20,7 @@ trait AckHandler
public function ack_outgoing_message_id($message_id, $datacenter)
{
// The server acknowledges that it received my message
//var_dump($this->datacenter->sockets[$datacenter]->outgoing_messages[$message_id]);
//var_dump($this->datacenter->sockets[$datacenter]->outgoing_messages[$message_id]);
if (!isset($this->datacenter->sockets[$datacenter]->outgoing_messages[$message_id])) {
\danog\MadelineProto\Logger::log(["WARNING: Couldn't find message id ".$message_id.' in the array of outgoing messages. Maybe try to increase its size?'], \danog\MadelineProto\Logger::WARNING);

View File

@ -456,25 +456,25 @@ trait AuthKeyHandler
throw new \danog\MadelineProto\SecurityException("p isn't a safe 2048-bit prime (p isn't a prime).");
}
/*
* ***********************************************************************
* Check validity of p
* Is (p - 1) / 2 a prime?
*
* Almost always fails
*/
/*
\danog\MadelineProto\Logger::log(['Executing p/g checks (2/3)...'], \danog\MadelineProto\Logger::VERBOSE);
if (!$p->subtract($this->one)->divide($this->two)[0]->isPrime()) {
throw new \danog\MadelineProto\SecurityException("p isn't a safe 2048-bit prime ((p - 1) / 2 isn't a prime).");
}
*/
/*
* ***********************************************************************
* Check validity of p
* Is (p - 1) / 2 a prime?
*
* Almost always fails
*/
/*
\danog\MadelineProto\Logger::log(['Executing p/g checks (2/3)...'], \danog\MadelineProto\Logger::VERBOSE);
if (!$p->subtract($this->one)->divide($this->two)[0]->isPrime()) {
throw new \danog\MadelineProto\SecurityException("p isn't a safe 2048-bit prime ((p - 1) / 2 isn't a prime).");
}
*/
/*
* ***********************************************************************
* Check validity of p
* 2^2047 < p < 2^2048
*/
/*
* ***********************************************************************
* Check validity of p
* 2^2047 < p < 2^2048
*/
\danog\MadelineProto\Logger::log(['Executing p/g checks (2/2)...'], \danog\MadelineProto\Logger::VERBOSE);
if ($p->compare($this->twoe2047) <= 0 // 2^2047 < p or p > 2^2047 or ! p <= 2^2047
|| $p->compare($this->twoe2048) >= 0 // p < 2^2048 or ! p >= 2^2048
@ -482,11 +482,11 @@ trait AuthKeyHandler
throw new \danog\MadelineProto\SecurityException("g isn't a safe 2048-bit prime (2^2047 < p < 2^2048 is false).");
}
/*
* ***********************************************************************
* Check validity of g
* 1 < g < p - 1
*/
/*
* ***********************************************************************
* Check validity of g
* 1 < g < p - 1
*/
\danog\MadelineProto\Logger::log(['Executing g check...'], \danog\MadelineProto\Logger::VERBOSE);
if ($g->compare($this->one) <= 0 // 1 < g or g > 1 or ! g <= 1
@ -559,6 +559,7 @@ trait AuthKeyHandler
$this->datacenter->sockets[$datacenter]->new_incoming = [];
}
}
throw new \danog\MadelineProto\SecurityException('An error occurred while binding temporary and permanent authorization keys.');
}
}

View File

@ -134,9 +134,11 @@ trait CallHandler
\danog\MadelineProto\Logger::log(['WARNING: Resetting auth key...'], \danog\MadelineProto\Logger::WARNING);
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null;
$this->init_authorization();
throw new \danog\MadelineProto\Exception('I had to recreate the temporary authorization key');
}
}
throw new \danog\MadelineProto\RPCErrorException($error, $error);
}
$only_updates = $this->handle_messages($aargs['datacenter']); // This method receives data from the socket, and parses stuff
@ -187,6 +189,7 @@ trait CallHandler
$this->init_authorization();
continue 3;
}
throw new \danog\MadelineProto\RPCErrorException('Received bad_msg_notification: '.self::BAD_MSG_ERROR_CODES[$server_answer['error_code']], $server_answer['error_code']);
break;
case 'boolTrue':
@ -241,6 +244,7 @@ trait CallHandler
return $this->method_call($method, $args, $aargs);
}
throw new \danog\MadelineProto\Exception('An error occurred while calling method '.$method.' ('.$last_error.').');
}
\danog\MadelineProto\Logger::log(['Got response for method '.$method.' @ try '.$count.' (response try '.$res_count.')'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
@ -258,6 +262,7 @@ trait CallHandler
if ($method === 'req_pq') {
throw new \danog\MadelineProto\RPCErrorException('RPC_CALL_FAIL');
}
throw new \danog\MadelineProto\Exception('An error occurred while calling method '.$method.' ('.$last_error.').');
}
@ -286,6 +291,7 @@ trait CallHandler
return $message_id;
}
throw new \danog\MadelineProto\Exception('An error occurred while sending object '.$object.'.');
}
}

View File

@ -73,7 +73,7 @@ trait Files
$constructor['key_fingerprint'] = $fingerprint;
$constructor['key'] = $key;
$constructor['iv'] = $iv;
// $constructor['md5_checksum'] = '';
// $constructor['md5_checksum'] = '';
}
return $constructor;
@ -316,6 +316,7 @@ trait Files
if ($res['_'] === 'upload.cdnFileReuploadNeeded') {
\danog\MadelineProto\Logger::log(['File is not stored on CDN, requesting reupload!'], \danog\MadelineProto\Logger::NOTICE);
$this->get_config([], ['datacenter' => $this->datacenter->curdc]);
try {
$this->add_cdn_hashes($message_media['file_token'], $this->method_call('upload.reuploadCdnFile', ['file_token' => $message_media['file_token'], 'request_token' => $res['request_token']], ['heavy' => true, 'datacenter' => $old_dc]));
} catch (\danog\MadelineProto\RPCErrorException $e) {

View File

@ -30,6 +30,7 @@ trait PeerHandler
var_dump(ord($char));
}*/
$this->chats[$user['id']] = $user;
try {
$this->get_pwr_chat($user['id'], false, true);
} catch (\danog\MadelineProto\Exception $e) {
@ -56,6 +57,7 @@ trait PeerHandler
case 'chatForbidden':
if (!isset($this->chats[-$chat['id']]) || $this->chats[-$chat['id']] !== $chat) {
$this->chats[-$chat['id']] = $chat;
try {
$this->get_pwr_chat(-$chat['id'], true, true);
} catch (\danog\MadelineProto\Exception $e) {
@ -75,6 +77,7 @@ trait PeerHandler
$bot_api_id = $this->to_supergroup($chat['id']);
if (!isset($this->chats[$bot_api_id]) || $this->chats[$bot_api_id] !== $chat) {
$this->chats[$bot_api_id] = $chat;
try {
if (!isset($this->full_chats[$bot_api_id]) || $this->full_chats[$bot_api_id]['full']['participants_count'] !== $this->get_full_info($bot_api_id)['full']['participants_count']) {
$this->get_pwr_chat($this->to_supergroup($chat['id']), true, true);
@ -219,6 +222,7 @@ trait PeerHandler
return $this->get_info('@'.$dbres['result']);
}
}
throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database');
}
$id = str_replace('@', '', $id);
@ -232,6 +236,7 @@ trait PeerHandler
return $this->get_info($id, false);
}
throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database');
}
@ -455,6 +460,7 @@ trait PeerHandler
$filters = ['channelParticipantsRecent', 'channelParticipantsAdmins', 'channelParticipantsKicked', 'channelParticipantsBots', 'channelParticipantsBanned'];
foreach ($filters as $filter) {
$offset = -$limit;
try {
$gres = $this->method_call('channels.getParticipants', ['channel' => $full['InputChannel'], 'filter' => ['_' => $filter, 'q' => ''], 'offset' => $offset += $limit, 'limit' => $limit], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
@ -553,6 +559,7 @@ trait PeerHandler
if (empty($this->qres)) {
return false;
}
try {
$payload = json_encode($this->qres);
$path = '/tmp/ids'.hash('sha256', $payload);
@ -574,6 +581,7 @@ trait PeerHandler
if ($res['_'] === 'contacts.resolvedPeer') {
return $res;
}
throw new \danog\MadelineProto\Exception('resolve_username returned an unexpected constructor: '.var_export($res, true));
}

View File

@ -272,6 +272,7 @@ trait ResponseHandler
}
\danog\MadelineProto\Logger::log(['No'], \danog\MadelineProto\Logger::VERBOSE);
}
throw new \danog\MadelineProto\ResponseException('Dunno how to handle '.PHP_EOL.var_export($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'], true));
break;
}
@ -318,6 +319,7 @@ trait ResponseHandler
switch ($server_answer['error_code']) {
case 303:
$this->datacenter->curdc = $aargs['datacenter'] = (int) preg_replace('/[^0-9]+/', '', $server_answer['error_message']);
throw new \danog\MadelineProto\Exception('Received request to switch to DC '.$this->datacenter->curdc);
case 401:
switch ($server_answer['error_message']) {
@ -342,6 +344,7 @@ trait ResponseHandler
if (is_numeric($seconds) && $seconds < $limit) {
\danog\MadelineProto\Logger::log(['Flood, waiting '.$seconds.' seconds...'], \danog\MadelineProto\Logger::NOTICE);
sleep($seconds);
throw new \danog\MadelineProto\Exception('Re-executing query...');
}
default:

View File

@ -152,6 +152,7 @@ trait UpdateHandler
return;
}
$this->load_channel_state($channel)['sync_loading'] = true;
try {
$input = $this->get_info('channel#'.$channel);
if (!isset($input['InputChannel'])) {
@ -176,6 +177,7 @@ trait UpdateHandler
if ($e->getMessage() === "You haven't joined this channel/supergroup") {
return false;
}
throw $e;
}
unset($input);
@ -394,10 +396,10 @@ trait UpdateHandler
return false;
}
// if ($cur_state['pts'] < $update['pts']) {
\danog\MadelineProto\Logger::log(['Applying pts. current pts: '.$cur_state['pts'].', new pts: '.$update['pts'].', channel id: '.$channel_id], \danog\MadelineProto\Logger::VERBOSE);
// if ($cur_state['pts'] < $update['pts']) {
\danog\MadelineProto\Logger::log(['Applying pts. current pts: '.$cur_state['pts'].', new pts: '.$update['pts'].', channel id: '.$channel_id], \danog\MadelineProto\Logger::VERBOSE);
$cur_state['pts'] = $update['pts'];
// }
// }
if ($channel_id === false && isset($options['date']) && $cur_state['date'] < $options['date']) {
$cur_state['date'] = $options['date'];

View File

@ -91,6 +91,7 @@ trait AuthKeyHandler
//var_dump($key);
if ($key['fingerprint'] !== $params['key_fingerprint']) {
$this->discard_secret_chat($params['id']);
throw new \danog\MadelineProto\SecurityException('Invalid key fingerprint!');
}
$key['visualization_orig'] = substr(sha1($key['auth_key'], true), 16);
@ -180,6 +181,7 @@ trait AuthKeyHandler
$key['visualization_46'] = substr(hash('sha256', $key['auth_key'], true), 20);
if ($key['fingerprint'] !== $params['key_fingerprint']) {
$this->method_call('messages.sendEncryptedService', ['peer' => $chat, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionAbortKey', 'exchange_id' => $params['exchange_id']]]], ['datacenter' => $this->datacenter->curdc]);
throw new \danog\MadelineProto\SecurityException('Invalid key fingerprint!');
}
$this->method_call('messages.sendEncryptedService', ['peer' => $chat, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionCommitKey', 'exchange_id' => $params['exchange_id'], 'key_fingerprint' => $key['fingerprint']]]], ['datacenter' => $this->datacenter->curdc]);
@ -201,6 +203,7 @@ trait AuthKeyHandler
}
if ($this->temp_rekeyed_secret_chats['fingerprint'] !== $params['key_fingerprint']) {
$this->method_call('messages.sendEncryptedService', ['peer' => $chat, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionAbortKey', 'exchange_id' => $params['exchange_id']]]], ['datacenter' => $this->datacenter->curdc]);
throw new \danog\MadelineProto\SecurityException('Invalid key fingerprint!');
}
\danog\MadelineProto\Logger::log(['Completing rekeying of secret chat '.$chat.'...'], \danog\MadelineProto\Logger::VERBOSE);
@ -246,6 +249,7 @@ trait AuthKeyHandler
if (isset($this->temp_rekeyed_secret_chats[$chat])) {
unset($this->temp_rekeyed_secret_chats[$chat]);
}
try {
$this->method_call('messages.discardEncryption', ['chat_id' => $chat], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) {

View File

@ -61,11 +61,13 @@ trait MessageHandler
if (isset($this->secret_chats[$message['message']['chat_id']]['old_key']['fingerprint'])) {
if ($auth_key_id !== $this->secret_chats[$message['message']['chat_id']]['old_key']['fingerprint']) {
$this->discard_secret_chat($message['message']['chat_id']);
throw new \danog\MadelineProto\SecurityException('Key fingerprint mismatch');
}
$old = true;
} else {
$this->discard_secret_chat($message['message']['chat_id']);
throw new \danog\MadelineProto\SecurityException('Key fingerprint mismatch');
}
}

View File

@ -58,7 +58,7 @@ trait ResponseHandler
$seq--;
if ($seq >= $update['message']['decrypted_message']['action']['start_seq_no'] && $seq <= $update['message']['decrypted_message']['action']['end_seq_no']) {
throw new \danog\MadelineProto\ResponseException('Resending of messages is not yet supported');
// $this->send_encrypted_message($update['message']['chat_id'], $update['message']['decrypted_message']);
// $this->send_encrypted_message($update['message']['chat_id'], $update['message']['decrypted_message']);
}
}

View File

@ -25,6 +25,7 @@ trait SeqNoHandler
if (isset($message['decrypted_message']['in_seq_no'])) {
if (($message['decrypted_message']['in_seq_no'] - $this->secret_chats[$chat_id]['out_seq_no_x']) / 2 < $last) {
$this->discard_secret_chat($chat_id);
throw new \danog\MadelineProto\SecurityException('in_seq_no is not increasing');
}
$last = ($message['decrypted_message']['in_seq_no'] - $this->secret_chats[$chat_id]['out_seq_no_x']) / 2;
@ -32,6 +33,7 @@ trait SeqNoHandler
}
if ($seqno > $this->secret_chats[$chat_id]['out_seq_no'] + 1) {
$this->discard_secret_chat($chat_id);
throw new \danog\MadelineProto\SecurityException('in_seq_no is too big');
}
@ -46,6 +48,7 @@ trait SeqNoHandler
if (isset($message['decrypted_message']['out_seq_no']) && $C < $this->secret_chats[$chat_id]['in_seq_no']) {
if (($message['decrypted_message']['out_seq_no'] - $this->secret_chats[$chat_id]['in_seq_no_x']) / 2 !== $C) {
$this->discard_secret_chat($chat_id);
throw new \danog\MadelineProto\SecurityException('out_seq_no hole: should be '.$C.', is '.(($message['decrypted_message']['out_seq_no'] - $this->secret_chats[$chat_id]['in_seq_no_x']) / 2));
} else {
$C++;
@ -60,6 +63,7 @@ trait SeqNoHandler
}
if ($seqno > $C) { // > C+1
$this->discard_secret_chat($chat_id);
throw new \danog\MadelineProto\SecurityException('WARNING: out_seq_no gap detected ('.$seqno.' > '.$C.')!');
return false;
}

View File

@ -70,13 +70,14 @@ class Serialization
}
class_exists('\Volatile');
\danog\MadelineProto\Logger::class_exists();
try {
$unserialized = \danog\Serialization::unserialize($unserialized);
} catch (Bug74586Exception $e) {
$unserialized = \danog\Serialization::unserialize($unserialized);
/*} catch (Exception $e) {
$unserialized = \danog\Serialization::unserialize($unserialized);
*/
/*} catch (Exception $e) {
$unserialized = \danog\Serialization::unserialize($unserialized);
*/
} catch (\Error $e) {
$unserialized = \danog\Serialization::unserialize($unserialized);
}

View File

@ -445,6 +445,7 @@ trait BotAPI
}
if (preg_match('/html/i', $arguments['parse_mode'])) {
$nmessage = '';
try {
$arguments['message'] = $this->html_fixtags($arguments['message']);
$dom = new \DOMDocument();

View File

@ -359,6 +359,7 @@ trait TL
$constructorData = $this->constructors->find_by_predicate($predicate, $layer);
if ($constructorData === false) {
\danog\MadelineProto\Logger::log([$object], \danog\MadelineProto\Logger::FATAL_ERROR);
throw new Exception('Could not extract type "'.$predicate.'"');
}
@ -449,6 +450,7 @@ trait TL
}
}
}
throw new Exception('Missing required parameter', $current_argument['name']);
}
if (!$this->is_array($arguments[$current_argument['name']]) && $current_argument['type'] === 'InputEncryptedChat') {

View File

@ -36,9 +36,11 @@ class SocketHandler extends \Threaded implements \Collectable
\danog\MadelineProto\Logger::log(['WARNING: Resetting auth key...'], \danog\MadelineProto\Logger::WARNING);
$this->API->datacenter->sockets[$this->current]->temp_auth_key = null;
$this->API->init_authorization();
throw new \danog\MadelineProto\Exception('I had to recreate the temporary authorization key');
}
}
throw new \danog\MadelineProto\RPCErrorException($this->error, $this->error);
}
$this->API->handle_messages($this->current);

View File

@ -78,6 +78,7 @@ trait AuthKeyHandler
$b = \phpseclib\Math\BigInteger::randomRange($this->two, $dh_config['p']->subtract($this->two));
$g_b = $dh_config['g']->powMod($b, $dh_config['p']);
$this->check_G($g_b, $dh_config['p']);
try {
$res = $this->method_call('phone.acceptCall', ['peer' => $call, 'g_b' => $g_b->toBytes(), 'protocol' => ['_' => 'phoneCallProtocol', 'udp_reflector' => true, 'udp_p2p' => true, 'min_layer' => 65, 'max_layer' => 65]], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
@ -92,6 +93,7 @@ trait AuthKeyHandler
return false;
}
throw $e;
}
$this->calls[$res['phone_call']['id']]->storage['b'] = $b;
@ -257,6 +259,7 @@ trait AuthKeyHandler
return;
}
\danog\MadelineProto\Logger::log(['Discarding call '.$call['id'].'...'], \danog\MadelineProto\Logger::VERBOSE);
try {
$res = $this->method_call('phone.discardCall', ['peer' => $call, 'duration' => time() - $this->calls[$call['id']]->whenCreated(), 'connection_id' => $this->calls[$call['id']]->getPreferredRelayID(), 'reason' => $reason], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) {

View File

@ -97,6 +97,7 @@ trait Login
}
$this->authorized = self::NOT_LOGGED_IN;
\danog\MadelineProto\Logger::log(['Logging in as a normal user...'], \danog\MadelineProto\Logger::NOTICE);
try {
$authorization = $this->method_call(
'auth.signIn',
@ -122,6 +123,7 @@ trait Login
return ['_' => 'account.needSignup'];
}
throw $e;
}
$this->authorized = self::LOGGED_IN;

View File

@ -18,6 +18,7 @@ if (file_exists('web_data.php')) {
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
$MadelineProto = false;
try {
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
} catch (\danog\MadelineProto\Exception $e) {