Added dialog list wrapper

This commit is contained in:
Daniil Gentili 2017-05-17 16:29:29 +01:00
parent 88fb5ecfb7
commit 2ba273d148
7 changed files with 45 additions and 13 deletions

View File

@ -19,9 +19,7 @@ class Button extends \Volatile implements \JsonSerializable
public function __construct($API, $message, $button)
{
foreach ($button as $key => $value) {
$this->{$key} = $value;
}
$this->data = $button;
$this->info['peer'] = $message['to_id'];
$this->info['id'] = $message['id'];
$this->info['API'] = $API;

View File

@ -62,6 +62,20 @@ class Logger
self::class_exists();
}
public static function utf8ize($d)
{
if (is_array($d) || $d instanceof \Volatile) {
foreach ($d as $k => $v) {
if ($k === 'bytes' || is_array($v) || $v instanceof \Volatile) {
$d[$k] = self::utf8ize($v);
}
}
} elseif (is_string($d)) {
return utf8_encode($d);
}
return $d;
}
public static function log($params, $level = self::NOTICE)
{
if (!self::$constructed) {
@ -76,7 +90,7 @@ class Logger
}
foreach (is_array($params) ? $params : [$params] as $param) {
if (!is_string($param)) {
$param = json_encode($param, JSON_PRETTY_PRINT);
$param = json_encode(self::utf8ize($param), JSON_PRETTY_PRINT);
}
$param = str_pad(basename(debug_backtrace()[0]['file'], '.php').$prefix.': ', 16 + strlen($prefix))."\t".$param;
switch (self::$mode) {

View File

@ -22,6 +22,7 @@ class MTProto extends \Volatile
use \danog\MadelineProto\MTProtoTools\AuthKeyHandler;
use \danog\MadelineProto\MTProtoTools\CallHandler;
use \danog\MadelineProto\MTProtoTools\Crypt;
use \danog\MadelineProto\MTProtoTools\DialogHandler;
use \danog\MadelineProto\MTProtoTools\MessageHandler;
use \danog\MadelineProto\MTProtoTools\MsgIdHandler;
use \danog\MadelineProto\MTProtoTools\PeerHandler;

View File

@ -116,7 +116,7 @@ trait CallHandler
}
switch ($server_answer['_']) {
case 'rpc_error':
$this->handle_rpc_error($server_answer, $aargs['datacenter']);
$this->handle_rpc_error($server_answer, $aargs);
break;
case 'bad_server_salt':
case 'bad_msg_notification':

View File

@ -131,7 +131,9 @@ trait ResponseHandler
case 'rpc_error':
$this->check_in_seq_no($datacenter, $current_msg_id);
$only_updates = false;
$this->handle_rpc_error($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'], $datacenter);
$aargs = ['datacenter' => &$datacenter];
$this->handle_rpc_error($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'], $aargs);
unset($aargs);
break;
case 'bad_server_salt':
@ -348,32 +350,33 @@ trait ResponseHandler
{
}
public function handle_rpc_error($server_answer, &$datacenter)
public function handle_rpc_error($server_answer, &$aargs)
{
switch ($server_answer['error_code']) {
case 303:
$this->datacenter->curdc = $datacenter = (int) preg_replace('/[^0-9]+/', '', $server_answer['error_message']);
$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']) {
case 'USER_DEACTIVATED':
case 'SESSION_REVOKED':
case 'SESSION_EXPIRED':
$this->datacenter->sockets[$datacenter]->temp_auth_key = null;
$this->datacenter->sockets[$datacenter]->auth_key = null;
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null;
$this->datacenter->sockets[$aargs['datacenter']]->auth_key = null;
$this->authorized = false;
$this->authorization = null;
$this->init_authorization(); // idk
throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']);
case 'AUTH_KEY_UNREGISTERED':
case 'AUTH_KEY_INVALID':
$this->datacenter->sockets[$datacenter]->temp_auth_key = null;
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null;
$this->init_authorization(); // idk
throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']);
}
case 420:
$seconds = preg_replace('/[^0-9]+/', '', $server_answer['error_message']);
if (is_numeric($seconds) && isset($this->settings['flood_timeout']['wait_if_lt']) && $seconds < $this->settings['flood_timeout']['wait_if_lt']) {
$limit = isset($aargs['FloodWaitLimit']) ? $aargs['FloodWaitLimit'] : $this->settings['flood_timeout']['wait_if_lt'];
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...');

View File

@ -283,7 +283,22 @@ trait TL
return $this->pack_double($object);
case 'string':
$object = pack('C*', ...unpack('C*', $object));
$l = strlen($object);
$concat = '';
if ($l <= 253) {
$concat .= chr($l);
$concat .= $object;
$concat .= pack('@'.$this->posmod((-$l - 1), 4));
} else {
$concat .= chr(254);
$concat .= substr($this->pack_signed_int($l), 0, 3);
$concat .= $object;
$concat .= pack('@'.$this->posmod(-$l, 4));
}
return $concat;
case 'bytes':
if (is_array($object)) $object = pack('C*', ...$object);
$l = strlen($object);
$concat = '';
if ($l <= 253) {
@ -519,6 +534,7 @@ trait TL
throw new Exception("deserialize: generated value isn't a string");
}
//return $type['type'] === 'bytes' ? unpack('C*', $x) : $x;
return $x;
case 'true':
return true;

View File

@ -71,7 +71,7 @@ $message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sem
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
echo 'Size of MadelineProto instance is '.strlen(serialize($MadelineProto)).' bytes'.PHP_EOL;
if (stripos(readline('Do you want to make the secret chat tests? (y/n)'), 'y') !== false) {
/*