1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 04:35:12 +01:00

Fixed bugs

This commit is contained in:
Daniil Gentili 2016-11-18 20:50:19 +00:00
parent 83e9ff8de9
commit 545b5629f6
8 changed files with 30 additions and 31 deletions

View File

@ -23,10 +23,8 @@ class API extends Tools
$this->API = new MTProto($params);
\danog\MadelineProto\Logger::log('Running APIFactory...');
foreach ($this->API->tl->methods->method_namespaced as $method) {
if (isset($method[1]) && !isset($this->{$method[0]})) {
$this->{$method[0]} = new APIFactory($method[0], $this->API);
}
foreach ($this->API->tl->methods->method_namespace as $namespace => $method) {
$this->{$method} = new APIFactory($method, $this->API);
}
\danog\MadelineProto\Logger::log('Ping...');

View File

@ -74,8 +74,8 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
'tl_schema' => [
'layer' => 55,
'src' => [
__DIR__.'/TL_mtproto_v1.json',
__DIR__.'/TL_telegram_v55.json',
'mtproto' => __DIR__.'/TL_mtproto_v1.json',
'telegram' => __DIR__.'/TL_telegram_v55.json',
],
],
'logger' => [

View File

@ -494,7 +494,6 @@ class AuthKeyHandler extends AckHandler
]
);
$int_message_id = $this->generate_message_id();
$this->check_message_id($int_message_id, true);
$message_id = \danog\PHP\Struct::pack('<Q', $int_message_id);
$seq_no = 0;

View File

@ -26,7 +26,9 @@ class MessageHandler extends Crypt
if ($int_message_id == null) {
$int_message_id = $this->generate_message_id();
}
$this->check_message_id($int_message_id, true);
if (!is_int($int_message_id)) {
throw new Exception("Specified message id isn't an integer");
}
$message_id = \danog\PHP\Struct::pack('<Q', $int_message_id);
if ($this->datacenter->temp_auth_key['auth_key'] == null || $this->datacenter->temp_auth_key['server_salt'] == null) {

View File

@ -81,7 +81,7 @@ class MsgIdHandler extends MessageHandler
if ($int_message_id <= $keys) {
$int_message_id = $keys + 4;
}
$this->check_message_id($int_message_id, true);
return $int_message_id;
}
}

View File

@ -17,22 +17,21 @@ class TL extends \danog\MadelineProto\Tools
public function __construct($filename)
{
\danog\MadelineProto\Logger::log('Loading TL schemes...');
$TL_dict = ['constructors' => [], 'methods' => []];
foreach ($filename as $file) {
$TL_dict['constructors'] = array_merge(json_decode(file_get_contents($file), true)['constructors'], $TL_dict['constructors']);
$TL_dict['methods'] = array_merge(json_decode(file_get_contents($file), true)['methods'], $TL_dict['methods']);
}
\danog\MadelineProto\Logger::log('Translating objects...');
$this->constructors = new \danog\MadelineProto\TL\TLConstructor();
foreach ($TL_dict['constructors'] as $elem) {
$this->constructors->add($elem);
}
\danog\MadelineProto\Logger::log('Translating methods...');
$this->methods = new \danog\MadelineProto\TL\TLMethod();
foreach ($TL_dict['methods'] as $elem) {
$this->methods->add($elem);
foreach ($filename as $type => $file) {
$type = $type === "mtproto";
$TL_dict = json_decode(file_get_contents($file), true);
\danog\MadelineProto\Logger::log('Translating objects...');
foreach ($TL_dict['constructors'] as $elem) {
$this->constructors->add($elem, $type);
}
\danog\MadelineProto\Logger::log('Translating methods...');
foreach ($TL_dict['methods'] as $elem) {
$this->methods->add($elem);
}
}
}

View File

@ -20,10 +20,10 @@ class TLConstructor
public $params = [];
public $key = 0;
public function add($json_dict)
public function add($json_dict, $mtproto)
{
$this->id[$this->key] = (int) $json_dict['id'];
$this->predicate[$this->key] = $json_dict['predicate'];
$this->predicate[$this->key] = (($mtproto && $json_dict['predicate'] == "message") ? "MT" : "").$json_dict['predicate'];
$this->type[$this->key] = $json_dict['type'];
$this->params[$this->key] = $json_dict['params'];
foreach ($this->params[$this->key] as &$param) {
@ -44,9 +44,9 @@ class TLConstructor
$param['type'] = 'Vector t';
}
if (preg_match('/^\%/', $param['subtype'])) {
$param['subtype'] = preg_replace('/^\%/', '', $param['subtype']);
$param['subtype'] = lcfirst(preg_replace('/^\%/', '', $param['subtype']));
}
//lcfirst
$param['subtype'] = (($mtproto && $param['subtype'] == "message") ? "MT" : "").$param['subtype'];
}
}
$this->key++;
@ -55,7 +55,6 @@ class TLConstructor
public function find_by_predicate($predicate)
{
$key = array_search($predicate, $this->predicate);
return ($key === false) ? false : [
'id' => $this->id[$key],
'predicate' => $this->predicate[$key],

View File

@ -18,7 +18,7 @@ class TLMethod
public $method = [];
public $type = [];
public $params = [];
public $method_namespaced = [];
public $method_namespace = [];
public $key = 0;
public function add($json_dict)
@ -27,7 +27,10 @@ class TLMethod
$this->method[$this->key] = $json_dict['method'];
$this->type[$this->key] = $json_dict['type'];
$this->params[$this->key] = $json_dict['params'];
$this->method_namespaced[$this->key] = explode('.', $json_dict['method']);
$namespace = explode('.', $json_dict['method']);
if (isset($namespace[1])) {
$this->method_namespace[$namespace[0]] = $namespace[0];
}
foreach ($this->params[$this->key] as &$param) {
$param['opt'] = false;
@ -63,7 +66,6 @@ class TLMethod
'method' => $this->method[$key],
'type' => $this->type[$key],
'params' => $this->params[$key],
'method_namespaced' => $this->method_namespaced[$key],
];
}
}